diff --git a/includes/class-main.php b/includes/class-main.php index 68672c29fccc1f957cfe4b777622915ea923bcfa..3f2c4ea65ccb90ed746055efd5e81350a145125d 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 1900db3b0dd004d532d4d1cbe0b477129310fcff..b5519b1f9b9502dd0662144152a8fce23d77fe96 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 ""