| 1 |
<?php |
| 2 |
/** |
| 3 |
* EasyInvoice Admin Class |
| 4 |
* |
| 5 |
* @package Easy_Invoice |
| 6 |
* @subpackage Admin |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace EasyInvoice\Admin; |
| 10 |
|
| 11 |
use EasyInvoice\Admin\AdminAssets; |
| 12 |
use EasyInvoice\Constants\PagesSlugs; |
| 13 |
use EasyInvoice\Controllers\InvoiceController; |
| 14 |
use EasyInvoice\Controllers\QuoteController; |
| 15 |
use EasyInvoice\Controllers\ClientController; |
| 16 |
use EasyInvoice\Controllers\SettingsController; |
| 17 |
use EasyInvoice\Controllers\ReportController; |
| 18 |
use EasyInvoice\Controllers\DashboardController; |
| 19 |
use EasyInvoice\Controllers\PaymentController; |
| 20 |
|
| 21 |
/** |
| 22 |
* EasyInvoiceAdmin is the main admin class that initializes all controllers |
| 23 |
*/ |
| 24 |
class EasyInvoiceAdmin { |
| 25 |
/** |
| 26 |
* Invoice controller instance |
| 27 |
* |
| 28 |
* @var InvoiceController |
| 29 |
*/ |
| 30 |
private $invoice_controller; |
| 31 |
|
| 32 |
/** |
| 33 |
* Quote controller instance |
| 34 |
* |
| 35 |
* @var QuoteController |
| 36 |
*/ |
| 37 |
private $quote_controller; |
| 38 |
|
| 39 |
/** |
| 40 |
* Client controller instance |
| 41 |
* |
| 42 |
* @var ClientController |
| 43 |
*/ |
| 44 |
private $client_controller; |
| 45 |
|
| 46 |
/** |
| 47 |
* Settings controller instance |
| 48 |
* |
| 49 |
* @var SettingsController |
| 50 |
*/ |
| 51 |
private $settings_controller; |
| 52 |
|
| 53 |
/** |
| 54 |
* Report controller instance |
| 55 |
* |
| 56 |
* @var ReportController |
| 57 |
*/ |
| 58 |
private $report_controller; |
| 59 |
|
| 60 |
/** |
| 61 |
* Dashboard controller instance |
| 62 |
* |
| 63 |
* @var DashboardController |
| 64 |
*/ |
| 65 |
private $dashboard_controller; |
| 66 |
|
| 67 |
/** |
| 68 |
* Payment controller instance |
| 69 |
* |
| 70 |
* @var PaymentController |
| 71 |
*/ |
| 72 |
private $payment_controller; |
| 73 |
|
| 74 |
/** |
| 75 |
* Template Builder controller instance |
| 76 |
* |
| 77 |
* @var \EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController |
| 78 |
*/ |
| 79 |
private $template_builder_controller; |
| 80 |
|
| 81 |
/** |
| 82 |
* Constructor |
| 83 |
*/ |
| 84 |
public function __construct() { |
| 85 |
$this->invoice_controller = new InvoiceController(); |
| 86 |
$this->quote_controller = new QuoteController(); |
| 87 |
$this->client_controller = new ClientController(); |
| 88 |
$this->settings_controller = new SettingsController(); |
| 89 |
$this->report_controller = new ReportController(); |
| 90 |
$this->dashboard_controller = new DashboardController(); |
| 91 |
$this->payment_controller = new PaymentController(); |
| 92 |
|
| 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(); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Initialize the admin class |
| 109 |
*/ |
| 110 |
public function init() { |
| 111 |
// Add menu items |
| 112 |
add_action('admin_menu', array($this, 'registerMenuPages')); |
| 113 |
|
| 114 |
// Register admin assets |
| 115 |
$admin_assets = new AdminAssets(); |
| 116 |
$admin_assets->register(); |
| 117 |
|
| 118 |
// Register invoice preview page |
| 119 |
add_action('admin_init', array($this, 'registerPreviewPage')); |
| 120 |
|
| 121 |
// Ensure proper page titles to avoid WordPress core issues |
| 122 |
add_filter('admin_title', array($this, 'setAdminTitle')); |
| 123 |
|
| 124 |
// Hide admin UI |
| 125 |
add_action('admin_head', array($this, 'hideAdminUi')); |
| 126 |
|
| 127 |
// Body class for layout fixes (admin bar offset, header strip alignment) |
| 128 |
add_filter('admin_body_class', array($this, 'adminBodyClass')); |
| 129 |
|
| 130 |
// Initialize controllers |
| 131 |
$this->invoice_controller->init(); |
| 132 |
$this->quote_controller->init(); |
| 133 |
$this->client_controller->init(); |
| 134 |
$this->settings_controller->init(); |
| 135 |
$this->report_controller->init(); |
| 136 |
$this->dashboard_controller->init(); |
| 137 |
$this->payment_controller->init(); |
| 138 |
|
| 139 |
// Main content hook |
| 140 |
add_action('easy_invoice_admin_main_content', array($this, 'mainPageContent')); |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Register admin menu pages |
| 145 |
*/ |
| 146 |
public function registerMenuPages() { |
| 147 |
// Main menu item |
| 148 |
add_menu_page( |
| 149 |
__('Easy Invoice', 'easy-invoice'), |
| 150 |
__('Easy Invoice', 'easy-invoice'), |
| 151 |
'manage_options', |
| 152 |
PagesSlugs::DASHBOARD, |
| 153 |
array($this, 'displayMainPage'), |
| 154 |
'dashicons-media-text', |
| 155 |
25 |
| 156 |
); |
| 157 |
|
| 158 |
// Dashboard submenu |
| 159 |
add_submenu_page( |
| 160 |
'easy-invoice', |
| 161 |
__('Dashboard', 'easy-invoice'), |
| 162 |
__('Dashboard', 'easy-invoice'), |
| 163 |
'manage_options', |
| 164 |
PagesSlugs::DASHBOARD, |
| 165 |
array($this, 'displayMainPage') |
| 166 |
); |
| 167 |
|
| 168 |
// All invoices submenu |
| 169 |
add_submenu_page( |
| 170 |
'easy-invoice', |
| 171 |
__('All Invoices', 'easy-invoice'), |
| 172 |
__('All Invoices', 'easy-invoice'), |
| 173 |
'manage_options', |
| 174 |
PagesSlugs::ALL_INVOICES, |
| 175 |
array($this, 'displayMainPage') |
| 176 |
); |
| 177 |
|
| 178 |
// Add new invoice submenu |
| 179 |
add_submenu_page( |
| 180 |
'easy-invoice-hidden', |
| 181 |
__('Add New Invoice', 'easy-invoice'), |
| 182 |
__('Add New', 'easy-invoice'), |
| 183 |
'manage_options', |
| 184 |
PagesSlugs::INVOICE_NEW, |
| 185 |
array($this, 'displayMainPage') |
| 186 |
); |
| 187 |
|
| 188 |
// All quotes submenu |
| 189 |
add_submenu_page( |
| 190 |
'easy-invoice', |
| 191 |
__('All Quotes', 'easy-invoice'), |
| 192 |
__('All Quotes', 'easy-invoice'), |
| 193 |
'manage_options', |
| 194 |
PagesSlugs::ALL_QUOTES, |
| 195 |
array($this, 'displayMainPage') |
| 196 |
); |
| 197 |
|
| 198 |
// Add new quote submenu |
| 199 |
add_submenu_page( |
| 200 |
'easy-invoice-hidden', |
| 201 |
__('Add New Quote', 'easy-invoice'), |
| 202 |
__('Add New Quote', 'easy-invoice'), |
| 203 |
'manage_options', |
| 204 |
PagesSlugs::QUOTE_NEW, |
| 205 |
array($this, 'displayMainPage') |
| 206 |
); |
| 207 |
|
| 208 |
// Payments submenu |
| 209 |
add_submenu_page( |
| 210 |
'easy-invoice-hidden', |
| 211 |
__('Payments', 'easy-invoice'), |
| 212 |
__('Payments', 'easy-invoice'), |
| 213 |
'manage_options', |
| 214 |
PagesSlugs::PAYMENTS, |
| 215 |
array($this, 'displayMainPage') |
| 216 |
); |
| 217 |
|
| 218 |
// Add new payment submenu |
| 219 |
add_submenu_page( |
| 220 |
'easy-invoice-hidden', |
| 221 |
__('Add New Payment', 'easy-invoice'), |
| 222 |
__('Add New Payment', 'easy-invoice'), |
| 223 |
'manage_options', |
| 224 |
PagesSlugs::PAYMENT_NEW, |
| 225 |
array($this, 'displayMainPage') |
| 226 |
); |
| 227 |
|
| 228 |
// Clients submenu |
| 229 |
add_submenu_page( |
| 230 |
'easy-invoice', |
| 231 |
__('All Clients', 'easy-invoice'), |
| 232 |
__('All Clients', 'easy-invoice'), |
| 233 |
'edit_posts', |
| 234 |
PagesSlugs::CLIENTS, |
| 235 |
array($this, 'displayMainPage') |
| 236 |
); |
| 237 |
|
| 238 |
// Item Library + Template Builder pages are reached via the |
| 239 |
// Easy Invoice in-app sidebar (templates/main-template.php), NOT |
| 240 |
// the WP admin submenu. We still register the page slugs so the |
| 241 |
// URLs resolve, but we parent them under 'easy-invoice-hidden' |
| 242 |
// so they don't render duplicate entries in the WP submenu — |
| 243 |
// the WP submenu showed the link AND the in-app sidebar showed |
| 244 |
// the same link, giving the user two visible navigation |
| 245 |
// entry-points to the same page. |
| 246 |
// |
| 247 |
// Registration is still gated on the addon being active — if |
| 248 |
// the addon is off, the slug isn't registered, so direct-URL |
| 249 |
// access returns the standard "you do not have sufficient |
| 250 |
// permissions" page. |
| 251 |
if (easy_invoice_has_pro() && \EasyInvoice\Addons\AddonManager::shouldLoad('item_library')) { |
| 252 |
add_submenu_page( |
| 253 |
'easy-invoice-hidden', |
| 254 |
__('Item Library', 'easy-invoice'), |
| 255 |
__('Item Library', 'easy-invoice'), |
| 256 |
'manage_options', |
| 257 |
'easy-invoice-pro-item-library', |
| 258 |
array($this, 'displayMainPage') |
| 259 |
); |
| 260 |
} |
| 261 |
|
| 262 |
if (easy_invoice_has_pro() && \EasyInvoice\Addons\AddonManager::shouldLoad('custom_templates')) { |
| 263 |
// Template listing — reachable from the in-app sidebar. |
| 264 |
add_submenu_page( |
| 265 |
'easy-invoice-hidden', |
| 266 |
__('Template Builder', 'easy-invoice'), |
| 267 |
__('Template Builder', 'easy-invoice'), |
| 268 |
'manage_options', |
| 269 |
'easy-invoice-templates', |
| 270 |
array($this, 'displayMainPage') |
| 271 |
); |
| 272 |
|
| 273 |
// Create New Template — used by deep-links from inside the |
| 274 |
// builder UI. |
| 275 |
add_submenu_page( |
| 276 |
'easy-invoice-hidden', |
| 277 |
__('Create New Template', 'easy-invoice'), |
| 278 |
__('Create New', 'easy-invoice'), |
| 279 |
'manage_options', |
| 280 |
'easy-invoice-templates-new', |
| 281 |
array($this, 'displayMainPage') |
| 282 |
); |
| 283 |
|
| 284 |
// Template Builder canvas — full-screen builder, reached |
| 285 |
// from the listing page's Edit / New buttons. |
| 286 |
add_submenu_page( |
| 287 |
'easy-invoice-hidden', |
| 288 |
__('Template Builder Page', 'easy-invoice'), |
| 289 |
__('Template Builder Page', 'easy-invoice'), |
| 290 |
'manage_options', |
| 291 |
'easy-invoice-template-builder', |
| 292 |
array($this, 'displayMainPage') |
| 293 |
); |
| 294 |
} |
| 295 |
|
| 296 |
// Hidden submenu pages - not shown in the menu but accessible |
| 297 |
add_submenu_page( |
| 298 |
'easy-invoice-hidden', // Use main menu as parent to avoid title issues |
| 299 |
__('Edit Client', 'easy-invoice'), |
| 300 |
__('Edit Client', 'easy-invoice'), |
| 301 |
'manage_options', |
| 302 |
PagesSlugs::CLIENT_EDIT, |
| 303 |
array($this, 'displayMainPage') |
| 304 |
); |
| 305 |
|
| 306 |
add_submenu_page( |
| 307 |
'easy-invoice-hidden', // Use main menu as parent to avoid title issues |
| 308 |
__('View Client', 'easy-invoice'), |
| 309 |
__('View Client', 'easy-invoice'), |
| 310 |
'manage_options', |
| 311 |
PagesSlugs::CLIENT_VIEW, |
| 312 |
array($this, 'displayMainPage') |
| 313 |
); |
| 314 |
|
| 315 |
add_submenu_page( |
| 316 |
'easy-invoice-hidden', // Use main menu as parent to avoid title issues |
| 317 |
__('Preview Invoice', 'easy-invoice'), |
| 318 |
__('Preview Invoice', 'easy-invoice'), |
| 319 |
'manage_options', |
| 320 |
PagesSlugs::INVOICE_PREVIEW, |
| 321 |
array($this, 'displayPreviewPage') |
| 322 |
); |
| 323 |
|
| 324 |
add_submenu_page( |
| 325 |
'easy-invoice-hidden', // Use main menu as parent to avoid title issues |
| 326 |
__('Preview Quote', 'easy-invoice'), |
| 327 |
__('Preview Quote', 'easy-invoice'), |
| 328 |
'manage_options', |
| 329 |
PagesSlugs::QUOTE_PREVIEW, |
| 330 |
array($this, 'displayMainPage') |
| 331 |
); |
| 332 |
|
| 333 |
// Reports — addon-gated (Personal tier). Slug registered as a |
| 334 |
// HIDDEN submenu so the WP admin sidebar doesn't double the |
| 335 |
// in-app sidebar entry. When the reports addon is disabled, the |
| 336 |
// slug isn't registered at all, so direct-URL access falls |
| 337 |
// through to WP's "no permission" page. |
| 338 |
if (\EasyInvoice\Addons\AddonManager::shouldLoad('reports')) { |
| 339 |
add_submenu_page( |
| 340 |
'easy-invoice-hidden', |
| 341 |
__('Reports', 'easy-invoice'), |
| 342 |
__('Reports', 'easy-invoice'), |
| 343 |
'manage_options', |
| 344 |
PagesSlugs::REPORTS, |
| 345 |
array($this, 'displayMainPage') |
| 346 |
); |
| 347 |
} |
| 348 |
|
| 349 |
// Settings submenu |
| 350 |
add_submenu_page( |
| 351 |
'easy-invoice', |
| 352 |
__('Settings', 'easy-invoice'), |
| 353 |
__('Settings', 'easy-invoice'), |
| 354 |
'manage_options', |
| 355 |
PagesSlugs::SETTINGS, |
| 356 |
array($this, 'displayMainPage') |
| 357 |
); |
| 358 |
|
| 359 |
// Addons submenu |
| 360 |
add_submenu_page( |
| 361 |
'easy-invoice', |
| 362 |
__('Addons', 'easy-invoice'), |
| 363 |
__('Addons', 'easy-invoice'), |
| 364 |
'manage_options', |
| 365 |
PagesSlugs::ADDONS, |
| 366 |
array($this, 'displayMainPage') |
| 367 |
); |
| 368 |
|
| 369 |
// License submenu |
| 370 |
add_submenu_page( |
| 371 |
'easy-invoice', |
| 372 |
__('License', 'easy-invoice'), |
| 373 |
__('License', 'easy-invoice'), |
| 374 |
'manage_options', |
| 375 |
PagesSlugs::LICENSE, |
| 376 |
array($this, 'displayMainPage') |
| 377 |
); |
| 378 |
|
| 379 |
// Free vs Pro submenu - only show in free version |
| 380 |
if (!easy_invoice_has_pro()) { |
| 381 |
add_submenu_page( |
| 382 |
'easy-invoice', |
| 383 |
__('Free vs Pro', 'easy-invoice'), |
| 384 |
__('Free vs Pro', 'easy-invoice'), |
| 385 |
'manage_options', |
| 386 |
'easy-invoice-free-vs-pro', |
| 387 |
array($this, 'displayMainPage') |
| 388 |
); |
| 389 |
} |
| 390 |
|
| 391 |
// Join Community submenu |
| 392 |
add_submenu_page( |
| 393 |
'easy-invoice-hidden', |
| 394 |
__('Join Community', 'easy-invoice'), |
| 395 |
__('Join Community', 'easy-invoice'), |
| 396 |
'read', |
| 397 |
'easy-invoice-join-community', |
| 398 |
array($this, 'redirectToCommunity') |
| 399 |
); |
| 400 |
} |
| 401 |
|
| 402 |
/** |
| 403 |
* Redirect to community page |
| 404 |
*/ |
| 405 |
public function redirectToCommunity() { |
| 406 |
wp_redirect(esc_url_raw('https://www.facebook.com/groups/mantrabraincommunity')); |
| 407 |
exit; |
| 408 |
} |
| 409 |
|
| 410 |
/** |
| 411 |
* Register invoice preview page. |
| 412 |
* |
| 413 |
* Placeholder kept as an extension point — the preview-page hook used to |
| 414 |
* be wired here but is now routed through the per-document preview |
| 415 |
* controller. Left in place so themes/plugins relying on a no-op |
| 416 |
* `registerPreviewPage()` call don't fatal. |
| 417 |
*/ |
| 418 |
public function registerPreviewPage() { |
| 419 |
// No-op: preview rendering is handled by the per-document controller. |
| 420 |
} |
| 421 |
|
| 422 |
/** |
| 423 |
* Display main page |
| 424 |
*/ |
| 425 |
public function displayMainPage() { |
| 426 |
include EASY_INVOICE_PLUGIN_DIR . 'templates/main-template.php'; |
| 427 |
} |
| 428 |
|
| 429 |
/** |
| 430 |
* Display preview page |
| 431 |
*/ |
| 432 |
public function displayPreviewPage() { |
| 433 |
$this->invoice_controller->display(['page' => PagesSlugs::INVOICE_PREVIEW]); |
| 434 |
} |
| 435 |
|
| 436 |
/** |
| 437 |
* Display license page |
| 438 |
*/ |
| 439 |
public function displayLicensePage() { |
| 440 |
include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/license-page.php'; |
| 441 |
} |
| 442 |
|
| 443 |
/** |
| 444 |
* Display addons page |
| 445 |
*/ |
| 446 |
public function displayAddonsPage() { |
| 447 |
if (class_exists('\\EasyInvoice\\Controllers\\AddonsController')) { |
| 448 |
(new \EasyInvoice\Controllers\AddonsController())->display(); |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
/** |
| 453 |
* Handle main page content based on the current page |
| 454 |
* |
| 455 |
* @param string $page Current page |
| 456 |
*/ |
| 457 |
public function mainPageContent($page) { |
| 458 |
switch ($page) { |
| 459 |
case PagesSlugs::DASHBOARD: |
| 460 |
$this->dashboard_controller->display(['page' => PagesSlugs::DASHBOARD]); |
| 461 |
break; |
| 462 |
|
| 463 |
case PagesSlugs::ALL_INVOICES: |
| 464 |
$this->invoice_controller->display(['page' => PagesSlugs::ALL_INVOICES]); |
| 465 |
break; |
| 466 |
|
| 467 |
case PagesSlugs::INVOICE_NEW: |
| 468 |
$this->invoice_controller->display(['page' => PagesSlugs::INVOICE_NEW]); |
| 469 |
break; |
| 470 |
|
| 471 |
case PagesSlugs::INVOICE_PREVIEW: |
| 472 |
$this->invoice_controller->display(['page' => PagesSlugs::INVOICE_PREVIEW]); |
| 473 |
break; |
| 474 |
|
| 475 |
case PagesSlugs::ALL_QUOTES: |
| 476 |
$this->quote_controller->display(['page' => PagesSlugs::ALL_QUOTES]); |
| 477 |
break; |
| 478 |
|
| 479 |
case PagesSlugs::QUOTE_NEW: |
| 480 |
$this->quote_controller->display(['page' => PagesSlugs::QUOTE_NEW]); |
| 481 |
break; |
| 482 |
|
| 483 |
case PagesSlugs::QUOTE_PREVIEW: |
| 484 |
$this->quote_controller->display(['page' => PagesSlugs::QUOTE_PREVIEW]); |
| 485 |
break; |
| 486 |
|
| 487 |
case PagesSlugs::PAYMENTS: |
| 488 |
if (isset($_GET['action'])) { |
| 489 |
$this->payment_controller->display(['page' => $_GET['action']]); |
| 490 |
} else { |
| 491 |
$this->payment_controller->display(['page' => PagesSlugs::PAYMENTS]); |
| 492 |
} |
| 493 |
break; |
| 494 |
|
| 495 |
case PagesSlugs::PAYMENT_NEW: |
| 496 |
$this->payment_controller->display(['page' => PagesSlugs::PAYMENT_NEW]); |
| 497 |
break; |
| 498 |
|
| 499 |
case PagesSlugs::CLIENTS: |
| 500 |
$this->client_controller->display(['page' => PagesSlugs::CLIENTS]); |
| 501 |
break; |
| 502 |
|
| 503 |
case PagesSlugs::CLIENT_EDIT: |
| 504 |
$this->client_controller->display(['page' => PagesSlugs::CLIENT_EDIT]); |
| 505 |
break; |
| 506 |
|
| 507 |
// Handle Pro features — gated on addon-state. The menu |
| 508 |
// registrations above are also addon-gated, so these cases |
| 509 |
// should only fire when the addon is enabled. Re-checking |
| 510 |
// shouldLoad() here is defensive in case the user hits the |
| 511 |
// page slug directly via URL. |
| 512 |
case 'easy-invoice-pro-item-library': |
| 513 |
if ( |
| 514 |
easy_invoice_has_pro() |
| 515 |
&& \EasyInvoice\Addons\AddonManager::shouldLoad('item_library') |
| 516 |
&& class_exists('\EasyInvoicePro\Addons\ItemLibrary\Controllers\ItemLibraryController') |
| 517 |
) { |
| 518 |
$item_library_controller = new \EasyInvoicePro\Addons\ItemLibrary\Controllers\ItemLibraryController(); |
| 519 |
$item_library_controller->displayMainPage(); |
| 520 |
} |
| 521 |
break; |
| 522 |
|
| 523 |
case 'easy-invoice-templates': |
| 524 |
if ( |
| 525 |
easy_invoice_has_pro() |
| 526 |
&& \EasyInvoice\Addons\AddonManager::shouldLoad('custom_templates') |
| 527 |
&& class_exists('\EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController') |
| 528 |
) { |
| 529 |
$template_builder_controller = new \EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController(); |
| 530 |
$template_builder_controller->displayMainPage(); |
| 531 |
} |
| 532 |
break; |
| 533 |
|
| 534 |
case 'easy-invoice-template-builder': |
| 535 |
if ( |
| 536 |
easy_invoice_has_pro() |
| 537 |
&& \EasyInvoice\Addons\AddonManager::shouldLoad('custom_templates') |
| 538 |
&& class_exists('\EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController') |
| 539 |
) { |
| 540 |
$template_builder_controller = new \EasyInvoicePro\Addons\CustomTemplates\Controllers\TemplateBuilderController(); |
| 541 |
$template_builder_controller->displayMainPage(); |
| 542 |
} |
| 543 |
break; |
| 544 |
|
| 545 |
case PagesSlugs::CLIENT_VIEW: |
| 546 |
$this->client_controller->display(['page' => PagesSlugs::CLIENT_VIEW]); |
| 547 |
break; |
| 548 |
|
| 549 |
case PagesSlugs::REPORTS: |
| 550 |
// Reports is addon-gated. The submenu page slug is only |
| 551 |
// registered when shouldLoad('reports') is true, so this |
| 552 |
// case ordinarily only fires for active-addon users — |
| 553 |
// but recheck defensively in case the page is reached |
| 554 |
// via direct URL right after the addon was disabled. |
| 555 |
if (\EasyInvoice\Addons\AddonManager::shouldLoad('reports')) { |
| 556 |
$this->report_controller->display(['page' => PagesSlugs::REPORTS]); |
| 557 |
} |
| 558 |
break; |
| 559 |
|
| 560 |
case PagesSlugs::SETTINGS: |
| 561 |
$this->settings_controller->display(['page' => PagesSlugs::SETTINGS]); |
| 562 |
break; |
| 563 |
|
| 564 |
case PagesSlugs::LICENSE: |
| 565 |
$this->displayLicensePage(); |
| 566 |
break; |
| 567 |
|
| 568 |
case PagesSlugs::ADDONS: |
| 569 |
$this->displayAddonsPage(); |
| 570 |
break; |
| 571 |
|
| 572 |
case PagesSlugs::EMAIL_SETTINGS: |
| 573 |
case PagesSlugs::EMAIL_SETTINGS_GENERAL: |
| 574 |
case PagesSlugs::EMAIL_SETTINGS_INVOICE: |
| 575 |
case PagesSlugs::EMAIL_SETTINGS_QUOTE: |
| 576 |
case PagesSlugs::EMAIL_SETTINGS_PAYMENT: |
| 577 |
$this->settings_controller->display(['page' => PagesSlugs::SETTINGS, 'subsection' => $page]); |
| 578 |
break; |
| 579 |
|
| 580 |
case 'easy-invoice-migration': |
| 581 |
include EASY_INVOICE_PLUGIN_DIR . 'includes/Migration/templates/migration-page.php'; |
| 582 |
break; |
| 583 |
|
| 584 |
case 'easy-invoice-free-vs-pro': |
| 585 |
include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/free-vs-pro-page.php'; |
| 586 |
break; |
| 587 |
|
| 588 |
default: |
| 589 |
// Addon pages render themselves via the |
| 590 |
// `easy_invoice_admin_main_content` action at priority 11. The |
| 591 |
// dispatcher must NOT fall through to the Dashboard for those |
| 592 |
// slugs, otherwise the Dashboard markup gets emitted first and |
| 593 |
// the addon panel renders on top of it (two pages stacked). |
| 594 |
// |
| 595 |
// We treat any slug that's either (a) prefixed with |
| 596 |
// `easy-invoice-addon-` or (b) registered in AddonRegistry as |
| 597 |
// an addon page — and just `break` to let the addon's own hook |
| 598 |
// handle the rendering. |
| 599 |
if (strpos($page, 'easy-invoice-addon-') === 0) { |
| 600 |
break; |
| 601 |
} |
| 602 |
if (class_exists('\\EasyInvoice\\Addons\\AddonRegistry')) { |
| 603 |
foreach (\EasyInvoice\Addons\AddonRegistry::all() as $_addon) { |
| 604 |
if (empty($_addon['settings_url'])) continue; |
| 605 |
$parsed = wp_parse_url($_addon['settings_url']); |
| 606 |
if (empty($parsed['query'])) continue; |
| 607 |
parse_str($parsed['query'], $q); |
| 608 |
if (($q['page'] ?? '') === $page) { |
| 609 |
return; // Addon owns this slug — bail without rendering. |
| 610 |
} |
| 611 |
} |
| 612 |
} |
| 613 |
$this->dashboard_controller->display(['page' => PagesSlugs::DASHBOARD]); |
| 614 |
break; |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
/** |
| 619 |
* Set proper admin title to avoid WordPress core issues |
| 620 |
* |
| 621 |
* @param string $title The current admin title |
| 622 |
* @return string The modified admin title |
| 623 |
*/ |
| 624 |
public function setAdminTitle($title) { |
| 625 |
$current_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; |
| 626 |
|
| 627 |
// Only modify titles for our plugin pages |
| 628 |
if (strpos($current_page, 'easy-invoice') === 0 || strpos($current_page, 'easy-quote') === 0) { |
| 629 |
$page_titles = [ |
| 630 |
'easy-invoice' => __('Dashboard', 'easy-invoice'), |
| 631 |
'easy-invoice-all' => __('All Invoices', 'easy-invoice'), |
| 632 |
'easy-invoice-builder' => __('Add New Invoice', 'easy-invoice'), |
| 633 |
'easy-invoice-preview' => __('Preview Invoice', 'easy-invoice'), |
| 634 |
'easy-quote-all' => __('All Quotes', 'easy-invoice'), |
| 635 |
'easy-invoice-quote-builder' => __('Add New Quote', 'easy-invoice'), |
| 636 |
'easy-quote-preview' => __('Preview Quote', 'easy-invoice'), |
| 637 |
'easy-invoice-payments' => __('Payments', 'easy-invoice'), |
| 638 |
'easy-invoice-payment-new' => __('Add New Payment', 'easy-invoice'), |
| 639 |
'easy-invoice-clients' => __('Clients', 'easy-invoice'), |
| 640 |
'easy-invoice-client-edit' => __('Edit Client', 'easy-invoice'), |
| 641 |
'easy-invoice-client-view' => __('View Client', 'easy-invoice'), |
| 642 |
'easy-invoice-reports' => __('Reports', 'easy-invoice'), |
| 643 |
'easy-invoice-settings' => __('Settings', 'easy-invoice'), |
| 644 |
'easy-invoice-email-settings' => __('Email Settings', 'easy-invoice'), |
| 645 |
'easy-invoice-migration' => __('Migration', 'easy-invoice'), |
| 646 |
'easy-invoice-free-vs-pro' => __('Free vs Pro', 'easy-invoice'), |
| 647 |
'easy-invoice-addons' => __('Addons', 'easy-invoice'), |
| 648 |
]; |
| 649 |
|
| 650 |
if (isset($page_titles[$current_page])) { |
| 651 |
return $page_titles[$current_page] . ' - ' . get_bloginfo('name'); |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
return $title; |
| 656 |
} |
| 657 |
|
| 658 |
/** |
| 659 |
* Body class for Easy Invoice full-width layout (used by hideAdminUi CSS). |
| 660 |
* |
| 661 |
* @param string $classes Space-separated classes. |
| 662 |
* @return string |
| 663 |
*/ |
| 664 |
public function adminBodyClass($classes) { |
| 665 |
$screen = get_current_screen(); |
| 666 |
if (!$screen || !isset($screen->id)) { |
| 667 |
return $classes; |
| 668 |
} |
| 669 |
if (strpos($screen->id, 'easy-invoice') !== false || strpos($screen->id, 'easy-quote') !== false) { |
| 670 |
$classes .= ' easy-invoice-admin-body'; |
| 671 |
} |
| 672 |
return $classes; |
| 673 |
} |
| 674 |
|
| 675 |
/** |
| 676 |
* Hide the WordPress admin UI for our custom pages |
| 677 |
*/ |
| 678 |
public function hideAdminUi() { |
| 679 |
$screen = get_current_screen(); |
| 680 |
if ($screen && property_exists($screen, 'id') && (strpos($screen->id, 'easy-invoice') !== false || strpos($screen->id, 'easy-quote') !== false)) { |
| 681 |
?> |
| 682 |
<style> |
| 683 |
#wpadminbar, |
| 684 |
#adminmenumain, |
| 685 |
#wpfooter { |
| 686 |
display: none !important; |
| 687 |
} |
| 688 |
#wpcontent { |
| 689 |
margin-left: 0 !important; |
| 690 |
padding: 0 !important; |
| 691 |
} |
| 692 |
.wrap { |
| 693 |
margin: 0 !important; |
| 694 |
padding: 0 !important; |
| 695 |
} |
| 696 |
/* |
| 697 |
* Admin bar is hidden but body.admin-bar often still gets top padding, |
| 698 |
* shifting #wpbody down while the fixed plugin sidebar stays at y=0 — header borders misalign. |
| 699 |
*/ |
| 700 |
body.easy-invoice-admin-body.admin-bar { |
| 701 |
padding-top: 0 !important; |
| 702 |
} |
| 703 |
body.easy-invoice-admin-body.admin-bar #wpbody, |
| 704 |
body.easy-invoice-admin-body.admin-bar #wpbody-content { |
| 705 |
padding-top: 0 !important; |
| 706 |
} |
| 707 |
</style> |
| 708 |
<?php |
| 709 |
} |
| 710 |
} |
| 711 |
} |
| 712 |
|