invoice_controller = new InvoiceController(); $this->quote_controller = new QuoteController(); $this->client_controller = new ClientController(); $this->settings_controller = new SettingsController(); $this->report_controller = new ReportController(); $this->dashboard_controller = new DashboardController(); $this->payment_controller = new PaymentController(); } /** * Initialize the admin class */ public function init() { // Add menu items add_action('admin_menu', array($this, 'registerMenuPages')); // Register admin assets $admin_assets = new AdminAssets(); $admin_assets->register(); // Register invoice preview page add_action('admin_init', array($this, 'registerPreviewPage')); // Ensure proper page titles to avoid WordPress core issues add_filter('admin_title', array($this, 'setAdminTitle')); // Hide admin UI add_action('admin_head', array($this, 'hideAdminUi')); // Initialize controllers $this->invoice_controller->init(); $this->quote_controller->init(); $this->client_controller->init(); $this->settings_controller->init(); $this->report_controller->init(); $this->dashboard_controller->init(); $this->payment_controller->init(); // Main content hook add_action('easy_invoice_admin_main_content', array($this, 'mainPageContent')); } /** * Register admin menu pages */ public function registerMenuPages() { // Main menu item add_menu_page( __('Easy Invoice', 'easy-invoice'), __('Easy Invoice', 'easy-invoice'), 'manage_options', PagesSlugs::DASHBOARD, array($this, 'displayMainPage'), 'dashicons-media-text', 25 ); // Dashboard submenu add_submenu_page( 'easy-invoice', __('Dashboard', 'easy-invoice'), __('Dashboard', 'easy-invoice'), 'manage_options', PagesSlugs::DASHBOARD, array($this, 'displayMainPage') ); // All invoices submenu add_submenu_page( 'easy-invoice', __('All Invoices', 'easy-invoice'), __('All Invoices', 'easy-invoice'), 'manage_options', PagesSlugs::ALL_INVOICES, array($this, 'displayMainPage') ); // Add new invoice submenu add_submenu_page( 'easy-invoice-hidden', __('Add New Invoice', 'easy-invoice'), __('Add New', 'easy-invoice'), 'manage_options', PagesSlugs::INVOICE_NEW, array($this, 'displayMainPage') ); // All quotes submenu add_submenu_page( 'easy-invoice', __('All Quotes', 'easy-invoice'), __('All Quotes', 'easy-invoice'), 'manage_options', PagesSlugs::ALL_QUOTES, array($this, 'displayMainPage') ); // Add new quote submenu add_submenu_page( 'easy-invoice-hidden', __('Add New Quote', 'easy-invoice'), __('Add New Quote', 'easy-invoice'), 'manage_options', PagesSlugs::QUOTE_NEW, array($this, 'displayMainPage') ); // Payments submenu add_submenu_page( 'easy-invoice-hidden', __('Payments', 'easy-invoice'), __('Payments', 'easy-invoice'), 'manage_options', PagesSlugs::PAYMENTS, array($this, 'displayMainPage') ); // Add new payment submenu add_submenu_page( 'easy-invoice-hidden', __('Add New Payment', 'easy-invoice'), __('Add New Payment', 'easy-invoice'), 'manage_options', PagesSlugs::PAYMENT_NEW, array($this, 'displayMainPage') ); // Clients submenu add_submenu_page( 'easy-invoice', __('All Clients', 'easy-invoice'), __('All Clients', 'easy-invoice'), 'manage_options', PagesSlugs::CLIENTS, array($this, 'displayMainPage') ); // Hidden submenu pages - not shown in the menu but accessible add_submenu_page( 'easy-invoice-hidden', // Use main menu as parent to avoid title issues __('Edit Client', 'easy-invoice'), __('Edit Client', 'easy-invoice'), 'manage_options', PagesSlugs::CLIENT_EDIT, array($this, 'displayMainPage') ); add_submenu_page( 'easy-invoice-hidden', // Use main menu as parent to avoid title issues __('View Client', 'easy-invoice'), __('View Client', 'easy-invoice'), 'manage_options', PagesSlugs::CLIENT_VIEW, array($this, 'displayMainPage') ); add_submenu_page( 'easy-invoice-hidden', // Use main menu as parent to avoid title issues __('Preview Invoice', 'easy-invoice'), __('Preview Invoice', 'easy-invoice'), 'manage_options', PagesSlugs::INVOICE_PREVIEW, array($this, 'displayPreviewPage') ); add_submenu_page( 'easy-invoice-hidden', // Use main menu as parent to avoid title issues __('Preview Quote', 'easy-invoice'), __('Preview Quote', 'easy-invoice'), 'manage_options', PagesSlugs::QUOTE_PREVIEW, array($this, 'displayMainPage') ); add_submenu_page( 'easy-invoice', __('Reports', 'easy-invoice'), __('Reports', 'easy-invoice'), 'manage_options', PagesSlugs::REPORTS, array($this, 'displayMainPage') ); // Settings submenu add_submenu_page( 'easy-invoice', __('Settings', 'easy-invoice'), __('Settings', 'easy-invoice'), 'manage_options', PagesSlugs::SETTINGS, array($this, 'displayMainPage') ); // License submenu add_submenu_page( 'easy-invoice', __('License', 'easy-invoice'), __('License', 'easy-invoice'), 'manage_options', PagesSlugs::LICENSE, array($this, 'displayMainPage') ); // Free vs Pro submenu - only show in free version if (!easy_invoice_has_pro()) { add_submenu_page( 'easy-invoice', __('Free vs Pro', 'easy-invoice'), __('Free vs Pro', 'easy-invoice'), 'manage_options', 'easy-invoice-free-vs-pro', array($this, 'displayMainPage') ); } } /** * Register invoice preview page */ public function registerPreviewPage() { //add_action('admin_action_easy_invoice_preview', array($this, 'displayPreviewPage')); } /** * Display main page */ public function displayMainPage() { include EASY_INVOICE_PLUGIN_DIR . 'templates/main-template.php'; } /** * Display preview page */ public function displayPreviewPage() { $this->invoice_controller->display(['page' => PagesSlugs::INVOICE_PREVIEW]); } /** * Display license page */ public function displayLicensePage() { include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/license-page.php'; } /** * Handle main page content based on the current page * * @param string $page Current page */ public function mainPageContent($page) { switch ($page) { case PagesSlugs::DASHBOARD: $this->dashboard_controller->display(['page' => PagesSlugs::DASHBOARD]); break; case PagesSlugs::ALL_INVOICES: $this->invoice_controller->display(['page' => PagesSlugs::ALL_INVOICES]); break; case PagesSlugs::INVOICE_NEW: $this->invoice_controller->display(['page' => PagesSlugs::INVOICE_NEW]); break; case PagesSlugs::INVOICE_PREVIEW: $this->invoice_controller->display(['page' => PagesSlugs::INVOICE_PREVIEW]); break; case PagesSlugs::ALL_QUOTES: $this->quote_controller->display(['page' => PagesSlugs::ALL_QUOTES]); break; case PagesSlugs::QUOTE_NEW: $this->quote_controller->display(['page' => PagesSlugs::QUOTE_NEW]); break; case PagesSlugs::QUOTE_PREVIEW: $this->quote_controller->display(['page' => PagesSlugs::QUOTE_PREVIEW]); break; case PagesSlugs::PAYMENTS: if (isset($_GET['action'])) { $this->payment_controller->display(['page' => $_GET['action']]); } else { $this->payment_controller->display(['page' => PagesSlugs::PAYMENTS]); } break; case PagesSlugs::PAYMENT_NEW: $this->payment_controller->display(['page' => PagesSlugs::PAYMENT_NEW]); break; case PagesSlugs::CLIENTS: $this->client_controller->display(['page' => PagesSlugs::CLIENTS]); break; case PagesSlugs::CLIENT_EDIT: $this->client_controller->display(['page' => PagesSlugs::CLIENT_EDIT]); break; case PagesSlugs::CLIENT_VIEW: $this->client_controller->display(['page' => PagesSlugs::CLIENT_VIEW]); break; case PagesSlugs::REPORTS: $this->report_controller->display(['page' => PagesSlugs::REPORTS]); break; case PagesSlugs::SETTINGS: $this->settings_controller->display(['page' => PagesSlugs::SETTINGS]); break; case PagesSlugs::LICENSE: $this->displayLicensePage(); break; case PagesSlugs::EMAIL_SETTINGS: case PagesSlugs::EMAIL_SETTINGS_GENERAL: case PagesSlugs::EMAIL_SETTINGS_INVOICE: case PagesSlugs::EMAIL_SETTINGS_QUOTE: case PagesSlugs::EMAIL_SETTINGS_PAYMENT: $this->settings_controller->display(['page' => PagesSlugs::SETTINGS, 'subsection' => $page]); break; case 'easy-invoice-migration': include EASY_INVOICE_PLUGIN_DIR . 'includes/Migration/templates/migration-page.php'; break; case 'easy-invoice-free-vs-pro': include EASY_INVOICE_PLUGIN_DIR . 'templates/admin/free-vs-pro-page.php'; break; default: $this->dashboard_controller->display(['page' => PagesSlugs::DASHBOARD]); break; } } /** * Set proper admin title to avoid WordPress core issues * * @param string $title The current admin title * @return string The modified admin title */ public function setAdminTitle($title) { $current_page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : ''; // Only modify titles for our plugin pages if (strpos($current_page, 'easy-invoice') === 0 || strpos($current_page, 'easy-quote') === 0) { $page_titles = [ 'easy-invoice' => __('Dashboard', 'easy-invoice'), 'easy-invoice-all' => __('All Invoices', 'easy-invoice'), 'easy-invoice-builder' => __('Add New Invoice', 'easy-invoice'), 'easy-invoice-preview' => __('Preview Invoice', 'easy-invoice'), 'easy-quote-all' => __('All Quotes', 'easy-invoice'), 'easy-invoice-quote-builder' => __('Add New Quote', 'easy-invoice'), 'easy-quote-preview' => __('Preview Quote', 'easy-invoice'), 'easy-invoice-payments' => __('Payments', 'easy-invoice'), 'easy-invoice-payment-new' => __('Add New Payment', 'easy-invoice'), 'easy-invoice-clients' => __('Clients', 'easy-invoice'), 'easy-invoice-client-edit' => __('Edit Client', 'easy-invoice'), 'easy-invoice-client-view' => __('View Client', 'easy-invoice'), 'easy-invoice-reports' => __('Reports', 'easy-invoice'), 'easy-invoice-settings' => __('Settings', 'easy-invoice'), 'easy-invoice-email-settings' => __('Email Settings', 'easy-invoice'), 'easy-invoice-migration' => __('Migration', 'easy-invoice'), 'easy-invoice-free-vs-pro' => __('Free vs Pro', 'easy-invoice'), ]; if (isset($page_titles[$current_page])) { return $page_titles[$current_page] . ' - ' . get_bloginfo('name'); } } return $title; } /** * Hide the WordPress admin UI for our custom pages */ public function hideAdminUi() { $screen = get_current_screen(); if ($screen && property_exists($screen, 'id') && strpos($screen->id, 'easy-invoice') !== false) { ?>