init_hooks(); $this->init_components(); } /** * Initialize WordPress hooks. * * @return void */ private function init_hooks(): void { // Load text domain. add_action( 'init', array( $this, 'load_textdomain' ) ); // Register assets. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_assets' ) ); // Add plugin action links. add_filter( 'plugin_action_links_' . WP_BNB_BASENAME, array( $this, 'add_action_links' ) ); } /** * Initialize plugin components. * * @return void */ private function init_components(): void { // Initialize License Manager (always active for admin). LicenseManager::get_instance(); // Initialize admin components. if ( is_admin() ) { $this->init_admin(); } // Initialize frontend components only if licensed. if ( ! is_admin() && LicenseManager::is_license_valid() ) { $this->init_frontend(); } } /** * Initialize admin components. * * @return void */ private function init_admin(): void { // Admin menu and settings will be added here. add_action( 'admin_menu', array( $this, 'register_admin_menu' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); } /** * Initialize frontend components. * * @return void */ private function init_frontend(): void { // Frontend shortcodes, blocks, and widgets will be added here. } /** * Load plugin text domain. * * @return void */ public function load_textdomain(): void { load_plugin_textdomain( 'wp-bnb', false, dirname( WP_BNB_BASENAME ) . '/languages' ); } /** * Enqueue admin assets. * * @param string $hook_suffix Current admin page hook. * @return void */ public function enqueue_admin_assets( string $hook_suffix ): void { // Only load on plugin pages. if ( strpos( $hook_suffix, 'wp-bnb' ) === false ) { return; } wp_enqueue_style( 'wp-bnb-admin', WP_BNB_URL . 'assets/css/admin.css', array(), WP_BNB_VERSION ); wp_enqueue_script( 'wp-bnb-admin', WP_BNB_URL . 'assets/js/admin.js', array( 'jquery' ), WP_BNB_VERSION, true ); wp_localize_script( 'wp-bnb-admin', 'wpBnbAdmin', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'wp_bnb_admin_nonce' ), 'i18n' => array( 'validating' => __( 'Validating...', 'wp-bnb' ), 'activating' => __( 'Activating...', 'wp-bnb' ), 'error' => __( 'An error occurred. Please try again.', 'wp-bnb' ), ), ) ); } /** * Enqueue frontend assets. * * @return void */ public function enqueue_frontend_assets(): void { // Only load if licensed. if ( ! LicenseManager::is_license_valid() ) { return; } wp_enqueue_style( 'wp-bnb-frontend', WP_BNB_URL . 'assets/css/frontend.css', array(), WP_BNB_VERSION ); wp_enqueue_script( 'wp-bnb-frontend', WP_BNB_URL . 'assets/js/frontend.js', array(), WP_BNB_VERSION, true ); } /** * Add plugin action links. * * @param array $links Existing plugin links. * @return array */ public function add_action_links( array $links ): array { $plugin_links = array( '' . esc_html__( 'Settings', 'wp-bnb' ) . '', ); return array_merge( $plugin_links, $links ); } /** * Register admin menu. * * @return void */ public function register_admin_menu(): void { // Main menu. add_menu_page( __( 'WP BnB', 'wp-bnb' ), __( 'WP BnB', 'wp-bnb' ), 'manage_options', 'wp-bnb', array( $this, 'render_dashboard_page' ), 'dashicons-building', 30 ); // Dashboard submenu. add_submenu_page( 'wp-bnb', __( 'Dashboard', 'wp-bnb' ), __( 'Dashboard', 'wp-bnb' ), 'manage_options', 'wp-bnb', array( $this, 'render_dashboard_page' ) ); // Settings submenu. add_submenu_page( 'wp-bnb', __( 'Settings', 'wp-bnb' ), __( 'Settings', 'wp-bnb' ), 'manage_options', 'wp-bnb-settings', array( $this, 'render_settings_page' ) ); } /** * Register plugin settings. * * @return void */ public function register_settings(): void { // License settings are handled by LicenseManager. // Additional settings will be added here. } /** * Render dashboard page. * * @return void */ public function render_dashboard_page(): void { $license_status = LicenseManager::get_cached_status(); ?>

' . esc_html__( 'activate your license', 'wp-bnb' ) . '' ); ?>

save_settings( $active_tab ); } ?>

