|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WordPress Admin Notifications |
|
4
|
|
|
* |
|
5
|
|
|
* Add static/dismissible admin notifications to WordPress |
|
6
|
|
|
* |
|
7
|
|
|
* @package amarkal-admin-notification |
|
8
|
|
|
* @author Askupa Software <[email protected]> |
|
9
|
|
|
* @link https://github.com/amarkal/amarkal-admin-notification |
|
10
|
|
|
* @copyright 2017 Askupa Software |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
// Prevent direct file access |
|
14
|
|
|
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Prevent loading the library more than once |
|
18
|
|
|
*/ |
|
19
|
|
|
if( defined( 'AMARKAL_ADMIN_NOTIFICATION' ) ) return false; |
|
20
|
|
|
define( 'AMARKAL_ADMIN_NOTIFICATION', true ); |
|
21
|
|
|
|
|
22
|
|
|
if(!function_exists('_amarkal_admin_notification_init')) |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Initiate admin notifications |
|
26
|
|
|
*/ |
|
27
|
|
|
function _amarkal_admin_notification_init() |
|
28
|
|
|
{ |
|
29
|
|
|
$notifier = Amarkal\Admin\Notifications::get_instance(); |
|
30
|
|
|
$notifier->init(); |
|
31
|
|
|
} |
|
32
|
|
|
add_action( 'init', '_amarkal_admin_notification_init' ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
if(!function_exists('amarkal_admin_notification')) |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* Register an admin notification. |
|
39
|
|
|
* |
|
40
|
|
|
* @param type $handle |
|
41
|
|
|
* @param type $html |
|
42
|
|
|
* @param type $type |
|
43
|
|
|
* @param type $dismissible |
|
44
|
|
|
* @param type $class |
|
45
|
|
|
* @param type $network |
|
46
|
|
|
*/ |
|
47
|
|
|
function amarkal_admin_notification( $handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false ) |
|
48
|
|
|
{ |
|
49
|
|
|
$notifier = Amarkal\Admin\Notifications::get_instance(); |
|
50
|
|
|
$notifier->register_notification($handle, array( |
|
51
|
|
|
'dismissible' => $dismissible, |
|
52
|
|
|
'class' => $class, |
|
53
|
|
|
'type' => $type, |
|
54
|
|
|
'html' => $html, |
|
55
|
|
|
'network' => $network |
|
56
|
|
|
)); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if(!function_exists('amarkal_reset_admin_notification')) |
|
61
|
|
|
{ |
|
62
|
|
|
/** |
|
63
|
|
|
* Reset a dismissed admin notification. |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $handle |
|
66
|
|
|
*/ |
|
67
|
|
|
function amarkal_reset_admin_notification( $handle ) |
|
68
|
|
|
{ |
|
69
|
|
|
$dismissed = get_site_option( 'amarkal_dismissed_notices', array() ); |
|
70
|
|
|
$offset = 0; |
|
71
|
|
|
foreach($dismissed as $id) |
|
72
|
|
|
{ |
|
73
|
|
|
if( $id === $handle ) break; |
|
74
|
|
|
$offset++; |
|
75
|
|
|
} |
|
76
|
|
|
array_splice( $dismissed, $offset, 1); |
|
77
|
|
|
update_site_option( 'amarkal_dismissed_notices', $dismissed ); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if(!function_exists('wp_admin_notification')) |
|
82
|
|
|
{ |
|
83
|
|
|
/** |
|
84
|
|
|
* @deprecated use amarkal_admin_notification instead |
|
85
|
|
|
*/ |
|
86
|
|
|
function wp_admin_notification( $handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false ) |
|
87
|
|
|
{ |
|
88
|
|
|
trigger_error('<b>wp_admin_notification()</b> has been deprecated. Use <b>amarkal_admin_notification</b> instead.'); |
|
89
|
|
|
amarkal_admin_notification( $handle, $html, $type, $dismissible, $class, $network ); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if(!function_exists('wp_reset_admin_notification')) |
|
94
|
|
|
{ |
|
95
|
|
|
/** |
|
96
|
|
|
* @deprecated use amarkal_reset_admin_notification instead |
|
97
|
|
|
*/ |
|
98
|
|
|
function wp_reset_admin_notification( $handle ) |
|
99
|
|
|
{ |
|
100
|
|
|
trigger_error('<b>wp_reset_admin_notification()</b> has been deprecated. Use <b>amarkal_reset_admin_notification</b> instead.'); |
|
101
|
|
|
amarkal_reset_admin_notification( $handle ); |
|
102
|
|
|
} |
|
103
|
|
|
} |
PHP has two types of connecting operators (logical operators, and boolean operators):
and&&or||The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&, or||.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
dieintroduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrowat this point:These limitations lead to logical operators rarely being of use in current PHP code.