| 1 |
<?php |
| 2 |
|
| 3 |
class berqNotifications { |
| 4 |
// public $notices = []; |
| 5 |
|
| 6 |
function __construct() { |
| 7 |
add_action('admin_notices', [$this, 'notification']); |
| 8 |
add_action('init', [$this, 'session']); |
| 9 |
} |
| 10 |
|
| 11 |
function session() { |
| 12 |
if (is_admin()) { |
| 13 |
session_start(); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
function notification() { |
| 18 |
|
| 19 |
if (empty($_SESSION['berqwp_user_notice'])) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
$notices = $_SESSION['berqwp_user_notice']; |
| 24 |
|
| 25 |
|
| 26 |
if (!empty($notices)) { |
| 27 |
foreach($notices as $notice) { |
| 28 |
$msg = $notice[1]; |
| 29 |
$class = $notice[0]; |
| 30 |
|
| 31 |
$notice = '<div class="notice notice-'.$class.' is-dismissible">'; |
| 32 |
$notice .= '<p>'; |
| 33 |
$notice .= __($msg, 'searchpro'); |
| 34 |
$notice .= '</p>'; |
| 35 |
$notice .= '</div>'; |
| 36 |
echo wp_kses_post($notice); |
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
$_SESSION['berqwp_user_notice'] = []; |
| 41 |
} |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
function notice($text) { |
| 46 |
$_SESSION['berqwp_user_notice'][] = ['info', $text]; |
| 47 |
} |
| 48 |
|
| 49 |
function error($text) { |
| 50 |
$_SESSION['berqwp_user_notice'][] = ['error', $text]; |
| 51 |
} |
| 52 |
|
| 53 |
function warning($text) { |
| 54 |
$_SESSION['berqwp_user_notice'][] = ['warning', $text]; |
| 55 |
} |
| 56 |
|
| 57 |
function success($text) { |
| 58 |
$_SESSION['berqwp_user_notice'][] = ['success', $text]; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
global $berqNotifications; |
| 63 |
$berqNotifications = new berqNotifications(); |