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' ) ); // Register custom post types and taxonomies. $this->register_post_types(); $this->register_taxonomies(); } /** * Register custom post types. * * @return void */ private function register_post_types(): void { Building::init(); Room::init(); Booking::init(); } /** * Register custom taxonomies. * * @return void */ private function register_taxonomies(): void { // Taxonomies must be registered before post types that use them. Amenity::init(); RoomType::init(); } /** * 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 seasons admin page. SeasonsAdmin::init(); // Initialize calendar admin page. CalendarAdmin::init(); // Initialize email notifier. EmailNotifier::init(); // Register AJAX handlers. add_action( 'wp_ajax_wp_bnb_check_availability', array( $this, 'ajax_check_availability' ) ); } /** * 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 { global $post_type; // Check if we're on plugin pages or editing our custom post types. $is_plugin_page = strpos( $hook_suffix, 'wp-bnb' ) !== false; $is_our_post_type = in_array( $post_type, array( Building::POST_TYPE, Room::POST_TYPE, Booking::POST_TYPE ), true ); $is_edit_screen = in_array( $hook_suffix, array( 'post.php', 'post-new.php' ), true ); if ( ! $is_plugin_page && ! ( $is_our_post_type && $is_edit_screen ) ) { return; } wp_enqueue_style( 'wp-bnb-admin', WP_BNB_URL . 'assets/css/admin.css', array(), WP_BNB_VERSION ); $script_deps = array( 'jquery' ); // Add media dependencies for room gallery. if ( Room::POST_TYPE === $post_type && $is_edit_screen ) { wp_enqueue_media(); $script_deps[] = 'jquery-ui-sortable'; } wp_enqueue_script( 'wp-bnb-admin', WP_BNB_URL . 'assets/js/admin.js', $script_deps, 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' ), 'postType' => $post_type, 'i18n' => array( 'validating' => __( 'Validating...', 'wp-bnb' ), 'activating' => __( 'Activating...', 'wp-bnb' ), 'error' => __( 'An error occurred. Please try again.', 'wp-bnb' ), 'selectImages' => __( 'Select Images', 'wp-bnb' ), 'addToGallery' => __( 'Add to Gallery', 'wp-bnb' ), 'confirmRemove' => __( 'Are you sure you want to remove this image?', 'wp-bnb' ), 'increase' => __( 'increase', 'wp-bnb' ), 'discount' => __( 'discount', 'wp-bnb' ), 'normalPrice' => __( 'Normal price', 'wp-bnb' ), 'checking' => __( 'Checking availability...', 'wp-bnb' ), 'available' => __( 'Available', 'wp-bnb' ), 'notAvailable' => __( 'Not available - conflicts with existing booking', 'wp-bnb' ), 'selectRoomAndDates' => __( 'Select room and dates to check availability', 'wp-bnb' ), 'nights' => __( 'nights', 'wp-bnb' ), 'night' => __( 'night', 'wp-bnb' ), 'calculating' => __( 'Calculating price...', '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' ) . '' ); ?>