'', 'type' => 'info', 'dismissible' => true, 'title' => '', 'actions' => [], 'screens' => [], // if empty → all screens 'image' => '', // new: optional image URL ]; $notice = wp_parse_args($args, $defaults); $notices = get_transient(self::TRANSIENT_KEY) ?: []; $notices[] = $notice; set_transient(self::TRANSIENT_KEY, $notices, 5 * MINUTE_IN_SECONDS); } /** * Display all notices. */ public static function display_notices() { $notices = get_transient(self::TRANSIENT_KEY); if (empty($notices)) { return; } $screen = get_current_screen(); foreach ($notices as $notice) { // Skip if this notice is restricted to specific screens if (!empty($notice['screens']) && !in_array($screen->id, $notice['screens'], true)) { continue; } $classes = ['notice', "notice-{$notice['type']}"]; if ($notice['dismissible']) { $classes[] = 'is-dismissible'; } echo '
' . esc_html($notice['title']) . '
'; } if (!empty($notice['message'])) { echo '' . wp_kses_post($notice['message']) . '
'; } if (!empty($notice['actions']) && is_array($notice['actions'])) { echo ''; foreach ($notice['actions'] as $action) { $class = !empty($action['primary']) ? 'button button-primary' : 'button'; printf( '%s', esc_url($action['url']), esc_attr($class), esc_html($action['label']) ); } echo '
'; } echo '