check_authentication(); wp_set_current_user( $user_id ); if ( is_wp_error( $auth ) ) { return array(); } /** * Filters the largest response, in bytes, that is carried inside the portal page. * * @since 1.0.0 * * @param int $max_bytes Byte limit per response. Default 204800. */ $max_bytes = (int) apply_filters( 'spacebay_bootstrap_max_bytes', 200 * 1024 ); $data = array(); foreach ( $paths as $path ) { $response = rest_do_request( new \WP_REST_Request( 'GET', '/spacebay/v1/' . $path ) ); if ( $response->is_error() || 200 !== $response->get_status() ) { continue; } $value = $response->get_data(); $encoded = wp_json_encode( $value ); // A very large community falls back to normal requests. if ( false === $encoded || strlen( $encoded ) > $max_bytes ) { continue; } $data[ $path ] = $value; } return $data; } /** * Returns the data passed to the Vue apps through a data attribute. * * @return array */ public static function base_config() { $user = wp_get_current_user(); $settings = Settings::all(); $portal_url = Portal::url(); $config = array( 'version' => SPACEBAY_VERSION, 'hasPro' => defined( 'SPACEBAY_PRO_VERSION' ), 'restUrl' => esc_url_raw( rest_url( 'spacebay/v1/' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'siteUrl' => esc_url_raw( home_url( '/' ) ), 'portalUrl' => esc_url_raw( $portal_url ), 'portalPath' => (string) wp_parse_url( $portal_url, PHP_URL_PATH ), 'routerMode' => Portal::uses_pretty_urls() ? 'history' : 'hash', 'adminUrl' => esc_url_raw( admin_url( 'admin.php?page=spacebay' ) ), 'assetsUrl' => esc_url_raw( SPACEBAY_URL . 'assets/' ), 'communityName' => $settings['community_name'], 'welcomeTitle' => $settings['welcome_title'], 'welcomeText' => $settings['welcome_message'], 'colorMode' => $settings['color_mode'], 'brandColor' => $settings['brand_color'], 'spaceIconColor' => $settings['space_icon_color'], 'logoUrl' => $settings['logo_id'] ? (string) wp_get_attachment_image_url( $settings['logo_id'], 'medium' ) : '', 'showName' => (bool) $settings['show_community_name'], 'setupDone' => (bool) get_option( 'spacebay_setup_done' ), 'isRtl' => is_rtl(), 'access' => $settings['access'], 'memberApproval' => (bool) $settings['member_approval'], 'messages' => $user->exists() && (bool) $settings['messages_enabled'], 'groupChats' => (bool) $settings['group_chats'], 'groupChatMax' => (int) $settings['group_chat_max'], // Add-ons that need a fast unread/updates poll (for example ringing calls) set this to true. 'fastPulse' => false, 'memberDirectory' => $user->exists() && ( 'off' !== $settings['member_directory'] || current_user_can( Capabilities::MANAGE ) ), 'gamification' => \SpaceBay\Gamification\Gamification::enabled(), 'leaderboard' => $user->exists() && \SpaceBay\Gamification\Gamification::leaderboard_enabled(), 'events' => \SpaceBay\Events\Events::enabled(), 'startOfWeek' => (int) get_option( 'start_of_week', 1 ), 'loginUrl' => esc_url_raw( Auth::login_url() ), 'registerUrl' => esc_url_raw( Auth::signup_url() ), 'auth' => array( 'pages' => Auth::has_pages(), 'signup' => Auth::signup_open(), // The form is only needed by visitors, who are the ones who can sign up. 'fields' => ! $user->exists() && Auth::signup_open() ? SignupFields::form() : array(), 'termsUrl' => esc_url_raw( (string) $settings['signup_terms_url'] ), 'minPassword' => SignupFields::MIN_PASSWORD, // False when a network administrator switched off new accounts for every site. 'networkOpen' => Auth::network_allows_signup(), // "Continue with Google / Facebook" buttons that are switched on and have their keys. 'social' => ! $user->exists() ? Social::buttons() : array(), // Addresses administrators copy into their Google and Facebook apps. 'callbacks' => current_user_can( Capabilities::MANAGE ) ? array( 'google' => Social::callback_url( 'google' ), 'facebook' => Social::callback_url( 'facebook' ), ) : array(), ), 'logoutUrl' => esc_url_raw( str_replace( '&', '&', wp_logout_url( $portal_url ) ) ), 'user' => $user->exists() ? array( 'id' => $user->ID, 'name' => $user->display_name, 'avatar' => get_avatar_url( $user->ID, array( 'size' => 96 ) ), 'canManage' => current_user_can( Capabilities::MANAGE ), 'canModerate' => current_user_can( Capabilities::MANAGE ) || current_user_can( Capabilities::MODERATE ), 'status' => self::account_status( $user->ID ), ) : null, ); /** * Filters the configuration passed to the portal and admin apps. * * @since 1.0.0 * * @param array $config Configuration. * @param \WP_User $user Current user (ID 0 for visitors). */ return apply_filters( 'spacebay_app_config', $config, $user ); } }