PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.0
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.0
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
← All changes | includes/Admin/EasyInvoiceAdmin.php +274 -68 2.1.102.4.0 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();
@@ -115,8 +124,11 @@
115 124
116 125 // Hide admin UI
117 126 add_action('admin_head', array($this, 'hideAdminUi'));
118 127
128 + // Body class for layout fixes (admin bar offset, header strip alignment)
129 + add_filter('admin_body_class', array($this, 'adminBodyClass'));
130 +
119 131 // Initialize controllers
120 132 $this->invoice_controller->init();
121 133 $this->quote_controller->init();
122 134 $this->client_controller->init();
@@ -129,8 +141,56 @@
129 141 add_action('easy_invoice_admin_main_content', array($this, 'mainPageContent'));
130 142 }
131 143
132 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 + /**
133 193 * Register admin menu pages
134 194 */
135 195 public function registerMenuPages() {
136 196 // Main menu item
@@ -136,9 +196,9 @@
136 196 // Main menu item
137 197 add_menu_page(
138 198 __('Easy Invoice', 'easy-invoice'),
139 199 __('Easy Invoice', 'easy-invoice'),
140 - 'manage_options',
200 + $this->menuCapability(PagesSlugs::DASHBOARD),
141 201 PagesSlugs::DASHBOARD,
142 202 array($this, 'displayMainPage'),
143 203 'dashicons-media-text',
144 204 25
@@ -148,9 +208,9 @@
148 208 add_submenu_page(
149 209 'easy-invoice',
150 210 __('Dashboard', 'easy-invoice'),
151 211 __('Dashboard', 'easy-invoice'),
152 - 'manage_options',
212 + $this->menuCapability(PagesSlugs::DASHBOARD),
153 213 PagesSlugs::DASHBOARD,
154 214 array($this, 'displayMainPage')
155 215 );
156 216
@@ -158,9 +218,9 @@
158 218 add_submenu_page(
159 219 'easy-invoice',
160 220 __('All Invoices', 'easy-invoice'),
161 221 __('All Invoices', 'easy-invoice'),
162 - 'manage_options',
222 + $this->menuCapability(PagesSlugs::ALL_INVOICES),
163 223 PagesSlugs::ALL_INVOICES,
164 224 array($this, 'displayMainPage')
165 225 );
166 226
@@ -168,9 +228,9 @@
168 228 add_submenu_page(
169 229 'easy-invoice-hidden',
170 230 __('Add New Invoice', 'easy-invoice'),
171 231 __('Add New', 'easy-invoice'),
172 - 'manage_options',
232 + $this->menuCapability(PagesSlugs::INVOICE_NEW),
173 233 PagesSlugs::INVOICE_NEW,
174 234 array($this, 'displayMainPage')
175 235 );
176 236
@@ -178,9 +238,9 @@
178 238 add_submenu_page(
179 239 'easy-invoice',
180 240 __('All Quotes', 'easy-invoice'),
181 241 __('All Quotes', 'easy-invoice'),
182 - 'manage_options',
242 + $this->menuCapability(PagesSlugs::ALL_QUOTES),
183 243 PagesSlugs::ALL_QUOTES,
184 244 array($this, 'displayMainPage')
185 245 );
186 246
@@ -188,9 +248,9 @@
188 248 add_submenu_page(
189 249 'easy-invoice-hidden',
190 250 __('Add New Quote', 'easy-invoice'),
191 251 __('Add New Quote', 'easy-invoice'),
192 - 'manage_options',
252 + $this->menuCapability(PagesSlugs::QUOTE_NEW),
193 253 PagesSlugs::QUOTE_NEW,
194 254 array($this, 'displayMainPage')
195 255 );
196 256
@@ -198,9 +258,9 @@
198 258 add_submenu_page(
199 259 'easy-invoice-hidden',
200 260 __('Payments', 'easy-invoice'),
201 261 __('Payments', 'easy-invoice'),
202 - 'manage_options',
262 + $this->menuCapability(PagesSlugs::PAYMENTS),
203 263 PagesSlugs::PAYMENTS,
204 264 array($this, 'displayMainPage')
205 265 );
206 266
@@ -208,9 +268,9 @@
208 268 add_submenu_page(
209 269 'easy-invoice-hidden',
210 270 __('Add New Payment', 'easy-invoice'),
211 271 __('Add New Payment', 'easy-invoice'),
212 - 'manage_options',
272 + $this->menuCapability(PagesSlugs::PAYMENT_NEW),
213 273 PagesSlugs::PAYMENT_NEW,
214 274 array($this, 'displayMainPage')
215 275 );
216 276
@@ -218,50 +278,66 @@
218 278 add_submenu_page(
219 279 'easy-invoice',
220 280 __('All Clients', 'easy-invoice'),
221 281 __('All Clients', 'easy-invoice'),
222 - 'edit_posts',
282 + $this->menuCapability(PagesSlugs::CLIENTS),
223 283 PagesSlugs::CLIENTS,
224 284 array($this, 'displayMainPage')
225 285 );
226 286
227 - // Item Library submenu - only show if Pro is active
228 - if (easy_invoice_has_pro()) {
287 + // Item Library + Template Builder pages are reached via the
288 + // Easy Invoice in-app sidebar (templates/main-template.php), NOT
289 + // the WP admin submenu. We still register the page slugs so the
290 + // URLs resolve, but we parent them under 'easy-invoice-hidden'
291 + // so they don't render duplicate entries in the WP submenu —
292 + // the WP submenu showed the link AND the in-app sidebar showed
293 + // the same link, giving the user two visible navigation
294 + // entry-points to the same page.
295 + //
296 + // Registration is still gated on the addon being active — if
297 + // the addon is off, the slug isn't registered, so direct-URL
298 + // access returns the standard "you do not have sufficient
299 + // permissions" page.
300 + if (easy_invoice_has_pro() && \EasyInvoice\Addons\AddonManager::shouldLoad('item_library')) {
229 301 add_submenu_page(
230 - 'easy-invoice',
302 + 'easy-invoice-hidden',
231 303 __('Item Library', 'easy-invoice'),
232 304 __('Item Library', 'easy-invoice'),
233 - 'manage_options',
305 + $this->menuCapability('easy-invoice-pro-item-library'),
234 306 'easy-invoice-pro-item-library',
235 307 array($this, 'displayMainPage')
236 308 );
237 -
238 - // Template Builder submenu - only show if Pro is active
309 + }
310 +
311 + if (easy_invoice_has_pro() && \EasyInvoice\Addons\AddonManager::shouldLoad('custom_templates')) {
312 + // Template listing — reachable from the in-app sidebar.
239 313 add_submenu_page(
240 - 'easy-invoice',
314 + 'easy-invoice-hidden',
241 315 __('Template Builder', 'easy-invoice'),
242 316 __('Template Builder', 'easy-invoice'),
243 - 'manage_options',
317 + $this->menuCapability('easy-invoice-templates'),
244 318 'easy-invoice-templates',
245 319 array($this, 'displayMainPage')
246 320 );
247 -
248 - // Create New Template submenu - only show if Pro is active
321 +
322 + // Create New Template — used by deep-links from inside the
323 + // builder UI.
249 324 add_submenu_page(
250 325 'easy-invoice-hidden',
251 326 __('Create New Template', 'easy-invoice'),
252 327 __('Create New', 'easy-invoice'),
253 - 'manage_options',
328 + $this->menuCapability('easy-invoice-templates-new'),
254 329 'easy-invoice-templates-new',
255 330 array($this, 'displayMainPage')
256 331 );
257 -
258 - // Template Builder Page submenu - only show if Pro is active (hidden page)
332 +
333 + // Template Builder canvas — full-screen builder, reached
334 + // from the listing page's Edit / New buttons.
259 335 add_submenu_page(
260 336 'easy-invoice-hidden',
261 337 __('Template Builder Page', 'easy-invoice'),
262 338 __('Template Builder Page', 'easy-invoice'),
263 - 'manage_options',
339 + $this->menuCapability('easy-invoice-template-builder'),
264 340 'easy-invoice-template-builder',
265 341 array($this, 'displayMainPage')
266 342 );
267 343 }
@@ -270,9 +346,9 @@
270 346 add_submenu_page(
271 347 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
272 348 __('Edit Client', 'easy-invoice'),
273 349 __('Edit Client', 'easy-invoice'),
274 - 'manage_options',
350 + $this->menuCapability(PagesSlugs::CLIENT_EDIT),
275 351 PagesSlugs::CLIENT_EDIT,
276 352 array($this, 'displayMainPage')
277 353 );
278 354
@@ -279,9 +355,9 @@
279 355 add_submenu_page(
280 356 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
281 357 __('View Client', 'easy-invoice'),
282 358 __('View Client', 'easy-invoice'),
283 - 'manage_options',
359 + $this->menuCapability(PagesSlugs::CLIENT_VIEW),
284 360 PagesSlugs::CLIENT_VIEW,
285 361 array($this, 'displayMainPage')
286 362 );
287 363
@@ -288,9 +364,9 @@
288 364 add_submenu_page(
289 365 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
290 366 __('Preview Invoice', 'easy-invoice'),
291 367 __('Preview Invoice', 'easy-invoice'),
292 - 'manage_options',
368 + $this->menuCapability(PagesSlugs::INVOICE_PREVIEW),
293 369 PagesSlugs::INVOICE_PREVIEW,
294 370 array($this, 'displayPreviewPage')
295 371 );
296 372
@@ -297,29 +373,46 @@
297 373 add_submenu_page(
298 374 'easy-invoice-hidden', // Use main menu as parent to avoid title issues
299 375 __('Preview Quote', 'easy-invoice'),
300 376 __('Preview Quote', 'easy-invoice'),
301 - 'manage_options',
377 + $this->menuCapability(PagesSlugs::QUOTE_PREVIEW),
302 378 PagesSlugs::QUOTE_PREVIEW,
303 379 array($this, 'displayMainPage')
304 380 );
305 381
382 + // Reports — addon-gated (Personal tier). Slug registered as a
383 + // HIDDEN submenu so the WP admin sidebar doesn't double the
384 + // in-app sidebar entry. When the reports addon is disabled, the
385 + // slug isn't registered at all, so direct-URL access falls
386 + // through to WP's "no permission" page.
387 + if (\EasyInvoice\Addons\AddonManager::shouldLoad('reports')) {
388 + add_submenu_page(
389 + 'easy-invoice-hidden',
390 + __('Reports', 'easy-invoice'),
391 + __('Reports', 'easy-invoice'),
392 + $this->menuCapability(PagesSlugs::REPORTS),
393 + PagesSlugs::REPORTS,
394 + array($this, 'displayMainPage')
395 + );
396 + }
397 +
398 + // Settings submenu
306 399 add_submenu_page(
307 400 'easy-invoice',
308 - __('Reports', 'easy-invoice'),
309 - __('Reports', 'easy-invoice'),
310 - 'manage_options',
311 - PagesSlugs::REPORTS,
401 + __('Settings', 'easy-invoice'),
402 + __('Settings', 'easy-invoice'),
403 + $this->menuCapability(PagesSlugs::SETTINGS),
404 + PagesSlugs::SETTINGS,
312 405 array($this, 'displayMainPage')
313 406 );
314 407
315 - // Settings submenu
408 + // Addons submenu
316 409 add_submenu_page(
317 410 'easy-invoice',
318 - __('Settings', 'easy-invoice'),
319 - __('Settings', 'easy-invoice'),
320 - 'manage_options',
321 - PagesSlugs::SETTINGS,
411 + __('Addons', 'easy-invoice'),
412 + __('Addons', 'easy-invoice'),
413 + $this->menuCapability(PagesSlugs::ADDONS),
414 + PagesSlugs::ADDONS,
322 415 array($this, 'displayMainPage')
323 416 );
324 417
325 418 // License submenu
@@ -326,9 +419,9 @@
326 419 add_submenu_page(
327 420 'easy-invoice',
328 421 __('License', 'easy-invoice'),
329 422 __('License', 'easy-invoice'),
330 - 'manage_options',
423 + $this->menuCapability(PagesSlugs::LICENSE),
331 424 PagesSlugs::LICENSE,
332 425 array($this, 'displayMainPage')
333 426 );
334 427
@@ -337,9 +430,9 @@
337 430 add_submenu_page(
338 431 'easy-invoice',
339 432 __('Free vs Pro', 'easy-invoice'),
340 433 __('Free vs Pro', 'easy-invoice'),
341 - 'manage_options',
434 + $this->menuCapability('easy-invoice-free-vs-pro'),
342 435 'easy-invoice-free-vs-pro',
343 436 array($this, 'displayMainPage')
344 437 );
345 438 }
@@ -358,17 +451,22 @@
358 451 /**
359 452 * Redirect to community page
360 453 */
361 454 public function redirectToCommunity() {
362 - wp_redirect(esc_url_raw('https://www.facebook.com/groups/mantrabraincommunity'));
455 + wp_safe_redirect(esc_url_raw('https://www.facebook.com/groups/mantrabraincommunity'));
363 456 exit;
364 457 }
365 458
366 459 /**
367 - * Register invoice preview page
460 + * Register invoice preview page.
461 + *
462 + * Placeholder kept as an extension point — the preview-page hook used to
463 + * be wired here but is now routed through the per-document preview
464 + * controller. Left in place so themes/plugins relying on a no-op
465 + * `registerPreviewPage()` call don't fatal.
368 466 */
369 467 public function registerPreviewPage() {
370 - //add_action('admin_action_easy_invoice_preview', array($this, 'displayPreviewPage'));
468 + // No-op: preview rendering is handled by the per-document controller.
371 469 }
372 470
373 471 /**
374 472 * Display main page
@@ -391,8 +489,17 @@
391 489 include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/license-page.php';
392 490 }
393 491
394 492 /**
493 + * Display addons page
494 + */
495 + public function displayAddonsPage() {
496 + if (class_exists('\\EasyInvoice\\Controllers\\AddonsController')) {
497 + (new \EasyInvoice\Controllers\AddonsController())->display();
498 + }
499 + }
500 +
501 + /**
395 502 * Handle main page content based on the current page
396 503 *
397 504 * @param string $page Current page
398 505 */
@@ -427,9 +534,9 @@
427 534 break;
428 535
429 536 case PagesSlugs::PAYMENTS:
430 537 if (isset($_GET['action'])) {
431 - $this->payment_controller->display(['page' => $_GET['action']]);
538 + $this->payment_controller->display(['page' => sanitize_key(wp_unslash($_GET['action']))]); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
432 539 } else {
433 540 $this->payment_controller->display(['page' => PagesSlugs::PAYMENTS]);
434 541 }
435 542 break;
@@ -445,36 +552,43 @@
445 552 case PagesSlugs::CLIENT_EDIT:
446 553 $this->client_controller->display(['page' => PagesSlugs::CLIENT_EDIT]);
447 554 break;
448 555
449 - // Handle Pro features
556 + // Handle Pro features — gated on addon-state. The menu
557 + // registrations above are also addon-gated, so these cases
558 + // should only fire when the addon is enabled. Re-checking
559 + // shouldLoad() here is defensive in case the user hits the
560 + // page slug directly via URL.
450 561 case 'easy-invoice-pro-item-library':
451 - if (easy_invoice_has_pro()) {
452 - // Use the Pro controller's displayMainPage method like other controllers
453 - if (class_exists('\EasyInvoicePro\Controllers\ItemLibraryController')) {
454 - $item_library_controller = new \EasyInvoicePro\Controllers\ItemLibraryController();
455 - $item_library_controller->displayMainPage();
456 - }
562 + if (
563 + easy_invoice_has_pro()
564 + && \EasyInvoice\Addons\AddonManager::shouldLoad('item_library')
565 + && class_exists('\EasyInvoicePro\Addons\ItemLibrary\Controllers\ItemLibraryController')
566 + ) {
567 + $item_library_controller = new \EasyInvoicePro\Addons\ItemLibrary\Controllers\ItemLibraryController();
568 + $item_library_controller->displayMainPage();
457 569 }
458 570 break;
459 -
571 +
460 572 case 'easy-invoice-templates':
461 - if (easy_invoice_has_pro()) {
462 - // Use the Pro controller's displayMainPage method like other controllers
463 - if (class_exists('\EasyInvoicePro\Controllers\TemplateBuilderController')) {
464 - $template_builder_controller = new \EasyInvoicePro\Controllers\TemplateBuilderController();
465 - $template_builder_controller->displayMainPage();
466 - }
573 + if (
574 + easy_invoice_has_pro()
575 + && \EasyInvoice\Addons\AddonManager::shouldLoad('custom_templates')
576 + && class_exists('\EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController')
577 + ) {
578 + $template_builder_controller = new \EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController();
579 + $template_builder_controller->displayMainPage();
467 580 }
468 581 break;
469 582
470 583 case 'easy-invoice-template-builder':
471 - if (easy_invoice_has_pro()) {
472 - // Use the Pro controller's displayMainPage method like other controllers
473 - if (class_exists('\EasyInvoicePro\Controllers\TemplateBuilderController')) {
474 - $template_builder_controller = new \EasyInvoicePro\Controllers\TemplateBuilderController();
475 - $template_builder_controller->displayMainPage();
476 - }
584 + if (
585 + easy_invoice_has_pro()
586 + && \EasyInvoice\Addons\AddonManager::shouldLoad('custom_templates')
587 + && class_exists('\EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController')
588 + ) {
589 + $template_builder_controller = new \EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController();
590 + $template_builder_controller->displayMainPage();
477 591 }
478 592 break;
479 593
480 594 case PagesSlugs::CLIENT_VIEW:
@@ -481,9 +595,16 @@
481 595 $this->client_controller->display(['page' => PagesSlugs::CLIENT_VIEW]);
482 596 break;
483 597
484 598 case PagesSlugs::REPORTS:
485 - $this->report_controller->display(['page' => PagesSlugs::REPORTS]);
599 + // Reports is addon-gated. The submenu page slug is only
600 + // registered when shouldLoad('reports') is true, so this
601 + // case ordinarily only fires for active-addon users —
602 + // but recheck defensively in case the page is reached
603 + // via direct URL right after the addon was disabled.
604 + if (\EasyInvoice\Addons\AddonManager::shouldLoad('reports')) {
605 + $this->report_controller->display(['page' => PagesSlugs::REPORTS]);
606 + }
486 607 break;
487 608
488 609 case PagesSlugs::SETTINGS:
489 610 $this->settings_controller->display(['page' => PagesSlugs::SETTINGS]);
@@ -492,8 +613,12 @@
492 613 case PagesSlugs::LICENSE:
493 614 $this->displayLicensePage();
494 615 break;
495 616
617 + case PagesSlugs::ADDONS:
618 + $this->displayAddonsPage();
619 + break;
620 +
496 621 case PagesSlugs::EMAIL_SETTINGS:
497 622 case PagesSlugs::EMAIL_SETTINGS_GENERAL:
498 623 case PagesSlugs::EMAIL_SETTINGS_INVOICE:
499 624 case PagesSlugs::EMAIL_SETTINGS_QUOTE:
@@ -509,8 +634,60 @@
509 634 include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/free-vs-pro-page.php';
510 635 break;
511 636
512 637 default:
638 + // Addon pages render themselves via the
639 + // `easy_invoice_admin_main_content` action at priority 11. The
640 + // dispatcher must NOT fall through to the Dashboard for those
641 + // slugs, otherwise the Dashboard markup gets emitted first and
642 + // the addon panel renders on top of it (two pages stacked).
643 + //
644 + // We treat any slug that's either (a) prefixed with
645 + // `easy-invoice-addon-` or (b) registered in AddonRegistry as
646 + // an addon page — and just `break` to let the addon's own hook
647 + // handle the rendering.
648 + if (strpos($page, 'easy-invoice-addon-') === 0) {
649 + break;
650 + }
651 +
652 + /**
653 + * Slugs whose page draws itself on the same hook at a later
654 + * priority, and which must therefore not get the Dashboard
655 + * rendered underneath them.
656 + *
657 + * Addon pages were special-cased by prefix above, which left
658 + * anything in the free plugin that renders the same way — the
659 + * credit note screen, for one — falling through to the
660 + * Dashboard and stacking two pages on top of each other. A
661 + * filter means the next such page registers itself instead of
662 + * editing this switch and rediscovering the same bug.
663 + *
664 + * @param string[] $slugs Page slugs that render themselves.
665 + */
666 + // "Create New Template" is a deep-link slug with no screen of
667 + // its own; send it to the builder rather than draw the Dashboard.
668 + if ('easy-invoice-templates-new' === $page) {
669 + echo '<script>window.location.replace(' . wp_json_encode(admin_url('admin.php?page=easy-invoice-template-builder&action=new')) . ');</script>';
670 + break;
671 + }
672 + $self_rendering = (array) apply_filters('easy_invoice_self_rendering_pages', [
673 + \EasyInvoice\Controllers\CreditNoteController::PAGE_SLUG,
674 + ]);
675 +
676 + if (in_array($page, $self_rendering, true)) {
677 + break;
678 + }
679 + if (class_exists('\\EasyInvoice\\Addons\\AddonRegistry')) {
680 + foreach (\EasyInvoice\Addons\AddonRegistry::all() as $_addon) {
681 + if (empty($_addon['settings_url'])) continue;
682 + $parsed = wp_parse_url($_addon['settings_url']);
683 + if (empty($parsed['query'])) continue;
684 + parse_str($parsed['query'], $q);
685 + if (($q['page'] ?? '') === $page) {
686 + return; // Addon owns this slug — bail without rendering.
687 + }
688 + }
689 + }
513 690 $this->dashboard_controller->display(['page' => PagesSlugs::DASHBOARD]);
514 691 break;
515 692 }
516 693 }
@@ -543,8 +720,9 @@
543 720 'easy-invoice-settings' => __('Settings', 'easy-invoice'),
544 721 'easy-invoice-email-settings' => __('Email Settings', 'easy-invoice'),
545 722 'easy-invoice-migration' => __('Migration', 'easy-invoice'),
546 723 'easy-invoice-free-vs-pro' => __('Free vs Pro', 'easy-invoice'),
724 + 'easy-invoice-addons' => __('Addons', 'easy-invoice'),
547 725 ];
548 726
549 727 if (isset($page_titles[$current_page])) {
550 728 return $page_titles[$current_page] . ' - ' . get_bloginfo('name');
@@ -554,13 +732,30 @@
554 732 return $title;
555 733 }
556 734
557 735 /**
736 + * Body class for Easy Invoice full-width layout (used by hideAdminUi CSS).
737 + *
738 + * @param string $classes Space-separated classes.
739 + * @return string
740 + */
741 + public function adminBodyClass($classes) {
742 + $screen = get_current_screen();
743 + if (!$screen || !isset($screen->id)) {
744 + return $classes;
745 + }
746 + if (strpos($screen->id, 'easy-invoice') !== false || strpos($screen->id, 'easy-quote') !== false) {
747 + $classes .= ' easy-invoice-admin-body';
748 + }
749 + return $classes;
750 + }
751 +
752 + /**
558 753 * Hide the WordPress admin UI for our custom pages
559 754 */
560 755 public function hideAdminUi() {
561 756 $screen = get_current_screen();
562 - if ($screen && property_exists($screen, 'id') && strpos($screen->id, 'easy-invoice') !== false) {
757 + if ($screen && property_exists($screen, 'id') && (strpos($screen->id, 'easy-invoice') !== false || strpos($screen->id, 'easy-quote') !== false)) {
563 758 ?>
564 759 <style>
565 760 #wpadminbar,
566 761 #adminmenumain,
@@ -573,8 +768,19 @@
573 768 }
574 769 .wrap {
575 770 margin: 0 !important;
576 771 padding: 0 !important;
772 + }
773 + /*
774 + * Admin bar is hidden but body.admin-bar often still gets top padding,
775 + * shifting #wpbody down while the fixed plugin sidebar stays at y=0 — header borders misalign.
776 + */
777 + body.easy-invoice-admin-body.admin-bar {
778 + padding-top: 0 !important;
779 + }
780 + body.easy-invoice-admin-body.admin-bar #wpbody,
781 + body.easy-invoice-admin-body.admin-bar #wpbody-content {
782 + padding-top: 0 !important;
577 783 }
578 784 </style>
579 785 <?php
580 786 }