Passed
Push — master ( af6e37...385462 )
by Brian
04:02
created

GetPaid_Admin::clear_notices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Contains the admin class.
4
 *
5
 */
6
7
defined( 'ABSPATH' ) || exit;
8
9
/**
10
 * The main admin class.
11
 *
12
 * @since       1.0.19
13
 */
14
class GetPaid_Admin {
15
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;
29
	
30
	/**
31
	 * Reports components.
32
	 *
33
	 * @var GetPaid_Reports
34
	 */
35
    public $reports;
36
37
    /**
38
	 * Class constructor.
39
	 */
40
	public function __construct(){
41
42
        $this->admin_path  = plugin_dir_path( __FILE__ );
43
		$this->admin_url   = plugins_url( '/', __FILE__ );
44
		$this->reports     = new GetPaid_Reports();
45
46
        if ( is_admin() ) {
47
			$this->init_admin_hooks();
48
        }
49
50
    }
51
52
    /**
53
	 * Init action and filter hooks
54
	 *
55
	 */
56
	private function init_admin_hooks() {
57
        add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
58
        add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59
        add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60
        add_action( 'admin_init', array( $this, 'activation_redirect') );
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_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
65
		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
66
        add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
67
		add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) );
68
		add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) );
69
		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
70
		do_action( 'getpaid_init_admin_hooks', $this );
71
72
    }
73
74
    /**
75
	 * Register admin scripts
76
	 *
77
	 */
78
	public function enqeue_scripts() {
79
        global $current_screen, $pagenow;
80
81
		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
82
		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
83
84
        if ( ! empty( $current_screen->post_type ) ) {
85
			$page = $current_screen->post_type;
86
        }
87
88
        // General styles.
89
        if ( false !== stripos( $page, 'wpi' ) ) {
90
91
            // Styles.
92
            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
93
            wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version );
94
            wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' );
95
            wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' );
96
97
            // Scripts.
98
            wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true );
99
            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION );
100
101
            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
102
            wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker' ),  $version );
103
            wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) );
104
105
        }
106
107
        // Payment form scripts.
108
		if ( 'wpi_payment_form' == $page && $editing ) {
109
            $this->load_payment_form_scripts();
110
        }
111
112
		if ( $page == 'wpinv-subscriptions' ) {
113
			wp_enqueue_script( 'postbox' );
114
		}
115
116
    }
117
118
    /**
119
	 * Returns admin js translations.
120
	 *
121
	 */
122
	protected function get_admin_i18() {
123
        global $post;
124
125
		$date_range = array(
126
			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
127
		);
128
129
		if ( $date_range['period'] == 'custom' ) {
130
			
131
			if ( isset( $_GET['from'] ) ) {
132
				$date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
133
			}
134
135
			if ( isset( $_GET['to'] ) ) {
136
				$date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
137
			}
138
139
		}
140
141
        $i18n = array(
142
            'ajax_url'                  => admin_url( 'admin-ajax.php' ),
143
            'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
144
			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
145
			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
146
			'rest_root'                 => esc_url_raw( rest_url() ),
147
			'date_range'                => $date_range,
148
            'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
149
            'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
150
            'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
151
            'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
152
            'tax'                       => wpinv_tax_amount(),
153
            'discount'                  => 0,
154
			'currency_symbol'           => wpinv_currency_symbol(),
155
			'currency'                  => wpinv_get_currency(),
156
            'currency_pos'              => wpinv_currency_position(),
157
            'thousand_sep'              => wpinv_thousands_separator(),
158
            'decimal_sep'               => wpinv_decimal_separator(),
159
            'decimals'                  => wpinv_decimals(),
160
            'save_invoice'              => __( 'Save Invoice', 'invoicing' ),
161
            'status_publish'            => wpinv_status_nicename( 'publish' ),
162
            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
163
            'delete_tax_rate'           => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ),
164
            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
165
            'FillBillingDetails'        => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ),
166
            'confirmCalcTotals'         => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ),
167
            'AreYouSure'                => __( 'Are you sure?', 'invoicing' ),
168
            'errDeleteItem'             => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ),
169
            'delete_subscription'       => __( 'Are you sure you want to delete this subscription?', 'invoicing' ),
170
            'action_edit'               => __( 'Edit', 'invoicing' ),
171
            'action_cancel'             => __( 'Cancel', 'invoicing' ),
172
            'item_description'          => __( 'Item Description', 'invoicing' ),
173
            'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
174
            'discount_description'      => __( 'Discount Description', 'invoicing' ),
175
            'searching'                 => __( 'Searching', 'invoicing' ),
176
        );
177
178
		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
179
180
			$invoice              = new WPInv_Invoice( $post );
181
			$i18n['save_invoice'] = sprintf(
182
				__( 'Save %s', 'invoicing' ),
183
				ucfirst( $invoice->get_invoice_quote_type() )
184
			);
185
186
			$i18n['invoice_description'] = sprintf(
187
				__( '%s Description', 'invoicing' ),
188
				ucfirst( $invoice->get_invoice_quote_type() )
189
			);
