PluginProbe
404 Solution / 4.3.3
404 Solution v4.3.3
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / php / wordpress / WPNotices.php

WPNotices.php in 404 Solution 4.3.3, at includes/php/wordpress/WPNotices.php

77 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 if (!defined('ABSPATH')) {
5 exit;
6 }
7
8 class ABJ_404_Solution_WPNotices {
9
10 /** @var array<ABJ_404_Solution_WPNotice> */
11 private static $adminNotices = array();
12
13 /**
14 * Test seam: clear the accumulated admin-notice queue without private-field
15 * reflection. Resets to the empty-array default (M105 singleton-reset seam).
16 *
17 * @return void
18 */
19 public static function resetForTests(): void {
20 self::$adminNotices = array();
21 }
22
23 /** Display a message with the specified importance level.
24 * @param string $noticeLevel see ABJ_404_Solution_WPNotice for notice levels.
25 * @param string $message
26 */
27 /**
28 * @param string $noticeLevel
29 * @param string $message
30 * @return void
31 */
32 public static function registerAdminMessage(string $noticeLevel, string $message): void {
33 $notice = new ABJ_404_Solution_WPNotice($noticeLevel, $message);
34
35 self::registerAdminNotice($notice);
36 }
37
38 /** Display a message with the specified importance level.
39 * @param ABJ_404_Solution_WPNotice $adminNotice
40 */
41 /**
42 * @param ABJ_404_Solution_WPNotice $adminNotice
43 * @return void
44 */
45 public static function registerAdminNotice(ABJ_404_Solution_WPNotice $adminNotice): void {
46 self::$adminNotices[] = $adminNotice;
47
48 self::$adminNotices = array_unique(self::$adminNotices, SORT_REGULAR);
49 }
50
51 /**
52 * @return string the messages to display.
53 */
54 static function echoAdminNotices() {
55 $f = abj_service('functions');
56
57 $allHTML = '';
58 if (!abj_service('admin_access_policy')->isPluginAdmin()) {
59 return '';
60 }
61
62 foreach (self::$adminNotices as $oneNotice) {
63 $html = ABJ_404_Solution_FileSystemService::readFileContents(ABJ404_PATH . "/includes/html/notice.html");
64 $html = $f->str_replace('{class}', 'notice is-dismissable is-dismissible ' . $oneNotice->getType(), $html);
65 $msg = $oneNotice->getMessage();
66 $html = $f->str_replace('{message}', esc_html(is_string($msg) ? $msg : (is_scalar($msg) ? (string)$msg : '')), $html);
67
68 $allHTML .= $html;
69 }
70
71 echo $allHTML;
72
73 return $allHTML;
74 }
75
76 }
77