diff --git a/bulk-actions-cron-offload.php b/bulk-actions-cron-offload.php index 1565e26a7d8e0c0e339cd4088a3e024e7063873d..90f256a2769c463294012dc466c2a1903e96d72d 100644 --- a/bulk-actions-cron-offload.php +++ b/bulk-actions-cron-offload.php @@ -15,6 +15,7 @@ namespace Automattic\WP\Bulk_Actions_Cron_Offload; // Plugin dependencies. +require __DIR__ . '/includes/trait-in-trash.php'; require __DIR__ . '/includes/trait-remove-one-time-args.php'; require __DIR__ . '/includes/trait-bulk-actions.php'; require __DIR__ . '/includes/utils.php'; diff --git a/includes/class-delete-permanently.php b/includes/class-delete-permanently.php index 6b0419a156a42ae3a7a5f8cac64ba20b67362cc1..68151d39fe919e627fe7fde2c32132e8b16bef41 100644 --- a/includes/class-delete-permanently.php +++ b/includes/class-delete-permanently.php @@ -14,7 +14,10 @@ class Delete_Permanently { /** * Common hooks and such */ - use Bulk_Actions; + use Bulk_Actions, In_Trash { + In_Trash::admin_notices insteadof Bulk_Actions; + In_Trash::hide_posts insteadof Bulk_Actions; + } /** * Class constants @@ -72,27 +75,6 @@ class Delete_Permanently { } } - /** - * Let the user know what's going on - * - * Not used for post-request redirect - */ - public static function admin_notices() { - $screen = get_current_screen(); - - $type = ''; - $message = ''; - - if ( 'edit' === $screen->base && isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) { - if ( Main::get_post_ids_for_pending_events( self::ACTION, $screen->post_type, 'trash' ) ) { - $type = 'warning'; - $message = self::admin_notice_hidden_pending_processing(); - } - } - - Main::render_admin_notice( $type, $message ); - } - /** * Provide post-redirect success message * @@ -119,28 +101,6 @@ class Delete_Permanently { public static function admin_notice_hidden_pending_processing() { return __( 'Some items that would normally be shown here are waiting to be deleted permanently. These items are hidden until then.', 'bulk-actions-cron-offload' ); } - - /** - * When a delete is pending for a given post type, hide those posts in the admin - * - * @param string $where Posts' WHERE clause. - * @param object $q WP_Query object. - * @return string - */ - public static function hide_posts( $where, $q ) { - if ( 'trash' !== $q->get( 'post_status' ) ) { - return $where; - } - - $post__not_in = Main::get_post_ids_for_pending_events( self::ACTION, $q->get( 'post_type' ), $q->get( 'post_status' ) ); - - if ( ! empty( $post__not_in ) ) { - $post__not_in = implode( ',', $post__not_in ); - $where .= ' AND ID NOT IN(' . $post__not_in . ')'; - } - - return $where; - } } Delete_Permanently::register_hooks(); diff --git a/includes/class-restore-from-trash.php b/includes/class-restore-from-trash.php index ff1a764885bdc0e90a4881fff14e0086e4b40b0f..416bcebe3732f7664402f1e8901a0d316718869b 100644 --- a/includes/class-restore-from-trash.php +++ b/includes/class-restore-from-trash.php @@ -14,7 +14,10 @@ class Restore_From_Trash { /** * Common hooks and such */ - use Bulk_Actions; + use Bulk_Actions, In_Trash { + In_Trash::admin_notices insteadof Bulk_Actions; + In_Trash::hide_posts insteadof Bulk_Actions; + } /** * Class constants @@ -72,27 +75,6 @@ class Restore_From_Trash { } } - /** - * Let the user know what's going on - * - * Not used for post-request redirect - */ - public static function admin_notices() { - $screen = get_current_screen(); - - $type = ''; - $message = ''; - - if ( 'edit' === $screen->base && isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) { - if ( Main::get_post_ids_for_pending_events( self::ACTION, $screen->post_type, 'trash' ) ) { - $type = 'warning'; - $message = self::admin_notice_hidden_pending_processing(); - } - } - - Main::render_admin_notice( $type, $message ); - } - /** * Provide post-redirect success message * @@ -119,28 +101,6 @@ class Restore_From_Trash { public static function admin_notice_hidden_pending_processing() { return __( 'Some items that would normally be shown here are waiting to be restored from the trash. These items are hidden until they are restored.', 'bulk-actions-cron-offload' ); } - - /** - * When a restore is pending for a given post type, hide those posts in the admin - * - * @param string $where Posts' WHERE clause. - * @param object $q WP_Query object. - * @return string - */ - public static function hide_posts( $where, $q ) { - if ( 'trash' !== $q->get( 'post_status' ) ) { - return $where; - } - - $post__not_in = Main::get_post_ids_for_pending_events( self::ACTION, $q->get( 'post_type' ), $q->get( 'post_status' ) ); - - if ( ! empty( $post__not_in ) ) { - $post__not_in = implode( ',', $post__not_in ); - $where .= ' AND ID NOT IN(' . $post__not_in . ')'; - } - - return $where; - } } Restore_From_Trash::register_hooks(); diff --git a/includes/trait-in-trash.php b/includes/trait-in-trash.php new file mode 100644 index 0000000000000000000000000000000000000000..e4b621feff6f575d7f5732ea4fc0c2d19db44e8b --- /dev/null +++ b/includes/trait-in-trash.php @@ -0,0 +1,56 @@ +<?php +/** + * Overrides for when viewing the trash + * + * @package Bulk_Actions_Cron_Offload + */ + +namespace Automattic\WP\Bulk_Actions_Cron_Offload; + +/** + * Trait In_Trash + */ +trait In_Trash { + /** + * Let the user know what's going on + * + * Not used for post-request redirect + */ + public static function admin_notices() { + $screen = get_current_screen(); + + $type = ''; + $message = ''; + + if ( 'edit' === $screen->base && isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) { + if ( Main::get_post_ids_for_pending_events( self::ACTION, $screen->post_type, 'trash' ) ) { + $type = 'warning'; + $message = self::admin_notice_hidden_pending_processing(); + } + } + + Main::render_admin_notice( $type, $message ); + } + + /** + * When a restore is pending for a given post type, hide those posts in the admin + * + * @param string $where Posts' WHERE clause. + * @param object $q WP_Query object. + * @return string + */ + public static function hide_posts( $where, $q ) { + if ( 'trash' !== $q->get( 'post_status' ) ) { + return $where; + } + + $post__not_in = Main::get_post_ids_for_pending_events( self::ACTION, $q->get( 'post_type' ), $q->get( 'post_status' ) ); + + if ( ! empty( $post__not_in ) ) { + $post__not_in = implode( ',', $post__not_in ); + $where .= ' AND ID NOT IN(' . $post__not_in . ')'; + } + + return $where; + } +}