__( 'Dashboard', 'spacebay' ), '/spaces' => __( 'Spaces', 'spacebay' ), '/topics' => __( 'Topics', 'spacebay' ), '/members' => __( 'Members', 'spacebay' ), '/settings' => __( 'Settings', 'spacebay' ), ); /** * Filters the screens of the admin app that get a submenu item. * * Keys are routes of the admin app ("/shops"), values are labels. * Add-ons add their screen with addRoute() in the admin app too. * * @since 1.0.0 * * @param array $screens Route => label. */ $extra = (array) apply_filters( 'spacebay_admin_screens', array() ); foreach ( $extra as $route => $label ) { $route = '/' . trim( sanitize_text_field( (string) $route ), '/' ); if ( '/' !== $route && ! isset( $screens[ $route ] ) ) { // Add-on screens go before Settings. $screens = array_slice( $screens, 0, -1, true ) + array( $route => (string) $label ) + array_slice( $screens, -1, 1, true ); } } foreach ( $screens as $route => $label ) { add_submenu_page( self::SLUG, $label, $label, Capabilities::MANAGE, '' === $route ? self::SLUG : self::SLUG . '#' . $route, '' === $route ? array( __CLASS__, 'render' ) : '__return_null' ); } } /** * Enqueues the admin app on the SpaceBay page only. * * @param string $hook_suffix Current admin page hook. * @return void */ public static function enqueue( $hook_suffix ) { if ( '' === self::$hook || self::$hook !== $hook_suffix ) { return; } // The media library is used to choose the community logo. wp_enqueue_media(); Assets::enqueue_app( 'admin' ); } /** * Adds a body class on the SpaceBay page so styles stay scoped. * * @param string $classes Space-separated body classes. * @return string */ public static function body_class( $classes ) { $screen = get_current_screen(); if ( $screen && self::$hook === $screen->id ) { $classes .= ' sbay-admin-page'; } return $classes; } /** * Renders the mount point of the admin app. * * @return void */ public static function render() { if ( ! current_user_can( Capabilities::MANAGE ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to access this page.', 'spacebay' ) ); } $config = Assets::base_config(); include SPACEBAY_PATH . 'templates/admin-page.php'; } /** * Opens the SpaceBay page once, right after a single activation. * * @return void */ public static function activation_redirect() { $user_id = (int) get_option( 'spacebay_activation_redirect' ); if ( ! $user_id || get_current_user_id() !== $user_id ) { return; } delete_option( 'spacebay_activation_redirect' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only check of the core bulk-activation flag. if ( wp_doing_ajax() || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( Capabilities::MANAGE ) ) { return; } wp_safe_redirect( admin_url( 'admin.php?page=' . self::SLUG ) ); exit; } }