@@ -6,12 +6,12 @@ |
||
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 | * Prevent loading the library more than once |
13 | 13 | */ |
14 | -if( defined( 'AMARKAL_ADMIN_NOTIFICATION' ) ) return; |
|
15 | -define( 'AMARKAL_ADMIN_NOTIFICATION', true ); |
|
14 | +if (defined('AMARKAL_ADMIN_NOTIFICATION')) return; |
|
15 | +define('AMARKAL_ADMIN_NOTIFICATION', true); |
|
16 | 16 | |
17 | 17 | require_once 'functions.php'; |
@@ -11,7 +11,9 @@ |
||
11 | 11 | /** |
12 | 12 | * Prevent loading the library more than once |
13 | 13 | */ |
14 | -if( defined( 'AMARKAL_ADMIN_NOTIFICATION' ) ) return; |
|
14 | +if( defined( 'AMARKAL_ADMIN_NOTIFICATION' ) ) { |
|
15 | + return; |
|
16 | +} |
|
15 | 17 | define( 'AMARKAL_ADMIN_NOTIFICATION', true ); |
16 | 18 | |
17 | 19 | require_once 'functions.php'; |
@@ -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 | ); |
@@ -11,9 +11,9 @@ 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 | -if(!function_exists('_amarkal_admin_notification_init')) |
|
16 | +if (!function_exists('_amarkal_admin_notification_init')) |
|
17 | 17 | { |
18 | 18 | /** |
19 | 19 | * Initiate admin notifications |
@@ -23,10 +23,10 @@ discard block |
||
23 | 23 | $notifier = Amarkal\Admin\Notifications::get_instance(); |
24 | 24 | $notifier->init(); |
25 | 25 | } |
26 | - add_action( 'init', '_amarkal_admin_notification_init' ); |
|
26 | + add_action('init', '_amarkal_admin_notification_init'); |
|
27 | 27 | } |
28 | 28 | |
29 | -if(!function_exists('amarkal_admin_notification')) |
|
29 | +if (!function_exists('amarkal_admin_notification')) |
|
30 | 30 | { |
31 | 31 | /** |
32 | 32 | * Register an admin notification. |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @param type $class |
39 | 39 | * @param type $network |
40 | 40 | */ |
41 | - function amarkal_admin_notification( $handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false ) |
|
41 | + function amarkal_admin_notification($handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false) |
|
42 | 42 | { |
43 | 43 | $notifier = Amarkal\Admin\Notifications::get_instance(); |
44 | 44 | $notifier->register_notification($handle, array( |
@@ -51,47 +51,47 @@ discard block |
||
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
54 | -if(!function_exists('amarkal_reset_admin_notification')) |
|
54 | +if (!function_exists('amarkal_reset_admin_notification')) |
|
55 | 55 | { |
56 | 56 | /** |
57 | 57 | * Reset a dismissed admin notification. |
58 | 58 | * |
59 | 59 | * @param string $handle |
60 | 60 | */ |
61 | - function amarkal_reset_admin_notification( $handle ) |
|
61 | + function amarkal_reset_admin_notification($handle) |
|
62 | 62 | { |
63 | - $dismissed = get_site_option( 'amarkal_dismissed_notices', array() ); |
|
63 | + $dismissed = get_site_option('amarkal_dismissed_notices', array()); |
|
64 | 64 | $offset = 0; |
65 | - foreach($dismissed as $id) |
|
65 | + foreach ($dismissed as $id) |
|
66 | 66 | { |
67 | - if( $id === $handle ) break; |
|
67 | + if ($id === $handle) break; |
|
68 | 68 | $offset++; |
69 | 69 | } |
70 | - array_splice( $dismissed, $offset, 1); |
|
71 | - update_site_option( 'amarkal_dismissed_notices', $dismissed ); |
|
70 | + array_splice($dismissed, $offset, 1); |
|
71 | + update_site_option('amarkal_dismissed_notices', $dismissed); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | -if(!function_exists('wp_admin_notification')) |
|
75 | +if (!function_exists('wp_admin_notification')) |
|
76 | 76 | { |
77 | 77 | /** |
78 | 78 | * @deprecated use amarkal_admin_notification instead |
79 | 79 | */ |
80 | - function wp_admin_notification( $handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false ) |
|
80 | + function wp_admin_notification($handle, $html, $type = 'success', $dismissible = false, $class = '', $network = false) |
|
81 | 81 | { |
82 | 82 | trigger_error('<b>wp_admin_notification()</b> has been deprecated. Use <b>amarkal_admin_notification</b> instead.'); |
83 | - amarkal_admin_notification( $handle, $html, $type, $dismissible, $class, $network ); |
|
83 | + amarkal_admin_notification($handle, $html, $type, $dismissible, $class, $network); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | -if(!function_exists('wp_reset_admin_notification')) |
|
87 | +if (!function_exists('wp_reset_admin_notification')) |
|
88 | 88 | { |
89 | 89 | /** |
90 | 90 | * @deprecated use amarkal_reset_admin_notification instead |
91 | 91 | */ |
92 | - function wp_reset_admin_notification( $handle ) |
|
92 | + function wp_reset_admin_notification($handle) |
|
93 | 93 | { |
94 | 94 | trigger_error('<b>wp_reset_admin_notification()</b> has been deprecated. Use <b>amarkal_reset_admin_notification</b> instead.'); |
95 | - amarkal_reset_admin_notification( $handle ); |
|
95 | + amarkal_reset_admin_notification($handle); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | \ No newline at end of file |
@@ -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 | * Prevent loading the library more than once |
13 | 13 | */ |
14 | -if( defined( 'AMARKAL_ADMIN_NOTIFICATION' ) ) return; |
|
15 | -define( 'AMARKAL_ADMIN_NOTIFICATION', true ); |
|
14 | +if (defined('AMARKAL_ADMIN_NOTIFICATION')) return; |
|
15 | +define('AMARKAL_ADMIN_NOTIFICATION', true); |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Load required classes |
@@ -11,7 +11,9 @@ |
||
11 | 11 | /** |
12 | 12 | * Prevent loading the library more than once |
13 | 13 | */ |
14 | -if( defined( 'AMARKAL_ADMIN_NOTIFICATION' ) ) return; |
|
14 | +if( defined( 'AMARKAL_ADMIN_NOTIFICATION' ) ) { |
|
15 | + return; |
|
16 | +} |
|
15 | 17 | define( 'AMARKAL_ADMIN_NOTIFICATION', true ); |
16 | 18 | |
17 | 19 | /** |