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

Standardize admin notice output

parent 2dc9274d
No related branches found
No related tags found
No related merge requests found
...@@ -112,31 +112,25 @@ class Delete_All { ...@@ -112,31 +112,25 @@ class Delete_All {
public static function admin_notices() { public static function admin_notices() {
$screen = get_current_screen(); $screen = get_current_screen();
$type = '';
$message = '';
if ( isset( $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) ) { if ( isset( $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) ) {
if ( 1 === (int) $_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' ); $message = __( 'Success! The trash will be emptied shortly.', 'bulk-edit-cron-offload' );
} else { } else {
$class = 'notice-error'; $type = 'error';
$message = __( 'A request to empty the trash is already pending for this post type.', 'bulk-edit-cron-offload' ); $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'] ) { } elseif ( 'edit' === $screen->base && isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) {
if ( self::action_next_scheduled( $screen->post_type ) ) { 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' ); $message = __( 'A pending request to empty the trash will be processed soon.', 'bulk-edit-cron-offload' );
} }
} }
// Nothing to display. Main::render_admin_notice( $type, $message );
if ( ! isset( $class ) || ! isset( $message ) ) {
return;
}
?>
<div class="notice <?php echo esc_attr( $class ); ?>">
<p><?php echo esc_html( $message ); ?></p>
</div>
<?php
} }
/** /**
......
...@@ -191,6 +191,25 @@ class Main { ...@@ -191,6 +191,25 @@ class Main {
unset( $_REQUEST['delete_all2'] ); 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 * Redirect, including a flag to indicate if the bulk process was scheduled successfully
* *
...@@ -215,22 +234,23 @@ class Main { ...@@ -215,22 +234,23 @@ class Main {
} }
/** /**
* Create cron event * Render an admin message of a given type
* *
* @param object $vars Bulk-request variables. * @param string $type Message type.
* @return bool * @param string $message Message to output.
* @return void
*/ */
public static function schedule_processing( $vars ) { public static function render_admin_notice( $type, $message ) {
return false !== wp_schedule_single_event( time(), self::CRON_EVENT, array( $vars ) ); // Lacking what's required.
} if ( empty( $type ) || empty( $message ) ) {
return;
}
/** ?>
* <div class="notice <?php echo esc_attr( 'notice-' . $type ); ?>">
* @param object $vars Bulk-request variables. <p><?php echo esc_html( $message ); ?></p>
* @return int </div>
*/ <?php
public static function next_scheduled( $vars ) {
return (int) wp_next_scheduled( self::CRON_EVENT, array( $vars ) );
} }
} }
......
...@@ -100,12 +100,15 @@ class Move_To_Trash { ...@@ -100,12 +100,15 @@ class Move_To_Trash {
public static function admin_notices() { public static function admin_notices() {
$screen = get_current_screen(); $screen = get_current_screen();
$type = '';
$message = '';
if ( isset( $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) ) { if ( isset( $_REQUEST[ self::ADMIN_NOTICE_KEY ] ) ) {
if ( 1 === (int) $_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' ); $message = __( 'Success! The selected posts will be moved to the trash shortly.', 'bulk-edit-cron-offload' );
} else { } else {
$class = 'notice-error'; $type = 'error';
$message = __( 'The selected posts are already scheduled to be moved to the trash.', 'bulk-edit-cron-offload' ); $message = __( 'The selected posts are already scheduled to be moved to the trash.', 'bulk-edit-cron-offload' );
} }
} elseif ( 'edit' === $screen->base ) { } elseif ( 'edit' === $screen->base ) {
...@@ -116,21 +119,12 @@ class Move_To_Trash { ...@@ -116,21 +119,12 @@ class Move_To_Trash {
$status = isset( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; $status = isset( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
if ( self::get_all_pending_actions( $screen->post_type, $status ) ) { 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' ); $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. Main::render_admin_notice( $type, $message );
if ( ! isset( $class ) || ! isset( $message ) ) {
return;
}
?>
<div class="notice <?php echo esc_attr( $class ); ?>">
<p><?php echo esc_html( $message ); ?></p>
</div>
<?php
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment