From 72c8e3b9cc59a0bc1daae7b5b1a947e8e7dba22f Mon Sep 17 00:00:00 2001 From: Roshan Sameer Date: Fri, 8 Jun 2018 11:54:47 +0545 Subject: [PATCH 1/3] Fix - on webhook bulk action footer delete selection --- includes/admin/class-wc-admin-webhooks.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/admin/class-wc-admin-webhooks.php b/includes/admin/class-wc-admin-webhooks.php index 1635642b76a..cb2b00599ba 100644 --- a/includes/admin/class-wc-admin-webhooks.php +++ b/includes/admin/class-wc-admin-webhooks.php @@ -189,12 +189,12 @@ class WC_Admin_Webhooks { wp_die( esc_html__( 'You do not have permission to edit Webhooks', 'woocommerce' ) ); } - if ( isset( $_REQUEST['action'] ) ) { // WPCS: input var okay, CSRF ok. + if ( isset( $_REQUEST['action'] ) || isset( $_REQUEST['action2'] ) ) { // WPCS: input var okay, CSRF ok. $webhooks = isset( $_REQUEST['webhook'] ) ? array_map( 'absint', (array) $_REQUEST['webhook'] ) : array(); // WPCS: input var okay, CSRF ok. + $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); // WPCS: input var okay, CSRF ok. + $action2 = sanitize_text_field( wp_unslash( $_REQUEST['action2'] ) ); // WPCS: input var okay, CSRF ok. - $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); // WPCS: input var okay, CSRF ok. - - if ( 'delete' === $action ) { + if ( 'delete' === $action || 'delete' === $action2 ) { $this->bulk_delete( $webhooks ); } } From 32b734a1c17b337fcd91ac9268eabaf9fade553b Mon Sep 17 00:00:00 2001 From: Roshan Sameer Date: Mon, 11 Jun 2018 15:05:13 +0545 Subject: [PATCH 2/3] Implementation of current action check in list table --- .../class-wc-admin-webhooks-table-list.php | 16 ++++++++++ includes/admin/class-wc-admin-webhooks.php | 29 ++----------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/includes/admin/class-wc-admin-webhooks-table-list.php b/includes/admin/class-wc-admin-webhooks-table-list.php index e96ca250fd6..5650228026c 100644 --- a/includes/admin/class-wc-admin-webhooks-table-list.php +++ b/includes/admin/class-wc-admin-webhooks-table-list.php @@ -207,6 +207,22 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table { ); } + /** + * Process bulk actions. + */ + public function process_bulk_action() { + $action = $this->current_action(); + $webhooks = isset( $_REQUEST['webhook'] ) ? array_map( 'absint', (array) $_REQUEST['webhook'] ) : array(); // WPCS: input var okay, CSRF ok. + + if ( ! current_user_can( 'manage_woocommerce' ) ) { + wp_die( esc_html__( 'You do not have permission to edit Webhooks', 'woocommerce' ) ); + } + + if ( 'delete' === $action ) { + WC_Admin_Webhooks::bulk_delete( $webhooks ); + } + } + /** * Generate the table navigation above or below the table. * Included to remove extra nonce input. diff --git a/includes/admin/class-wc-admin-webhooks.php b/includes/admin/class-wc-admin-webhooks.php index cb2b00599ba..0fb308cf853 100644 --- a/includes/admin/class-wc-admin-webhooks.php +++ b/includes/admin/class-wc-admin-webhooks.php @@ -150,7 +150,7 @@ class WC_Admin_Webhooks { * * @param array $webhooks List of webhooks IDs. */ - private function bulk_delete( $webhooks ) { + public function bulk_delete( $webhooks ) { foreach ( $webhooks as $webhook_id ) { $webhook = new WC_Webhook( (int) $webhook_id ); $webhook->delete( true ); @@ -179,27 +179,6 @@ class WC_Admin_Webhooks { } } - /** - * Bulk actions. - */ - private function bulk_actions() { - check_admin_referer( 'woocommerce-settings' ); - - if ( ! current_user_can( 'manage_woocommerce' ) ) { - wp_die( esc_html__( 'You do not have permission to edit Webhooks', 'woocommerce' ) ); - } - - if ( isset( $_REQUEST['action'] ) || isset( $_REQUEST['action2'] ) ) { // WPCS: input var okay, CSRF ok. - $webhooks = isset( $_REQUEST['webhook'] ) ? array_map( 'absint', (array) $_REQUEST['webhook'] ) : array(); // WPCS: input var okay, CSRF ok. - $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); // WPCS: input var okay, CSRF ok. - $action2 = sanitize_text_field( wp_unslash( $_REQUEST['action2'] ) ); // WPCS: input var okay, CSRF ok. - - if ( 'delete' === $action || 'delete' === $action2 ) { - $this->bulk_delete( $webhooks ); - } - } - } - /** * Webhooks admin actions. */ @@ -210,11 +189,6 @@ class WC_Admin_Webhooks { $this->save(); } - // Bulk actions. - if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['webhook'] ) ) { // WPCS: input var okay, CSRF ok. - $this->bulk_actions(); - } - // Delete webhook. if ( isset( $_GET['delete'] ) ) { // WPCS: input var okay, CSRF ok. $this->delete(); @@ -299,6 +273,7 @@ class WC_Admin_Webhooks { $count = count( $data_store->get_webhooks_ids() ); if ( 0 < $count ) { + $webhooks_table_list->process_bulk_action(); $webhooks_table_list->prepare_items(); echo ''; From 384f54f95188da852c254f55cddb066d87bd0c76 Mon Sep 17 00:00:00 2001 From: Roshan Sameer Date: Thu, 14 Jun 2018 16:40:48 +0545 Subject: [PATCH 3/3] Static call --- includes/admin/class-wc-admin-webhooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin-webhooks.php b/includes/admin/class-wc-admin-webhooks.php index 0fb308cf853..ddc6cb2dab4 100644 --- a/includes/admin/class-wc-admin-webhooks.php +++ b/includes/admin/class-wc-admin-webhooks.php @@ -150,7 +150,7 @@ class WC_Admin_Webhooks { * * @param array $webhooks List of webhooks IDs. */ - public function bulk_delete( $webhooks ) { + public static function bulk_delete( $webhooks ) { foreach ( $webhooks as $webhook_id ) { $webhook = new WC_Webhook( (int) $webhook_id ); $webhook->delete( true );