render_license_settings(); break; default: $this->render_general_settings(); break; } ?>

array( 'class' => 'dashicons-yes-alt', 'color' => '#00a32a', 'label' => __( 'Valid', 'wp-bnb' ), ), 'invalid' => array( 'class' => 'dashicons-dismiss', 'color' => '#d63638', 'label' => __( 'Invalid', 'wp-bnb' ), ), 'expired' => array( 'class' => 'dashicons-warning', 'color' => '#dba617', 'label' => __( 'Expired', 'wp-bnb' ), ), 'revoked' => array( 'class' => 'dashicons-dismiss', 'color' => '#d63638', 'label' => __( 'Revoked', 'wp-bnb' ), ), 'inactive' => array( 'class' => 'dashicons-marker', 'color' => '#72aee6', 'label' => __( 'Inactive', 'wp-bnb' ), ), 'unchecked' => array( 'class' => 'dashicons-info', 'color' => '#72aee6', 'label' => __( 'Not checked', 'wp-bnb' ), ), 'unconfigured' => array( 'class' => 'dashicons-admin-generic', 'color' => '#646970', 'label' => __( 'Not configured', 'wp-bnb' ), ), ); $badge = $badges[ $status ] ?? $badges['unconfigured']; ?> save_license_settings(); break; default: $this->save_general_settings(); break; } } /** * Save general settings. * * @return void */ private function save_general_settings(): void { if ( isset( $_POST['wp_bnb_business_name'] ) ) { update_option( 'wp_bnb_business_name', sanitize_text_field( wp_unslash( $_POST['wp_bnb_business_name'] ) ) ); } if ( isset( $_POST['wp_bnb_currency'] ) ) { update_option( 'wp_bnb_currency', sanitize_text_field( wp_unslash( $_POST['wp_bnb_currency'] ) ) ); } add_settings_error( 'wp_bnb_settings', 'settings_saved', __( 'Settings saved.', 'wp-bnb' ), 'success' ); settings_errors( 'wp_bnb_settings' ); } /** * Save license settings. * * @return void */ private function save_license_settings(): void { $data = array( 'license_key' => isset( $_POST['wp_bnb_license_key'] ) ? sanitize_text_field( wp_unslash( $_POST['wp_bnb_license_key'] ) ) : '', 'server_url' => isset( $_POST['wp_bnb_license_server_url'] ) ? esc_url_raw( wp_unslash( $_POST['wp_bnb_license_server_url'] ) ) : '', 'server_secret' => isset( $_POST['wp_bnb_license_server_secret'] ) ? sanitize_text_field( wp_unslash( $_POST['wp_bnb_license_server_secret'] ) ) : '', ); LicenseManager::save_settings( $data ); add_settings_error( 'wp_bnb_settings', 'settings_saved', __( 'License settings saved.', 'wp-bnb' ), 'success' ); settings_errors( 'wp_bnb_settings' ); } /** * Get Twig environment. * * @return Environment */ public function get_twig(): Environment { if ( null === $this->twig ) { $loader = new FilesystemLoader( WP_BNB_PATH . 'templates' ); $this->twig = new Environment( $loader, array( 'cache' => WP_DEBUG ? false : WP_BNB_PATH . 'cache/twig', 'debug' => WP_DEBUG, ) ); } return $this->twig; } /** * Render a Twig template. * * @param string $template Template name. * @param array $context Template context. * @return string */ public function render( string $template, array $context = array() ): string { return $this->get_twig()->render( $template, $context ); } }