PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.1.2
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.1.2
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / EasyInvoice.php

EasyInvoice.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.1.2, at includes/EasyInvoice.php

726 lines 27.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main EasyInvoice Plugin Class
4 *
5 * @package EasyInvoice
6 * @author Your Name
7 * @copyright Copyright (c) 2023, Your Company
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 */
11
12 namespace EasyInvoice;
13
14 use EasyInvoice\PostTypes\InvoicePostType;
15 use EasyInvoice\PostTypes\PaymentPostType;
16
17 /**
18 * EasyInvoice main plugin class.
19 *
20 * @since 1.0.0
21 */
22 class EasyInvoice {
23 /**
24 * Plugin instance.
25 *
26 * @since 1.0.0
27 * @access private
28 * @var EasyInvoice
29 */
30 private static $instance = null;
31
32 /**
33 * Payment gateway manager instance.
34 *
35 * @since 1.0.0
36 * @access private
37 * @var PaymentGatewayManager
38 */
39 private $gateway_manager;
40
41 /**
42 * Get plugin instance.
43 *
44 * @since 1.0.0
45 * @return EasyInvoice
46 */
47 public static function getInstance(): EasyInvoice {
48 if ( null === self::$instance ) {
49 self::$instance = new self();
50 }
51 return self::$instance;
52 }
53
54 /**
55 * Initialize the plugin.
56 *
57 * @since 1.0.0
58 * @return void
59 */
60 public function init() {
61 // Define plugin constants.
62 $this->defineConstants();
63
64 // Initialize payment gateways first.
65 $this->initPaymentGateways();
66
67 // Note: Post types are now registered separately with proper timing
68
69 // Initialize template loader
70 $template_loader = new TemplateLoader();
71 $template_loader->init();
72
73 // Flush rewrite rules on first load to ensure public quote URLs work
74 if (get_option('easy_invoice_flush_rewrite_rules', false) === false) {
75 add_action('init', function() {
76 flush_rewrite_rules();
77 update_option('easy_invoice_flush_rewrite_rules', true);
78 }, 20);
79 }
80
81 // Also flush rewrite rules when post types are registered
82 add_action('init', function() {
83 if (get_option('easy_invoice_post_types_registered', false) === false) {
84 flush_rewrite_rules();
85 update_option('easy_invoice_post_types_registered', true);
86 }
87 }, 25);
88
89 // Initialize admin functionality if in admin area.
90 if ( is_admin() ) {
91 $this->initAdmin();
92 }
93
94 // Initialize background services
95 \EasyInvoice\Services\QuoteExpirationService::init();
96 }
97
98 /**
99 * Define plugin constants.
100 *
101 * @since 1.0.0
102 * @access private
103 * @return void
104 */
105 private function defineConstants(): void {
106 if ( ! defined( 'EASY_INVOICE_VERSION' ) ) {
107 define( 'EASY_INVOICE_VERSION', '1.0.0' );
108 }
109
110 if ( ! defined( 'EASY_INVOICE_FILE' ) ) {
111 define( 'EASY_INVOICE_FILE', dirname( dirname( __FILE__ ) ) . '/easy-invoice.php' );
112 }
113
114 if ( ! defined( 'EASY_INVOICE_PATH' ) ) {
115 define( 'EASY_INVOICE_PATH', plugin_dir_path( EASY_INVOICE_FILE ) );
116 }
117
118 if ( ! defined( 'EASY_INVOICE_URL' ) ) {
119 define( 'EASY_INVOICE_URL', plugin_dir_url( EASY_INVOICE_FILE ) );
120 }
121
122 if ( ! defined( 'EASY_INVOICE_ASSETS_URL' ) ) {
123 define( 'EASY_INVOICE_ASSETS_URL', EASY_INVOICE_URL . 'assets/' );
124 }
125 }
126
127 /**
128 * Initialize admin functionality.
129 *
130 * @since 1.0.0
131 * @access private
132 * @return void
133 */
134 private function initAdmin() {
135 // Load admin class if we're in the admin area.
136 $admin = new Admin\EasyInvoiceAdmin();
137 $admin->init();
138
139 // Initialize AJAX handlers.
140 $ajax = new Admin\EasyInvoiceAjax();
141 $ajax->init();
142
143 // Show draft invoices in the main list.
144 add_action( 'pre_get_posts', [ $this, 'modifyInvoiceAdminQuery' ] );
145
146 // Add custom columns to invoice list.
147 add_filter( 'manage_easy_invoice_posts_columns', [ $this, 'addInvoiceColumns' ] );
148 add_action( 'manage_easy_invoice_posts_custom_column', [ $this, 'populateInvoiceColumns' ], 10, 2 );
149
150 // Add custom columns to payment list.
151 add_filter( 'manage_easy_invoice_payment_posts_columns', [ $this, 'addPaymentColumns' ] );
152 add_action( 'manage_easy_invoice_payment_posts_custom_column', [ $this, 'populatePaymentColumns' ], 10, 2 );
153
154 // Add admin action to flush rewrite rules
155 add_action('admin_post_flush_easy_invoice_rewrite_rules', [$this, 'handleFlushRewriteRules']);
156
157 // Add admin action to fix quote slugs
158 add_action('admin_post_fix_easy_invoice_quote_slugs', [$this, 'handleFixQuoteSlugs']);
159
160 // Add admin action to manually register post types
161 add_action('admin_post_register_easy_invoice_post_types', [$this, 'handleRegisterPostTypes']);
162
163 // Disable admin notices on Easy Invoice pages for clean UI
164 add_action( 'admin_notices', [ $this, 'disableAdminNoticesOnEasyInvoicePages' ], 1 );
165 }
166
167 /**
168 * Modify the main query for easy_invoice post type in admin to include drafts.
169 *
170 * @since 1.0.0
171 * @param \WP_Query $query The WP_Query instance (passed by reference).
172 * @return void
173 */
174 public function modifyInvoiceAdminQuery( \WP_Query $query ) {
175 // Check if we are on the main query for the 'easy_invoice' post type admin page.
176 if ( ! is_admin() || ! $query->is_main_query() || $query->get( 'post_type' ) !== 'easy_invoice' ) {
177 return;
178 }
179
180 // Check if a specific post_status is already set in the query.
181 $current_status = $query->get( 'post_status' );
182 if ( empty( $current_status ) || $current_status === '' ||
183 ( is_array( $current_status ) && count( $current_status ) === 1 && $current_status[0] === 'any' ) ) {
184
185 // Also check for explicit views like 'all'.
186 if ( isset( $_GET['post_status'] ) && $_GET['post_status'] !== 'all' ) {
187 return;
188 }
189
190 // Include all needed statuses.
191 $query->set( 'post_status', [
192 'publish',
193 'private',
194 'draft',
195 'pending',
196 'future',
197 'pending-bank',
198 'pending-cheque'
199 ] );
200 }
201 }
202
203 /**
204 * Initialize payment gateways.
205 *
206 * @since 1.0.0
207 * @access private
208 * @return void
209 */
210 private function initPaymentGateways() {
211 if ( ! $this->gateway_manager ) {
212 $this->gateway_manager = new PaymentGatewayManager();
213
214 // Register payment gateways.
215 $gateways = [
216 new Gateways\PayPalGateway(),
217 ];
218
219 foreach ( $gateways as $gateway ) {
220 $this->gateway_manager->registerGateway( $gateway );
221 }
222
223 // Initialize all gateways.
224 $this->gateway_manager->initGateways();
225
226 // Set default payment methods if not already set.
227 $this->setDefaultPaymentMethods();
228 }
229 }
230
231 /**
232 * Set default payment methods and their details.
233 *
234 * @since 1.0.0
235 * @access private
236 * @return void
237 */
238 private function setDefaultPaymentMethods() {
239 $payment_methods = get_option( 'easy_invoice_payment_methods', [] );
240
241 $defaults_updated = false;
242
243 // Bank Transfer, Cheque, and Cash payment defaults moved to Pro plugin
244
245 if ( $defaults_updated ) {
246 update_option( 'easy_invoice_payment_methods', array_unique( $payment_methods ) );
247 }
248 }
249
250 /**
251 * Get payment gateway manager.
252 *
253 * @since 1.0.0
254 * @return PaymentGatewayManager
255 */
256 public function getGatewayManager(): PaymentGatewayManager {
257 if ( ! $this->gateway_manager ) {
258 $this->initPaymentGateways();
259 }
260 return $this->gateway_manager;
261 }
262
263 /**
264 * Register custom post types.
265 *
266 * @since 1.0.0
267 * @return void
268 */
269 public function registerPostTypes() {
270 // Register Invoice post type.
271 register_post_type( \EasyInvoice\Constants\PostTypes::EASY_INVOICE_POST_TYPE, [
272 'labels' => [
273 'name' => _x( 'Invoices', 'post type general name', 'easy-invoice' ),
274 'singular_name' => _x( 'Invoice', 'post type singular name', 'easy-invoice' ),
275 'menu_name' => _x( 'Invoices', 'admin menu', 'easy-invoice' ),
276 'name_admin_bar' => _x( 'Invoice', 'add new on admin bar', 'easy-invoice' ),
277 'add_new' => _x( 'Add New', 'invoice', 'easy-invoice' ),
278 'add_new_item' => __( 'Add New Invoice', 'easy-invoice' ),
279 'new_item' => __( 'New Invoice', 'easy-invoice' ),
280 'edit_item' => __( 'Edit Invoice', 'easy-invoice' ),
281 'view_item' => __( 'View Invoice', 'easy-invoice' ),
282 'all_items' => __( 'All Invoices', 'easy-invoice' ),
283 'search_items' => __( 'Search Invoices', 'easy-invoice' ),
284 'parent_item_colon' => __( 'Parent Invoices:', 'easy-invoice' ),
285 'not_found' => __( 'No invoices found.', 'easy-invoice' ),
286 'not_found_in_trash' => __( 'No invoices found in Trash.', 'easy-invoice' )
287 ],
288 'description' => __( 'Invoices for Easy Invoice plugin.', 'easy-invoice' ),
289 'public' => true,
290 'publicly_queryable' => true,
291 'show_ui' => false,
292 'show_in_menu' => false,
293 'query_var' => true,
294 'rewrite' => [ 'slug' => 'invoice' ],
295 'capability_type' => 'post',
296 'has_archive' => false,
297 'hierarchical' => false,
298 'menu_position' => null,
299 'supports' => [ 'title', 'editor', 'custom-fields' ]
300 ]);
301
302 // Register Quote post type.
303 $quote_post_type = \EasyInvoice\Constants\PostTypes::EASY_INVOICE_QUOTE_POST_TYPE;
304
305 $result = register_post_type( $quote_post_type, [
306 'labels' => [
307 'name' => _x( 'Quotes', 'post type general name', 'easy-invoice' ),
308 'singular_name' => _x( 'Quote', 'post type singular name', 'easy-invoice' ),
309 'menu_name' => _x( 'Quotes', 'admin menu', 'easy-invoice' ),
310 'name_admin_bar' => _x( 'Quote', 'add new on admin bar', 'easy-invoice' ),
311 'add_new' => _x( 'Add New', 'quote', 'easy-invoice' ),
312 'add_new_item' => __( 'Add New Quote', 'easy-invoice' ),
313 'new_item' => __( 'New Quote', 'easy-invoice' ),
314 'edit_item' => __( 'Edit Quote', 'easy-invoice' ),
315 'view_item' => __( 'View Quote', 'easy-invoice' ),
316 'all_items' => __( 'All Quotes', 'easy-invoice' ),
317 'search_items' => __( 'Search Quotes', 'easy-invoice' ),
318 'parent_item_colon' => __( 'Parent Quotes:', 'easy-invoice' ),
319 'not_found' => __( 'No quotes found.', 'easy-invoice' ),
320 'not_found_in_trash' => __( 'No quotes found in Trash.', 'easy-invoice' )
321 ],
322 'description' => __( 'Quotes for Easy Invoice plugin.', 'easy-invoice' ),
323 'public' => true,
324 'publicly_queryable' => true,
325 'show_ui' => false,
326 'show_in_menu' => false,
327 'query_var' => true,
328 'rewrite' => [ 'slug' => 'easy-invoice-quote', 'with_front' => false ],
329 'capability_type' => 'post',
330 'has_archive' => false,
331 'hierarchical' => false,
332 'menu_position' => null,
333 'supports' => [ 'title', 'editor', 'custom-fields' ]
334 ]);
335
336
337
338 // Register Payment post type.
339 register_post_type( 'easy_invoice_payment', [
340 'labels' => [
341 'name' => _x( 'Payments', 'post type general name', 'easy-invoice' ),
342 'singular_name' => _x( 'Payment', 'post type singular name', 'easy-invoice' ),
343 'menu_name' => _x( 'Payments', 'admin menu', 'easy-invoice' ),
344 'name_admin_bar' => _x( 'Payment', 'add new on admin bar', 'easy-invoice' ),
345 'add_new' => _x( 'Add New', 'payment', 'easy-invoice' ),
346 'add_new_item' => __( 'Add New Payment', 'easy-invoice' ),
347 'new_item' => __( 'New Payment', 'easy-invoice' ),
348 'edit_item' => __( 'Edit Payment', 'easy-invoice' ),
349 'view_item' => __( 'View Payment', 'easy-invoice' ),
350 'all_items' => __( 'All Payments', 'easy-invoice' ),
351 'search_items' => __( 'Search Payments', 'easy-invoice' ),
352 'parent_item_colon' => __( 'Parent Payments:', 'easy-invoice' ),
353 'not_found' => __( 'No payments found.', 'easy-invoice' ),
354 'not_found_in_trash' => __( 'No payments found in Trash.', 'easy-invoice' )
355 ],
356 'description' => __( 'Payments for Easy Invoice plugin.', 'easy-invoice' ),
357 'public' => false,
358 'publicly_queryable' => false,
359 'show_ui' => true,
360 'show_in_menu' => 'edit.php?post_type=easy_invoice',
361 'query_var' => true,
362 'rewrite' => [ 'slug' => 'payment' ],
363 'capability_type' => 'post',
364 'has_archive' => false,
365 'hierarchical' => false,
366 'menu_position' => null,
367 'supports' => [ 'title', 'author', 'custom-fields' ],
368 'show_in_rest' => false,
369 ] );
370
371
372 // Force flush rewrite rules after post type registration
373 $this->flushRewriteRules();
374
375 // Force an immediate rewrite rules flush
376 flush_rewrite_rules(true);
377 }
378
379 /**
380 * Flush rewrite rules to ensure custom post type URLs work
381 */
382 private function flushRewriteRules() {
383 // Only flush if we haven't done it recently
384 $last_flush = get_option('easy_invoice_last_rewrite_flush', 0);
385 $current_time = time();
386
387 if ($current_time - $last_flush > 300) { // 5 minutes
388 flush_rewrite_rules();
389 update_option('easy_invoice_last_rewrite_flush', $current_time);
390 }
391 }
392
393 /**
394 * Manually flush rewrite rules (public method for admin use)
395 */
396 public function forceFlushRewriteRules() {
397 flush_rewrite_rules();
398 update_option('easy_invoice_last_rewrite_flush', time());
399 update_option('easy_invoice_flush_rewrite_rules', false);
400 update_option('easy_invoice_post_types_registered', false);
401 }
402
403 /**
404 * Add columns to invoice list table.
405 *
406 * @since 1.0.0
407 * @param array $columns List of columns.
408 * @return array Modified list of columns.
409 */
410 public function addInvoiceColumns( $columns ) {
411 $date_column = isset( $columns['date'] ) ? $columns['date'] : '';
412 unset( $columns['date'] );
413
414 $columns['invoice_number'] = __( 'Invoice #', 'easy-invoice' );
415 $columns['client'] = __( 'Client', 'easy-invoice' );
416 $columns['amount'] = __( 'Amount', 'easy-invoice' );
417 $columns['status'] = __( 'Status', 'easy-invoice' );
418 $columns['issue_date'] = __( 'Issue Date', 'easy-invoice' );
419 $columns['due_date'] = __( 'Due Date', 'easy-invoice' );
420
421 if ( $date_column ) {
422 $columns['date'] = $date_column;
423 }
424
425 return $columns;
426 }
427
428 /**
429 * Populate custom columns for invoice list table.
430 *
431 * @since 1.0.0
432 * @param string $column Column name.
433 * @param int $post_id Post ID.
434 * @return void
435 */
436 public function populateInvoiceColumns( $column, $post_id ) {
437 switch ( $column ) {
438 case 'invoice_number':
439 $invoice_number = get_post_meta( $post_id, '_invoice_number', true );
440 echo esc_html( ! empty( $invoice_number ) ? $invoice_number : "INV-{$post_id}" );
441 break;
442 case 'client':
443 $client_id = get_post_meta( $post_id, '_client_id', true );
444 if ( $client_id ) {
445 $client = get_post( $client_id );
446 if ( $client ) {
447 echo esc_html( $client->post_title );
448 } else {
449 echo esc_html__('', 'easy-invoice');
450 }
451 } else {
452 echo esc_html__('', 'easy-invoice');
453 }
454 break;
455 case 'amount':
456 $total = get_post_meta( $post_id, '_invoice_total', true );
457 if ( ! empty( $total ) ) {
458 echo esc_html( '$' . number_format( $total, 2 ) );
459 } else {
460 echo esc_html__('', 'easy-invoice');
461 }
462 break;
463 case 'status':
464 $status = get_post_meta( $post_id, '_payment_status', true );
465 if ( ! empty( $status ) ) {
466 echo '<span class="invoice-status status-' . esc_attr( $status ) . '">' . esc_html( ucfirst( $status ) ) . '</span>';
467 } else {
468 echo esc_html__('', 'easy-invoice');
469 }
470 break;
471 case 'issue_date':
472 $issue_date = get_post_meta( $post_id, '_issue_date', true );
473 if ( ! empty( $issue_date ) ) {
474 echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $issue_date ) ) );
475 } else {
476 echo esc_html__('', 'easy-invoice');
477 }
478 break;
479 case 'due_date':
480 $due_date = get_post_meta( $post_id, '_due_date', true );
481 if ( ! empty( $due_date ) ) {
482 echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $due_date ) ) );
483 } else {
484 echo '';
485 }
486 break;
487 }
488 }
489
490 /**
491 * Add columns to payment list table.
492 *
493 * @since 1.0.0
494 * @param array $columns List of columns.
495 * @return array Modified list of columns.
496 */
497 public function addPaymentColumns( $columns ) {
498 $date_column = isset( $columns['date'] ) ? $columns['date'] : '';
499 unset( $columns['date'] );
500
501 $columns['invoice'] = __( 'Invoice', 'easy-invoice' );
502 $columns['amount'] = __( 'Amount', 'easy-invoice' );
503 $columns['method'] = __( 'Method', 'easy-invoice' );
504 $columns['status'] = __( 'Status', 'easy-invoice' );
505 $columns['transaction_id'] = __( 'Transaction ID', 'easy-invoice' );
506
507 if ( $date_column ) {
508 $columns['date'] = $date_column;
509 }
510
511 return $columns;
512 }
513
514 /**
515 * Populate custom columns for payment list table.
516 *
517 * @since 1.0.0
518 * @param string $column Column name.
519 * @param int $post_id Post ID.
520 * @return void
521 */
522 public function populatePaymentColumns( $column, $post_id ) {
523 switch ( $column ) {
524 case 'invoice':
525 $invoice_id = get_post_meta( $post_id, '_invoice_id', true );
526 if ( $invoice_id ) {
527 $invoice = get_post( $invoice_id );
528 if ( $invoice ) {
529 $invoice_number = get_post_meta( $invoice_id, '_invoice_number', true );
530 if ( ! $invoice_number ) {
531 $invoice_number = "INV-{$invoice_id}";
532 }
533 echo '<a href="' . esc_url( admin_url( 'post.php?post=' . $invoice_id . '&action=edit' ) ) . '">' . esc_html( $invoice_number ) . '</a>';
534 } else {
535 echo '';
536 }
537 } else {
538 echo '';
539 }
540 break;
541 case 'amount':
542 $amount = get_post_meta( $post_id, '_amount', true );
543 $currency = get_post_meta( $post_id, '_currency_symbol', true ) ?: '$';
544 if ( ! empty( $amount ) ) {
545 echo esc_html( $currency . number_format( $amount, 2 ) );
546 } else {
547 echo '';
548 }
549 break;
550 case 'method':
551 $method = get_post_meta( $post_id, '_payment_method', true );
552 if ( ! empty( $method ) ) {
553 echo esc_html( ucfirst( $method ) );
554 } else {
555 echo '';
556 }
557 break;
558 case 'status':
559 $status = get_post_meta( $post_id, '_status', true );
560 if ( ! empty( $status ) ) {
561 echo '<span class="payment-status status-' . esc_attr( $status ) . '">' . esc_html( ucfirst( $status ) ) . '</span>';
562 } else {
563 echo '';
564 }
565 break;
566 case 'transaction_id':
567 $transaction_id = get_post_meta( $post_id, '_transaction_id', true );
568 if ( ! empty( $transaction_id ) ) {
569 echo esc_html( $transaction_id );
570 } else {
571 echo '';
572 }
573 break;
574 }
575 }
576
577 /**
578 * Register custom post statuses.
579 *
580 * @since 1.0.0
581 * @return void
582 */
583 public function registerCustomStatuses() {
584 // Register custom post statuses for invoices and payments.
585 $statuses = [
586 'pending-bank' => [
587 'label' => _x( 'Pending Bank Transfer', 'Invoice status', 'easy-invoice' ),
588 'public' => true,
589 'exclude_from_search' => false,
590 'show_in_admin_all_list' => true,
591 'show_in_admin_status_list' => true,
592 'label_count' => _n_noop(
593 'Pending Bank Transfer <span class="count">(%s)</span>',
594 'Pending Bank Transfer <span class="count">(%s)</span>',
595 'easy-invoice'
596 ),
597 ],
598 'pending-cheque' => [
599 'label' => _x( 'Pending Cheque', 'Invoice status', 'easy-invoice' ),
600 'public' => true,
601 'exclude_from_search' => false,
602 'show_in_admin_all_list' => true,
603 'show_in_admin_status_list' => true,
604 'label_count' => _n_noop(
605 'Pending Cheque <span class="count">(%s)</span>',
606 'Pending Cheque <span class="count">(%s)</span>',
607 'easy-invoice'
608 ),
609 ],
610 ];
611
612 foreach ( $statuses as $status => $args ) {
613 register_post_status( $status, $args );
614 }
615 }
616
617 /**
618 * Handle admin action to flush rewrite rules
619 */
620 public function handleFlushRewriteRules() {
621 if (!current_user_can('manage_options')) {
622 wp_die('Unauthorized');
623 }
624
625 check_admin_referer('flush_easy_invoice_rewrite_rules');
626
627 $this->forceFlushRewriteRules();
628
629 // Get the referer to determine which page to redirect back to
630 $referer = wp_get_referer();
631 $redirect_url = admin_url('admin.php?page=easy-quote-all&rewrite_flushed=1'); // Default fallback
632
633 if ($referer) {
634 // Check if user was on invoice page
635 if (strpos($referer, 'page=easy-invoice-all') !== false) {
636 $redirect_url = admin_url('admin.php?page=easy-invoice-all&rewrite_flushed=1');
637 } elseif (strpos($referer, 'page=easy-quote-all') !== false) {
638 $redirect_url = admin_url('admin.php?page=easy-quote-all&rewrite_flushed=1');
639 }
640 }
641
642 wp_redirect($redirect_url);
643 exit;
644 }
645
646 /**
647 * Handle admin action to manually register post types
648 */
649 public function handleRegisterPostTypes() {
650 if (!current_user_can('manage_options')) {
651 wp_die('Unauthorized');
652 }
653
654 check_admin_referer('register_easy_invoice_post_types');
655
656 $this->registerPostTypes();
657 $this->forceFlushRewriteRules();
658
659 // Get the referer to determine which page to redirect back to
660 $referer = wp_get_referer();
661 $redirect_url = admin_url('admin.php?page=easy-quote-all&post_types_registered=1'); // Default fallback
662
663 if ($referer) {
664 // Check if user was on invoice page
665 if (strpos($referer, 'page=easy-invoice-all') !== false) {
666 $redirect_url = admin_url('admin.php?page=easy-invoice-all&post_types_registered=1');
667 } elseif (strpos($referer, 'page=easy-quote-all') !== false) {
668 $redirect_url = admin_url('admin.php?page=easy-quote-all&post_types_registered=1');
669 }
670 }
671
672 wp_redirect($redirect_url);
673 exit;
674 }
675
676 /**
677 * Disable admin notices on Easy Invoice pages for clean UI.
678 *
679 * @since 1.0.0
680 * @return void
681 */
682 public function disableAdminNoticesOnEasyInvoicePages() {
683 // Get current page
684 $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
685
686 // Check if we're on an Easy Invoice page
687 $easy_invoice_pages = [
688 'easy-invoice', // Dashboard
689 'easy-invoice-all', // All invoices
690 'easy-invoice-builder', // Invoice builder
691 'easy-invoice-preview', // Invoice preview
692 'easy-quote-all', // All quotes
693 'easy-invoice-quote-builder', // Quote builder
694 'easy-quote-preview', // Quote preview
695 'easy-invoice-payments', // All payments
696 'easy-invoice-payment-new', // Add new payment
697 'easy-invoice-clients', // All clients
698 'easy-invoice-client-edit', // Edit client
699 'easy-invoice-client-view', // View client
700 'easy-invoice-reports', // Reports
701 'easy-invoice-settings', // Main settings
702 'easy-invoice-email-settings', // Email settings
703 'easy-invoice-email-settings-general',
704 'easy-invoice-email-settings-invoice',
705 'easy-invoice-email-settings-quote',
706 'easy-invoice-email-settings-payment',
707 'easy-invoice-pro-settings', // Pro settings
708 'easy-invoice-pro-translations', // Pro translations
709 'easy-invoice-migration', // Migration page
710 'easy-invoice-license', // License page
711 'easy-invoice-free-vs-pro'
712 ];
713
714 // Check if current page is an Easy Invoice page
715 if ( in_array( $page, $easy_invoice_pages ) ) {
716 // Remove all admin notices by removing the action
717 remove_all_actions( 'admin_notices' );
718
719 // Also remove network and user admin notices
720 remove_all_actions( 'network_admin_notices' );
721 remove_all_actions( 'user_admin_notices' );
722 remove_all_actions( 'all_admin_notices' );
723 }
724 }
725 }
726