From 56976f631f198c007b4e389d2958dca4f654c1e8 Mon Sep 17 00:00:00 2001 From: Erick Hitter <git-contrib@ethitter.com> Date: Thu, 14 Sep 2017 19:08:39 -0700 Subject: [PATCH] Move the common query bits --- includes/class-delete-all.php | 8 -------- includes/class-delete-permanently.php | 8 -------- includes/class-edit.php | 8 -------- includes/class-move-to-trash.php | 8 -------- includes/class-restore-from-trash.php | 8 -------- includes/trait-bulk-actions.php | 21 ++++++++++++++++++++- 6 files changed, 20 insertions(+), 41 deletions(-) diff --git a/includes/class-delete-all.php b/includes/class-delete-all.php index 5eb4ace..149e17f 100644 --- a/includes/class-delete-all.php +++ b/includes/class-delete-all.php @@ -141,14 +141,6 @@ class Delete_All { * @return string */ public static function hide_posts( $where, $q ) { - if ( ! is_admin() || ! $q->is_main_query() ) { - return $where; - } - - if ( 'edit' !== get_current_screen()->base ) { - return $where; - } - if ( 'trash' !== $q->get( 'post_status' ) ) { return $where; } diff --git a/includes/class-delete-permanently.php b/includes/class-delete-permanently.php index 5d989b4..e968758 100644 --- a/includes/class-delete-permanently.php +++ b/includes/class-delete-permanently.php @@ -125,14 +125,6 @@ class Delete_Permanently { * @return string */ public static function hide_posts( $where, $q ) { - if ( ! is_admin() || ! $q->is_main_query() ) { - return $where; - } - - if ( 'edit' !== get_current_screen()->base ) { - return $where; - } - if ( 'trash' !== $q->get( 'post_status' ) ) { return $where; } diff --git a/includes/class-edit.php b/includes/class-edit.php index 2e7ce48..b39f753 100644 --- a/includes/class-edit.php +++ b/includes/class-edit.php @@ -133,14 +133,6 @@ class Edit { * @return string */ public static function hide_posts( $where, $q ) { - if ( ! is_admin() || ! $q->is_main_query() ) { - return $where; - } - - if ( 'edit' !== get_current_screen()->base ) { - return $where; - } - if ( 'trash' === $q->get( 'post_status' ) ) { return $where; } diff --git a/includes/class-move-to-trash.php b/includes/class-move-to-trash.php index 51d60b1..379dd25 100644 --- a/includes/class-move-to-trash.php +++ b/includes/class-move-to-trash.php @@ -132,14 +132,6 @@ class Move_To_Trash { * @return string */ public static function hide_posts( $where, $q ) { - if ( ! is_admin() || ! $q->is_main_query() ) { - return $where; - } - - if ( 'edit' !== get_current_screen()->base ) { - return $where; - } - if ( 'trash' === $q->get( 'post_status' ) ) { return $where; } diff --git a/includes/class-restore-from-trash.php b/includes/class-restore-from-trash.php index 2b982be..b36c6a5 100644 --- a/includes/class-restore-from-trash.php +++ b/includes/class-restore-from-trash.php @@ -125,14 +125,6 @@ class Restore_From_Trash { * @return string */ public static function hide_posts( $where, $q ) { - if ( ! is_admin() || ! $q->is_main_query() ) { - return $where; - } - - if ( 'edit' !== get_current_screen()->base ) { - return $where; - } - if ( 'trash' !== $q->get( 'post_status' ) ) { return $where; } diff --git a/includes/trait-bulk-actions.php b/includes/trait-bulk-actions.php index 74fd489..4c90149 100644 --- a/includes/trait-bulk-actions.php +++ b/includes/trait-bulk-actions.php @@ -28,10 +28,29 @@ trait Bulk_Actions { */ public static function register_extra_hooks() {} + /** + * When an edit 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 ( ! is_admin() || ! $q->is_main_query() ) { + return $where; + } + + if ( 'edit' !== get_current_screen()->base ) { + return $where; + } + + return parent::hide_posts( $where, $q ); + } + /** * Strip the custom notice key, otherwise it turns up in pagination and other unwanted places. * - * @param array $args Array of one-time query args + * @param array $args Array of one-time query args. * @return array */ public static function remove_notice_arg( $args ) { -- GitLab