From 1f47e9c921fd94915f4300636fe6422caac23da1 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 21 May 2014 17:59:37 -0500 Subject: [PATCH] Don't use an anonymous function to trigger admin notices --- stream.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/stream.php b/stream.php index afce76ace..85fb48640 100755 --- a/stream.php +++ b/stream.php @@ -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' ) ); @@ -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 @@ -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( '
%s
', $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( '
%s
', 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.