PHP code example of brianhenryie / bh-wp-private-uploads
1. Go to this page and download the library: Download brianhenryie/bh-wp-private-uploads library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
brianhenryie / bh-wp-private-uploads example snippets
$settings = new class() implements \BrianHenryIE\WP_Private_Uploads\Private_Uploads_Settings_Interface {
use \BrianHenryIE\WP_Private_Uploads\Private_Uploads_Settings_Trait;
public function get_plugin_slug(): string {
return 'my-plugin';
}
};
$private_uploads = \BrianHenryIE\WP_Private_Uploads\Private_Uploads::instance( $settings );
// Move the file and record it with a post owned by the user, attached to e.g. a WooCommerce order.
$result = $private_uploads->move_file_to_private_uploads_and_create_post(
tmp_file: '/local/path/to/doc.pdf',
filename: 'target-filename.pdf',
post_author_id: $user_id, // Omit for no owner (`post_author` = `0`).
post_parent_id: $order_id,
);
$post_id = $result->post_id;
// Download a remote file and record it with a post.
$result = $private_uploads->download_remote_file_to_private_uploads_and_create_post(
file_url: 'https://example.org/doc.pdf',
filename: 'target-filename.pdf',
post_author_id: $user_id,
);
$settings = new class() implements \BrianHenryIE\WP_Private_Uploads\API\Private_Uploads_Settings_Interface {
use \BrianHenryIE\WP_Private_Uploads\API\Private_Uploads_Settings_Trait;
public function get_plugin_slug(): string {
return 'my-plugin';
}
/**
* Defaults to the plugin slug when using Private_Uploads_Settings_Trait.
*/
public function get_uploads_subdirectory_name(): string {
return 'email-attachments';
}
};
$private_uploads = \BrianHenryIE\WP_Private_Uploads\Private_Uploads::instance( $settings );
$settings = new class() implements \BrianHenryIE\WP_Private_Uploads\API\Private_Uploads_Settings_Interface {
use \BrianHenryIE\WP_Private_Uploads\API\Private_Uploads_Settings_Trait;
public function get_plugin_slug(): string {
return 'my-plugin';
}
/**
* Defaults to no CLI commands when using Private_Uploads_Settings_Trait.
*/
public function get_cli_base(): ?string {
return 'my-plugin';
}
};
$private_uploads = \BrianHenryIE\WP_Private_Uploads\Private_Uploads::instance( $settings );
$private_uploads = new Private_Uploads( $private_uploads_settings, $logger );
// Add the hooks:
new BH_WP_Private_Uploads_Hooks( $private_uploads, $private_uploads_settings, $logger );
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.