nus should not appear on single WordPress setups. * * Comments and posts made by users will still show in their activity. */ if ( ! is_multisite() ) { return; } // Menus for logged in user. if ( is_user_logged_in() ) { // Setup the logged in user variables. $blogs_slug = bp_get_blogs_slug(); // Add the "Sites" sub menu. $wp_admin_nav[] = array( 'parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => __( 'Sites', 'buddypress' ), 'href' => bp_loggedin_user_url( bp_members_get_path_chunks( array( $blogs_slug ) ) ), ); // My Sites. $wp_admin_nav[] = array( 'parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-my-sites', 'title' => __( 'My Sites', 'buddypress' ), 'href' => bp_loggedin_user_url( bp_members_get_path_chunks( array( $blogs_slug, 'my-sites' ) ) ), 'position' => 10, ); // Create a Site. if ( bp_blog_signup_enabled() ) { $url = bp_get_blogs_directory_url( array( 'create_single_item' => 1, ) ); $wp_admin_nav[] = array( 'parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-create', 'title' => __( 'Create a Site', 'buddypress' ), 'href' => $url, 'position' => 99 ); } } parent::setup_admin_bar( $wp_admin_nav ); } /** * Set up the title for pages and . */ public function setup_title() { // Set up the component options navigation for Site. if ( bp_is_blogs_component() ) { $bp = buddypress(); if ( bp_is_my_profile() ) { if ( bp_is_active( 'xprofile' ) ) { $bp->bp_options_title = __( 'My Sites', 'buddypress' ); } // If we are not viewing the logged in user, set up the current // users avatar and name. } else { $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => bp_displayed_user_id(), 'type' => 'thumb', 'alt' => sprintf( /* translators: %s: member name */ __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ), ) ); $bp->bp_options_title = bp_get_displayed_user_fullname(); } } parent::setup_title(); } /** * Setup cache groups * * @since 2.2.0 */ public function setup_cache_groups() { // Global groups. wp_cache_add_global_groups( array( 'bp_blog_meta' ) ); parent::setup_cache_groups(); } /** * Add the Blog Create rewrite tags. * * @since 12.0.0 * * @param array $rewrite_tags Optional. See BP_Component::add_rewrite_tags() for * description. */ public function add_rewrite_tags( $rewrite_tags = array() ) { $rewrite_tags = array( 'create_single_item' => '([1]{1,})', 'directory_action' => '([^/]+)', 'directory_action_variables' => '(.+?)', ); parent::add_rewrite_tags( $rewrite_tags ); } /** * Add the Registration and Activation rewrite rules. * * @since 12.0.0 * * @param array $rewrite_rules Optional. See BP_Component::add_rewrite_rules() for * description. */ public function add_rewrite_rules( $rewrite_rules = array() ) { $create_slug = bp_rewrites_get_slug( 'blogs', 'blog_create', 'create' ); $rewrite_rules = array( 'directory_action_variables' => array( 'regex' => $this->root_slug . '/([^/]+)/(.+?)/?$', 'order' => 70, 'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['directory_action'] . '=$matches[1]&' . $this->rewrite_ids['directory_action_variables'] . '=$matches[2]', ), 'directory_action' => array( 'regex' => $this->root_slug . '/([^/]+)/?$', 'order' => 60, 'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['directory_action'] . '=$matches[1]', ), 'create_single_item' => array( 'regex' => $this->root_slug . '/' . $create_slug . '/?$', 'order' => 50, 'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['create_single_item'] . '=1', ), ); parent::add_rewrite_rules( $rewrite_rules ); } /** * Parse the WP_Query and eventually display the component's directory or single item. * * @since 12.0.0 * * @param WP_Query $query Required. See BP_Component::parse_query() for * description. */ public function parse_query( $query ) { /* * Only Multisite configs have a Sites directory. * If BP Rewrites are not in use, no need to parse BP URI globals another time. * Legacy Parser should have already set these. */ if ( ! is_multisite() || 'rewrites' !== bp_core_get_query_parser() ) { return parent::parse_query( $query ); } // Get the BuddyPress main instance. $bp = buddypress(); if ( home_url( '/' ) === bp_get_requested_url() && bp_is_directory_homepage( $this->id ) ) { $query->set( $this->rewrite_ids['directory'], 1 ); } if ( 1 === (int) $query->get( $this->rewrite_ids['directory'] ) ) { $bp->current_component = 'blogs'; $is_blog_create = 1 === (int) $query->get( $this->rewrite_ids['create_single_item'] ); if ( $is_blog_create ) { $bp->current_action = 'create'; } else { $current_action = $query->get( $this->rewrite_ids['directory_action'] ); if ( $current_action ) { $bp->current_action = $current_action; } $action_variables = $query->get( $this->rewrite_ids['directory_action_variables'] ); if ( $action_variables ) { if ( ! is_array( $action_variables ) ) { $bp->action_variables = explode( '/', ltrim( $action_variables, '/' ) ); } else { $bp->action_variables = $action_variables; } } } // Set the BuddyPress queried object. if ( isset( $bp->pages->blogs->id ) && ( ! bp_current_action() || bp_is_current_action( 'create' ) ) ) { $query->queried_object = get_post( $bp->pages->blogs->id ); $query->queried_object_id = $query->queried_object->ID; } } parent::parse_query( $query ); } /** * Init the BP REST API. * * @since 6.0.0 * * @param array $controllers Optional. See BP_Component::rest_api_init() for * description. */ public function rest_api_init( $controllers = array() ) { if ( is_multisite() ) { $controllers = array( 'BP_REST_Blogs_Endpoint', ); // Support to Blog Avatar. if ( bp_is_active( 'blogs', 'site-icon' ) ) { $controllers[] = 'BP_REST_Attachments_Blog_Avatar_Endpoint'; } } parent::rest_api_init( $controllers ); } /** * Register the BP Blogs Blocks. * * @since 9.0.0 * @since 12.0.0 Use the WP Blocks API v2. * * @param array $blocks Optional. See BP_Component::blocks_init() for * description. */ public function blocks_init( $blocks = array() ) { $blocks = array(); if ( is_multisite() && bp_is_active( 'activity' ) ) { $blocks['bp/recent-posts'] = array( 'metadata' => trailingslashit( buddypress()->plugin_dir ) . 'bp-blogs/blocks/recent-posts', 'render_callback' => 'bp_blogs_render_recent_posts_block', ); } parent::blocks_init( $blocks ); } }