diff --git a/includes/class-delete-all.php b/includes/class-delete-all.php index 111352fb181e2dd3b90d1c99f35d70d881024b63..dc540b562f8cf40ff73e5ede0018735b675c34e2 100644 --- a/includes/class-delete-all.php +++ b/includes/class-delete-all.php @@ -112,31 +112,25 @@ class Delete_All { public static function admin_notices() { $screen = get_current_screen(); + $type = ''; + $message = ''; + if ( isset( $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) ) { if ( 1 === (int) $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) { - $class = 'notice-success'; + $type = 'success'; $message = __( 'Success! The trash will be emptied shortly.', 'bulk-edit-cron-offload' ); } else { - $class = 'notice-error'; + $type = 'error'; $message = __( 'A request to empty the trash is already pending for this post type.', 'bulk-edit-cron-offload' ); } } elseif ( 'edit' === $screen->base && isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) { if ( self::action_next_scheduled( $screen->post_type ) ) { - $class = 'notice-warning'; + $type = 'warning'; $message = __( 'A pending request to empty the trash will be processed soon.', 'bulk-edit-cron-offload' ); } } - // Nothing to display. - if ( ! isset( $class ) || ! isset( $message ) ) { - return; - } - - ?> - <div class="notice <?php echo esc_attr( $class ); ?>"> - <p><?php echo esc_html( $message ); ?></p> - </div> - <?php + Main::render_admin_notice( $type, $message ); } /** diff --git a/includes/class-main.php b/includes/class-main.php index ec22ea52bc76105c9bf9223d0854b01b0197ffce..2597d9b2fac9dafc96c8de18bd02a6afcd74b663 100644 --- a/includes/class-main.php +++ b/includes/class-main.php @@ -191,6 +191,25 @@ class Main { unset( $_REQUEST['delete_all2'] ); } + /** + * Create cron event + * + * @param object $vars Bulk-request variables. + * @return bool + */ + public static function schedule_processing( $vars ) { + return false !== wp_schedule_single_event( time(), self::CRON_EVENT, array( $vars ) ); + } + + /** + * + * @param object $vars Bulk-request variables. + * @return int + */ + public static function next_scheduled( $vars ) { + return (int) wp_next_scheduled( self::CRON_EVENT, array( $vars ) ); + } + /** * Redirect, including a flag to indicate if the bulk process was scheduled successfully * @@ -215,22 +234,23 @@ class Main { } /** - * Create cron event + * Render an admin message of a given type * - * @param object $vars Bulk-request variables. - * @return bool + * @param string $type Message type. + * @param string $message Message to output. + * @return void */ - public static function schedule_processing( $vars ) { - return false !== wp_schedule_single_event( time(), self::CRON_EVENT, array( $vars ) ); - } + public static function render_admin_notice( $type, $message ) { + // Lacking what's required. + if ( empty( $type ) || empty( $message ) ) { + return; + } - /** - * - * @param object $vars Bulk-request variables. - * @return int - */ - public static function next_scheduled( $vars ) { - return (int) wp_next_scheduled( self::CRON_EVENT, array( $vars ) ); + ?> + <div class="notice <?php echo esc_attr( 'notice-' . $type ); ?>"> + <p><?php echo esc_html( $message ); ?></p> + </div> + <?php } } diff --git a/includes/class-move-to-trash.php b/includes/class-move-to-trash.php index 587a5fb1d97d3752ca924a3033ba01ce1df9dd23..d137aea33f6582378071329dbb127b2c93b2f741 100644 --- a/includes/class-move-to-trash.php +++ b/includes/class-move-to-trash.php @@ -100,12 +100,15 @@ class Move_To_Trash { public static function admin_notices() { $screen = get_current_screen(); + $type = ''; + $message = ''; + if ( isset( $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) ) { if ( 1 === (int) $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) { - $class = 'notice-success'; + $type = 'success'; $message = __( 'Success! The selected posts will be moved to the trash shortly.', 'bulk-edit-cron-offload' ); } else { - $class = 'notice-error'; + $type = 'error'; $message = __( 'The selected posts are already scheduled to be moved to the trash.', 'bulk-edit-cron-offload' ); } } elseif ( 'edit' === $screen->base ) { @@ -116,21 +119,12 @@ class Move_To_Trash { $status = isset( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; if ( self::get_all_pending_actions( $screen->post_type, $status ) ) { - $class = 'notice-warning'; + $type = 'warning'; $message = __( 'Some items that would normally be shown here are waiting to be moved to the trash. These items are hidden until they are moved.', 'bulk-edit-cron-offload' ); } } - // Nothing to display. - if ( ! isset( $class ) || ! isset( $message ) ) { - return; - } - - ?> - <div class="notice <?php echo esc_attr( $class ); ?>"> - <p><?php echo esc_html( $message ); ?></p> - </div> - <?php + Main::render_admin_notice( $type, $message ); } /**