diff --git a/includes/Framework/AdminNoticeHandler.php b/includes/Framework/AdminNoticeHandler.php index 4e17ec8be..1201d9f60 100644 --- a/includes/Framework/AdminNoticeHandler.php +++ b/includes/Framework/AdminNoticeHandler.php @@ -1,12 +1,11 @@ plugin = $plugin; + $this->plugin = $plugin; // render any admin notices, delayed notices, and - add_action( 'admin_notices', array( $this, 'render_admin_notices' ), 15 ); - add_action( 'admin_footer', array( $this, 'render_delayed_admin_notices' ), 15 ); - add_action( 'admin_footer', array( $this, 'render_admin_notice_js' ), 20 ); + add_action( 'admin_notices', array( $this, 'render_admin_notices' ), 15 ); + add_action( 'admin_footer', array( $this, 'render_delayed_admin_notices' ), 15 ); + add_action( 'admin_footer', array( $this, 'render_admin_notice_js' ), 20 ); // AJAX handler to dismiss any warning/error notices add_action( 'wp_ajax_wc_plugin_framework_' . $this->get_plugin()->get_id() . '_dismiss_notice', array( $this, 'handle_dismiss_notice' ) ); @@ -56,7 +56,7 @@ public function __construct( $plugin ) { * @since 3.0.0 * @param string $message the notice message to display * @param string $message_id the message id - * @param array $params { + * @param array $params { * Optional parameters. * * @type bool $dismissible If the notice should be dismissible @@ -67,11 +67,14 @@ public function __construct( $plugin ) { */ public function add_admin_notice( $message, $message_id, $params = [] ) { - $params = wp_parse_args( $params, array( - 'dismissible' => true, - 'always_show_on_settings' => true, - 'notice_class' => 'updated', - ) ); + $params = wp_parse_args( + $params, + array( + 'dismissible' => true, + 'always_show_on_settings' => true, + 'notice_class' => 'updated', + ) + ); if ( $this->should_display_notice( $message_id, $params ) ) { $this->admin_notices[ $message_id ] = array( @@ -89,7 +92,7 @@ public function add_admin_notice( $message, $message_id, $params = [] ) { * * @since 3.0.0 * @param string $message_id the message id - * @param array $params { + * @param array $params { * Optional parameters. * * @type bool $dismissible If the notice should be dismissible @@ -105,10 +108,13 @@ public function should_display_notice( $message_id, $params = [] ) { return false; } - $params = wp_parse_args( $params, array( - 'dismissible' => true, - 'always_show_on_settings' => true, - ) ); + $params = wp_parse_args( + $params, + array( + 'dismissible' => true, + 'always_show_on_settings' => true, + ) + ); // if the notice is always shown on the settings page, and we're on the settings page if ( $params['always_show_on_settings'] && $this->get_plugin()->is_plugin_settings() ) { @@ -151,7 +157,6 @@ public function render_admin_notices( $is_visible = true ) { echo '
'; self::$admin_notice_placeholder_rendered = true; } - } @@ -171,7 +176,7 @@ public function render_delayed_admin_notices() { * @since 3.0.0 * @param string $message the notice message to display * @param string $message_id the message id - * @param array $params { + * @param array $params { * Optional parameters. * * @type bool $dismissible If the notice should be dismissible @@ -183,12 +188,15 @@ public function render_delayed_admin_notices() { */ public function render_admin_notice( $message, $message_id, $params = [] ) { - $params = wp_parse_args( $params, array( - 'dismissible' => true, - 'is_visible' => true, - 'always_show_on_settings' => true, - 'notice_class' => 'updated', - ) ); + $params = wp_parse_args( + $params, + array( + 'dismissible' => true, + 'is_visible' => true, + 'always_show_on_settings' => true, + 'notice_class' => 'updated', + ) + ); $classes = array( 'notice', @@ -202,7 +210,7 @@ public function render_admin_notice( $message, $message_id, $params = [] ) { $classes[] = 'is-dismissible'; } - echo sprintf( + printf( '

%5$s

', esc_attr( implode( ' ', $classes ) ), esc_attr( $this->get_plugin()->get_id() ), @@ -285,7 +293,7 @@ function log_dismissed_notice( pluginID, messageID ) { * * @since 3.0.0 * @param string $message_id the message identifier - * @param int $user_id optional user identifier, defaults to current user + * @param int $user_id optional user identifier, defaults to current user */ public function dismiss_notice( $message_id, $user_id = null ) { if ( is_null( $user_id ) ) { @@ -303,7 +311,7 @@ public function dismiss_notice( $message_id, $user_id = null ) { * @param string $message_id notice identifier * @param string|int $user_id */ - do_action( 'wc_' . $this->get_plugin()->get_id(). '_dismiss_notice', $message_id, $user_id ); + do_action( 'wc_' . $this->get_plugin()->get_id() . '_dismiss_notice', $message_id, $user_id ); } @@ -312,7 +320,7 @@ public function dismiss_notice( $message_id, $user_id = null ) { * * @since 3.0.0 * @param string $message_id the message identifier - * @param int $user_id optional user identifier, defaults to current user + * @param int $user_id optional user identifier, defaults to current user */ public function undismiss_notice( $message_id, $user_id = null ) { if ( is_null( $user_id ) ) { @@ -330,7 +338,7 @@ public function undismiss_notice( $message_id, $user_id = null ) { * * @since 3.0.0 * @param string $message_id the message identifier - * @param int $user_id optional user identifier, defaults to current user + * @param int $user_id optional user identifier, defaults to current user * @return boolean true if the message has been dismissed by the admin user */ public function is_notice_dismissed( $message_id, $user_id = null ) { @@ -386,6 +394,4 @@ public function handle_dismiss_notice() { protected function get_plugin() { return $this->plugin; } - - }