From 2d371ac76a6a2626f03b0ee49a13bbbcafc5555f Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Thu, 12 Mar 2020 13:35:22 -0300 Subject: [PATCH 1/2] restore action handling to WC status, use data store to delete actions --- classes/ActionScheduler_AdminView.php | 1 + .../abstracts/ActionScheduler_Abstract_ListTable.php | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/classes/ActionScheduler_AdminView.php b/classes/ActionScheduler_AdminView.php index d0d77945..d92a7fb3 100644 --- a/classes/ActionScheduler_AdminView.php +++ b/classes/ActionScheduler_AdminView.php @@ -91,6 +91,7 @@ public function process_admin_ui() { */ public function render_admin_ui() { $table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() ); + $table->process_actions(); $table->display_page(); } diff --git a/classes/abstracts/ActionScheduler_Abstract_ListTable.php b/classes/abstracts/ActionScheduler_Abstract_ListTable.php index b7a46d6f..038da246 100644 --- a/classes/abstracts/ActionScheduler_Abstract_ListTable.php +++ b/classes/abstracts/ActionScheduler_Abstract_ListTable.php @@ -140,7 +140,6 @@ protected function process_bulk_action() { global $wpdb; // Detect when a bulk action is being triggered. $action = $this->current_action(); - if ( ! $action ) { return; } @@ -161,13 +160,14 @@ protected function process_bulk_action() { } /** - * Default code for deleting entries. We trust ids_sql because it is + * Default code for deleting entries. * validated already by process_bulk_action() */ protected function bulk_delete( array $ids, $ids_sql ) { - global $wpdb; - - $wpdb->query( "DELETE FROM {$this->table_name} WHERE {$this->ID} IN $ids_sql" ); + $store = ActionScheduler::store(); + foreach ( $ids as $action_id ) { + $store->delete( $action_id ); + } } /** From 45d7de504988e74310b85987820270ce5b06320e Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Thu, 12 Mar 2020 16:35:39 -0300 Subject: [PATCH 2/2] reuse list table object, call process_actions once --- classes/ActionScheduler_AdminView.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/classes/ActionScheduler_AdminView.php b/classes/ActionScheduler_AdminView.php index d92a7fb3..c1fd0d72 100644 --- a/classes/ActionScheduler_AdminView.php +++ b/classes/ActionScheduler_AdminView.php @@ -10,6 +10,9 @@ class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated { private static $screen_id = 'tools_page_action-scheduler'; + /** @var ActionScheduler_ListTable */ + protected $list_table; + /** * @return ActionScheduler_AdminView * @codeCoverageIgnore @@ -82,19 +85,31 @@ public function register_menu() { * Triggers processing of any pending actions. */ public function process_admin_ui() { - $table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() ); - $table->process_actions(); + $this->get_list_table(); } /** * Renders the Admin UI */ public function render_admin_ui() { - $table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() ); - $table->process_actions(); + $table = $this->get_list_table(); $table->display_page(); } + /** + * Get the admin UI object and process any requested actions. + * + * @return ActionScheduler_ListTable + */ + protected function get_list_table() { + if ( null === $this->list_table ) { + $this->list_table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() ); + $this->list_table->process_actions(); + } + + return $this->list_table; + } + /** * Provide more information about the screen and its data in the help tab. */