add_notice( $text, $type, $class, $dismissible ); } /** * Add admin notices to the $notices array. * * @since 1.5 * @param string $text The notice text. * @param string $type The notice type. * @param string $class The notice class. * @return void */ public function add_notice( $text = '', $type = '', $class = '', $dismissible = true ) { // Add type to class. $class .= $type ? ' notice-' . $type : ''; // notice-info, notice-success, notice-warning, notice-error $this->notices[] = [ 'text' => $text, 'type' => $type, 'class' => $class, 'dismissible' => $dismissible, ]; } /** * Return the $notices. * * @since 1.5 * @return array $notices The notice. */ public function get_notices() { if ( empty( $this->notices ) ) { return false; // bail early if no notices. } return $this->notices; } /** * Render admin notices in the WP admin. * * @since 1.5 * @return void */ public function alm_admin_notices() { $notices = $this->get_notices(); if ( ! $notices ) { return; // bail early if no notices. } // Loop notices. foreach ( $notices as $notice ) { $open = '

'; $close = '

' ?>
get_svg( $notice['type'] ); if ( $svg ) { echo wp_kses_post( $svg ); } } echo wp_kses_post( $open ) . wp_kses_post( $notice['text'] ) . wp_kses_post( $close ); ?>
'; case 'warning': return ''; case 'info': return ''; // case 'error': // return ''; } } /** * Allow SVGs in wp_kses. */ public function alm_wp_kses_allowed_html( $tags ) { $tags['svg'] = [ 'xmlns' => [], 'fill' => [], 'viewbox' => [], 'role' => [], 'aria-hidden' => [], 'focusable' => [], 'stroke' => [], 'stroke-width' => [], 'width' => [], 'height' => [], ]; $tags['path'] = [ 'd' => [], 'fill' => [], 'stroke-linecap' => [], 'stroke-linejoin' => [], ]; return $tags; } } }