feat: add S3-compatible storage provider (MinIO, Ceph, R2, etc.)
Adds a new 'S3-Compatible Storage' provider that works with any
S3-API-compatible object storage service, including MinIO, Ceph,
Cloudflare R2, Backblaze B2, and others.
Changes:
- New provider class: classes/providers/storage/s3-compatible-provider.php
- Provider key: s3compatible
- Reads user-configured endpoint URL from settings
- Uses path-style URL access (required by most S3-compatible services)
- Supports credentials via AS3CF_S3COMPAT_ACCESS_KEY_ID /
AS3CF_S3COMPAT_SECRET_ACCESS_KEY wp-config.php constants
- Disables AWS-specific features (Block Public Access, Object Ownership)
- New provider SVG icons (s3compatible.svg, -link.svg, -round.svg)
- Registered provider in main plugin class with endpoint setting support
- Updated StorageProviderSubPage to show endpoint URL input for S3-compatible
- Built pro settings bundle with rollup (Svelte 4.2.19)
- Added package.json and updated rollup.config.mjs for pro-only builds
This commit is contained in:
157
classes/pro/tools/add-metadata.php
Normal file
157
classes/pro/tools/add-metadata.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Add_Metadata_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Tool;
|
||||
|
||||
class Add_Metadata extends Background_Tool {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'add_metadata';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $show_tool_constants = array(
|
||||
'AS3CF_SHOW_ADD_METADATA_TOOL',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected static $requires_bucket_access = false;
|
||||
|
||||
/**
|
||||
* Limit the item types that this tool handles.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $source_types = array(
|
||||
'media-library',
|
||||
);
|
||||
|
||||
/**
|
||||
* Get a list of key names for tools that are related to the current tool.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_related_tools() {
|
||||
$last_started = get_site_option( $this->prefix . '_' . $this->get_tool_key() . '_last_started' );
|
||||
|
||||
if ( empty( $last_started ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return array(
|
||||
'reverse_add_metadata',
|
||||
'verify_add_metadata',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle start.
|
||||
*/
|
||||
public function handle_start() {
|
||||
update_site_option( $this->prefix . '_' . $this->get_tool_key() . '_last_started', time() );
|
||||
|
||||
parent::handle_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Should render.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_render() {
|
||||
if ( ! $this->as3cf->is_pro_plugin_setup() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( false !== static::show_tool_constant() && constant( static::show_tool_constant() ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->is_active();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tool's name. Defaults to its title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
return __( 'Add Metadata', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Add metadata for all media not offloaded', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return htmlspecialchars( __( "If you already have your site's media in a bucket in the cloud, you can configure WP Offload Media for this bucket and storage paths, then run this tool to go through all your media that hasn't been offloaded yet and add the metadata WP Offload Media needs to manage your media in that bucket and rewrite URLs. After this tool runs, it will give you an undo option (remove all metadata added by this tool) and an option to go through all the media items that we added metadata for, check that the files exist in the bucket, and remove any new metadata where files are missing.", 'amazon-s3-and-cloudfront' ), ENT_QUOTES );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text() {
|
||||
return __( 'Add Metadata', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Adding metadata to Media Library', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Adding metadata…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Message for error notice
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'Add Metadata Errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at adding metadata to your media library have resulted in errors.', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%s</strong> — %s', $title, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Add_Metadata_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
89
classes/pro/tools/analyze-and-repair.php
Normal file
89
classes/pro/tools/analyze-and-repair.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Tool;
|
||||
|
||||
abstract class Analyze_And_Repair extends Background_Tool {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'analyze_and_repair';
|
||||
|
||||
/**
|
||||
* Limit the item types that this tool handles.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $source_types = array(
|
||||
'media-library',
|
||||
);
|
||||
|
||||
/**
|
||||
* Should render.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_render() {
|
||||
if ( ! $this->as3cf->is_pro_plugin_setup() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( false !== static::show_tool_constant() && constant( static::show_tool_constant() ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->is_active();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Analyze & Repair', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text() {
|
||||
return __( 'Analyze & Repair', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Analyzing and repairing offload metadata.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Repairing…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Message for error notice
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'Analyze & Repair Errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at analyzing and repairing your offload metadata have resulted in errors.', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%s</strong> — %s', $title, $message );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools\Analyze_And_Repair;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Analyze_And_Repair\Reverse_Add_Metadata_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Tools\Analyze_And_Repair;
|
||||
|
||||
class Reverse_Add_Metadata extends Analyze_And_Repair {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'reverse_add_metadata';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $show_tool_constants = array(
|
||||
'AS3CF_SHOW_REVERSE_ADD_METADATA_TOOL',
|
||||
);
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Remove metadata added by the Add Metadata tool', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __( 'If you have previously used the Add Metadata tool to create new items but now wish to remove all those records, you can use this tool. It will not remove any offload metadata not created with the Add Metadata tool such as regular Media Library offloads.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text() {
|
||||
return __( 'Remove Metadata', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Removing metadata added by the Add Metadata tool.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Removing metadata…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Reverse_Add_Metadata_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
67
classes/pro/tools/analyze-and-repair/verify-add-metadata.php
Normal file
67
classes/pro/tools/analyze-and-repair/verify-add-metadata.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools\Analyze_And_Repair;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Analyze_And_Repair\Verify_Add_Metadata_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Tools\Analyze_And_Repair;
|
||||
|
||||
class Verify_Add_Metadata extends Analyze_And_Repair {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'verify_add_metadata';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $show_tool_constants = array(
|
||||
'AS3CF_SHOW_VERIFY_ADD_METADATA_TOOL',
|
||||
);
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Find items with files missing in bucket and remove metadata, mark others verified', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __( 'You can use this tool to check that files exist in the bucket for items recently created with the Add Metadata tool. New metadata items with files missing from the bucket will be removed. It will not remove any offload metadata not created with the Add Metadata tool such as regular Media Library offloads.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Finding items with files missing in bucket and removing their metadata, marking others as verified.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Verifying…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Verify_Add_Metadata_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
152
classes/pro/tools/copy-buckets.php
Normal file
152
classes/pro/tools/copy-buckets.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Copy_Buckets_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Tool;
|
||||
|
||||
class Copy_Buckets extends Background_Tool {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'copy_buckets';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tab = 'media';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $show_tool_constants = array(
|
||||
'AS3CF_SHOW_COPY_BUCKETS_TOOL',
|
||||
'WPOS3_SHOW_COPY_BUCKETS_TOOL',
|
||||
);
|
||||
|
||||
/**
|
||||
* Should render.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_render() {
|
||||
if ( ! $this->as3cf->is_pro_plugin_setup() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( false !== static::show_tool_constant() && constant( static::show_tool_constant() ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->is_active();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
return __( 'Copy Files', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Copy files to new bucket', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text() {
|
||||
return __( 'Begin Copy', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Copying media items between buckets.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Copying…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __( 'Would you like to consolidate your offloaded media files by copying them into the currently selected bucket? All existing offloaded media URLs will be updated to reference the new bucket.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prompt text for when tool could be run in response to settings change.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_prompt_text() {
|
||||
global $as3cf;
|
||||
|
||||
$mesg = __( 'Would you like to copy media files from their current bucket to this new bucket?', 'amazon-s3-and-cloudfront' );
|
||||
$mesg .= ' ';
|
||||
$mesg .= $as3cf::more_info_link(
|
||||
'/wp-offload-media/doc/how-to-copy-media-between-buckets/',
|
||||
'copy+buckets',
|
||||
'change'
|
||||
);
|
||||
|
||||
return $mesg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get_doc_url() {
|
||||
global $as3cf;
|
||||
|
||||
$args = array( 'utm_campaign' => 'copy+buckets' );
|
||||
|
||||
return $as3cf::dbrains_url( '/wp-offload-media/doc/how-to-copy-media-between-buckets/', $args, 'change' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Message for error notice.
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'Copy Bucket Errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at copying your media library between buckets have resulted in errors.', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%s</strong> — %s', $title, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Copy_Buckets_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
95
classes/pro/tools/download-and-remover.php
Normal file
95
classes/pro/tools/download-and-remover.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Download_And_Remover_Process;
|
||||
|
||||
class Download_And_Remover extends Downloader {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'download_and_remover';
|
||||
|
||||
/**
|
||||
* Message for error notice
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'Removal Errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at removing your media library from the bucket have resulted in errors.', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%s</strong> — %s', $title, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Should render.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_render() {
|
||||
if ( ! $this->as3cf->is_plugin_setup() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->count_offloaded_media_files();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Remove all files from bucket', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __( 'This tool goes through all your media and deletes files from the bucket. If the file doesn\'t exist on your server, it will download it before deleting.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text() {
|
||||
return __( 'Remove Files', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Removing media from bucket', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Removing…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Download_And_Remover_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
183
classes/pro/tools/downloader.php
Normal file
183
classes/pro/tools/downloader.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Downloader_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Tool;
|
||||
|
||||
class Downloader extends Background_Tool {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'downloader';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected static $deactivate_prompt_rendered = false;
|
||||
|
||||
/**
|
||||
* Initialize Downloader
|
||||
*/
|
||||
public function init() {
|
||||
parent::init();
|
||||
|
||||
if ( ! $this->as3cf->is_pro_plugin_setup( true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->maybe_render_deactivate_prompt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe render deactivate plugin prompt.
|
||||
*/
|
||||
private function maybe_render_deactivate_prompt() {
|
||||
if ( self::$deactivate_prompt_rendered ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $this->as3cf->get_setting( 'remove-local-file' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action( 'load-plugins.php', array( $this, 'deactivate_plugin_assets' ) );
|
||||
add_action( 'admin_footer', array( $this, 'deactivate_plugin_modal' ) );
|
||||
|
||||
self::$deactivate_prompt_rendered = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the modal for plugin deactivation
|
||||
*
|
||||
* TODO: Could be replaced with Modal.svelte using REST-API for modal button's actions etc.
|
||||
*/
|
||||
public function deactivate_plugin_assets() {
|
||||
$this->as3cf->enqueue_script(
|
||||
'as3cf-pro-downloader-deactivate-plugin-script',
|
||||
'assets/js/pro/tools/downloader-deactivate-plugin',
|
||||
array( 'as3cf-modal', 'wp-api-request' )
|
||||
);
|
||||
|
||||
wp_localize_script( 'as3cf-pro-downloader-deactivate-plugin-script', 'as3cfpro_downloader', array(
|
||||
'plugin_url' => $this->as3cf->get_plugin_page_url( array( 'hash' => '/tools' ) ),
|
||||
'plugin_slug' => $this->as3cf->get_plugin_row_slug(),
|
||||
) );
|
||||
|
||||
wp_enqueue_style( 'as3cf-modal' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the view for the plugin deactivation modal
|
||||
*/
|
||||
public function deactivate_plugin_modal() {
|
||||
global $pagenow;
|
||||
if ( 'plugins.php' !== $pagenow ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->as3cf->render_view( 'deactivate-plugin-prompt' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Message for error notice
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'Download Errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at downloading your media library from the bucket have resulted in errors.', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%s</strong> — %s', $title, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Should render.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_render() {
|
||||
if ( ! $this->as3cf->is_pro_plugin_setup() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->count_offloaded_media_files();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Download all files from bucket to server', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __( 'If you\'ve ever had the "Remove Local Media" option on, some media files are likely missing on your server. You can use this tool to download any missing files back to your server.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prompt text for when tool could be run in response to settings change.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_prompt_text() {
|
||||
global $as3cf;
|
||||
|
||||
$mesg = __( 'You\'ve disabled the "Remove Local Media" option. Do you want to download all media files previously offloaded and removed from the server? This tool will not remove the media files from the bucket, and only downloads files that are missing from the server.', 'amazon-s3-and-cloudfront' );
|
||||
$mesg .= ' ';
|
||||
$mesg .= $as3cf::settings_more_info_link(
|
||||
'remove-local-file',
|
||||
'',
|
||||
'remove+local+file'
|
||||
);
|
||||
|
||||
return $mesg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text() {
|
||||
return __( 'Download Files', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Downloading media from bucket', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Downloading…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Downloader_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
213
classes/pro/tools/elementor-analyze-and-repair.php
Normal file
213
classes/pro/tools/elementor-analyze-and-repair.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Elementor_Analyze_And_Repair_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Tool;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Integrations\Elementor;
|
||||
|
||||
class Elementor_Analyze_And_Repair extends Background_Tool {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'elementor_analyze_and_repair';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected static $requires_bucket_access = false;
|
||||
|
||||
/**
|
||||
* Limit the item types that this tool handles.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $source_types = array(
|
||||
'media-library',
|
||||
);
|
||||
|
||||
/**
|
||||
* Initialize tool
|
||||
*/
|
||||
public function init() {
|
||||
parent::init();
|
||||
|
||||
if ( ! $this->as3cf->is_pro_plugin_setup( true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->maybe_show_notice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a notice about this tool to the user under certain conditions.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function maybe_show_notice() {
|
||||
if ( wp_doing_ajax() || ! Elementor::is_installed() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notice_id = 'elementor-analyze-and-repair';
|
||||
$tool_completed_id = $this->get_tool_key() . '_completed';
|
||||
$tool_not_needed_key = $this->prefix . '_' . $this->get_tool_key() . '_not_needed';
|
||||
$tool_not_needed = get_site_option( $tool_not_needed_key ) !== false;
|
||||
|
||||
// If the tool has already run or we previously deemed it's not needed just ensure the
|
||||
// notice isn't there, removing it if needed.
|
||||
$tool_completed_notice = $this->as3cf->notices->find_notice_by_id( $tool_completed_id );
|
||||
if ( ! empty( $tool_completed_notice ) || $tool_not_needed ) {
|
||||
$this->as3cf->notices->remove_notice_by_id( $notice_id );
|
||||
if ( false === $tool_not_needed ) {
|
||||
update_site_option( $tool_not_needed_key, time() );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Exit out if the notice already exists
|
||||
$notice = $this->as3cf->notices->find_notice_by_id( $notice_id );
|
||||
if ( ! empty( $notice ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// count posts with elementor and offloaded media files
|
||||
$media_counts = $this->as3cf->media_counts();
|
||||
$process_object = $this->get_background_process_class();
|
||||
$elementor_items = $process_object->get_elementor_items_count();
|
||||
|
||||
// Either OME or Elementor have never been used, there can't be an overlap of items.
|
||||
if ( 0 === $media_counts['offloaded'] || 0 === $elementor_items ) {
|
||||
update_site_option( $tool_not_needed_key, time() );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->as3cf->notices->add_notice(
|
||||
sprintf(
|
||||
__(
|
||||
'There is content created with Elementor
|
||||
that may need to be checked for broken media links. Go to the WP Offload Media settings page and run the
|
||||
Elementor Analyze and repair tool. <a href="%s">Get started »</a>',
|
||||
'amazon-s3-and-cloudfront'
|
||||
),
|
||||
$this->as3cf->get_plugin_page_url()
|
||||
),
|
||||
array(
|
||||
'custom_id' => $notice_id,
|
||||
'type' => 'notice-info',
|
||||
'flash' => false,
|
||||
'only_show_to_user' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Message for error notice
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'Elementor Analyze and Repair errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at analyzing and repairing Elementor content resulted in errors', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%s</strong> — %s', $title, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Should render.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_render() {
|
||||
if ( ! $this->as3cf->is_pro_plugin_setup() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( defined( 'AS3CF_SHOW_ELEMENTOR_TOOL' ) && AS3CF_SHOW_ELEMENTOR_TOOL ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( defined( 'AS3CF_SHOW_ELEMENTOR_TOOL' ) && ! AS3CF_SHOW_ELEMENTOR_TOOL ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->count_offloaded_media_files();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tool's name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
return __( 'Elementor Analyze & Repair', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Analyze and repair content created with Elementor', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __(
|
||||
'This tools goes through all content created with Elementor. It will check all media URLs found and if
|
||||
needed repair any broken URLs to offloaded media files.',
|
||||
'amazon-s3-and-cloudfront'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text() {
|
||||
return __( 'Analyze and repair', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Analyze and repair URLs in Elementor content', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Repairing…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Elementor_Analyze_And_Repair_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
118
classes/pro/tools/move-objects.php
Normal file
118
classes/pro/tools/move-objects.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Move_Objects_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Tool;
|
||||
|
||||
class Move_Objects extends Background_Tool {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'move_objects';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $show_tool_constants = array(
|
||||
'AS3CF_SHOW_MOVE_OBJECTS_TOOL',
|
||||
);
|
||||
|
||||
/**
|
||||
* Should render.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_render() {
|
||||
if ( ! $this->as3cf->is_pro_plugin_setup() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( false !== static::show_tool_constant() && constant( static::show_tool_constant() ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->is_active();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Move files to new path prefix', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text() {
|
||||
return __( 'Begin Move', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Moving media items to new path prefix.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Moving…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __( 'Would you like to move your offloaded media files to paths that match the current path prefix settings? All existing offloaded media URLs will be updated to reference the new paths.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get_doc_url() {
|
||||
global $as3cf;
|
||||
|
||||
$args = array( 'utm_campaign' => 'move+objects' );
|
||||
|
||||
return $as3cf::dbrains_url( '/wp-offload-media/doc/how-to-move-media-to-a-new-bucket-path/', $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Message for error notice.
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'Move Objects Errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at moving your media library to new paths have resulted in errors.', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%1$s</strong> — %2$s', $title, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Move_Objects_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
106
classes/pro/tools/move-private-objects.php
Normal file
106
classes/pro/tools/move-private-objects.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Move_Private_Objects_Process;
|
||||
|
||||
class Move_Private_Objects extends Move_Objects {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'move_private_objects';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $show_tool_constants = array(
|
||||
'AS3CF_SHOW_MOVE_PRIVATE_OBJECTS_TOOL',
|
||||
);
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Move files to new private path', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Moving media items to new private path.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __( 'Would you like to move your offloaded media files to paths that match the current private path settings? All existing offloaded private media URLs will be updated to reference the new paths.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prompt text for when tool could be run in response to settings change.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_prompt_text() {
|
||||
global $as3cf;
|
||||
|
||||
$mesg = '<h3>' . __( 'Private Path Updated: Would you like to move existing media to the new private path?', 'amazon-s3-and-cloudfront' ) . '</h3>';
|
||||
$mesg .= '<br>';
|
||||
$mesg .= '<p>' . __( 'You just updated the private media path. Any media you make private from now on will use this new path.', 'amazon-s3-and-cloudfront' ) . '</p>';
|
||||
$mesg .= '<p>';
|
||||
$mesg .= __( 'You can also move existing private media to this new path. We recommend keeping the path consistent across all private media.', 'amazon-s3-and-cloudfront' );
|
||||
$mesg .= ' ';
|
||||
$mesg .= $as3cf::more_info_link(
|
||||
'/wp-offload-media/doc/how-to-move-media-to-a-new-bucket-path/',
|
||||
'move+objects',
|
||||
'private-path'
|
||||
);
|
||||
$mesg .= '</p>';
|
||||
|
||||
return $mesg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get_doc_url() {
|
||||
global $as3cf;
|
||||
|
||||
$args = array( 'utm_campaign' => 'move+objects' );
|
||||
|
||||
return $as3cf::dbrains_url( '/wp-offload-media/doc/how-to-move-media-to-a-new-bucket-path/', $args, 'private-path' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Message for error notice.
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'Move Objects Errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at moving your media library to new private paths have resulted in errors.', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%1$s</strong> — %2$s', $title, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Move_Private_Objects_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
125
classes/pro/tools/move-public-objects.php
Normal file
125
classes/pro/tools/move-public-objects.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Move_Public_Objects_Process;
|
||||
|
||||
class Move_Public_Objects extends Move_Objects {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'move_public_objects';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $show_tool_constants = array(
|
||||
'AS3CF_SHOW_MOVE_PUBLIC_OBJECTS_TOOL',
|
||||
);
|
||||
|
||||
/**
|
||||
* Add notice strings for when tool will not prompt.
|
||||
*
|
||||
* @param array $strings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_js_strings( $strings ) {
|
||||
global $as3cf;
|
||||
|
||||
$notice_link = $as3cf::more_info_link( '/wp-offload-media/doc/how-to-move-media-to-a-new-bucket-path/', 'error-media+move+objects' );
|
||||
$notice_msg = __( '<strong>Warning</strong> — Because you\'ve turned off %1$s, we will not offer to move existing media to the new path as it could result in overwriting some media in your bucket. %2$s', 'amazon-s3-and-cloudfront' );
|
||||
|
||||
$strings['no_move_objects_year_month_notice'] = sprintf( $notice_msg, __( 'Year/Month', 'amazon-s3-and-cloudfront' ), $notice_link );
|
||||
$strings['no_move_objects_object_versioning_notice'] = sprintf( $notice_msg, __( 'Object Versioning', 'amazon-s3-and-cloudfront' ), $notice_link );
|
||||
|
||||
return $strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Move files to new storage path', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Moving media items to new storage path.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __( 'Would you like to move your offloaded media files to paths that match the current storage path settings? All existing offloaded media URLs will be updated to reference the new paths.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prompt text for when tool could be run in response to settings change.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_prompt_text() {
|
||||
global $as3cf;
|
||||
|
||||
$mesg = '<h3>' . __( 'Storage Path Updated: Would you like to move existing media to the new path?', 'amazon-s3-and-cloudfront' ) . '</h3>';
|
||||
$mesg .= '<br>';
|
||||
$mesg .= '<p>' . __( 'You just updated the storage path. Any new media you offload from now on will use this new path.', 'amazon-s3-and-cloudfront' ) . '</p>';
|
||||
$mesg .= '<p>';
|
||||
$mesg .= __( 'You can also move existing media to this new path. Beware however that moving existing media will update URLs and will result in 404s for any sites embedding or linking to your media. It could also have a negative impact on SEO. If you\'re unsure about this, we recommend not moving existing media to the new path.', 'amazon-s3-and-cloudfront' );
|
||||
$mesg .= ' ';
|
||||
$mesg .= $as3cf::more_info_link(
|
||||
'/wp-offload-media/doc/how-to-move-media-to-a-new-bucket-path/',
|
||||
'move+objects',
|
||||
'public-path'
|
||||
);
|
||||
$mesg .= '</p>';
|
||||
|
||||
return $mesg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get_doc_url() {
|
||||
global $as3cf;
|
||||
|
||||
$args = array( 'utm_campaign' => 'move+objects' );
|
||||
|
||||
return $as3cf::dbrains_url( '/wp-offload-media/doc/how-to-move-media-to-a-new-bucket-path/', $args, 'public-path' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Message for error notice.
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'Move Objects Errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at moving your media library to new storage paths have resulted in errors.', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%1$s</strong> — %2$s', $title, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Move_Public_Objects_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
120
classes/pro/tools/remove-local-files.php
Normal file
120
classes/pro/tools/remove-local-files.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Remove_Local_Files_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Tool;
|
||||
|
||||
class Remove_Local_Files extends Background_Tool {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'remove_local_files';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected static $requires_bucket_access = false;
|
||||
|
||||
/**
|
||||
* Should render.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_render() {
|
||||
if ( ! $this->as3cf->is_pro_plugin_setup() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->as3cf->get_setting( 'remove-local-file', false ) && $this->count_offloaded_media_files();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Remove all files from server', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __( 'You can use this tool to delete all media files from your local server that have already been offloaded.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prompt text for when tool could be run in response to settings change.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_prompt_text() {
|
||||
global $as3cf;
|
||||
|
||||
$mesg = __( 'You\'ve enabled the "Remove Local Media" option. Do you want to remove all existing files from the server that have already been offloaded?', 'amazon-s3-and-cloudfront' );
|
||||
$mesg .= ' ';
|
||||
$mesg .= $as3cf::settings_more_info_link(
|
||||
'remove-local-file',
|
||||
'',
|
||||
'remove+local+files'
|
||||
);
|
||||
|
||||
return $mesg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text() {
|
||||
return __( 'Begin Removal', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Removing media files from your local server.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Removing local…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Message for error notice
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'Remove From Local Errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at removing your offloaded media library files from the server have resulted in errors.', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%s</strong> — %s', $title, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Remove_Local_Files_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
142
classes/pro/tools/update-acls.php
Normal file
142
classes/pro/tools/update-acls.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Update_ACLs_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Tool;
|
||||
|
||||
class Update_ACLs extends Background_Tool {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'update_acls';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tab = 'media';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $show_tool_constants = array(
|
||||
'AS3CF_SHOW_UPDATE_ACLS_TOOL',
|
||||
);
|
||||
|
||||
/**
|
||||
* Should render.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_render() {
|
||||
if ( ! $this->as3cf->is_pro_plugin_setup() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( false !== static::show_tool_constant() && constant( static::show_tool_constant() ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->is_active();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Update Object ACLs', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text() {
|
||||
return __( 'Begin Update', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Updating object ACLs in bucket.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Updating ACLs…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __( 'After disabling Block All Public Access for a bucket, you many need to update all the objects in the bucket to apply appropriate public and private ACLs so that they can be used correctly.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prompt text for when tool could be run in response to settings change.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_prompt_text() {
|
||||
global $as3cf;
|
||||
|
||||
$mesg = __( 'It looks like your configuration has changed to require public and private ACLs on objects, would you like to update the ACLs on your objects?', 'amazon-s3-and-cloudfront' );
|
||||
$mesg .= ' ';
|
||||
$mesg .= $as3cf::more_info_link(
|
||||
'/wp-offload-media/doc/block-all-public-access-to-bucket/',
|
||||
'update+acls',
|
||||
'disable-block-access'
|
||||
);
|
||||
|
||||
return $mesg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get_doc_url() {
|
||||
global $as3cf;
|
||||
|
||||
$args = array( 'utm_campaign' => 'update+acls' );
|
||||
|
||||
return $as3cf::dbrains_url( '/wp-offload-media/doc/block-all-public-access-to-bucket/', $args, 'disable-block-access' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Message for error notice.
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'Update ACLs Errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at updating object ACLs have resulted in errors.', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%1$s</strong> — %2$s', $title, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Update_ACLs_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
262
classes/pro/tools/uploader.php
Normal file
262
classes/pro/tools/uploader.php
Normal file
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Uploader_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Tool;
|
||||
use Exception;
|
||||
|
||||
class Uploader extends Background_Tool {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'uploader';
|
||||
|
||||
/**
|
||||
* Initialize Uploader
|
||||
*/
|
||||
public function init() {
|
||||
parent::init();
|
||||
|
||||
$this->error_setting_migration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate old upload errors to new setting key.
|
||||
*
|
||||
* TODO: Move this into next migration so it no longer fires
|
||||
* TODO: every time the plugin serves a request for tool state!
|
||||
*/
|
||||
protected function error_setting_migration() {
|
||||
$errors = $this->as3cf->get_setting( 'bulk_upload_errors', false );
|
||||
|
||||
if ( ! empty( $errors ) ) {
|
||||
$this->update_errors( $errors );
|
||||
$this->as3cf->remove_setting( 'bulk_upload_errors' );
|
||||
$this->as3cf->save_settings();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get info for tool, including current status.
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get_info() {
|
||||
$media_counts = $this->as3cf->media_counts();
|
||||
$human_percentage = $this->percent_offloaded();
|
||||
|
||||
$strings = array(
|
||||
'title_initial' => __( 'Your media needs to be offloaded', 'amazon-s3-and-cloudfront' ),
|
||||
'title_partial_complete' => __( '<strong>%s%%</strong> of your media has been offloaded', 'amazon-s3-and-cloudfront' ),
|
||||
'title_complete' => __( '<strong>100%</strong> of your media has been offloaded, congratulations!', 'amazon-s3-and-cloudfront' ),
|
||||
);
|
||||
|
||||
switch ( $human_percentage ) {
|
||||
case 0: // Entire library needs uploading
|
||||
$progress_description = $strings['title_initial'];
|
||||
break;
|
||||
|
||||
case 100: // Entire media library uploaded
|
||||
$progress_description = $strings['title_complete'];
|
||||
break;
|
||||
|
||||
default: // Media library upload partially complete
|
||||
$progress_description = sprintf( $strings['title_partial_complete'], $human_percentage );
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'total_progress' => $human_percentage,
|
||||
'total_processed' => (int) $media_counts['offloaded'],
|
||||
'total_items' => (int) $media_counts['total'],
|
||||
'progress_description' => $progress_description,
|
||||
);
|
||||
|
||||
return array_merge( parent::get_info(), $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the percentage of media library items offloaded, to the nearest integer.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function percent_offloaded() {
|
||||
static $human_percentage;
|
||||
|
||||
if ( is_null( $human_percentage ) ) {
|
||||
$media_counts = $this->as3cf->media_counts();
|
||||
|
||||
if ( empty( $media_counts['total'] ) || empty( $media_counts['offloaded'] ) ) {
|
||||
$human_percentage = 0;
|
||||
} else {
|
||||
$uploaded_percentage = (float) $media_counts['offloaded'] / $media_counts['total'];
|
||||
$human_percentage = (int) floor( $uploaded_percentage * 100 );
|
||||
|
||||
// Percentage of library needs uploading.
|
||||
if ( 0 === $human_percentage && $uploaded_percentage > 0 ) {
|
||||
$human_percentage = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $human_percentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the tool be rendered?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_render() {
|
||||
// Don't show tool if pro not set up.
|
||||
if ( ! $this->as3cf->is_pro_plugin_setup() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$media_counts = $this->as3cf->media_counts();
|
||||
|
||||
// Don't show upload tool if media library empty.
|
||||
if ( 0 === $media_counts['total'] ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Message for error notice
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'Offload Errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at offloading your media library have resulted in errors.', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%s</strong> — %s', $title, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle start.
|
||||
*/
|
||||
public function handle_start() {
|
||||
$notice_id = $this->get_tool_key() . '_license_limit';
|
||||
$this->as3cf->notices->remove_notice_by_id( $notice_id );
|
||||
|
||||
parent::handle_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tool's name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
return __( 'Offload Media', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Your media needs to be offloaded', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text for when tool is partially complete.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text_partial_complete() {
|
||||
return __( 'Offload Media', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text for when tool is complete.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text_complete() {
|
||||
return __( 'Offload Media', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __( 'This tool goes through all your media items and offloads their files to the bucket.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prompt text for when tool could be run in response to settings change.
|
||||
* Defaults to more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_prompt_text() {
|
||||
global $as3cf;
|
||||
|
||||
$mesg = __( 'You\'ve enabled the "Offload Media" option. Do you want to copy all yet to be offloaded media files to the bucket?', 'amazon-s3-and-cloudfront' );
|
||||
$mesg .= ' ';
|
||||
$mesg .= $as3cf::settings_more_info_link(
|
||||
'copy-to-s3',
|
||||
'',
|
||||
'copy+to+s3'
|
||||
);
|
||||
|
||||
return $mesg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text() {
|
||||
return __( 'Offload Now', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text for when tool is partially complete.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text_partial_complete() {
|
||||
return __( 'Offload Remaining Now', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Offloading media items to bucket.', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Offloading…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Uploader_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
131
classes/pro/tools/woocommerce-product-urls.php
Normal file
131
classes/pro/tools/woocommerce-product-urls.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\Tools;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Background_Tool_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Processes\Woocommerce_Product_Urls_Process;
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\Background_Tool;
|
||||
|
||||
class Woocommerce_Product_Urls extends Background_Tool {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tool_key = 'woocommerce_product_urls';
|
||||
|
||||
/**
|
||||
* Limit the item types that this tool handles.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $source_types = array(
|
||||
'media-library',
|
||||
);
|
||||
|
||||
/**
|
||||
* Message for error notice
|
||||
*
|
||||
* @param string|null $message Optional message to override the default for the tool.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_error_notice_message( $message = null ) {
|
||||
$title = __( 'WooCommerce verify and update errors', 'amazon-s3-and-cloudfront' );
|
||||
$message = empty( $message ) ? __( 'Previous attempts at verifying and updating WooCommerce products have resulted in errors.', 'amazon-s3-and-cloudfront' ) : $message;
|
||||
|
||||
return sprintf( '<strong>%s</strong> — %s', $title, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Should render.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function should_render() {
|
||||
if ( ! $this->as3cf->is_pro_plugin_setup() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( defined( 'AS3CF_SHOW_WOOCOMMERCE_TOOL' ) && AS3CF_SHOW_WOOCOMMERCE_TOOL ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( defined( 'AS3CF_SHOW_WOOCOMMERCE_TOOL' ) && ! AS3CF_SHOW_WOOCOMMERCE_TOOL ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WooCommerce' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->count_offloaded_media_files();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tool's name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
return __( 'WooCommerce Analyze & Repair', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title_text() {
|
||||
return __( 'Verify and update WooCommerce downloadable products', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get more info text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_more_info_text() {
|
||||
return __(
|
||||
'This tools goes through all your WooCommerce products with downloadable files. It marks all
|
||||
downloadable files as private in the bucket. It also replaces shortcodes created by previous versions
|
||||
of this plugin with proper URLs.',
|
||||
'amazon-s3-and-cloudfront'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get button text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_button_text() {
|
||||
return __( 'Verify and update', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_queued_status(): string {
|
||||
return __( 'Verify and update WooCommerce downloadable files', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get short queued status text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_short_queued_status(): string {
|
||||
return _x( 'Repairing…', 'Short tool running message', 'amazon-s3-and-cloudfront' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get background process class.
|
||||
*
|
||||
* @return Background_Tool_Process|null
|
||||
*/
|
||||
protected function get_background_process_class() {
|
||||
return new Woocommerce_Product_Urls_Process( $this->as3cf, $this );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user