@@ -14,71 +14,71 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $admin_url; |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $admin_url; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
30 | + /** |
|
31 | + * Reports components. |
|
32 | + * |
|
33 | + * @var GetPaid_Reports |
|
34 | + */ |
|
35 | 35 | public $reports; |
36 | 36 | |
37 | 37 | /** |
38 | - * Class constructor. |
|
39 | - */ |
|
40 | - public function __construct(){ |
|
38 | + * Class constructor. |
|
39 | + */ |
|
40 | + public function __construct(){ |
|
41 | 41 | |
42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | - $this->reports = new GetPaid_Reports(); |
|
43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | + $this->reports = new GetPaid_Reports(); |
|
45 | 45 | |
46 | 46 | if ( is_admin() ) { |
47 | - $this->init_admin_hooks(); |
|
47 | + $this->init_admin_hooks(); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Init action and filter hooks |
|
54 | - * |
|
55 | - */ |
|
56 | - private function init_admin_hooks() { |
|
53 | + * Init action and filter hooks |
|
54 | + * |
|
55 | + */ |
|
56 | + private function init_admin_hooks() { |
|
57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
64 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
65 | 65 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
66 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
66 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
67 | 67 | |
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
71 | - * Register admin scripts |
|
72 | - * |
|
73 | - */ |
|
74 | - public function enqeue_scripts() { |
|
71 | + * Register admin scripts |
|
72 | + * |
|
73 | + */ |
|
74 | + public function enqeue_scripts() { |
|
75 | 75 | global $current_screen, $pagenow; |
76 | 76 | |
77 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
78 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
77 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
78 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
79 | 79 | |
80 | 80 | if ( ! empty( $current_screen->post_type ) ) { |
81 | - $page = $current_screen->post_type; |
|
81 | + $page = $current_screen->post_type; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | // General styles. |
@@ -101,21 +101,21 @@ discard block |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | // Payment form scripts. |
104 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
104 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
105 | 105 | $this->load_payment_form_scripts(); |
106 | 106 | } |
107 | 107 | |
108 | - if ( $page == 'wpinv-subscriptions' ) { |
|
109 | - wp_enqueue_script( 'postbox' ); |
|
110 | - } |
|
108 | + if ( $page == 'wpinv-subscriptions' ) { |
|
109 | + wp_enqueue_script( 'postbox' ); |
|
110 | + } |
|
111 | 111 | |
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | - * Returns admin js translations. |
|
116 | - * |
|
117 | - */ |
|
118 | - protected function get_admin_i18() { |
|
115 | + * Returns admin js translations. |
|
116 | + * |
|
117 | + */ |
|
118 | + protected function get_admin_i18() { |
|
119 | 119 | global $post; |
120 | 120 | |
121 | 121 | $i18n = array( |
@@ -151,50 +151,50 @@ discard block |
||
151 | 151 | 'searching' => __( 'Searching', 'invoicing' ), |
152 | 152 | ); |
153 | 153 | |
154 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
154 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
155 | 155 | |
156 | - $invoice = new WPInv_Invoice( $post ); |
|
157 | - $i18n['save_invoice'] = sprintf( |
|
158 | - __( 'Save %s', 'invoicing' ), |
|
159 | - ucfirst( $invoice->get_type() ) |
|
160 | - ); |
|
156 | + $invoice = new WPInv_Invoice( $post ); |
|
157 | + $i18n['save_invoice'] = sprintf( |
|
158 | + __( 'Save %s', 'invoicing' ), |
|
159 | + ucfirst( $invoice->get_type() ) |
|
160 | + ); |
|
161 | 161 | |
162 | - $i18n['invoice_description'] = sprintf( |
|
163 | - __( '%s Description', 'invoicing' ), |
|
164 | - ucfirst( $invoice->get_type() ) |
|
165 | - ); |
|
162 | + $i18n['invoice_description'] = sprintf( |
|
163 | + __( '%s Description', 'invoicing' ), |
|
164 | + ucfirst( $invoice->get_type() ) |
|
165 | + ); |
|
166 | 166 | |
167 | - } |
|
168 | - return $i18n; |
|
167 | + } |
|
168 | + return $i18n; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
172 | - * Loads payment form js. |
|
173 | - * |
|
174 | - */ |
|
175 | - protected function load_payment_form_scripts() { |
|
172 | + * Loads payment form js. |
|
173 | + * |
|
174 | + */ |
|
175 | + protected function load_payment_form_scripts() { |
|
176 | 176 | global $post; |
177 | 177 | |
178 | 178 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
179 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
180 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
179 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
180 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
181 | 181 | |
182 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
183 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
182 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
183 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
184 | 184 | |
185 | - wp_localize_script( |
|
185 | + wp_localize_script( |
|
186 | 186 | 'wpinv-admin-payment-form-script', |
187 | 187 | 'wpinvPaymentFormAdmin', |
188 | 188 | array( |
189 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
190 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
191 | - 'currency' => wpinv_currency_symbol(), |
|
192 | - 'position' => wpinv_currency_position(), |
|
193 | - 'decimals' => (int) wpinv_decimals(), |
|
194 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
195 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
196 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
197 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
189 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
190 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
191 | + 'currency' => wpinv_currency_symbol(), |
|
192 | + 'position' => wpinv_currency_position(), |
|
193 | + 'decimals' => (int) wpinv_decimals(), |
|
194 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
195 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
196 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
197 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
198 | 198 | ) |
199 | 199 | ); |
200 | 200 | |
@@ -203,20 +203,20 @@ discard block |
||
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
206 | - * Add our classes to admin pages. |
|
206 | + * Add our classes to admin pages. |
|
207 | 207 | * |
208 | 208 | * @param string $classes |
209 | 209 | * @return string |
210 | - * |
|
211 | - */ |
|
210 | + * |
|
211 | + */ |
|
212 | 212 | public function admin_body_class( $classes ) { |
213 | - global $pagenow, $post, $current_screen; |
|
213 | + global $pagenow, $post, $current_screen; |
|
214 | 214 | |
215 | 215 | |
216 | 216 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
217 | 217 | |
218 | 218 | if ( ! empty( $current_screen->post_type ) ) { |
219 | - $page = $current_screen->post_type; |
|
219 | + $page = $current_screen->post_type; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -225,29 +225,29 @@ discard block |
||
225 | 225 | |
226 | 226 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
227 | 227 | $classes .= ' wpinv-cpt wpinv'; |
228 | - } |
|
228 | + } |
|
229 | 229 | |
230 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
230 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
231 | 231 | $classes .= ' getpaid-is-invoice-cpt'; |
232 | 232 | } |
233 | 233 | |
234 | - return $classes; |
|
234 | + return $classes; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
238 | - * Maybe show the AyeCode Connect Notice. |
|
239 | - */ |
|
240 | - public function init_ayecode_connect_helper(){ |
|
238 | + * Maybe show the AyeCode Connect Notice. |
|
239 | + */ |
|
240 | + public function init_ayecode_connect_helper(){ |
|
241 | 241 | |
242 | 242 | new AyeCode_Connect_Helper( |
243 | 243 | array( |
244 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
245 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
246 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
247 | - 'connect_button' => __("Connect Site","invoicing"), |
|
248 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
249 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
250 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
244 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
245 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
246 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
247 | + 'connect_button' => __("Connect Site","invoicing"), |
|
248 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
249 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
250 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
251 | 251 | ), |
252 | 252 | array( 'wpi-addons' ) |
253 | 253 | ); |
@@ -259,21 +259,21 @@ discard block |
||
259 | 259 | */ |
260 | 260 | public function activation_redirect() { |
261 | 261 | |
262 | - // Bail if no activation redirect. |
|
263 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
264 | - return; |
|
265 | - } |
|
262 | + // Bail if no activation redirect. |
|
263 | + if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
264 | + return; |
|
265 | + } |
|
266 | 266 | |
267 | - // Delete the redirect transient. |
|
268 | - delete_transient( '_wpinv_activation_redirect' ); |
|
267 | + // Delete the redirect transient. |
|
268 | + delete_transient( '_wpinv_activation_redirect' ); |
|
269 | 269 | |
270 | - // Bail if activating from network, or bulk |
|
271 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
272 | - return; |
|
273 | - } |
|
270 | + // Bail if activating from network, or bulk |
|
271 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
272 | + return; |
|
273 | + } |
|
274 | 274 | |
275 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
276 | - exit; |
|
275 | + wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
276 | + exit; |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -288,162 +288,162 @@ discard block |
||
288 | 288 | |
289 | 289 | } |
290 | 290 | |
291 | - /** |
|
291 | + /** |
|
292 | 292 | * Sends a payment reminder to a customer. |
293 | - * |
|
294 | - * @param array $args |
|
293 | + * |
|
294 | + * @param array $args |
|
295 | 295 | */ |
296 | 296 | public function send_customer_invoice( $args ) { |
297 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
297 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
298 | 298 | |
299 | - if ( $sent ) { |
|
300 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
301 | - } else { |
|
302 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
303 | - } |
|
299 | + if ( $sent ) { |
|
300 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
301 | + } else { |
|
302 | + $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
303 | + } |
|
304 | 304 | |
305 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
306 | - exit; |
|
307 | - } |
|
305 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
306 | + exit; |
|
307 | + } |
|
308 | 308 | |
309 | - /** |
|
309 | + /** |
|
310 | 310 | * Sends a payment reminder to a customer. |
311 | - * |
|
312 | - * @param array $args |
|
311 | + * |
|
312 | + * @param array $args |
|
313 | 313 | */ |
314 | 314 | public function send_customer_payment_reminder( $args ) { |
315 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
315 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
316 | 316 | |
317 | - if ( $sent ) { |
|
318 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
319 | - } else { |
|
320 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
321 | - } |
|
317 | + if ( $sent ) { |
|
318 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
319 | + } else { |
|
320 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
321 | + } |
|
322 | 322 | |
323 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
324 | - exit; |
|
325 | - } |
|
323 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
324 | + exit; |
|
325 | + } |
|
326 | 326 | |
327 | - /** |
|
327 | + /** |
|
328 | 328 | * Resets tax rates. |
329 | - * |
|
329 | + * |
|
330 | 330 | */ |
331 | 331 | public function admin_reset_tax_rates() { |
332 | 332 | |
333 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
334 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
335 | - exit; |
|
333 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
334 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
335 | + exit; |
|
336 | 336 | |
337 | - } |
|
337 | + } |
|
338 | 338 | |
339 | 339 | /** |
340 | - * Returns an array of admin notices. |
|
341 | - * |
|
342 | - * @since 1.0.19 |
|
340 | + * Returns an array of admin notices. |
|
341 | + * |
|
342 | + * @since 1.0.19 |
|
343 | 343 | * @return array |
344 | - */ |
|
345 | - public function get_notices() { |
|
346 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
344 | + */ |
|
345 | + public function get_notices() { |
|
346 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
347 | 347 | return is_array( $notices ) ? $notices : array(); |
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Clears all admin notices |
|
352 | - * |
|
353 | - * @access public |
|
354 | - * @since 1.0.19 |
|
355 | - */ |
|
356 | - public function clear_notices() { |
|
357 | - delete_option( 'wpinv_admin_notices' ); |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Saves a new admin notice |
|
362 | - * |
|
363 | - * @access public |
|
364 | - * @since 1.0.19 |
|
365 | - */ |
|
366 | - public function save_notice( $type, $message ) { |
|
367 | - $notices = $this->get_notices(); |
|
368 | - |
|
369 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
370 | - $notices[ $type ] = array(); |
|
371 | - } |
|
372 | - |
|
373 | - $notices[ $type ][] = $message; |
|
374 | - |
|
375 | - update_option( 'wpinv_admin_notices', $notices ); |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Displays a success notice |
|
380 | - * |
|
381 | - * @param string $msg The message to qeue. |
|
382 | - * @access public |
|
383 | - * @since 1.0.19 |
|
384 | - */ |
|
385 | - public function show_success( $msg ) { |
|
386 | - $this->save_notice( 'success', $msg ); |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Displays a error notice |
|
391 | - * |
|
392 | - * @access public |
|
393 | - * @param string $msg The message to qeue. |
|
394 | - * @since 1.0.19 |
|
395 | - */ |
|
396 | - public function show_error( $msg ) { |
|
397 | - $this->save_notice( 'error', $msg ); |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * Displays a warning notice |
|
402 | - * |
|
403 | - * @access public |
|
404 | - * @param string $msg The message to qeue. |
|
405 | - * @since 1.0.19 |
|
406 | - */ |
|
407 | - public function show_warning( $msg ) { |
|
408 | - $this->save_notice( 'warning', $msg ); |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Displays a info notice |
|
413 | - * |
|
414 | - * @access public |
|
415 | - * @param string $msg The message to qeue. |
|
416 | - * @since 1.0.19 |
|
417 | - */ |
|
418 | - public function show_info( $msg ) { |
|
419 | - $this->save_notice( 'info', $msg ); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Show notices |
|
424 | - * |
|
425 | - * @access public |
|
426 | - * @since 1.0.19 |
|
427 | - */ |
|
428 | - public function show_notices() { |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * Clears all admin notices |
|
352 | + * |
|
353 | + * @access public |
|
354 | + * @since 1.0.19 |
|
355 | + */ |
|
356 | + public function clear_notices() { |
|
357 | + delete_option( 'wpinv_admin_notices' ); |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Saves a new admin notice |
|
362 | + * |
|
363 | + * @access public |
|
364 | + * @since 1.0.19 |
|
365 | + */ |
|
366 | + public function save_notice( $type, $message ) { |
|
367 | + $notices = $this->get_notices(); |
|
368 | + |
|
369 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
370 | + $notices[ $type ] = array(); |
|
371 | + } |
|
372 | + |
|
373 | + $notices[ $type ][] = $message; |
|
374 | + |
|
375 | + update_option( 'wpinv_admin_notices', $notices ); |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Displays a success notice |
|
380 | + * |
|
381 | + * @param string $msg The message to qeue. |
|
382 | + * @access public |
|
383 | + * @since 1.0.19 |
|
384 | + */ |
|
385 | + public function show_success( $msg ) { |
|
386 | + $this->save_notice( 'success', $msg ); |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Displays a error notice |
|
391 | + * |
|
392 | + * @access public |
|
393 | + * @param string $msg The message to qeue. |
|
394 | + * @since 1.0.19 |
|
395 | + */ |
|
396 | + public function show_error( $msg ) { |
|
397 | + $this->save_notice( 'error', $msg ); |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * Displays a warning notice |
|
402 | + * |
|
403 | + * @access public |
|
404 | + * @param string $msg The message to qeue. |
|
405 | + * @since 1.0.19 |
|
406 | + */ |
|
407 | + public function show_warning( $msg ) { |
|
408 | + $this->save_notice( 'warning', $msg ); |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Displays a info notice |
|
413 | + * |
|
414 | + * @access public |
|
415 | + * @param string $msg The message to qeue. |
|
416 | + * @since 1.0.19 |
|
417 | + */ |
|
418 | + public function show_info( $msg ) { |
|
419 | + $this->save_notice( 'info', $msg ); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Show notices |
|
424 | + * |
|
425 | + * @access public |
|
426 | + * @since 1.0.19 |
|
427 | + */ |
|
428 | + public function show_notices() { |
|
429 | 429 | |
430 | 430 | $notices = $this->get_notices(); |
431 | 431 | $this->clear_notices(); |
432 | 432 | |
433 | - foreach ( $notices as $type => $messages ) { |
|
433 | + foreach ( $notices as $type => $messages ) { |
|
434 | 434 | |
435 | - if ( ! is_array( $messages ) ) { |
|
436 | - continue; |
|
437 | - } |
|
435 | + if ( ! is_array( $messages ) ) { |
|
436 | + continue; |
|
437 | + } |
|
438 | 438 | |
439 | 439 | $type = sanitize_key( $type ); |
440 | - foreach ( $messages as $message ) { |
|
440 | + foreach ( $messages as $message ) { |
|
441 | 441 | $message = wp_kses_post( $message ); |
442 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
442 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | } |
446 | 446 | |
447 | - } |
|
447 | + } |
|
448 | 448 | |
449 | 449 | } |