notices = array(); add_action( 'admin_init', array( $this, 'nag_ignore' ) ); add_action( 'admin_notices', array( $this, 'add_notice' ), 50 ); } public function add_msg( $msg, $type, $global = false ) { $this->notices[] = array( 'msg' => $msg, 'type' => $type, 'global' => $global ); $this->nag_ignore(); } public function get_msgs( $globals = false ) { if ( $globals ) { return array_filter( $this->notices, function( $v ) { return $v['global']; } ); } return $this->notices; } public function clear_msgs( $globals = true ) { if ( $globals ) { $this->notices = array_filter( $this->notices, function( $v ) { return ! $v['global']; } ); } else { $this->notices = array(); } } public function show_msgs( $globals = false ) { $msgs = $this->get_msgs( $globals ); if ( ! empty( $msgs ) ) { foreach ( $msgs as $key => $msg ) { if ( ! $globals && $msg['global'] ) { continue; } echo '
' . $msg['msg'] . '
'; if ( 'error' !== $msg['type'] ) { echo '' . esc_html_e( 'Dismiss Notice', 'woodmart' ) . ''; echo ''; } echo '