PluginProbe
404 Solution / 4.2.0
404 Solution v4.2.0
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.2.0, at includes/php/wordpress/WPNotices.php

68 lines 2.0 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 /** Display a message with the specified importance level.
14 * @param string $noticeLevel see ABJ_404_Solution_WPNotice for notice levels.
15 * @param string $message
16 */
17 /**
18 * @param string $noticeLevel
19 * @param string $message
20 * @return void
21 */
22 public static function registerAdminMessage(string $noticeLevel, string $message): void {
23 $notice = new ABJ_404_Solution_WPNotice($noticeLevel, $message);
24
25 self::registerAdminNotice($notice);
26 }
27
28 /** Display a message with the specified importance level.
29 * @param ABJ_404_Solution_WPNotice $adminNotice
30 */
31 /**
32 * @param ABJ_404_Solution_WPNotice $adminNotice
33 * @return void
34 */
35 public static function registerAdminNotice(ABJ_404_Solution_WPNotice $adminNotice): void {
36 self::$adminNotices[] = $adminNotice;
37
38 self::$adminNotices = array_unique(self::$adminNotices, SORT_REGULAR);
39 }
40
41 /**
42 * @return string the messages to display.
43 */
44 static function echoAdminNotices() {
45 $f = abj_service('functions');
46 $abj404logic = abj_service('plugin_logic');
47
48 $allHTML = '';
49 if (!$abj404logic->userIsPluginAdmin()) {
50 return '';
51 }
52
53 foreach (self::$adminNotices as $oneNotice) {
54 $html = ABJ_404_Solution_Functions::readFileContents(ABJ404_PATH . "/includes/html/notice.html");
55 $html = $f->str_replace('{class}', 'notice is-dismissable is-dismissible ' . $oneNotice->getType(), $html);
56 $msg = $oneNotice->getMessage();
57 $html = $f->str_replace('{message}', esc_html(is_string($msg) ? $msg : (is_scalar($msg) ? (string)$msg : '')), $html);
58
59 $allHTML .= $html;
60 }
61
62 echo $allHTML;
63
64 return $allHTML;
65 }
66
67 }
68