Skip to content
Snippets Groups Projects
Commit 23dd496c authored by Erick Hitter's avatar Erick Hitter
Browse files

Move trash-specific things to a trait

parent 3c4fc0d9
No related branches found
No related tags found
No related merge requests found
......@@ -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';
......
......@@ -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();
......@@ -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();
<?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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment