@@ -10,20 +10,20 @@ discard block |
||
10 | 10 | * @copyright 2016 Askupa Software |
11 | 11 | */ |
12 | 12 | |
13 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
13 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Prevent loading the library more than once |
17 | 17 | */ |
18 | -if( defined( 'WP_ADMIN_NOTIFICATION' ) ) return; |
|
19 | -define( 'WP_ADMIN_NOTIFICATION', true ); |
|
18 | +if (defined('WP_ADMIN_NOTIFICATION')) return; |
|
19 | +define('WP_ADMIN_NOTIFICATION', true); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Require the handler class |
23 | 23 | */ |
24 | 24 | require_once 'handler.php'; |
25 | 25 | |
26 | -if(!function_exists('wp_admin_notification')) |
|
26 | +if (!function_exists('wp_admin_notification')) |
|
27 | 27 | { |
28 | 28 | /** |
29 | 29 | * |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param type $class |
35 | 35 | * @param type $network |
36 | 36 | */ |
37 | - function wp_admin_notification( $handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false ) |
|
37 | + function wp_admin_notification($handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false) |
|
38 | 38 | { |
39 | 39 | $notifier = WPAdminNotifications::get_instance(); |
40 | 40 | $notifier->register_notification($handle, array( |
@@ -47,22 +47,22 @@ discard block |
||
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | -if(!function_exists('wp_reset_admin_notification')) |
|
50 | +if (!function_exists('wp_reset_admin_notification')) |
|
51 | 51 | { |
52 | 52 | /** |
53 | 53 | * |
54 | 54 | * @param string $handle |
55 | 55 | */ |
56 | - function wp_reset_admin_notification( $handle ) |
|
56 | + function wp_reset_admin_notification($handle) |
|
57 | 57 | { |
58 | - $dismissed = get_option( 'wp_dismissed_notices' ); |
|
58 | + $dismissed = get_option('wp_dismissed_notices'); |
|
59 | 59 | $offset = 0; |
60 | - foreach($dismissed as $id) |
|
60 | + foreach ($dismissed as $id) |
|
61 | 61 | { |
62 | - if( $id === $handle ) break; |
|
62 | + if ($id === $handle) break; |
|
63 | 63 | $offset++; |
64 | 64 | } |
65 | - array_splice( $dismissed, $offset, 1); |
|
66 | - update_option( 'wp_dismissed_notices', $dismissed ); |
|
65 | + array_splice($dismissed, $offset, 1); |
|
66 | + update_option('wp_dismissed_notices', $dismissed); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | \ No newline at end of file |
@@ -15,7 +15,9 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Prevent loading the library more than once |
17 | 17 | */ |
18 | -if( defined( 'WP_ADMIN_NOTIFICATION' ) ) return; |
|
18 | +if( defined( 'WP_ADMIN_NOTIFICATION' ) ) { |
|
19 | + return; |
|
20 | +} |
|
19 | 21 | define( 'WP_ADMIN_NOTIFICATION', true ); |
20 | 22 | |
21 | 23 | /** |
@@ -59,7 +61,9 @@ discard block |
||
59 | 61 | $offset = 0; |
60 | 62 | foreach($dismissed as $id) |
61 | 63 | { |
62 | - if( $id === $handle ) break; |
|
64 | + if( $id === $handle ) { |
|
65 | + break; |
|
66 | + } |
|
63 | 67 | $offset++; |
64 | 68 | } |
65 | 69 | array_splice( $dismissed, $offset, 1); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if(!class_exists('WP_Admin_Notifications')) |
|
3 | +if (!class_exists('WP_Admin_Notifications')) |
|
4 | 4 | { |
5 | 5 | class WPAdminNotifications |
6 | 6 | { |
@@ -20,50 +20,50 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public static function get_instance() |
22 | 22 | { |
23 | - if( null === static::$instance ) |
|
23 | + if (null === static::$instance) |
|
24 | 24 | { |
25 | 25 | static::$instance = new static(); |
26 | 26 | } |
27 | 27 | return static::$instance; |
28 | 28 | } |
29 | 29 | |
30 | - public function register_notification( $handle, $options ) |
|
30 | + public function register_notification($handle, $options) |
|
31 | 31 | { |
32 | - if( 0 === count( $this->notifications ) ) |
|
32 | + if (0 === count($this->notifications)) |
|
33 | 33 | { |
34 | 34 | $this->init(); |
35 | 35 | } |
36 | 36 | |
37 | - if( !key_exists( $handle, $this->notifications ) ) |
|
37 | + if (!key_exists($handle, $this->notifications)) |
|
38 | 38 | { |
39 | 39 | $this->notifications[$handle] = $options; |
40 | 40 | } |
41 | - else trigger_error( "The handle <strong>$handle</strong> has already been registered. Please choose a different handle for your notification." ); |
|
41 | + else trigger_error("The handle <strong>$handle</strong> has already been registered. Please choose a different handle for your notification."); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function render_notifications() |
45 | 45 | { |
46 | - foreach($this->notifications as $handle => $notification) |
|
46 | + foreach ($this->notifications as $handle => $notification) |
|
47 | 47 | { |
48 | - $this->render_notification( $handle, $notification ); |
|
48 | + $this->render_notification($handle, $notification); |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | 52 | public function render_network_notifications() |
53 | 53 | { |
54 | - foreach( $this->notifications as $handle => $notification ) |
|
54 | + foreach ($this->notifications as $handle => $notification) |
|
55 | 55 | { |
56 | - if( $notification['network'] ) $this->render_notification( $handle, $notification ); |
|
56 | + if ($notification['network']) $this->render_notification($handle, $notification); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
60 | 60 | public function dismiss_notification() |
61 | 61 | { |
62 | - $id = filter_input( INPUT_POST, 'id' ); |
|
63 | - if( !in_array( $id, $this->dismissed_notices ) ) |
|
62 | + $id = filter_input(INPUT_POST, 'id'); |
|
63 | + if (!in_array($id, $this->dismissed_notices)) |
|
64 | 64 | { |
65 | 65 | $this->dismissed_notices[] = $id; |
66 | - update_option( 'wp_dismissed_notices', $this->dismissed_notices); |
|
66 | + update_option('wp_dismissed_notices', $this->dismissed_notices); |
|
67 | 67 | } |
68 | 68 | die(); |
69 | 69 | } |
@@ -86,24 +86,24 @@ discard block |
||
86 | 86 | |
87 | 87 | private function init() |
88 | 88 | { |
89 | - add_action( 'admin_notices', array( $this, 'render_notifications' ) ); |
|
90 | - add_action( 'network_admin_notices', array( $this, 'render_network_notifications' ) ); |
|
91 | - add_action( 'wp_ajax_dismiss_admin_notification', array( $this, 'dismiss_notification' ) ); |
|
92 | - add_action( 'admin_head', array( $this, 'render_script' ) ); |
|
89 | + add_action('admin_notices', array($this, 'render_notifications')); |
|
90 | + add_action('network_admin_notices', array($this, 'render_network_notifications')); |
|
91 | + add_action('wp_ajax_dismiss_admin_notification', array($this, 'dismiss_notification')); |
|
92 | + add_action('admin_head', array($this, 'render_script')); |
|
93 | 93 | $this->dismissed_notices = get_option('wp_dismissed_notices'); |
94 | - if( false === $this->dismissed_notices ) $this->dismissed_notices = array(); |
|
94 | + if (false === $this->dismissed_notices) $this->dismissed_notices = array(); |
|
95 | 95 | var_dump($this->dismissed_notices); |
96 | 96 | } |
97 | 97 | |
98 | - private function render_notification( $id, $n ) |
|
98 | + private function render_notification($id, $n) |
|
99 | 99 | { |
100 | - if( in_array( $id, $this->dismissed_notices ) ) return; |
|
100 | + if (in_array($id, $this->dismissed_notices)) return; |
|
101 | 101 | |
102 | 102 | printf( |
103 | 103 | '<div id="%s" class="notice notice-%s %s%s"><p>%s</p></div>', |
104 | 104 | $id, |
105 | 105 | $n['type'], |
106 | - $n['dismissible']?'is-dismissible ':'', |
|
106 | + $n['dismissible'] ? 'is-dismissible ' : '', |
|
107 | 107 | $n['class'], |
108 | 108 | $n['html'] |
109 | 109 | ); |
@@ -37,8 +37,9 @@ discard block |
||
37 | 37 | if( !key_exists( $handle, $this->notifications ) ) |
38 | 38 | { |
39 | 39 | $this->notifications[$handle] = $options; |
40 | + } else { |
|
41 | + trigger_error( "The handle <strong>$handle</strong> has already been registered. Please choose a different handle for your notification." ); |
|
40 | 42 | } |
41 | - else trigger_error( "The handle <strong>$handle</strong> has already been registered. Please choose a different handle for your notification." ); |
|
42 | 43 | } |
43 | 44 | |
44 | 45 | public function render_notifications() |
@@ -53,7 +54,9 @@ discard block |
||
53 | 54 | { |
54 | 55 | foreach( $this->notifications as $handle => $notification ) |
55 | 56 | { |
56 | - if( $notification['network'] ) $this->render_notification( $handle, $notification ); |
|
57 | + if( $notification['network'] ) { |
|
58 | + $this->render_notification( $handle, $notification ); |
|
59 | + } |
|
57 | 60 | } |
58 | 61 | } |
59 | 62 | |
@@ -91,13 +94,17 @@ discard block |
||
91 | 94 | add_action( 'wp_ajax_dismiss_admin_notification', array( $this, 'dismiss_notification' ) ); |
92 | 95 | add_action( 'admin_head', array( $this, 'render_script' ) ); |
93 | 96 | $this->dismissed_notices = get_option('wp_dismissed_notices'); |
94 | - if( false === $this->dismissed_notices ) $this->dismissed_notices = array(); |
|
97 | + if( false === $this->dismissed_notices ) { |
|
98 | + $this->dismissed_notices = array(); |
|
99 | + } |
|
95 | 100 | var_dump($this->dismissed_notices); |
96 | 101 | } |
97 | 102 | |
98 | 103 | private function render_notification( $id, $n ) |
99 | 104 | { |
100 | - if( in_array( $id, $this->dismissed_notices ) ) return; |
|
105 | + if( in_array( $id, $this->dismissed_notices ) ) { |
|
106 | + return; |
|
107 | + } |
|
101 | 108 | |
102 | 109 | printf( |
103 | 110 | '<div id="%s" class="notice notice-%s %s%s"><p>%s</p></div>', |