*/ private static $adminNotices = array(); /** * Test seam: clear the accumulated admin-notice queue without private-field * reflection. Resets to the empty-array default (M105 singleton-reset seam). * * @return void */ public static function resetForTests(): void { self::$adminNotices = array(); } /** Display a message with the specified importance level. * @param string $noticeLevel see ABJ_404_Solution_WPNotice for notice levels. * @param string $message */ /** * @param string $noticeLevel * @param string $message * @return void */ public static function registerAdminMessage(string $noticeLevel, string $message): void { $notice = new ABJ_404_Solution_WPNotice($noticeLevel, $message); self::registerAdminNotice($notice); } /** Display a message with the specified importance level. * @param ABJ_404_Solution_WPNotice $adminNotice */ /** * @param ABJ_404_Solution_WPNotice $adminNotice * @return void */ public static function registerAdminNotice(ABJ_404_Solution_WPNotice $adminNotice): void { self::$adminNotices[] = $adminNotice; self::$adminNotices = array_unique(self::$adminNotices, SORT_REGULAR); } /** * @return string the messages to display. */ static function echoAdminNotices() { $f = abj_service('functions'); $allHTML = ''; if (!abj_service('admin_access_policy')->isPluginAdmin()) { return ''; } foreach (self::$adminNotices as $oneNotice) { $html = ABJ_404_Solution_FileSystemService::readFileContents(ABJ404_PATH . "/includes/html/notice.html"); $html = $f->str_replace('{class}', 'notice is-dismissable is-dismissible ' . $oneNotice->getType(), $html); $msg = $oneNotice->getMessage(); $html = $f->str_replace('{message}', esc_html(is_string($msg) ? $msg : (is_scalar($msg) ? (string)$msg : '')), $html); $allHTML .= $html; } echo $allHTML; return $allHTML; } }