PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.4
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.4
2.4.3 2.4.4 2.4.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 All 60 releases
← All changes | includes/Admin/EasyInvoiceAdmin.php +261 -68 2.1.21 → 2.4.4 View file →
@@ -73,9 +73,9 @@
73 73
74 74 /**
75 75 * Template Builder controller instance
76 76 *
77 - * @var \EasyInvoicePro\Controllers\TemplateBuilderController
77 + * @var \EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController
78 78 */
79 79 private $template_builder_controller;
80 80
81 81 /**
@@ -89,11 +89,19 @@
89 89 $this->report_controller = new ReportController();
90 90 $this->dashboard_controller = new DashboardController();
91 91 $this->payment_controller = new PaymentController();
92 92
93 - // Initialize Template Builder controller if Pro is active
94 - if (easy_invoice_has_pro() && class_exists('\EasyInvoicePro\Controllers\TemplateBuilderController')) {
95 - $this->template_builder_controller = new \EasyInvoicePro\Controllers\TemplateBuilderController();
93 + // Initialize Template Builder controller if Pro is active AND
94 + // the custom_templates addon is enabled. The addon owns this
95 + // feature — see addons/CustomTemplates/addon.php in the Pro
96 + // plugin. Constructing the controller here always-on would
97 + // register its admin_menu hook regardless of addon state.
98 + if (
99 + easy_invoice_has_pro()
100 + && \EasyInvoice\Addons\AddonManager::shouldLoad('custom_templates')
101 + && class_exists('\EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController')
102 + ) {
103 + $this->template_builder_controller = new \EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController();
96 104 }
97 105 }
98 106
99 107 /**
@@ -101,8 +109,9 @@
101 109 */
102 110 public function init() {
103 111 // Add menu items
104 112 add_action('admin_menu', array($this, 'registerMenuPages'));
113 + add_action('admin_menu', array($this, 'relaxMenuCapabilities'), 9999);
105 114
106 115 // Register admin assets
107 116 $admin_assets = new AdminAssets();
108 117 $admin_assets->register();
@@ -132,8 +141,74 @@
132 141 add_action('easy_invoice_admin_main_content', array($this, 'mainPageContent'));
133 142 }
134 143
135 144 /**
145 + * Let an addon lower the capability a menu page demands.
146 + *
147 + * Every page is registered with `manage_options`, which is right for a
148 + * site with one administrator and wrong the moment the Team Roles addon
149 + * hands a colleague an "EI Viewer" role: WordPress refused them every
150 + * screen before the plugin's own capability checks were even consulted.
151 + * add_submenu_page() drops a page outright when the current user lacks
152 + * the capability, so the plugin's own pages pass through menuCapability()
153 + * at registration; this late pass covers pages registered elsewhere.
154 + */
155 + public function menuCapability($slug) {
156 + /** This filter is documented in relaxMenuCapabilities(). */
157 + return (string) apply_filters('easy_invoice_menu_capability', 'manage_options', (string) $slug);
158 + }
159 +
160 + public function relaxMenuCapabilities() {
161 + global $menu, $submenu;
162 + $relax = static function ($cap, $slug) {
163 + if (!is_string($slug) || 0 !== strpos($slug, 'easy-') ) {
164 + return $cap;
165 + }
166 + /**
167 + * Filter the capability required to open an Easy Invoice admin page.
168 + *
169 + * @param string $cap Capability registered for the page.
170 + * @param string $slug Page slug.
171 + */
172 + return (string) apply_filters('easy_invoice_menu_capability', $cap, $slug);
173 + };
174 + if (is_array($menu)) {
175 + foreach ($menu as $i => $item) {
176 + if (isset($item[1], $item[2])) {
177 + $menu[$i][1] = $relax($item[1], $item[2]);
178 + }
179 + }
180 + }
181 + if (is_array($submenu)) {
182 + foreach ($submenu as $parent => $items) {
183 + foreach ((array) $items as $i => $item) {
184 + if (isset($item[1], $item[2])) {
185 + $submenu[$parent][$i][1] = $relax($item[1], $item[2]);
186 + }
187 + }
188 + }
189 + }
190 + }
191 +
192 + /**
193 + * The admin menu mark: the same document-and-tick glyph as the plugin
194 + * icon, monochrome so it follows WordPress' menu colour schemes. Falls
195 + * back to a dashicon if the file is ever missing from the build.
196 + *
197 + * @return string Data URI, or a dashicon class.
198 + */
199 + public static function menuIcon() {
200 + static $icon = null;
201 + if ($icon !== null) {
202 + return $icon;
203 + }
204 + $file = EASY_INVOICE_PLUGIN_DIR . 'assets/images/menu-icon.svg';
205 + $svg = is_readable($file) ? file_get_contents($file) : '';
206 + $icon = $svg ? 'data:image/svg+xml;base64,' . base64_encode($svg) : 'dashicons-media-text';
207 + return $icon;
208 + }
209 +
210 + /**
136 211 * Register admin menu pages
137 212 */
138 213 public function registerMenuPages() {
139 214 // Main menu item
@@ -139,12 +214,12 @@
139 214 // Main menu item
140 215 add_menu_page(
141 216 __('Easy Invoice', 'easy-invoice'),
142 217 __('Easy Invoice', 'easy-invoice'),
143 - 'manage_options',
218 + $this->menuCapability(PagesSlugs::DASHBOARD),
144 219 PagesSlugs::DASHBOARD,
145 220 array($this, 'displayMainPage'),
146 - 'dashicons-media-text',
221 + self::menuIcon(),
147 222 25
148 223 );
149 224
150 225 // Dashboard submenu
@@ -151,9 +226,9 @@
151 226 add_submenu_page(
152 227 'easy-invoice',
153 228 __('Dashboard', 'easy-invoice'),
154 229 __('Dashboard', 'easy-invoice'),
155 - 'manage_options',
230 + $this->menuCapability(PagesSlugs::DASHBOARD),
156 231 PagesSlugs::DASHBOARD,
157 232 array($this, 'displayMainPage')
158 233 );
159 234
@@ -161,9 +236,9 @@
161 236 add_submenu_page(
162 237 'easy-invoice',
163 238 __('All Invoices', 'easy-invoice'),
164 239 __('All Invoices', 'easy-invoice'),
165 - 'manage_options',
240 + $this->menuCapability(PagesSlugs::ALL_INVOICES),
166 241 PagesSlugs::ALL_INVOICES,
167 242 array($this, 'displayMainPage')
168 243 );
169 244
@@ -171,9 +246,9 @@
171 246 add_submenu_page(
172 247 'easy-invoice-hidden',
173 248 __('Add New Invoice', 'easy-invoice'),
174 249 __('Add New', 'easy-invoice'),
175 - 'manage_options',
250 + $this->menuCapability(PagesSlugs::INVOICE_NEW),
176 251 PagesSlugs::INVOICE_NEW,
177 252 array($this, 'displayMainPage')
178 253 );
179 254
@@ -181,9 +256,9 @@
181 256 add_submenu_page(
182 257 'easy-invoice',
183 258 __('All Quotes', 'easy-invoice'),
184 259 __('All Quotes', 'easy-invoice'),
185 - 'manage_options',
260 + $this->menuCapability(PagesSlugs::ALL_QUOTES),
186 261 PagesSlugs::ALL_QUOTES,
187 262 array($this, 'displayMainPage')
188 263 );
189 264
@@ -191,9 +266,9 @@
191 266 add_submenu_page(
192 267 'easy-invoice-hidden',
193 268 __('Add New Quote', 'easy-invoice'),
194 269 __('Add New Quote', 'easy-invoice'),
195 - 'manage_options',
270 + $this->menuCapability(PagesSlugs::QUOTE_NEW),
196 271 PagesSlugs::QUOTE_NEW,
197 272 array($this, 'displayMainPage')
198 273 );
199 274
@@ -201,9 +276,9 @@
201 276 add_submenu_page(
202 277 'easy-invoice-hidden',
203 278 __('Payments', 'easy-invoice'),
204 279 __('Payments', 'easy-invoice'),
205 - 'manage_options',
280 + $this->menuCapability(PagesSlugs::PAYMENTS),
206 281 PagesSlugs::PAYMENTS,
207 282 array($this, 'displayMainPage')
208 283 );
209 284
@@ -211,9 +286,9 @@
211 286 add_submenu_page(
212 287 'easy-invoice-hidden',
213 288 __('Add New Payment', 'easy-invoice'),
214 289 __('Add New Payment', 'easy-invoice'),
215 - 'manage_options',
290 + $this->menuCapability(PagesSlugs::PAYMENT_NEW),
216 291 PagesSlugs::PAYMENT_NEW,
217 292 array($this, 'displayMainPage')
218 293 );
219 294
@@ -221,50 +296,66 @@
221 296 add_submenu_page(
222 297 'easy-invoice',
223 298 __('All Clients', 'easy-invoice'),
224 299 __('All Clients', 'easy-invoice'),
225 - 'edit_posts',
300 + $this->menuCapability(PagesSlugs::CLIENTS),
226 301 PagesSlugs::CLIENTS,
227 302 array($this, 'displayMainPage')
228 303 );
229 304
230 - // Item Library submenu - only show if Pro is active
231 - if (easy_invoice_has_pro()) {
305 + // Item Library + Template Builder pages are reached via the
306 + // Easy Invoice in-app sidebar (templates/main-template.php), NOT
307 + // the WP admin submenu. We still register the page slugs so the
308 + // URLs resolve, but we parent them under 'easy-invoice-hidden'
309 + // so they don't render duplicate entries in the WP submenu —
310 + // the WP submenu showed the link AND the in-app sidebar showed
311 + // the same link, giving the user two visible navigation
312 + // entry-points to the same page.
313 + //
314 + // Registration is still gated on the addon being active — if
315 + // the addon is off, the slug isn't registered, so direct-URL
316 + // access returns the standard "you do not have sufficient
317 + // permissions" page.
318 + if (easy_invoice_has_pro() && \EasyInvoice\Addons\AddonManager::shouldLoad('item_library')) {
232 319 add_submenu_page(
233 - 'easy-invoice',
320 + 'easy-invoice-hidden',
234 321 __('Item Library', 'easy-invoice'),
235 322 __('Item Library', 'easy-invoice'),
236 - 'manage_options',
323 + $this->menuCapability('easy-invoice-pro-item-library'),
237 324 'easy-invoice-pro-item-library',
238 325 array($this, 'displayMainPage')
239 326 );
240 -
241 - // Template Builder submenu - only show if Pro is active
327 + }
328 +
329 + if (easy_invoice_has_pro() && \EasyInvoice\Addons\AddonManager::shouldLoad('custom_templates')) {
330 + // Template listing — reachable from the in-app sidebar.
242 331 add_submenu_page(
243 - 'easy-invoice',
332 + 'easy-invoice-hidden',
244 333 __('Template Builder', 'easy-invoice'),
245 334 __('Template Builder', 'easy-invoice'),
246 - 'manage_options',
335 + $this->menuCapability('easy-invoice-templates'),
247 336 'easy-invoice-templates',
248 337 array($this, 'displayMainPage')
249 338 );
250 -
251 - // Create New Template submenu - only show if Pro is active
339 +
340 + // Create New Template — used by deep-links from inside the
341 + // builder UI.
252 342 add_submenu_page(
253 343 'easy-invoice-hidden',
254 344 __('Create New Template', 'easy-invoice'),
255 345 __('Create New', 'easy-invoice'),
256 - 'manage_options',
346 + $this->menuCapability('easy-invoice-templates-new'),
257 347 'easy-invoice-templates-new',
258 348 array($this, 'displayMainPage')
259 349 );
260 -
261 - // Template Builder Page submenu - only show if Pro is active (hidden page)
350 +
351 + // Template Builder canvas — full-screen builder, reached
352 + // from the listing page's Edit / New buttons.
262 353 add_submenu_page(
263 354 'easy-invoice-hidden',
264 355 __('Template Builder Page', 'easy-invoice'),
265 356 __('Template Builder Page', 'easy-invoice'),
266 - 'manage_options',
357 + $this->menuCapability('easy-invoice-template-builder'),
267 358 'easy-invoice-template-builder',
268 359 array($this, 'displayMainPage')
269 360 );
270 361 }
@@ -273,9 +364,9 @@
273 364 add_submenu_page(
274 365 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
275 366 __('Edit Client', 'easy-invoice'),
276 367 __('Edit Client', 'easy-invoice'),
277 - 'manage_options',
368 + $this->menuCapability(PagesSlugs::CLIENT_EDIT),
278 369 PagesSlugs::CLIENT_EDIT,
279 370 array($this, 'displayMainPage')
280 371 );
281 372
@@ -282,9 +373,9 @@
282 373 add_submenu_page(
283 374 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
284 375 __('View Client', 'easy-invoice'),
285 376 __('View Client', 'easy-invoice'),
286 - 'manage_options',
377 + $this->menuCapability(PagesSlugs::CLIENT_VIEW),
287 378 PagesSlugs::CLIENT_VIEW,
288 379 array($this, 'displayMainPage')
289 380 );
290 381
@@ -291,9 +382,9 @@
291 382 add_submenu_page(
292 383 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
293 384 __('Preview Invoice', 'easy-invoice'),
294 385 __('Preview Invoice', 'easy-invoice'),
295 - 'manage_options',
386 + $this->menuCapability(PagesSlugs::INVOICE_PREVIEW),
296 387 PagesSlugs::INVOICE_PREVIEW,
297 388 array($this, 'displayPreviewPage')
298 389 );
299 390
@@ -300,29 +391,46 @@
300 391 add_submenu_page(
301 392 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
302 393 __('Preview Quote', 'easy-invoice'),
303 394 __('Preview Quote', 'easy-invoice'),
304 - 'manage_options',
395 + $this->menuCapability(PagesSlugs::QUOTE_PREVIEW),
305 396 PagesSlugs::QUOTE_PREVIEW,
306 397 array($this, 'displayMainPage')
307 398 );
308 399
400 + // Reports — addon-gated (Personal tier). Slug registered as a
401 + // HIDDEN submenu so the WP admin sidebar doesn't double the
402 + // in-app sidebar entry. When the reports addon is disabled, the
403 + // slug isn't registered at all, so direct-URL access falls
404 + // through to WP's "no permission" page.
405 + if (\EasyInvoice\Addons\AddonManager::shouldLoad('reports')) {
406 + add_submenu_page(
407 + 'easy-invoice-hidden',
408 + __('Reports', 'easy-invoice'),
409 + __('Reports', 'easy-invoice'),
410 + $this->menuCapability(PagesSlugs::REPORTS),
411 + PagesSlugs::REPORTS,
412 + array($this, 'displayMainPage')
413 + );
414 + }
415 +
416 + // Settings submenu
309 417 add_submenu_page(
310 418 'easy-invoice',
311 - __('Reports', 'easy-invoice'),
312 - __('Reports', 'easy-invoice'),
313 - 'manage_options',
314 - PagesSlugs::REPORTS,
419 + __('Settings', 'easy-invoice'),
420 + __('Settings', 'easy-invoice'),
421 + $this->menuCapability(PagesSlugs::SETTINGS),
422 + PagesSlugs::SETTINGS,
315 423 array($this, 'displayMainPage')
316 424 );
317 425
318 - // Settings submenu
426 + // Addons submenu
319 427 add_submenu_page(
320 428 'easy-invoice',
321 - __('Settings', 'easy-invoice'),
322 - __('Settings', 'easy-invoice'),
323 - 'manage_options',
324 - PagesSlugs::SETTINGS,
429 + __('Addons', 'easy-invoice'),
430 + __('Addons', 'easy-invoice'),
431 + $this->menuCapability(PagesSlugs::ADDONS),
432 + PagesSlugs::ADDONS,
325 433 array($this, 'displayMainPage')
326 434 );
327 435
328 436 // License submenu
@@ -329,9 +437,9 @@
329 437 add_submenu_page(
330 438 'easy-invoice',
331 439 __('License', 'easy-invoice'),
332 440 __('License', 'easy-invoice'),
333 - 'manage_options',
441 + $this->menuCapability(PagesSlugs::LICENSE),
334 442 PagesSlugs::LICENSE,
335 443 array($this, 'displayMainPage')
336 444 );
337 445
@@ -340,9 +448,9 @@
340 448 add_submenu_page(
341 449 'easy-invoice',
342 450 __('Free vs Pro', 'easy-invoice'),
343 451 __('Free vs Pro', 'easy-invoice'),
344 - 'manage_options',
452 + $this->menuCapability('easy-invoice-free-vs-pro'),
345 453 'easy-invoice-free-vs-pro',
346 454 array($this, 'displayMainPage')
347 455 );
348 456 }
@@ -361,17 +469,22 @@
361 469 /**
362 470 * Redirect to community page
363 471 */
364 472 public function redirectToCommunity() {
365 - wp_redirect(esc_url_raw('https://www.facebook.com/groups/mantrabraincommunity'));
473 + wp_safe_redirect(esc_url_raw('https://www.facebook.com/groups/mantrabraincommunity'));
366 474 exit;
367 475 }
368 476
369 477 /**
370 - * Register invoice preview page
478 + * Register invoice preview page.
479 + *
480 + * Placeholder kept as an extension point — the preview-page hook used to
481 + * be wired here but is now routed through the per-document preview
482 + * controller. Left in place so themes/plugins relying on a no-op
483 + * `registerPreviewPage()` call don't fatal.
371 484 */
372 485 public function registerPreviewPage() {
373 - //add_action('admin_action_easy_invoice_preview', array($this, 'displayPreviewPage'));
486 + // No-op: preview rendering is handled by the per-document controller.
374 487 }
375 488
376 489 /**
377 490 * Display main page
@@ -394,8 +507,17 @@
394 507 include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/license-page.php';
395 508 }
396 509
397 510 /**
511 + * Display addons page
512 + */
513 + public function displayAddonsPage() {
514 + if (class_exists('\\EasyInvoice\\Controllers\\AddonsController')) {
515 + (new \EasyInvoice\Controllers\AddonsController())->display();
516 + }
517 + }
518 +
519 + /**
398 520 * Handle main page content based on the current page
399 521 *
400 522 * @param string $page Current page
401 523 */
@@ -430,9 +552,9 @@
430 552 break;
431 553
432 554 case PagesSlugs::PAYMENTS:
433 555 if (isset($_GET['action'])) {
434 - $this->payment_controller->display(['page' => $_GET['action']]);
556 + $this->payment_controller->display(['page' => sanitize_key(wp_unslash($_GET['action']))]); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
435 557 } else {
436 558 $this->payment_controller->display(['page' => PagesSlugs::PAYMENTS]);
437 559 }
438 560 break;
@@ -448,36 +570,43 @@
448 570 case PagesSlugs::CLIENT_EDIT:
449 571 $this->client_controller->display(['page' => PagesSlugs::CLIENT_EDIT]);
450 572 break;
451 573
452 - // Handle Pro features
574 + // Handle Pro features — gated on addon-state. The menu
575 + // registrations above are also addon-gated, so these cases
576 + // should only fire when the addon is enabled. Re-checking
577 + // shouldLoad() here is defensive in case the user hits the
578 + // page slug directly via URL.
453 579 case 'easy-invoice-pro-item-library':
454 - if (easy_invoice_has_pro()) {
455 - // Use the Pro controller's displayMainPage method like other controllers
456 - if (class_exists('\EasyInvoicePro\Controllers\ItemLibraryController')) {
457 - $item_library_controller = new \EasyInvoicePro\Controllers\ItemLibraryController();
458 - $item_library_controller->displayMainPage();
459 - }
580 + if (
581 + easy_invoice_has_pro()
582 + && \EasyInvoice\Addons\AddonManager::shouldLoad('item_library')
583 + && class_exists('\EasyInvoicePro\Addons\ItemLibrary\Controllers\ItemLibraryController')
584 + ) {
585 + $item_library_controller = new \EasyInvoicePro\Addons\ItemLibrary\Controllers\ItemLibraryController();
586 + $item_library_controller->displayMainPage();
460 587 }
461 588 break;
462 -
589 +
463 590 case 'easy-invoice-templates':
464 - if (easy_invoice_has_pro()) {
465 - // Use the Pro controller's displayMainPage method like other controllers
466 - if (class_exists('\EasyInvoicePro\Controllers\TemplateBuilderController')) {
467 - $template_builder_controller = new \EasyInvoicePro\Controllers\TemplateBuilderController();
468 - $template_builder_controller->displayMainPage();
469 - }
591 + if (
592 + easy_invoice_has_pro()
593 + && \EasyInvoice\Addons\AddonManager::shouldLoad('custom_templates')
594 + && class_exists('\EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController')
595 + ) {
596 + $template_builder_controller = new \EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController();
597 + $template_builder_controller->displayMainPage();
470 598 }
471 599 break;
472 600
473 601 case 'easy-invoice-template-builder':
474 - if (easy_invoice_has_pro()) {
475 - // Use the Pro controller's displayMainPage method like other controllers
476 - if (class_exists('\EasyInvoicePro\Controllers\TemplateBuilderController')) {
477 - $template_builder_controller = new \EasyInvoicePro\Controllers\TemplateBuilderController();
478 - $template_builder_controller->displayMainPage();
479 - }
602 + if (
603 + easy_invoice_has_pro()
604 + && \EasyInvoice\Addons\AddonManager::shouldLoad('custom_templates')
605 + && class_exists('\EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController')
606 + ) {
607 + $template_builder_controller = new \EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController();
608 + $template_builder_controller->displayMainPage();
480 609 }
481 610 break;
482 611
483 612 case PagesSlugs::CLIENT_VIEW:
@@ -484,9 +613,16 @@
484 613 $this->client_controller->display(['page' => PagesSlugs::CLIENT_VIEW]);
485 614 break;
486 615
487 616 case PagesSlugs::REPORTS:
488 - $this->report_controller->display(['page' => PagesSlugs::REPORTS]);
617 + // Reports is addon-gated. The submenu page slug is only
618 + // registered when shouldLoad('reports') is true, so this
619 + // case ordinarily only fires for active-addon users —
620 + // but recheck defensively in case the page is reached
621 + // via direct URL right after the addon was disabled.
622 + if (\EasyInvoice\Addons\AddonManager::shouldLoad('reports')) {
623 + $this->report_controller->display(['page' => PagesSlugs::REPORTS]);
624 + }
489 625 break;
490 626
491 627 case PagesSlugs::SETTINGS:
492 628 $this->settings_controller->display(['page' => PagesSlugs::SETTINGS]);
@@ -495,8 +631,12 @@
495 631 case PagesSlugs::LICENSE:
496 632 $this->displayLicensePage();
497 633 break;
498 634
635 + case PagesSlugs::ADDONS:
636 + $this->displayAddonsPage();
637 + break;
638 +
499 639 case PagesSlugs::EMAIL_SETTINGS:
500 640 case PagesSlugs::EMAIL_SETTINGS_GENERAL:
501 641 case PagesSlugs::EMAIL_SETTINGS_INVOICE:
502 642 case PagesSlugs::EMAIL_SETTINGS_QUOTE:
@@ -512,8 +652,60 @@
512 652 include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/free-vs-pro-page.php';
513 653 break;
514 654
515 655 default:
656 + // Addon pages render themselves via the
657 + // `easy_invoice_admin_main_content` action at priority 11. The
658 + // dispatcher must NOT fall through to the Dashboard for those
659 + // slugs, otherwise the Dashboard markup gets emitted first and
660 + // the addon panel renders on top of it (two pages stacked).
661 + //
662 + // We treat any slug that's either (a) prefixed with
663 + // `easy-invoice-addon-` or (b) registered in AddonRegistry as
664 + // an addon page — and just `break` to let the addon's own hook
665 + // handle the rendering.
666 + if (strpos($page, 'easy-invoice-addon-') === 0) {
667 + break;
668 + }
669 +
670 + /**
671 + * Slugs whose page draws itself on the same hook at a later
672 + * priority, and which must therefore not get the Dashboard
673 + * rendered underneath them.
674 + *
675 + * Addon pages were special-cased by prefix above, which left
676 + * anything in the free plugin that renders the same way — the
677 + * credit note screen, for one — falling through to the
678 + * Dashboard and stacking two pages on top of each other. A
679 + * filter means the next such page registers itself instead of
680 + * editing this switch and rediscovering the same bug.
681 + *
682 + * @param string[] $slugs Page slugs that render themselves.
683 + */
684 + // "Create New Template" is a deep-link slug with no screen of
685 + // its own; send it to the builder rather than draw the Dashboard.
686 + if ('easy-invoice-templates-new' === $page) {
687 + echo '<script>window.location.replace(' . wp_json_encode(admin_url('admin.php?page=easy-invoice-template-builder&action=new')) . ');</script>';
688 + break;
689 + }
690 + $self_rendering = (array) apply_filters('easy_invoice_self_rendering_pages', [
691 + \EasyInvoice\Controllers\CreditNoteController::PAGE_SLUG,
692 + ]);
693 +
694 + if (in_array($page, $self_rendering, true)) {
695 + break;
696 + }
697 + if (class_exists('\\EasyInvoice\\Addons\\AddonRegistry')) {
698 + foreach (\EasyInvoice\Addons\AddonRegistry::all() as $_addon) {
699 + if (empty($_addon['settings_url'])) continue;
700 + $parsed = wp_parse_url($_addon['settings_url']);
701 + if (empty($parsed['query'])) continue;
702 + parse_str($parsed['query'], $q);
703 + if (($q['page'] ?? '') === $page) {
704 + return; // Addon owns this slug — bail without rendering.
705 + }
706 + }
707 + }
516 708 $this->dashboard_controller->display(['page' => PagesSlugs::DASHBOARD]);
517 709 break;
518 710 }
519 711 }
@@ -546,8 +738,9 @@
546 738 'easy-invoice-settings' => __('Settings', 'easy-invoice'),
547 739 'easy-invoice-email-settings' => __('Email Settings', 'easy-invoice'),
548 740 'easy-invoice-migration' => __('Migration', 'easy-invoice'),
549 741 'easy-invoice-free-vs-pro' => __('Free vs Pro', 'easy-invoice'),
742 + 'easy-invoice-addons' => __('Addons', 'easy-invoice'),
550 743 ];
551 744
552 745 if (isset($page_titles[$current_page])) {
553 746 return $page_titles[$current_page] . ' - ' . get_bloginfo('name');