*/ private array $page_hooks = array(); public function register_hooks(): void { add_action( 'admin_menu', array( $this, 'register_menu' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); } public function register_menu(): void { $icon = 'dashicons-cloud-saved'; $this->page_hooks[] = (string) add_menu_page( __( 'ConnectCue', 'connectcue' ), __( 'ConnectCue', 'connectcue' ), 'manage_options', 'connectcue', array( $this, 'render_dashboard' ), $icon, 58 ); $this->page_hooks[] = (string) add_submenu_page( 'connectcue', __( 'Dashboard', 'connectcue' ), __( 'Dashboard', 'connectcue' ), 'manage_options', 'connectcue', array( $this, 'render_dashboard' ) ); $this->page_hooks[] = (string) add_submenu_page( 'connectcue', __( 'Settings', 'connectcue' ), __( 'Settings', 'connectcue' ), 'manage_options', 'connectcue-settings', array( $this, 'render_settings' ) ); $this->page_hooks[] = (string) add_submenu_page( 'connectcue', __( 'System Status', 'connectcue' ), __( 'System Status', 'connectcue' ), 'manage_options', 'connectcue-system', array( $this, 'render_system' ) ); } public function register_settings(): void { register_setting( 'connectcue_settings_group', Options::OPTION_NAME, array( 'type' => 'array', 'sanitize_callback' => array( Options::class, 'sanitize' ), 'default' => Options::defaults(), 'show_in_rest' => false, ) ); } public function enqueue_assets( string $hook_suffix ): void { if ( ! in_array( $hook_suffix, array_filter( $this->page_hooks ), true ) ) { return; } wp_enqueue_style( 'connectcue-admin', CONNECTCUE_URL . 'assets/admin/admin.css', array(), CONNECTCUE_VERSION ); wp_enqueue_script( 'connectcue-admin', CONNECTCUE_URL . 'assets/admin/admin.js', array(), CONNECTCUE_VERSION, array( 'in_footer' => true, 'strategy' => 'defer', ) ); } public function render_dashboard(): void { $this->guard(); $settings = Options::get_all(); require CONNECTCUE_PATH . 'admin/views/dashboard.php'; } public function render_settings(): void { $this->guard(); $settings = Options::get_all(); require CONNECTCUE_PATH . 'admin/views/settings.php'; } public function render_system(): void { $this->guard(); $settings = Options::get_all(); $system = $this->system_status(); require CONNECTCUE_PATH . 'admin/views/system.php'; } private function guard(): void { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', 'connectcue' ) ); } } /** * Build system status rows. * * @return array> */ private function system_status(): array { global $wp_version; $theme = wp_get_theme(); return array( 'wordpress' => array( 'label' => __( 'WordPress version', 'connectcue' ), 'value' => (string) $wp_version, 'good' => version_compare( (string) $wp_version, '6.4', '>=' ), ), 'php' => array( 'label' => __( 'PHP version', 'connectcue' ), 'value' => PHP_VERSION, 'good' => version_compare( PHP_VERSION, '8.0', '>=' ), ), 'https' => array( 'label' => __( 'HTTPS', 'connectcue' ), 'value' => is_ssl() ? __( 'Enabled', 'connectcue' ) : __( 'Not detected', 'connectcue' ), 'good' => is_ssl(), ), 'rest' => array( 'label' => __( 'Health endpoint', 'connectcue' ), 'value' => rest_url( 'connectcue/v1/ping' ), 'good' => true, ), 'theme' => array( 'label' => __( 'Active theme', 'connectcue' ), 'value' => $theme->get( 'Name' ) . ' ' . $theme->get( 'Version' ), 'good' => true, ), 'multisite' => array( 'label' => __( 'Multisite', 'connectcue' ), 'value' => is_multisite() ? __( 'Yes', 'connectcue' ) : __( 'No', 'connectcue' ), 'good' => true, ), ); } }