Added empty trash action
This commit is contained in:
parent
052380e191
commit
56c49daea8
|
@ -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 '<div class="alignleft actions"><a class="button apply" href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=webhooks&status=trash&empty_trash=1' ) ) . '">' . __( 'Empty Trash' ) . '</a></div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare table list items.
|
||||
*/
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue