From 079f67a580ec4c349874ef45722a5e5fbb5e18b5 Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Tue, 12 Sep 2017 20:37:35 -0700
Subject: [PATCH] Start notices for pending move actions

---
 includes/class-delete-all.php    |  2 +-
 includes/class-move-to-trash.php | 34 +++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/includes/class-delete-all.php b/includes/class-delete-all.php
index f5d4412..91de829 100644
--- a/includes/class-delete-all.php
+++ b/includes/class-delete-all.php
@@ -115,7 +115,7 @@ class Delete_All {
 		if ( isset( $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) ) {
 			if ( 1 === (int) $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) {
 				$class = 'notice-success';
-				$message = __( 'Success! The trash will be emptied soon.', 'bulk-edit-cron-offload' );
+				$message = __( 'Success! The trash will be emptied shortly.', 'bulk-edit-cron-offload' );
 			} else {
 				$class = 'notice-error';
 				$message = __( 'A request to empty the trash is already pending for this post type.', 'bulk-edit-cron-offload' );
diff --git a/includes/class-move-to-trash.php b/includes/class-move-to-trash.php
index 5a28774..3b880f8 100644
--- a/includes/class-move-to-trash.php
+++ b/includes/class-move-to-trash.php
@@ -14,7 +14,7 @@ class Move_To_Trash {
 	/**
 	 * Class constants
 	 */
-	const CRON_EVENT = 'bulk_edit_cron_offload_move_to_trash';
+	const ADMIN_NOTICE_KEY = 'bulk_edit_cron_offload_move_to_trash';
 
 	/**
 	 * Register this bulk process' hooks
@@ -22,6 +22,8 @@ class Move_To_Trash {
 	public static function register_hooks() {
 		add_action( Main::build_hook( 'trash' ), array( __CLASS__, 'process' ) );
 		add_action( Main::build_cron_hook( 'trash' ), array( __CLASS__, 'process_via_cron' ) );
+
+		add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) );
 	}
 
 	/**
@@ -84,6 +86,36 @@ class Move_To_Trash {
 			do_action( 'bulk_edit_cron_offload_move_to_trash_request_no_posts', $vars->posts, $vars );
 		}
 	}
+
+	/**
+	 * Let the user know what's going on
+	 */
+	public static function admin_notices() {
+		$screen = get_current_screen();
+
+		if ( isset( $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) ) {
+			if ( 1 === (int) $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) {
+				$class = 'notice-success';
+				$message = __( 'Success! The selected posts will be moved to the trash shortly.', 'bulk-edit-cron-offload' );
+			} else {
+				$class = 'notice-error';
+				$message = __( 'An unknown error occurred.', 'bulk-edit-cron-offload' );
+			}
+		}
+
+		// TODO: show a notice if any move requests are pending for this post type ($screen->post_type).
+
+		// 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
+	}
 }
 
 Move_To_Trash::register_hooks();
-- 
GitLab