190
191
		}
192
		return $i18n;
193
	}
194
195
	/**
196
	 * Change the admin footer text on GetPaid admin pages.
197
	 *
198
	 * @since  2.0.0
199
	 * @param  string $footer_text
200
	 * @return string
201
	 */
202
	public function admin_footer_text( $footer_text ) {
203
		global $current_screen;
204
205
		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
206
207
        if ( ! empty( $current_screen->post_type ) ) {
208
			$page = $current_screen->post_type;
209
        }
210
211
        // General styles.
212
        if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
213
214
			// Change the footer text
215
			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
216
217
				$rating_url  = esc_url(
218
					wp_nonce_url(
219
						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
220
						'getpaid-nonce',
221
						'getpaid-nonce'
222
						)
223
				);
224
225
				$footer_text = sprintf(
226
					/* translators: %s: five stars */
227
					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
228
					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
229
				);
230
231
			} else {
232
233
				$footer_text = sprintf(
234
					/* translators: %s: GetPaid */
235
					__( 'Thank you for using %s!', 'invoicing' ),
236
					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
237
				);
238
239
			}
240
241
		}
242
243
		return $footer_text;
244
	}
245
246
	/**
247
	 * Redirects to wp.org to rate the plugin.
248
	 *
249
	 * @since  2.0.0
250
	 */
251
	public function redirect_to_wordpress_rating_page() {
252
		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
253
		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
254
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
255
	}
256
257
    /**
258
	 * Loads payment form js.
259
	 *
260
	 */
261
	protected function load_payment_form_scripts() {
262
        global $post;
263
264
        wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
265
		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
266
		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
267
268
		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
269
		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
270
271
		wp_localize_script(
272
            'wpinv-admin-payment-form-script',
273
            'wpinvPaymentFormAdmin',
274
            array(
275
				'elements'      => wpinv_get_data( 'payment-form-elements' ),
276
				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
277
				'currency'      => wpinv_currency_symbol(),
278
				'position'      => wpinv_currency_position(),
279
				'decimals'      => (int) wpinv_decimals(),
280
				'thousands_sep' => wpinv_thousands_separator(),
281
				'decimals_sep'  => wpinv_decimal_separator(),
282
				'form_items'    => gepaid_get_form_items( $post->ID ),
283
				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
284
            )
285
        );
286
287
        wp_enqueue_script( 'wpinv-admin-payment-form-script' );
288
289
    }
290
291
    /**
292
	 * Add our classes to admin pages.
293
     *
294
     * @param string $classes
295
     * @return string
296
	 *
297
	 */
298
    public function admin_body_class( $classes ) {
299
		global $pagenow, $post, $current_screen;
300
301
302
        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
303
304
        if ( ! empty( $current_screen->post_type ) ) {
305
			$page = $current_screen->post_type;
306
        }
307
308
        if ( false !== stripos( $page, 'wpi' ) ) {
309
            $classes .= ' wpi-' . sanitize_key( $page );
310
        }
311
312
        if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
313
            $classes .= ' wpinv-cpt wpinv';
314
		}
315
		
316
		if ( getpaid_is_invoice_post_type( $page ) ) {
317
            $classes .= ' getpaid-is-invoice-cpt';
318
        }
319
320
		return $classes;
321
    }
322
323
    /**
324
	 * Maybe show the AyeCode Connect Notice.
325
	 */
326
	public function init_ayecode_connect_helper(){
327
328
        new AyeCode_Connect_Helper(
329
            array(
330
				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
331
				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
332
				'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>" ),
333
				'connect_button'    => __("Connect Site","invoicing"),
334
				'connecting_button'    => __("Connecting...","invoicing"),
335
				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
336
				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
337
            ),
338
            array( 'wpi-addons' )
339
        );
340
341
    }
342
343
	/**
344
	 * Redirect users to settings on activation.
345
	 *
346
	 * @return void
347
	 */
348
	public function activation_redirect() {
349
350
		$redirected = get_option( 'wpinv_redirected_to_settings' );
351
352
		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
353
			return;
354
		}
355
356
		// Bail if activating from network, or bulk
357
		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
358
			return;
359
		}
360
361
	    update_option( 'wpinv_redirected_to_settings', 1 );
362
363
        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
364
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
365
366
	}
367
368
    /**
369
     * Fires an admin action after verifying that a user can fire them.
370
     */
371
    public function maybe_do_admin_action() {
372
373
        if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
374
            $key = sanitize_key( $_REQUEST['getpaid-admin-action'] );
375
            do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST );
376
        }
377
378
    }
379
380
	/**
381
     * Sends a payment reminder to a customer.
382
	 * 
383
	 * @param array $args
384
     */
385
    public function send_customer_invoice( $args ) {
386
		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
387
388
		if ( $sent ) {
389
			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
390
		} else {
391
			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
392
		}
393
394
		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
395
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
396
	}
397
398
	/**
399
     * Sends a payment reminder to a customer.
400
	 * 
401
	 * @param array $args
402
     */
