| 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 |
|