From 23dd496c07277ccc1e3c5a552d83ad05e65ffd00 Mon Sep 17 00:00:00 2001 From: Erick Hitter <git-contrib@ethitter.com> Date: Fri, 15 Sep 2017 17:53:36 -0700 Subject: [PATCH] Move trash-specific things to a trait --- bulk-actions-cron-offload.php | 1 + includes/class-delete-permanently.php | 48 ++--------------------- includes/class-restore-from-trash.php | 48 ++--------------------- includes/trait-in-trash.php | 56 +++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 88 deletions(-) create mode 100644 includes/trait-in-trash.php diff --git a/bulk-actions-cron-offload.php b/bulk-actions-cron-offload.php index 1565e26..90f256a 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 6b0419a..68151d3 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 ff1a764..416bceb 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 0000000..e4b621f --- /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; + } +} -- GitLab