Skip to content

Commit

Permalink
Don't use an anonymous function to trigger admin notices
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejarrett committed May 21, 2014
1 parent 3df78dd commit 1f47e9c
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ private function __construct() {
// Install the plugin
add_action( 'wp_stream_before_db_notices', array( __CLASS__, 'install' ) );

// Trigger admin notices
add_action( 'all_admin_notices', array( __CLASS__, 'admin_notices' ) );

// Load languages
add_action( 'plugins_loaded', array( __CLASS__, 'i18n' ) );

Expand Down Expand Up @@ -248,7 +251,7 @@ public static function is_valid_php_version() {
}

/**
* Show an error or other message, using admin_notice or WP-CLI logger
* Handle notice messages according to the appropriate context (WP-CLI or the WP Admin)
*
* @param string $message
* @param bool $is_error
Expand All @@ -263,15 +266,28 @@ public static function notice( $message, $is_error = true ) {
WP_CLI::success( $message );
}
} else {
$print_message = function () use ( $message, $is_error ) {
$class_name = ( $is_error ? 'error' : 'updated' );
$html_message = sprintf( '<div class="%s">%s</div>', $class_name, wpautop( $message ) );
echo wp_kses_post( $html_message );
};
add_action( 'all_admin_notices', $print_message );
self::admin_notices( $message, $is_error );
}
}

/**
* Show an error or other message in the WP Admin
*
* @param string $message
* @param bool $is_error
* @return void
*/
public static function admin_notices( $message, $is_error = true ) {
if ( empty( $message ) ) {
return;
}

$class_name = $is_error ? 'error' : 'updated';
$html_message = sprintf( '<div class="%s">%s</div>', esc_attr( $class_name ), wpautop( $message ) );

echo wp_kses_post( $html_message );
}

/**
* Displays an HTML comment in the frontend head to indicate that Stream is activated,
* and which version of Stream is currently in use.
Expand Down

0 comments on commit 1f47e9c

Please sign in to comment.