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