diff --git a/bulk-edit-cron-offload.php b/bulk-edit-cron-offload.php index 5297a8dd51d0b7f2c0913fd08f89d0230d2c1686..3ad5ed762314167b5afe7d734cacc5d7674d4fdd 100644 --- a/bulk-edit-cron-offload.php +++ b/bulk-edit-cron-offload.php @@ -10,8 +10,5 @@ namespace Automattic\WP\Bulk_Edit_Cron_Offload; -// Plugin dependencies -require __DIR__ . '/includes/abstract-class-singleton.php'; - // Plugin functionality require __DIR__ . '/includes/class-main.php'; diff --git a/includes/abstract-class-singleton.php b/includes/abstract-class-singleton.php deleted file mode 100644 index 5c8042f8b4a3fb97a80c17e81d3a75a2a104482b..0000000000000000000000000000000000000000 --- a/includes/abstract-class-singleton.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -namespace Automattic\WP\Bulk_Edit_Cron_Offload; - -abstract class Singleton { - /** - * Class instance - */ - private static $__instances = array(); - - public static function instance() { - $caller = get_called_class(); - - if ( ! isset( self::$__instances[ $caller ] ) ) { - self::$__instances[ $caller ] = new $caller(); - - self::$__instances[ $caller ]->class_init(); - } - - return self::$__instances[ $caller ]; - } - - protected function __construct() {} - - /** - * PLUGIN SETUP - */ - - /** - * Register hooks - */ - protected function class_init() {} -} diff --git a/includes/class-main.php b/includes/class-main.php index 72fef52b2d1a469294c4f04613d575d9429afeb7..80cbdb0a689446ac4dce40cf8a295c1ea291bb03 100644 --- a/includes/class-main.php +++ b/includes/class-main.php @@ -2,73 +2,28 @@ namespace Automattic\WP\Bulk_Edit_Cron_Offload; -class Main extends Singleton { - /** - * Requested action - */ - private $action = null; - - /** - * Posts to process - */ - private $posts = null; - - /** - * Taxonomy terms to add - */ - private $tax_input = null; - - /** - * Post author to set - */ - private $post_author = null; - - /** - * Comment status to set - */ - private $comment_status = null; - - /** - * Ping status to set - */ - private $ping_status = null; - - /** - * New post status - */ - private $post_status = null; - - /** - * Posts' stick status - */ - private $post_sticky = null; - - /** - * Posts' format - */ - private $post_format = null; - +class Main { /** * Register action */ - public function class_init() { - add_action( 'load-edit.php', array( $this, 'intercept' ) ); + public static function init() { + add_action( 'load-edit.php', array( __CLASS__, 'intercept' ) ); } /** * Call appropriate handler */ - public function intercept() { + public static function intercept() { // Nothing to do if ( ! isset( $_REQUEST['action'] ) ) { return; } // Parse request to determine what to do - $this->populate_vars(); + $vars = self::capture_vars(); // Now what? - switch ( $this->action ) { + switch ( $vars->action ) { case 'delete_all' : break; @@ -92,54 +47,53 @@ class Main extends Singleton { } /** - * Capture relevant variables to be stored in cron events + * Capture relevant variables */ - private function populate_vars() { - $this->action = $_REQUEST['action']; + private static function capture_vars() { + $vars = new \stdClass(); + + // Capture request variables + $vars->action = $_REQUEST['action']; if ( isset( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { - $this->posts = array_map( 'absint', $_REQUEST['post'] ); + $vars->posts = array_map( 'absint', $_REQUEST['post'] ); } if ( isset( $_REQUEST['tax_input'] ) && is_array( $_REQUEST['tax_input'] ) ) { - $this->tax_input = $_REQUEST['tax_input']; + $vars->tax_input = $_REQUEST['tax_input']; } if ( isset( $_REQUEST['post_author'] ) && -1 !== (int) $_REQUEST['post_author'] ) { - $this->post_author = $_REQUEST['post_author']; + $vars->post_author = $_REQUEST['post_author']; } if ( isset( $_REQUEST['comment_status'] ) && ! empty( $_REQUEST['comment_status'] ) ) { - $this->comment_status = $_REQUEST['comment_status']; + $vars->comment_status = $_REQUEST['comment_status']; } if ( isset( $_REQUEST['ping_status'] ) && ! empty( $_REQUEST['ping_status'] ) ) { - $this->ping_status = $_REQUEST['ping_status']; + $vars->ping_status = $_REQUEST['ping_status']; } if ( isset( $_REQUEST['_status'] ) && -1 !== (int) $_REQUEST['_status'] ) { - $this->post_status = $_REQUEST['_status']; + $vars->post_status = $_REQUEST['_status']; } if ( isset( $_REQUEST['sticky'] ) && -1 !== (int) $_REQUEST['sticky'] ) { - $this->post_sticky = $_REQUEST['sticky']; + $vars->post_sticky = $_REQUEST['sticky']; } if ( isset( $_REQUEST['post_format'] ) && -1 !== (int) $_REQUEST['post_format'] ) { - $this->post_format = $_REQUEST['post_format']; + $vars->post_format = $_REQUEST['post_format']; } // Stop Core from processing bulk request unset( $_REQUEST['action'] ); unset( $_REQUEST['action2'] ); - } - /** - * Get data for this bulk request - */ - private function get_vars() { - return get_object_vars( $this ); + // Return captured variables + return $vars; } } -Main::instance(); +Main::init();