-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
152 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
= 1.8.0 = | ||
|
||
Added: | ||
* Bulk full offload | ||
|
||
= 1.7.1 - 31.12.2023 = | ||
|
||
Fixed: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
/** | ||
* Full Offload module | ||
* | ||
* Manage removing physical files from the media library. | ||
* | ||
* @link https://vcore.au | ||
* | ||
* @package CF_Images | ||
* @subpackage CF_Images/App/Modules | ||
* @author Anton Vanyukov <[email protected]> | ||
* | ||
* @since 1.8.0 | ||
*/ | ||
|
||
namespace CF_Images\App\Modules; | ||
|
||
use CF_Images\App\Traits; | ||
|
||
if ( ! defined( 'WPINC' ) ) { | ||
die; | ||
} | ||
|
||
/** | ||
* Full_Offload class. | ||
* | ||
* @since 1.8.0 | ||
*/ | ||
class Full_Offload extends Module { | ||
use Traits\Ajax; | ||
use Traits\Stats; | ||
|
||
/** | ||
* Action name. | ||
* | ||
* @var string | ||
*/ | ||
private $action = 'full-remove'; | ||
|
||
/** | ||
* Init the module. | ||
* | ||
* @since 1.8.0 | ||
*/ | ||
public function init() { | ||
// Bulk remove actions. | ||
add_filter( 'cf_images_bulk_actions', array( $this, 'add_bulk_action' ) ); | ||
add_filter( 'cf_images_wp_query_args', array( $this, 'add_wp_query_args' ), 10, 2 ); | ||
add_action( 'cf_images_bulk_step', array( $this, 'bulk_step' ), 10, 2 ); | ||
} | ||
|
||
/** | ||
* Extend bulk action so that the AJAX callback accepts the bulk request. | ||
* | ||
* @since 1.8.0 | ||
* @see Media::ajax_bulk_process() | ||
* | ||
* @param array $actions Supported actions. | ||
* | ||
* @return array | ||
*/ | ||
public function add_bulk_action( array $actions ): array { | ||
if ( ! in_array( $this->action, $actions, true ) ) { | ||
$actions[] = $this->action; | ||
} | ||
|
||
return $actions; | ||
} | ||
|
||
/** | ||
* Adjust the WP_Query args for bulk compress action. | ||
* | ||
* @since 1.8.0 | ||
* @see Ajax::get_wp_query_args() | ||
* | ||
* @param array $args WP_Query args. | ||
* @param string $action Executing action. | ||
* | ||
* @return array | ||
*/ | ||
public function add_wp_query_args( array $args, string $action ): array { | ||
if ( $this->action !== $action ) { | ||
return $args; | ||
} | ||
|
||
$args['meta_query'] = array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query | ||
array( | ||
'key' => '_cloudflare_image_offloaded', | ||
'compare' => 'NOT EXISTS', | ||
), | ||
array( | ||
'key' => '_cloudflare_image_id', | ||
'compare' => 'EXISTS', | ||
), | ||
); | ||
|
||
return $args; | ||
} | ||
|
||
/** | ||
* Perform bulk step. | ||
* | ||
* @since 1.8.0 | ||
* @see Media::ajax_bulk_process() | ||
* | ||
* @param int $attachment_id Attachment ID. | ||
* @param string $action Executing action. | ||
*/ | ||
public function bulk_step( int $attachment_id, string $action ) { | ||
if ( $this->action !== $action ) { | ||
return; | ||
} | ||
|
||
$this->media()->ajax_delete_image( $attachment_id ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters