@@ -41,8 +41,9 @@ discard block |
||
41 | 41 | if( !key_exists( $handle, $this->notifications ) ) |
42 | 42 | { |
43 | 43 | $this->notifications[$handle] = $options; |
44 | + } else { |
|
45 | + trigger_error( "The handle <strong>$handle</strong> has already been registered. Please choose a different handle for your notification." ); |
|
44 | 46 | } |
45 | - else trigger_error( "The handle <strong>$handle</strong> has already been registered. Please choose a different handle for your notification." ); |
|
46 | 47 | } |
47 | 48 | |
48 | 49 | public function render_notifications() |
@@ -57,7 +58,9 @@ discard block |
||
57 | 58 | { |
58 | 59 | foreach( $this->notifications as $handle => $notification ) |
59 | 60 | { |
60 | - if( $notification['network'] ) $this->render_notification( $handle, $notification ); |
|
61 | + if( $notification['network'] ) { |
|
62 | + $this->render_notification( $handle, $notification ); |
|
63 | + } |
|
61 | 64 | } |
62 | 65 | } |
63 | 66 | |
@@ -74,7 +77,9 @@ discard block |
||
74 | 77 | |
75 | 78 | public function render_script() |
76 | 79 | { |
77 | - if( 0 === count( $this->notifications ) ) return; |
|
80 | + if( 0 === count( $this->notifications ) ) { |
|
81 | + return; |
|
82 | + } |
|
78 | 83 | ?> |
79 | 84 | <script> |
80 | 85 | jQuery(document).ready(function($){ |
@@ -91,7 +96,9 @@ discard block |
||
91 | 96 | |
92 | 97 | private function render_notification( $id, $n ) |
93 | 98 | { |
94 | - if( in_array( $id, $this->dismissed_notices ) ) return; |
|
99 | + if( in_array( $id, $this->dismissed_notices ) ) { |
|
100 | + return; |
|
101 | + } |
|
95 | 102 | |
96 | 103 | printf( |
97 | 104 | '<div id="%s" class="notice notice-%s %s%s"><p>%s</p></div>', |
@@ -20,7 +20,7 @@ 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 | } |
@@ -29,52 +29,52 @@ discard block |
||
29 | 29 | |
30 | 30 | public function init() |
31 | 31 | { |
32 | - add_action( 'admin_notices', array( $this, 'render_notifications' ) ); |
|
33 | - add_action( 'network_admin_notices', array( $this, 'render_network_notifications' ) ); |
|
34 | - add_action( 'wp_ajax_dismiss_admin_notification', array( $this, 'dismiss_notification' ) ); |
|
35 | - add_action( 'admin_footer', array( $this, 'render_script' ) ); // Must be hooked to a late action hook |
|
36 | - $this->dismissed_notices = get_site_option( 'amarkal_dismissed_notices', array() ); |
|
32 | + add_action('admin_notices', array($this, 'render_notifications')); |
|
33 | + add_action('network_admin_notices', array($this, 'render_network_notifications')); |
|
34 | + add_action('wp_ajax_dismiss_admin_notification', array($this, 'dismiss_notification')); |
|
35 | + add_action('admin_footer', array($this, 'render_script')); // Must be hooked to a late action hook |
|
36 | + $this->dismissed_notices = get_site_option('amarkal_dismissed_notices', array()); |
|
37 | 37 | } |
38 | 38 | |
39 | - public function register_notification( $handle, $options ) |
|
39 | + public function register_notification($handle, $options) |
|
40 | 40 | { |
41 | - if( !key_exists( $handle, $this->notifications ) ) |
|
41 | + if (!key_exists($handle, $this->notifications)) |
|
42 | 42 | { |
43 | 43 | $this->notifications[$handle] = $options; |
44 | 44 | } |
45 | - else trigger_error( "The handle <strong>$handle</strong> has already been registered. Please choose a different handle for your notification." ); |
|
45 | + else trigger_error("The handle <strong>$handle</strong> has already been registered. Please choose a different handle for your notification."); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | public function render_notifications() |
49 | 49 | { |
50 | - foreach($this->notifications as $handle => $notification) |
|
50 | + foreach ($this->notifications as $handle => $notification) |
|
51 | 51 | { |
52 | - $this->render_notification( $handle, $notification ); |
|
52 | + $this->render_notification($handle, $notification); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
56 | 56 | public function render_network_notifications() |
57 | 57 | { |
58 | - foreach( $this->notifications as $handle => $notification ) |
|
58 | + foreach ($this->notifications as $handle => $notification) |
|
59 | 59 | { |
60 | - if( $notification['network'] ) $this->render_notification( $handle, $notification ); |
|
60 | + if ($notification['network']) $this->render_notification($handle, $notification); |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | 64 | public function dismiss_notification() |
65 | 65 | { |
66 | - $id = filter_input( INPUT_POST, 'id' ); |
|
67 | - if( !in_array( $id, $this->dismissed_notices ) ) |
|
66 | + $id = filter_input(INPUT_POST, 'id'); |
|
67 | + if (!in_array($id, $this->dismissed_notices)) |
|
68 | 68 | { |
69 | 69 | $this->dismissed_notices[] = $id; |
70 | - update_site_option( 'amarkal_dismissed_notices', $this->dismissed_notices); |
|
70 | + update_site_option('amarkal_dismissed_notices', $this->dismissed_notices); |
|
71 | 71 | } |
72 | 72 | wp_die(); |
73 | 73 | } |
74 | 74 | |
75 | 75 | public function render_script() |
76 | 76 | { |
77 | - if( 0 === count( $this->notifications ) ) return; |
|
77 | + if (0 === count($this->notifications)) return; |
|
78 | 78 | ?> |
79 | 79 | <script> |
80 | 80 | jQuery(document).ready(function($){ |
@@ -89,15 +89,15 @@ discard block |
||
89 | 89 | <?php |
90 | 90 | } |
91 | 91 | |
92 | - private function render_notification( $id, $n ) |
|
92 | + private function render_notification($id, $n) |
|
93 | 93 | { |
94 | - if( in_array( $id, $this->dismissed_notices ) ) return; |
|
94 | + if (in_array($id, $this->dismissed_notices)) return; |
|
95 | 95 | |
96 | 96 | printf( |
97 | 97 | '<div id="%s" class="notice notice-%s %s%s"><p>%s</p></div>', |
98 | 98 | $id, |
99 | 99 | $n['type'], |
100 | - $n['dismissible']?'is-dismissible ':'', |
|
100 | + $n['dismissible'] ? 'is-dismissible ' : '', |
|
101 | 101 | $n['class'], |
102 | 102 | $n['html'] |
103 | 103 | ); |
@@ -6,7 +6,7 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | // Prevent direct file access |
9 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
9 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
10 | 10 | |
11 | 11 | // Load module functions |
12 | 12 | require_once 'functions.php'; |
@@ -11,15 +11,15 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | // Prevent direct file access |
14 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
14 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Prevent loading the library more than once |
18 | 18 | */ |
19 | -if( defined( 'AMARKAL_ADMIN_NOTIFICATION' ) ) return false; |
|
20 | -define( 'AMARKAL_ADMIN_NOTIFICATION', true ); |
|
19 | +if (defined('AMARKAL_ADMIN_NOTIFICATION')) return false; |
|
20 | +define('AMARKAL_ADMIN_NOTIFICATION', true); |
|
21 | 21 | |
22 | -if(!function_exists('_amarkal_admin_notification_init')) |
|
22 | +if (!function_exists('_amarkal_admin_notification_init')) |
|
23 | 23 | { |
24 | 24 | /** |
25 | 25 | * Initiate admin notifications |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | $notifier = Amarkal\Admin\Notifications::get_instance(); |
30 | 30 | $notifier->init(); |
31 | 31 | } |
32 | - add_action( 'init', '_amarkal_admin_notification_init' ); |
|
32 | + add_action('init', '_amarkal_admin_notification_init'); |
|
33 | 33 | } |
34 | 34 | |
35 | -if(!function_exists('amarkal_admin_notification')) |
|
35 | +if (!function_exists('amarkal_admin_notification')) |
|
36 | 36 | { |
37 | 37 | /** |
38 | 38 | * Register an admin notification. |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param type $class |
45 | 45 | * @param type $network |
46 | 46 | */ |
47 | - function amarkal_admin_notification( $handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false ) |
|
47 | + function amarkal_admin_notification($handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false) |
|
48 | 48 | { |
49 | 49 | $notifier = Amarkal\Admin\Notifications::get_instance(); |
50 | 50 | $notifier->register_notification($handle, array( |
@@ -57,47 +57,47 @@ discard block |
||
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
60 | -if(!function_exists('amarkal_reset_admin_notification')) |
|
60 | +if (!function_exists('amarkal_reset_admin_notification')) |
|
61 | 61 | { |
62 | 62 | /** |
63 | 63 | * Reset a dismissed admin notification. |
64 | 64 | * |
65 | 65 | * @param string $handle |
66 | 66 | */ |
67 | - function amarkal_reset_admin_notification( $handle ) |
|
67 | + function amarkal_reset_admin_notification($handle) |
|
68 | 68 | { |
69 | - $dismissed = get_site_option( 'amarkal_dismissed_notices', array() ); |
|
69 | + $dismissed = get_site_option('amarkal_dismissed_notices', array()); |
|
70 | 70 | $offset = 0; |
71 | - foreach($dismissed as $id) |
|
71 | + foreach ($dismissed as $id) |
|
72 | 72 | { |
73 | - if( $id === $handle ) break; |
|
73 | + if ($id === $handle) break; |
|
74 | 74 | $offset++; |
75 | 75 | } |
76 | - array_splice( $dismissed, $offset, 1); |
|
77 | - update_site_option( 'amarkal_dismissed_notices', $dismissed ); |
|
76 | + array_splice($dismissed, $offset, 1); |
|
77 | + update_site_option('amarkal_dismissed_notices', $dismissed); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | -if(!function_exists('wp_admin_notification')) |
|
81 | +if (!function_exists('wp_admin_notification')) |
|
82 | 82 | { |
83 | 83 | /** |
84 | 84 | * @deprecated use amarkal_admin_notification instead |
85 | 85 | */ |
86 | - function wp_admin_notification( $handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false ) |
|
86 | + function wp_admin_notification($handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false) |
|
87 | 87 | { |
88 | 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 ); |
|
89 | + amarkal_admin_notification($handle, $html, $type, $dismissible, $class, $network); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | -if(!function_exists('wp_reset_admin_notification')) |
|
93 | +if (!function_exists('wp_reset_admin_notification')) |
|
94 | 94 | { |
95 | 95 | /** |
96 | 96 | * @deprecated use amarkal_reset_admin_notification instead |
97 | 97 | */ |
98 | - function wp_reset_admin_notification( $handle ) |
|
98 | + function wp_reset_admin_notification($handle) |
|
99 | 99 | { |
100 | 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 ); |
|
101 | + amarkal_reset_admin_notification($handle); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | \ No newline at end of file |
@@ -16,7 +16,9 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * Prevent loading the library more than once |
18 | 18 | */ |
19 | -if( defined( 'AMARKAL_ADMIN_NOTIFICATION' ) ) return false; |
|
19 | +if( defined( 'AMARKAL_ADMIN_NOTIFICATION' ) ) { |
|
20 | + return false; |
|
21 | +} |
|
20 | 22 | define( 'AMARKAL_ADMIN_NOTIFICATION', true ); |
21 | 23 | |
22 | 24 | if(!function_exists('_amarkal_admin_notification_init')) |
@@ -70,7 +72,9 @@ discard block |
||
70 | 72 | $offset = 0; |
71 | 73 | foreach($dismissed as $id) |
72 | 74 | { |
73 | - if( $id === $handle ) break; |
|
75 | + if( $id === $handle ) { |
|
76 | + break; |
|
77 | + } |
|
74 | 78 | $offset++; |
75 | 79 | } |
76 | 80 | array_splice( $dismissed, $offset, 1); |
@@ -6,13 +6,13 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | // Prevent direct file access |
9 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
9 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Load module functions. If this amarkal module has not been loaded, |
13 | 13 | * functions.php will not return false. |
14 | 14 | */ |
15 | -if(false !== (require_once 'functions.php')) |
|
15 | +if (false !== (require_once 'functions.php')) |
|
16 | 16 | { |
17 | 17 | // Load required classes if not using composer |
18 | 18 | require_once 'Notifications.php'; |