From 56c49daea83c6ed9aa303231fca84b8d7f7c0d43 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 9 Jan 2015 23:03:22 -0200 Subject: [PATCH] Added empty trash action --- .../class-wc-admin-webhooks-table-list.php | 11 ++++++ includes/admin/class-wc-admin-webhooks.php | 34 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/includes/admin/class-wc-admin-webhooks-table-list.php b/includes/admin/class-wc-admin-webhooks-table-list.php index d55a9cd98dd..b62fe3fab0f 100644 --- a/includes/admin/class-wc-admin-webhooks-table-list.php +++ b/includes/admin/class-wc-admin-webhooks-table-list.php @@ -251,6 +251,17 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table { ); } + /** + * Extra controls to be displayed between bulk actions and pagination + * + * @param string $which + */ + protected function extra_tablenav( $which ) { + if ( 'top' == $which && isset( $_GET['status'] ) && 'trash' == $_GET['status'] && current_user_can( 'delete_shop_webhooks' ) ) { + echo '
' . __( 'Empty Trash' ) . '
'; + } + } + /** * Prepare table list items. */ diff --git a/includes/admin/class-wc-admin-webhooks.php b/includes/admin/class-wc-admin-webhooks.php index ba62891aa8e..33e287cb4a5 100644 --- a/includes/admin/class-wc-admin-webhooks.php +++ b/includes/admin/class-wc-admin-webhooks.php @@ -243,6 +243,33 @@ class WC_Admin_Webhooks { } } + /** + * Empty Trash + */ + public function empty_trash() { + if ( ! current_user_can( 'delete_shop_webhooks' ) ) { + wp_die( __( 'You don\'t have permissions to delete Webhooks!', 'woocommerce' ) ); + } + + $webhooks = get_posts( array( + 'post_type' => 'shop_webhook', + 'ignore_sticky_posts' => true, + 'nopaging' => true, + 'post_status' => 'trash', + 'fields' => 'ids' + ) ); + + foreach ( $webhooks as $webhook_id ) { + wp_delete_post( $webhook_id, true ); + } + + $qty = count( $webhooks ); + + // Redirect to webhooks page + wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks&deleted=' . $qty ) ); + exit(); + } + /** * Webhooks admin actions */ @@ -259,10 +286,15 @@ class WC_Admin_Webhooks { $this->create(); } - // Create + // Bulk actions if ( isset( $_GET['action'] ) && isset( $_GET['webhook'] ) ) { $this->bulk_actions(); } + + // Bulk actions + if ( isset( $_GET['empty_trash'] ) ) { + $this->empty_trash(); + } } } }