403
    public function send_customer_payment_reminder( $args ) {
404
		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
405
406
		if ( $sent ) {
407
			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
408
		} else {
409
			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
410
		}
411
412
		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
413
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
414
	}
415
416
	/**
417
     * Resets tax rates.
418
	 * 
419
     */
420
    public function admin_reset_tax_rates() {
421
422
		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
423
		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
424
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
425
426
	}
427
428
	/**
429
     * Resets admin pages.
430
	 * 
431
     */
432
    public function admin_create_missing_pages() {
433
		$installer = new GetPaid_Installer();
434
		$installer->create_pages();
435
		$this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) );
436
		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
437
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
438
	}
439
440
	/**
441
     * Creates an missing admin tables.
442
	 * 
443
     */
444
    public function admin_create_missing_tables() {
445
		global $wpdb;
446
		$installer = new GetPaid_Installer();
447
448
		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) {
449
			$installer->create_subscriptions_table();
450
451
			if ( $wpdb->last_error !== '' ) {
452
				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
453
			}
454
		}
455
456
		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) {
457
			$installer->create_invoices_table();
458
459
			if ( $wpdb->last_error !== '' ) {
460
				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
461
			}
462
		}
463
464
		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) {
465
			$installer->create_invoice_items_table();
466
467
			if ( $wpdb->last_error !== '' ) {
468
				$this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error );
469
			}
470
		}
471
472
		if ( ! $this->has_notices() ) {
473
			$this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) );
474
		}
475
476
		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
477
		exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
478
	}
479
480
    /**
481
	 * Returns an array of admin notices.
482
	 *
483
	 * @since       1.0.19
484
     * @return array
485
	 */
486
	public function get_notices() {
487
		$notices = get_option( 'wpinv_admin_notices' );
488
        return is_array( $notices ) ? $notices : array();
489
	}
490
491
	/**
492
	 * Checks if we have any admin notices.
493
	 *
494
	 * @since       2.0.4
495
     * @return array
496
	 */
497
	public function has_notices() {
498
		return count( $this->get_notices() ) > 0;
0 ignored issues
show
Bug Best Practice introduced by
The expression return count($this->get_notices()) > 0 returns the type boolean which is incompatible with the documented return type array.
Loading history...
499
	}
500
501
	/**
502
	 * Clears all admin notices
503
	 *
504
	 * @access      public
505
	 * @since       1.0.19
506
	 */
507
	public function clear_notices() {
508
		delete_option( 'wpinv_admin_notices' );
509
	}
510
511
	/**
512
	 * Saves a new admin notice
513
	 *
514
	 * @access      public
515
	 * @since       1.0.19
516
	 */
517
	public function save_notice( $type, $message ) {
518
		$notices = $this->get_notices();
519
520
		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
521
			$notices[ $type ] = array();
522
		}
523
524
		$notices[ $type ][] = $message;
525
526
		update_option( 'wpinv_admin_notices', $notices );
527
	}
528
529
	/**
530
	 * Displays a success notice
531
	 *
532
	 * @param       string $msg The message to qeue.
533
	 * @access      public
534
	 * @since       1.0.19
535
	 */
536
	public function show_success( $msg ) {
537
		$this->save_notice( 'success', $msg );
538
	}
539
540
	/**
541
	 * Displays a error notice
542
	 *
543
	 * @access      public
544
	 * @param       string $msg The message to qeue.
545
	 * @since       1.0.19
546
	 */
547
	public function show_error( $msg ) {
548
		$this->save_notice( 'error', $msg );
549
	}
550
551
	/**
552
	 * Displays a warning notice
553
	 *
554
	 * @access      public
555
	 * @param       string $msg The message to qeue.
556
	 * @since       1.0.19
557
	 */
558
	public function show_warning( $msg ) {
559
		$this->save_notice( 'warning', $msg );
560
	}
561
562
	/**
563
	 * Displays a info notice
564
	 *
565
	 * @access      public
566
	 * @param       string $msg The message to qeue.
567
	 * @since       1.0.19
568
	 */
569
	public function show_info( $msg ) {
570
		$this->save_notice( 'info', $msg );
571
	}
572
573
	/**
574
	 * Show notices
575
	 *
576
	 * @access      public
577
	 * @since       1.0.19
578
	 */
579
	public function show_notices() {
580
581
        $notices = $this->get_notices();
582
        $this->clear_notices();
583
584
		foreach ( $notices as $type => $messages ) {
585
586
			if ( ! is_array( $messages ) ) {
587
				continue;
588
			}
589
590
            $type  = sanitize_key( $type );
591
			foreach ( $messages as $message ) {
592
                $message = wp_kses_post( $message );
593
				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
594
            }
595
596
        }
597
598
		foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) {
599
600
			if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) {
601
				$url     = esc_url(
602
					wp_nonce_url(
603
						add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
604
						'getpaid-nonce',
605
						'getpaid-nonce'
606
					)
607
				);
608
				$message  = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' );
609
				$message2 = __( 'Generate Pages', 'invoicing' );
610
				echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>";
611
				break;
612
			}
613
614
		}
615
616
	}
617
618
}
619