init_hooks(); } /** * Initialize hooks */ private function init_hooks(): void { add_action('admin_menu', [$this, 'add_menu_pages']); add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_assets']); } /** * Add admin menu pages */ public function add_menu_pages(): void { add_menu_page( __('QuickBundles', 'quickbundles'), __('QuickBundles', 'quickbundles'), 'manage_woocommerce', 'quick-bundles', [$this, 'render_dashboard_page'], 'dashicons-cart', 56 ); add_submenu_page( 'quick-bundles', __('Dashboard', 'quickbundles'), __('Dashboard', 'quickbundles'), 'manage_woocommerce', 'quick-bundles', [$this, 'render_dashboard_page'] ); add_submenu_page( 'quick-bundles', __('Add New Bundle', 'quickbundles'), __('Add New Bundle', 'quickbundles'), 'manage_woocommerce', 'quick-bundles-new', [$this, 'render_editor_page'] ); } /** * Enqueue admin assets */ public function enqueue_admin_assets(string $hook): void { // Only load on our admin pages if (!strpos($hook, 'quick-bundles')) { return; } // Register and enqueue Chakra UI wp_register_style( 'chakra-ui', QBND_PLUGIN_URL . 'assets/vendor/chakra-ui/chakra-ui.min.css', [], '2.8.2' ); wp_enqueue_style('chakra-ui'); // Register and enqueue admin styles wp_register_style( 'qbnd-admin', QBND_PLUGIN_URL . 'assets/css/admin.css', ['chakra-ui'], QBND_VERSION ); wp_enqueue_style('qbnd-admin'); // Register and enqueue admin scripts wp_register_script( 'qbnd-admin', QBND_PLUGIN_URL . 'build/admin.js', ['wp-element', 'wp-components', 'wp-api-fetch'], QBND_VERSION, [ 'strategy' => 'defer', 'in_footer' => true ] ); wp_enqueue_script('qbnd-admin'); // Pass data to JavaScript wp_localize_script('qbnd-admin', 'qbndAdmin', [ 'nonce' => wp_create_nonce('wp_rest'), 'root' => esc_url_raw(rest_url()), 'adminUrl' => admin_url(), 'currency' => [ 'symbol' => get_woocommerce_currency_symbol(), 'position' => get_option('woocommerce_currency_pos'), 'debug' => [ 'raw_symbol' => get_woocommerce_currency_symbol(), 'currency_code' => get_woocommerce_currency(), 'position_raw' => get_option('woocommerce_currency_pos'), ] ], 'strings' => [ 'saveBundle' => __('Save Bundle', 'quickbundles'), 'addProducts' => __('Add Products', 'quickbundles'), 'setDiscount' => __('Set Discount', 'quickbundles'), 'configureTimer' => __('Configure Timer', 'quickbundles'), ], ]); } /** * Render dashboard page */ public function render_dashboard_page(): void { ?>