| @@ -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,56 @@ | ||
| 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 | + /** | |
| 136 | 193 | * Register admin menu pages |
| 137 | 194 | */ |
| 138 | 195 | public function registerMenuPages() { |
| 139 | 196 | // Main menu item |
| @@ -139,9 +196,9 @@ | ||
| 139 | 196 | // Main menu item |
| 140 | 197 | add_menu_page( |
| 141 | 198 | __('Easy Invoice', 'easy-invoice'), |
| 142 | 199 | __('Easy Invoice', 'easy-invoice'), |
| 143 | - 'manage_options', | |
| 200 | + $this->menuCapability(PagesSlugs::DASHBOARD), | |
| 144 | 201 | PagesSlugs::DASHBOARD, |
| 145 | 202 | array($this, 'displayMainPage'), |
| 146 | 203 | 'dashicons-media-text', |
| 147 | 204 | 25 |
| @@ -151,9 +208,9 @@ | ||
| 151 | 208 | add_submenu_page( |
| 152 | 209 | 'easy-invoice', |
| 153 | 210 | __('Dashboard', 'easy-invoice'), |
| 154 | 211 | __('Dashboard', 'easy-invoice'), |
| 155 | - 'manage_options', | |
| 212 | + $this->menuCapability(PagesSlugs::DASHBOARD), | |
| 156 | 213 | PagesSlugs::DASHBOARD, |
| 157 | 214 | array($this, 'displayMainPage') |
| 158 | 215 | ); |
| 159 | 216 | |
| @@ -161,9 +218,9 @@ | ||
| 161 | 218 | add_submenu_page( |
| 162 | 219 | 'easy-invoice', |
| 163 | 220 | __('All Invoices', 'easy-invoice'), |
| 164 | 221 | __('All Invoices', 'easy-invoice'), |
| 165 | - 'manage_options', | |
| 222 | + $this->menuCapability(PagesSlugs::ALL_INVOICES), | |
| 166 | 223 | PagesSlugs::ALL_INVOICES, |
| 167 | 224 | array($this, 'displayMainPage') |
| 168 | 225 | ); |
| 169 | 226 | |
| @@ -171,9 +228,9 @@ | ||
| 171 | 228 | add_submenu_page( |
| 172 | 229 | 'easy-invoice-hidden', |
| 173 | 230 | __('Add New Invoice', 'easy-invoice'), |
| 174 | 231 | __('Add New', 'easy-invoice'), |
| 175 | - 'manage_options', | |
| 232 | + $this->menuCapability(PagesSlugs::INVOICE_NEW), | |
| 176 | 233 | PagesSlugs::INVOICE_NEW, |
| 177 | 234 | array($this, 'displayMainPage') |
| 178 | 235 | ); |
| 179 | 236 | |
| @@ -181,9 +238,9 @@ | ||
| 181 | 238 | add_submenu_page( |
| 182 | 239 | 'easy-invoice', |
| 183 | 240 | __('All Quotes', 'easy-invoice'), |
| 184 | 241 | __('All Quotes', 'easy-invoice'), |
| 185 | - 'manage_options', | |
| 242 | + $this->menuCapability(PagesSlugs::ALL_QUOTES), | |
| 186 | 243 | PagesSlugs::ALL_QUOTES, |
| 187 | 244 | array($this, 'displayMainPage') |
| 188 | 245 | ); |
| 189 | 246 | |
| @@ -191,9 +248,9 @@ | ||
| 191 | 248 | add_submenu_page( |
| 192 | 249 | 'easy-invoice-hidden', |
| 193 | 250 | __('Add New Quote', 'easy-invoice'), |
| 194 | 251 | __('Add New Quote', 'easy-invoice'), |
| 195 | - 'manage_options', | |
| 252 | + $this->menuCapability(PagesSlugs::QUOTE_NEW), | |
| 196 | 253 | PagesSlugs::QUOTE_NEW, |
| 197 | 254 | array($this, 'displayMainPage') |
| 198 | 255 | ); |
| 199 | 256 | |
| @@ -201,9 +258,9 @@ | ||
| 201 | 258 | add_submenu_page( |
| 202 | 259 | 'easy-invoice-hidden', |
| 203 | 260 | __('Payments', 'easy-invoice'), |
| 204 | 261 | __('Payments', 'easy-invoice'), |
| 205 | - 'manage_options', | |
| 262 | + $this->menuCapability(PagesSlugs::PAYMENTS), | |
| 206 | 263 | PagesSlugs::PAYMENTS, |
| 207 | 264 | array($this, 'displayMainPage') |
| 208 | 265 | ); |
| 209 | 266 | |
| @@ -211,9 +268,9 @@ | ||
| 211 | 268 | add_submenu_page( |
| 212 | 269 | 'easy-invoice-hidden', |
| 213 | 270 | __('Add New Payment', 'easy-invoice'), |
| 214 | 271 | __('Add New Payment', 'easy-invoice'), |
| 215 | - 'manage_options', | |
| 272 | + $this->menuCapability(PagesSlugs::PAYMENT_NEW), | |
| 216 | 273 | PagesSlugs::PAYMENT_NEW, |
| 217 | 274 | array($this, 'displayMainPage') |
| 218 | 275 | ); |
| 219 | 276 | |
| @@ -221,50 +278,66 @@ | ||
| 221 | 278 | add_submenu_page( |
| 222 | 279 | 'easy-invoice', |
| 223 | 280 | __('All Clients', 'easy-invoice'), |
| 224 | 281 | __('All Clients', 'easy-invoice'), |
| 225 | - 'edit_posts', | |
| 282 | + $this->menuCapability(PagesSlugs::CLIENTS), | |
| 226 | 283 | PagesSlugs::CLIENTS, |
| 227 | 284 | array($this, 'displayMainPage') |
| 228 | 285 | ); |
| 229 | 286 | |
| 230 | - // Item Library submenu - only show if Pro is active | |
| 231 | - 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')) { | |
| 232 | 301 | add_submenu_page( |
| 233 | - 'easy-invoice', | |
| 302 | + 'easy-invoice-hidden', | |
| 234 | 303 | __('Item Library', 'easy-invoice'), |
| 235 | 304 | __('Item Library', 'easy-invoice'), |
| 236 | - 'manage_options', | |
| 305 | + $this->menuCapability('easy-invoice-pro-item-library'), | |
| 237 | 306 | 'easy-invoice-pro-item-library', |
| 238 | 307 | array($this, 'displayMainPage') |
| 239 | 308 | ); |
| 240 | - | |
| 241 | - // 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. | |
| 242 | 313 | add_submenu_page( |
| 243 | - 'easy-invoice', | |
| 314 | + 'easy-invoice-hidden', | |
| 244 | 315 | __('Template Builder', 'easy-invoice'), |
| 245 | 316 | __('Template Builder', 'easy-invoice'), |
| 246 | - 'manage_options', | |
| 317 | + $this->menuCapability('easy-invoice-templates'), | |
| 247 | 318 | 'easy-invoice-templates', |
| 248 | 319 | array($this, 'displayMainPage') |
| 249 | 320 | ); |
| 250 | - | |
| 251 | - // 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. | |
| 252 | 324 | add_submenu_page( |
| 253 | 325 | 'easy-invoice-hidden', |
| 254 | 326 | __('Create New Template', 'easy-invoice'), |
| 255 | 327 | __('Create New', 'easy-invoice'), |
| 256 | - 'manage_options', | |
| 328 | + $this->menuCapability('easy-invoice-templates-new'), | |
| 257 | 329 | 'easy-invoice-templates-new', |
| 258 | 330 | array($this, 'displayMainPage') |
| 259 | 331 | ); |
| 260 | - | |
| 261 | - // 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. | |
| 262 | 335 | add_submenu_page( |
| 263 | 336 | 'easy-invoice-hidden', |
| 264 | 337 | __('Template Builder Page', 'easy-invoice'), |
| 265 | 338 | __('Template Builder Page', 'easy-invoice'), |
| 266 | - 'manage_options', | |
| 339 | + $this->menuCapability('easy-invoice-template-builder'), | |
| 267 | 340 | 'easy-invoice-template-builder', |
| 268 | 341 | array($this, 'displayMainPage') |
| 269 | 342 | ); |
| 270 | 343 | } |
| @@ -273,9 +346,9 @@ | ||
| 273 | 346 | add_submenu_page( |
| 274 | 347 | 'easy-invoice-hidden', // Use main menu as parent to avoid title issues |
| 275 | 348 | __('Edit Client', 'easy-invoice'), |
| 276 | 349 | __('Edit Client', 'easy-invoice'), |
| 277 | - 'manage_options', | |
| 350 | + $this->menuCapability(PagesSlugs::CLIENT_EDIT), | |
| 278 | 351 | PagesSlugs::CLIENT_EDIT, |
| 279 | 352 | array($this, 'displayMainPage') |
| 280 | 353 | ); |
| 281 | 354 | |
| @@ -282,9 +355,9 @@ | ||
| 282 | 355 | add_submenu_page( |
| 283 | 356 | 'easy-invoice-hidden', // Use main menu as parent to avoid title issues |
| 284 | 357 | __('View Client', 'easy-invoice'), |
| 285 | 358 | __('View Client', 'easy-invoice'), |
| 286 | - 'manage_options', | |
| 359 | + $this->menuCapability(PagesSlugs::CLIENT_VIEW), | |
| 287 | 360 | PagesSlugs::CLIENT_VIEW, |
| 288 | 361 | array($this, 'displayMainPage') |
| 289 | 362 | ); |
| 290 | 363 | |
| @@ -291,9 +364,9 @@ | ||
| 291 | 364 | add_submenu_page( |
| 292 | 365 | 'easy-invoice-hidden', // Use main menu as parent to avoid title issues |
| 293 | 366 | __('Preview Invoice', 'easy-invoice'), |
| 294 | 367 | __('Preview Invoice', 'easy-invoice'), |
| 295 | - 'manage_options', | |
| 368 | + $this->menuCapability(PagesSlugs::INVOICE_PREVIEW), | |
| 296 | 369 | PagesSlugs::INVOICE_PREVIEW, |
| 297 | 370 | array($this, 'displayPreviewPage') |
| 298 | 371 | ); |
| 299 | 372 | |
| @@ -300,29 +373,46 @@ | ||
| 300 | 373 | add_submenu_page( |
| 301 | 374 | 'easy-invoice-hidden', // Use main menu as parent to avoid title issues |
| 302 | 375 | __('Preview Quote', 'easy-invoice'), |
| 303 | 376 | __('Preview Quote', 'easy-invoice'), |
| 304 | - 'manage_options', | |
| 377 | + $this->menuCapability(PagesSlugs::QUOTE_PREVIEW), | |
| 305 | 378 | PagesSlugs::QUOTE_PREVIEW, |
| 306 | 379 | array($this, 'displayMainPage') |
| 307 | 380 | ); |
| 308 | 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 | |
| 309 | 399 | add_submenu_page( |
| 310 | 400 | 'easy-invoice', |
| 311 | - __('Reports', 'easy-invoice'), | |
| 312 | - __('Reports', 'easy-invoice'), | |
| 313 | - 'manage_options', | |
| 314 | - PagesSlugs::REPORTS, | |
| 401 | + __('Settings', 'easy-invoice'), | |
| 402 | + __('Settings', 'easy-invoice'), | |
| 403 | + $this->menuCapability(PagesSlugs::SETTINGS), | |
| 404 | + PagesSlugs::SETTINGS, | |
| 315 | 405 | array($this, 'displayMainPage') |
| 316 | 406 | ); |
| 317 | 407 | |
| 318 | - // Settings submenu | |
| 408 | + // Addons submenu | |
| 319 | 409 | add_submenu_page( |
| 320 | 410 | 'easy-invoice', |
| 321 | - __('Settings', 'easy-invoice'), | |
| 322 | - __('Settings', 'easy-invoice'), | |
| 323 | - 'manage_options', | |
| 324 | - PagesSlugs::SETTINGS, | |
| 411 | + __('Addons', 'easy-invoice'), | |
| 412 | + __('Addons', 'easy-invoice'), | |
| 413 | + $this->menuCapability(PagesSlugs::ADDONS), | |
| 414 | + PagesSlugs::ADDONS, | |
| 325 | 415 | array($this, 'displayMainPage') |
| 326 | 416 | ); |
| 327 | 417 | |
| 328 | 418 | // License submenu |
| @@ -329,9 +419,9 @@ | ||
| 329 | 419 | add_submenu_page( |
| 330 | 420 | 'easy-invoice', |
| 331 | 421 | __('License', 'easy-invoice'), |
| 332 | 422 | __('License', 'easy-invoice'), |
| 333 | - 'manage_options', | |
| 423 | + $this->menuCapability(PagesSlugs::LICENSE), | |
| 334 | 424 | PagesSlugs::LICENSE, |
| 335 | 425 | array($this, 'displayMainPage') |
| 336 | 426 | ); |
| 337 | 427 | |
| @@ -340,9 +430,9 @@ | ||
| 340 | 430 | add_submenu_page( |
| 341 | 431 | 'easy-invoice', |
| 342 | 432 | __('Free vs Pro', 'easy-invoice'), |
| 343 | 433 | __('Free vs Pro', 'easy-invoice'), |
| 344 | - 'manage_options', | |
| 434 | + $this->menuCapability('easy-invoice-free-vs-pro'), | |
| 345 | 435 | 'easy-invoice-free-vs-pro', |
| 346 | 436 | array($this, 'displayMainPage') |
| 347 | 437 | ); |
| 348 | 438 | } |
| @@ -361,17 +451,22 @@ | ||
| 361 | 451 | /** |
| 362 | 452 | * Redirect to community page |
| 363 | 453 | */ |
| 364 | 454 | public function redirectToCommunity() { |
| 365 | - wp_redirect(esc_url_raw('https://www.facebook.com/groups/mantrabraincommunity')); | |
| 455 | + wp_safe_redirect(esc_url_raw('https://www.facebook.com/groups/mantrabraincommunity')); | |
| 366 | 456 | exit; |
| 367 | 457 | } |
| 368 | 458 | |
| 369 | 459 | /** |
| 370 | - * 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. | |
| 371 | 466 | */ |
| 372 | 467 | public function registerPreviewPage() { |
| 373 | - //add_action('admin_action_easy_invoice_preview', array($this, 'displayPreviewPage')); | |
| 468 | + // No-op: preview rendering is handled by the per-document controller. | |
| 374 | 469 | } |
| 375 | 470 | |
| 376 | 471 | /** |
| 377 | 472 | * Display main page |
| @@ -394,8 +489,17 @@ | ||
| 394 | 489 | include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/license-page.php'; |
| 395 | 490 | } |
| 396 | 491 | |
| 397 | 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 | + /** | |
| 398 | 502 | * Handle main page content based on the current page |
| 399 | 503 | * |
| 400 | 504 | * @param string $page Current page |
| 401 | 505 | */ |
| @@ -430,9 +534,9 @@ | ||
| 430 | 534 | break; |
| 431 | 535 | |
| 432 | 536 | case PagesSlugs::PAYMENTS: |
| 433 | 537 | if (isset($_GET['action'])) { |
| 434 | - $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 | |
| 435 | 539 | } else { |
| 436 | 540 | $this->payment_controller->display(['page' => PagesSlugs::PAYMENTS]); |
| 437 | 541 | } |
| 438 | 542 | break; |
| @@ -448,36 +552,43 @@ | ||
| 448 | 552 | case PagesSlugs::CLIENT_EDIT: |
| 449 | 553 | $this->client_controller->display(['page' => PagesSlugs::CLIENT_EDIT]); |
| 450 | 554 | break; |
| 451 | 555 | |
| 452 | - // 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. | |
| 453 | 561 | 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 | - } | |
| 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(); | |
| 460 | 569 | } |
| 461 | 570 | break; |
| 462 | - | |
| 571 | + | |
| 463 | 572 | 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 | - } | |
| 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(); | |
| 470 | 580 | } |
| 471 | 581 | break; |
| 472 | 582 | |
| 473 | 583 | 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 | - } | |
| 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(); | |
| 480 | 591 | } |
| 481 | 592 | break; |
| 482 | 593 | |
| 483 | 594 | case PagesSlugs::CLIENT_VIEW: |
| @@ -484,9 +595,16 @@ | ||
| 484 | 595 | $this->client_controller->display(['page' => PagesSlugs::CLIENT_VIEW]); |
| 485 | 596 | break; |
| 486 | 597 | |
| 487 | 598 | case PagesSlugs::REPORTS: |
| 488 | - $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 | + } | |
| 489 | 607 | break; |
| 490 | 608 | |
| 491 | 609 | case PagesSlugs::SETTINGS: |
| 492 | 610 | $this->settings_controller->display(['page' => PagesSlugs::SETTINGS]); |
| @@ -495,8 +613,12 @@ | ||
| 495 | 613 | case PagesSlugs::LICENSE: |
| 496 | 614 | $this->displayLicensePage(); |
| 497 | 615 | break; |
| 498 | 616 | |
| 617 | + case PagesSlugs::ADDONS: | |
| 618 | + $this->displayAddonsPage(); | |
| 619 | + break; | |
| 620 | + | |
| 499 | 621 | case PagesSlugs::EMAIL_SETTINGS: |
| 500 | 622 | case PagesSlugs::EMAIL_SETTINGS_GENERAL: |
| 501 | 623 | case PagesSlugs::EMAIL_SETTINGS_INVOICE: |
| 502 | 624 | case PagesSlugs::EMAIL_SETTINGS_QUOTE: |
| @@ -512,8 +634,60 @@ | ||
| 512 | 634 | include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/free-vs-pro-page.php'; |
| 513 | 635 | break; |
| 514 | 636 | |
| 515 | 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 | + } | |
| 516 | 690 | $this->dashboard_controller->display(['page' => PagesSlugs::DASHBOARD]); |
| 517 | 691 | break; |
| 518 | 692 | } |
| 519 | 693 | } |
| @@ -546,8 +720,9 @@ | ||
| 546 | 720 | 'easy-invoice-settings' => __('Settings', 'easy-invoice'), |
| 547 | 721 | 'easy-invoice-email-settings' => __('Email Settings', 'easy-invoice'), |
| 548 | 722 | 'easy-invoice-migration' => __('Migration', 'easy-invoice'), |
| 549 | 723 | 'easy-invoice-free-vs-pro' => __('Free vs Pro', 'easy-invoice'), |
| 724 | + 'easy-invoice-addons' => __('Addons', 'easy-invoice'), | |
| 550 | 725 | ]; |
| 551 | 726 | |
| 552 | 727 | if (isset($page_titles[$current_page])) { |
| 553 | 728 | return $page_titles[$current_page] . ' - ' . get_bloginfo('name'); |