Commit 82fa3375 authored by Erick Hitter's avatar Erick Hitter

Working bulk actions, sans tests

parent 78130edb
...@@ -9,6 +9,13 @@ ...@@ -9,6 +9,13 @@
* Class WP_Revisions_Control_Bulk_Actions. * Class WP_Revisions_Control_Bulk_Actions.
*/ */
class WP_Revisions_Control_Bulk_Actions { class WP_Revisions_Control_Bulk_Actions {
/**
* Singleton.
*
* @var static
*/
private static $__instance;
/** /**
* Supported post types. * Supported post types.
* *
...@@ -31,11 +38,32 @@ class WP_Revisions_Control_Bulk_Actions { ...@@ -31,11 +38,32 @@ class WP_Revisions_Control_Bulk_Actions {
protected $actions; protected $actions;
/** /**
* Constructor. * Silence is golden!
*/
private function __construct() {}
/**
* Singleton implementation.
*
* @param array $post_types Supported post types, used only on instantiation.
* @return static
*/
public static function get_instance( $post_types = array() ) {
if ( ! is_a( static::$__instance, __CLASS__ ) ) {
static::$__instance = new self();
static::$__instance->setup( $post_types );
}
return static::$__instance;
}
/**
* One-time actions.
* *
* @param array $post_types Supported post types. * @param array $post_types Supported post types.
*/ */
public function __construct( $post_types ) { public function setup( $post_types ) {
if ( empty( $post_types ) || ! is_array( $post_types ) ) { if ( empty( $post_types ) || ! is_array( $post_types ) ) {
return; return;
} }
...@@ -43,7 +71,7 @@ class WP_Revisions_Control_Bulk_Actions { ...@@ -43,7 +71,7 @@ class WP_Revisions_Control_Bulk_Actions {
$this->post_types = $post_types; $this->post_types = $post_types;
$this->register_actions(); $this->register_actions();
add_action( 'load-edit.php', array( $this, 'setup' ) ); add_action( 'load-edit.php', array( $this, 'register_admin_hooks' ) );
add_filter( 'removable_query_args', array( $this, 'remove_message_query_args' ) ); add_filter( 'removable_query_args', array( $this, 'remove_message_query_args' ) );
} }
...@@ -62,7 +90,7 @@ class WP_Revisions_Control_Bulk_Actions { ...@@ -62,7 +90,7 @@ class WP_Revisions_Control_Bulk_Actions {
/** /**
* Register various hooks. * Register various hooks.
*/ */
public function setup() { public function register_admin_hooks() {
$screen = get_current_screen(); $screen = get_current_screen();
if ( null === $screen ) { if ( null === $screen ) {
...@@ -129,23 +157,21 @@ class WP_Revisions_Control_Bulk_Actions { ...@@ -129,23 +157,21 @@ class WP_Revisions_Control_Bulk_Actions {
return $redirect_to; return $redirect_to;
} }
$response = array( $response = array_fill_keys( $this->get_message_query_args(), 0 );
$action => 1,
);
switch ( str_replace( $this->action_base, '', $action ) ) { switch ( str_replace( $this->action_base, '', $action ) ) {
case 'purge_all': case 'purge_all':
$this->purge_all( $ids ); $this->purge_all( $ids );
$response[ $action ] = 1;
break; break;
case 'purge_excess': case 'purge_excess':
$this->purge_excess( $ids ); $this->purge_excess( $ids );
$response[ $action ] = 1;
break; break;
default: default:
$response = array( $response[ $this->action_base . 'missing' ] = 1;
$this->action_base . 'missing' => 1,
);
break; break;
} }
...@@ -186,7 +212,7 @@ class WP_Revisions_Control_Bulk_Actions { ...@@ -186,7 +212,7 @@ class WP_Revisions_Control_Bulk_Actions {
foreach ( $this->get_message_query_args() as $arg ) { foreach ( $this->get_message_query_args() as $arg ) {
// phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
if ( isset( $_GET[ $arg ] ) ) { if ( isset( $_GET[ $arg ] ) && 1 === (int) $_GET[ $arg ] ) {
$message = $arg; $message = $arg;
break; break;
} }
......
...@@ -142,7 +142,7 @@ class WP_Revisions_Control { ...@@ -142,7 +142,7 @@ class WP_Revisions_Control {
add_action( 'save_post', array( $this, 'action_save_post' ) ); add_action( 'save_post', array( $this, 'action_save_post' ) );
// Bulk actions. // Bulk actions.
new WP_Revisions_Control_Bulk_Actions( $post_types ); WP_Revisions_Control_Bulk_Actions::get_instance( $post_types );
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment