From a62feed59ddf4207cdc9b9e0d6709de2dd1d28f6 Mon Sep 17 00:00:00 2001 From: Erick Hitter <git-contrib@ethitter.com> Date: Thu, 14 Sep 2017 17:51:52 -0700 Subject: [PATCH] Bail if nothing is chosen --- includes/class-main.php | 21 +++++++++++++++++++++ languages/bulk-actions-cron-offload.pot | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/includes/class-main.php b/includes/class-main.php index 68672c2..3f2c4ea 100644 --- a/includes/class-main.php +++ b/includes/class-main.php @@ -16,6 +16,11 @@ class Main { */ const ACTION = 'bulk_actions_cron_offload_'; + /** + * Generic admin notices + */ + const ADMIN_NOTICE_KEY = 'bulk_actions_cron_offload_general'; + /** * Common cron action */ @@ -28,6 +33,8 @@ class Main { add_action( self::CRON_EVENT, array( __CLASS__, 'do_cron' ) ); add_action( 'load-edit.php', array( __CLASS__, 'intercept' ) ); + + add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) ); } /** @@ -59,6 +66,11 @@ class Main { return; } + // Nothing to do. + if ( empty( $vars->posts ) ) { + self::do_admin_redirect( self::ADMIN_NOTICE_KEY, false ); + } + // Pass request to a class to handle offloading to cron, UX, etc. do_action( $action, $vars ); @@ -207,6 +219,15 @@ class Main { return in_array( $action, $allowed_actions, true ); } + /** + * Let the user know what's going on + */ + public static function admin_notices() { + if ( isset( $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) && '-1' === $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) { + self::render_admin_notice( 'error', __( 'The requested bulk action was not processed because no posts were selected.', 'bulk-actions-cron-offload' ) ); + } + } + /** * Build a WP hook specific to a bulk request * diff --git a/languages/bulk-actions-cron-offload.pot b/languages/bulk-actions-cron-offload.pot index 1900db3..b5519b1 100644 --- a/languages/bulk-actions-cron-offload.pot +++ b/languages/bulk-actions-cron-offload.pot @@ -5,7 +5,7 @@ msgstr "" "Project-Id-Version: Bulk Actions Cron Offload 1.0\n" "Report-Msgid-Bugs-To: " "https://wordpress.org/support/plugin/bulk-actions-cron-offload\n" -"POT-Creation-Date: 2017-09-14 22:18:30+00:00\n" +"POT-Creation-Date: 2017-09-15 00:51:21+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -65,6 +65,10 @@ msgid "" "These items are hidden until they are processed." msgstr "" +#: includes/class-main.php:227 +msgid "The requested bulk action was not processed because no posts were selected." +msgstr "" + #: includes/class-move-to-trash.php:111 msgid "Success! The selected posts will be moved to the trash shortly." msgstr "" -- GitLab