Ticket #6026: 6026.smaller-steps.02.patch
File 6026.smaller-steps.02.patch, 81.3 KB (added by , 8 years ago) |
---|
-
src/bp-activity/bp-activity-template.php
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php index c2d33b1..c425666 100644
function bp_has_activities( $args = '' ) { 221 221 $object = $bp->groups->id; 222 222 $primary_id = bp_get_current_group_id(); 223 223 $show_hidden = (bool) ( groups_is_user_member( bp_loggedin_user_id(), $primary_id ) || bp_current_user_can( 'bp_moderate' ) ); 224 } elseif ( bp_is_site() ) { 225 $object = $bp->blogs->id; 226 $primary_id = bp_blogs_get_current_site_id(); 227 $show_hidden = false; 224 228 } else { 225 229 $object = false; 226 230 $primary_id = false; … … function bp_activity_show_filters( $context = '' ) { 3812 3816 } elseif ( bp_is_active( 'groups' ) && bp_is_group() ) { 3813 3817 $context = 'group'; 3814 3818 3819 // On individual site pages, default to 'site'. 3820 } elseif ( bp_is_active( 'blogs', 'site' ) && bp_is_site() ) { 3821 $context = 'site'; 3822 3815 3823 // 'activity' everywhere else. 3816 3824 } else { 3817 3825 $context = 'activity'; -
src/bp-blogs/bp-blogs-activity.php
diff --git src/bp-blogs/bp-blogs-activity.php src/bp-blogs/bp-blogs-activity.php index b3fe3ee..c259897 100644
function bp_blogs_register_activity_actions() { 25 25 __( 'New site created', 'buddypress' ), 26 26 'bp_blogs_format_activity_action_new_blog', 27 27 __( 'New Sites', 'buddypress' ), 28 array( 'activity', 'member' ),28 array( 'activity', 'member', 'site' ), 29 29 0 30 30 ); 31 31 } … … function bp_blogs_register_post_tracking_args( $params = null, $post_type = 0 ) 77 77 $params->admin_filter = __( 'New post published', 'buddypress' ); 78 78 $params->format_callback = 'bp_blogs_format_activity_action_new_blog_post'; 79 79 $params->front_filter = __( 'Posts', 'buddypress' ); 80 $params->contexts = array( 'activity', 'member' );80 $params->contexts = array( 'activity', 'member', 'site' ); 81 81 $params->position = 5; 82 82 83 83 if ( post_type_supports( $post_type, 'comments' ) ) { … … function bp_blogs_register_post_tracking_args( $params = null, $post_type = 0 ) 105 105 $params->comments_tracking->admin_filter = __( 'New post comment posted', 'buddypress' ); 106 106 $params->comments_tracking->format_callback = 'bp_blogs_format_activity_action_new_blog_comment'; 107 107 $params->comments_tracking->front_filter = __( 'Comments', 'buddypress' ); 108 $params->comments_tracking->contexts = array( 'activity', 'member' );108 $params->comments_tracking->contexts = array( 'activity', 'member', 'site' ); 109 109 $params->comments_tracking->position = 10; 110 110 } 111 111 } -
src/bp-blogs/classes/class-bp-blogs-blog.php
diff --git src/bp-blogs/classes/class-bp-blogs-blog.php src/bp-blogs/classes/class-bp-blogs-blog.php index c84adb9..556d4c1 100644
class BP_Blogs_Blog { 820 820 821 821 return $user_blog; 822 822 } 823 824 /** 825 * List the User ids who are contributors or subscribers of the site. 826 * If the detail parameter is set to true, this list will be organized 827 * according to the contribution "power" of users. 828 * 829 * @since 2.7.0 830 * 831 * @param int $blog_id The blog ID to get users for. 832 * @param int $is_contributor Get only contributors (1) or subscribers (0). 833 * @return array The list of users of the blog 834 */ 835 public static function get_site_user_ids( $blog_id, $is_contributor = null ) { 836 global $wpdb; 837 838 $bp = buddypress(); 839 840 $sql = array( 841 'select' => "SELECT user_id, is_contributor FROM {$bp->blogs->table_name}", 842 'where' => array( 843 'blog_id' => $wpdb->prepare( 'blog_id = %d', $blog_id ), 844 ), 845 ); 846 847 if ( ! is_null( $is_contributor ) ) { 848 $sql['where']['is_contributor'] = $wpdb->prepare( 'is_contributor = %d', $is_contributor ); 849 } 850 851 $sql['where'] = 'WHERE ' . join( ' AND ', $sql['where'] ); 852 $query = join( ' ', $sql ); 853 854 return $wpdb->get_results( $query, OBJECT_K ); 855 } 856 857 /** 858 * Returns the number of recorded Users for a blog 859 * 860 * @since 2.7.0 861 * 862 * @param int $blog_id The blog ID to get the users count for. 863 * @return int The number of users. 864 */ 865 public static function get_site_users_count( $blog_id ) { 866 global $wpdb; 867 868 $bp = buddypress(); 869 870 $users_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( user_id ) FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) ); 871 872 if ( empty( $users_count ) ) { 873 return false; 874 } 875 876 return (int) $users_count; 877 } 823 878 } -
src/bp-blogs/classes/class-bp-blogs-component.php
diff --git src/bp-blogs/classes/class-bp-blogs-component.php src/bp-blogs/classes/class-bp-blogs-component.php index ee9b204..6ccb129 100644
class BP_Blogs_Component extends BP_Component { 107 107 add_post_type_support( $post_type, 'buddypress-activity' ); 108 108 } 109 109 } 110 111 /** Single Site globals *******************************************************/ 112 113 if ( is_multisite() && bp_is_blogs_component() && bp_current_action() && bp_is_active( $this->id, 'site' ) ) { 114 // Initialize a global placeholder for the site. 115 $this->site = new stdClass; 116 117 // Set the current Site object 118 if ( bp_is_current_action( bp_blogs_get_root_site_slug() ) ) { 119 $this->current_site = bp_blogs_get_site( bp_get_root_blog_id() ); 120 } else { 121 $this->current_site = bp_blogs_get_site( bp_current_action() ); 122 } 123 124 if ( empty( $this->current_site->blog_id ) ) { 125 $this->current_site = 0; 126 return; 127 } 128 129 // It's a single Site 130 $bp->is_single_item = true; 131 $bp->current_item = $this->current_site->slug; 132 $bp->current_action = bp_action_variable( 0 ); 133 array_shift( $bp->action_variables ); 134 135 if ( is_super_admin() || $this->current_site->is_admin ) { 136 bp_update_is_item_admin( true, $bp->blogs->id ); 137 } 138 139 // By Default grant access 140 $this->current_site->user_has_access = true; 141 142 // If the site is not public, non members can't access 143 if ( ! $this->current_site->public && ! $this->current_site->is_member && ! bp_is_item_admin() ) { 144 $this->current_site->user_has_access = false; 145 } 146 147 // Check once if the current site has a custom front template 148 $this->current_site->front_template = bp_blogs_get_site_front_template( $this->current_site ); 149 150 // Initialize the nav for the current site. 151 $this->nav = new BP_Core_Nav( $this->current_site->blog_id ); 152 153 // Set current_site to 0 to prevent debug errors. 154 } else { 155 $this->current_site = 0; 156 } 157 } 158 159 /** 160 * Set up canonical stack for this component. 161 * 162 * @since 2.7.0 163 */ 164 public function setup_canonical_stack() { 165 $bp = buddypress(); 166 167 if ( ! bp_is_blogs_component() ) { 168 return; 169 } 170 171 if ( empty( $this->current_site ) ) { 172 return; 173 } 174 175 if ( ! bp_current_action() ) { 176 $bp->current_action = 'home'; 177 } 178 179 // Prepare for a redirect to the canonical URL 180 $bp->canonical_stack['base_url'] = bp_blogs_get_site_community_url( $this->current_site->slug ); 181 182 if ( bp_current_action() ) { 183 $bp->canonical_stack['action'] = bp_current_action(); 184 } 185 186 if ( ! empty( $bp->action_variables ) ) { 187 $bp->canonical_stack['action_variables'] = bp_action_variables(); 188 } 189 190 /** 191 * When viewing the default extension, the canonical URL should not have 192 * that extension's slug, unless more has been tacked onto the URL via 193 * action variables 194 */ 195 if ( bp_is_current_action( 'home' ) && empty( $bp->action_variables ) ) { 196 unset( $bp->canonical_stack['action'] ); 197 } 110 198 } 111 199 112 200 /** … … class BP_Blogs_Component extends BP_Component { 150 238 } 151 239 152 240 /** 153 * Set up component navigation for bp-blogs .241 * Set up component navigation for bp-blogs and for the Site's feature. 154 242 * 155 243 * @see BP_Component::setup_nav() for a description of arguments. 156 244 * … … class BP_Blogs_Component extends BP_Component { 176 264 } elseif ( bp_loggedin_user_domain() ) { 177 265 $user_domain = bp_loggedin_user_domain(); 178 266 } else { 179 return;267 $user_domain = false; 180 268 } 181 269 182 $slug = bp_get_blogs_slug(); 183 $parent_url = trailingslashit( $user_domain . $slug ); 184 185 // Add 'Sites' to the main navigation. 186 $count = (int) bp_get_total_blog_count_for_user(); 187 $class = ( 0 === $count ) ? 'no-count' : 'count'; 188 $nav_text = sprintf( 189 /* translators: %s: Site count for the current user */ 190 __( 'Sites %s', 'buddypress' ), 191 sprintf( 192 '<span class="%s">%s</span>', 193 esc_attr( $class ), 194 bp_core_number_format( $count ) 195 ) 196 ); 197 $main_nav = array( 198 'name' => $nav_text, 199 'slug' => $slug, 200 'position' => 30, 201 'screen_function' => 'bp_blogs_screen_my_blogs', 202 'default_subnav_slug' => 'my-sites', 203 'item_css_id' => $this->id 204 ); 270 if ( ! empty( $user_domain ) ) { 271 $slug = bp_get_blogs_slug(); 272 $parent_url = trailingslashit( $user_domain . $slug ); 273 274 // Add 'Sites' to the main navigation. 275 $count = (int) bp_get_total_blog_count_for_user(); 276 $class = ( 0 === $count ) ? 'no-count' : 'count'; 277 $nav_text = sprintf( 278 /* translators: %s: Site count for the current user */ 279 __( 'Sites %s', 'buddypress' ), 280 sprintf( 281 '<span class="%s">%s</span>', 282 esc_attr( $class ), 283 bp_core_number_format( $count ) 284 ) 285 ); 286 $main_nav = array( 287 'name' => $nav_text, 288 'slug' => $slug, 289 'position' => 30, 290 'screen_function' => 'bp_blogs_screen_my_blogs', 291 'default_subnav_slug' => 'my-sites', 292 'item_css_id' => $this->id 293 ); 205 294 206 $sub_nav[] = array( 207 'name' => __( 'My Sites', 'buddypress' ), 208 'slug' => 'my-sites', 209 'parent_url' => $parent_url, 210 'parent_slug' => $slug, 211 'screen_function' => 'bp_blogs_screen_my_blogs', 212 'position' => 10 213 ); 295 $sub_nav[] = array( 296 'name' => __( 'My Sites', 'buddypress' ), 297 'slug' => 'my-sites', 298 'parent_url' => $parent_url, 299 'parent_slug' => $slug, 300 'screen_function' => 'bp_blogs_screen_my_blogs', 301 'position' => 10 302 ); 303 } 214 304 215 305 // Setup navigation. 216 306 parent::setup_nav( $main_nav, $sub_nav ); 307 308 // Build the Site navigation 309 if ( bp_is_blogs_component() && bp_is_single_item() ) { 310 311 /** Set the Primary Navigation of the Site ************************************/ 312 313 /** 314 * Use this filter to add your public primary nav items. 315 * 316 * NB: Make sure to use a position greater than 20 for your 317 * custom items. 318 * 319 * @since 2.7.0 320 * 321 * @param array $site_main_nav The list of public nav items. 322 * @param object $value The current site displayed. 323 */ 324 $site_main_nav = apply_filters( 'bp_blogs_setup_site_public_primary_nav', array( 'site_home' => array( 325 'name' => __( 'Home', 'buddypress' ), 326 'slug' => 'home', 327 'position' => 0, 328 'screen_function' => 'bp_blogs_screen_site_home', 329 'default_subnav_slug' => false, 330 ), 331 ), $this->current_site ); 332 333 if ( bp_blogs_current_site_has_access() ) { 334 // Fix the scope for Ajax filtering when members is the home page 335 $site_main_nav['site_home']['item_css_id'] = 'members'; 336 337 if ( $this->current_site->front_template || ( bp_is_active( 'activity' ) && bp_blogs_current_site_is_public() ) ) { 338 /** 339 * Only add the members nav if it's not the home's nav 340 */ 341 $site_main_nav[] = array( 342 'name' => sprintf( _x( 'Members <span>%s</span>', 'Single Site members screen nav', 'buddypress' ), $this->current_site->total_users ), 343 'slug' => 'members', 344 'position' => 20, 345 'screen_function' => 'bp_blogs_screen_site_home', 346 'default_subnav_slug' => false, 347 ); 348 349 // Default scope is home 350 $site_main_nav['site_home']['item_css_id'] = 'home'; 351 352 /** 353 * If the theme is using a custom front, create 354 * an activity nav if the site is public 355 */ 356 if ( $this->current_site->front_template && bp_is_active( 'activity' ) && bp_blogs_current_site_is_public() ) { 357 $site_main_nav[] = array( 358 'name' => _x( 'Activity', 'Single Site activity screen nav', 'buddypress' ), 359 'slug' => 'activity', 360 'position' => 10, 361 'screen_function' => 'bp_blogs_screen_site_home', 362 'default_subnav_slug' => false, 363 ); 364 } 365 } 366 367 // Manage Main nav 368 $site_main_nav[] = array( 369 'name' => _x( 'Manage', 'Single Blog manage screen nav', 'buddypress' ), 370 'slug' => 'manage', 371 'position' => 1000, 372 'screen_function' => 'bp_blogs_screen_site_manage', 373 'default_subnav_slug' => 'settings', 374 'site_admin_only' => ! bp_is_item_admin(), 375 ); 376 377 /** 378 * Use this filter to add your restricted primary nav items. 379 * 380 * NB: Make sure to use a position greater than 20 for your 381 * custom items. 382 * 383 * @since 2.7.0 384 * 385 * @param array $site_main_nav The list of restricted nav items. 386 * @param object $value The current site displayed. 387 */ 388 $site_main_nav = apply_filters( 'bp_blogs_setup_site_restricted_primary_nav', $site_main_nav, $this->current_site ); 389 } 390 391 // Loop in nav items to create the primary nav. 392 foreach ( $site_main_nav as $nav_item ) { 393 bp_core_new_nav_item( $nav_item, 'blogs' ); 394 } 395 396 /** Set the secondary navigation of the Site **********************************/ 397 398 $site_link = bp_blogs_get_site_community_url( $this->current_site->slug ); 399 400 /** 401 * General settings 402 * 403 * Edit the preferences for the current site. 404 * Access is restricted to The site admins. 405 */ 406 bp_core_new_subnav_item( array( 407 'name' => _x( 'Settings', 'Single Blog setting screen', 'buddypress' ), 408 'slug' => 'settings', 409 'parent_url' => trailingslashit( $site_link . 'manage' ), 410 'parent_slug' => 'manage', 411 'screen_function' => 'bp_blogs_screen_site_manage', 412 'position' => 0, 413 'user_has_access' => bp_is_item_admin(), 414 'no_access_url' => $site_link, 415 'show_in_admin_bar' => true, 416 ), 'blogs' ); 417 418 /** 419 * @todo Site's logo 420 * 421 * Edit the logo for the current site. 422 * Access is restricted to the site admins. 423 */ 424 425 /** 426 * @todo Site's Cover Image 427 * 428 * Edit the cover image for the current site. 429 * Access is restricted to the site admins. 430 */ 431 432 /** 433 * Manage members. 434 * 435 * Eventually remove subscriptions. 436 */ 437 bp_core_new_subnav_item( array( 438 'name' => _x( 'Members', 'Single Site manage members screen', 'buddypress' ), 439 'slug' => 'members', 440 'parent_url' => trailingslashit( $site_link . 'manage' ), 441 'parent_slug' => 'manage', 442 'screen_function' => 'bp_blogs_screen_site_manage', 443 'position' => 20, 444 'user_has_access' => bp_is_item_admin(), 445 'no_access_url' => $site_link, 446 'show_in_admin_bar' => true, 447 ), 'blogs' ); 448 } 449 450 /** 451 * Use this action to add your custom secondary nav items. 452 * 453 * NB: Make sure to use the parent slug of the primary nav item 454 * you defined filtering `bp_blogs_setup_site_public_primary_nav` 455 * or `bp_blogs_setup_site_restricted_primary_nav`. 456 * 457 * @since 2.7.0 458 * 459 * @param array $site_main_nav The list of restricted nav items. 460 * @param object $value The current site displayed. 461 */ 462 do_action( 'bp_blogs_setup_site_secondary_nav', $this->current_site ); 217 463 } 218 464 219 465 /** … … class BP_Blogs_Component extends BP_Component { 292 538 293 539 // If we are not viewing the logged in user, set up the current 294 540 // users avatar and name. 295 } else {541 } elseif ( ! bp_is_my_profile() && ! bp_is_single_item() ) { 296 542 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 297 543 'item_id' => bp_displayed_user_id(), 298 544 'type' => 'thumb', 299 545 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) 300 546 ) ); 301 547 $bp->bp_options_title = bp_get_displayed_user_fullname(); 548 549 // Viewing a single site. 550 } elseif ( bp_is_single_item() ) { 551 $bp->bp_options_title = $this->current_site->name; 552 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 553 'item_id' => $this->current_site->blog_id, 554 'object' => 'blogs', 555 'type' => 'thumb', 556 'avatar_dir' => 'blog-avatars', 557 'alt' => __( 'Site Profile Logo', 'buddypress' ) 558 ) ); 559 560 if ( empty( $bp->bp_options_avatar ) ) { 561 $bp->bp_options_avatar = '<img src="' . esc_url( bp_core_avatar_default_thumb() ) . '" alt="' . esc_attr__( 'No Site Profile Photo', 'buddypress' ) . '" class="avatar" />'; 562 } 302 563 } 303 564 } 304 565 -
src/bp-blogs/classes/class-bp-blogs-theme-compat.php
diff --git src/bp-blogs/classes/class-bp-blogs-theme-compat.php src/bp-blogs/classes/class-bp-blogs-theme-compat.php index 04623e5..2af4110 100644
class BP_Blogs_Theme_Compat { 32 32 /** 33 33 * Are we looking at something that needs Blogs theme compatibility? 34 34 * 35 * @since 1.7.0 35 * @since 1.7.0 36 * @since 2.7.0 Add the site's feature theme compat. 36 37 */ 37 38 public function is_blogs() { 38 39 39 40 // Bail if not looking at a group. 40 if ( ! bp_is_blogs_component() ) 41 if ( ! bp_is_blogs_component() ) { 41 42 return; 43 } 42 44 43 45 // Bail if looking at a users sites. 44 if ( bp_is_user() ) 46 if ( bp_is_user() ) { 45 47 return; 48 } 46 49 47 50 // Blog Directory. 48 if ( is_multisite() && ! bp_current_action() ) {51 if ( is_multisite() && ! bp_current_action() && ! bp_current_item() ) { 49 52 bp_update_is_directory( true, 'blogs' ); 50 53 51 54 /** … … class BP_Blogs_Theme_Compat { 61 64 add_filter( 'bp_replace_the_content', array( $this, 'directory_content' ) ); 62 65 63 66 // Create blog. 64 } elseif ( is_user_logged_in() && bp_blog_signup_enabled() ) {67 } elseif ( is_user_logged_in() && bp_blog_signup_enabled() && bp_is_create_blog() ) { 65 68 add_filter( 'bp_get_buddypress_template', array( $this, 'create_template_hierarchy' ) ); 66 69 add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) ); 67 70 add_filter( 'bp_replace_the_content', array( $this, 'create_content' ) ); 71 72 // Single site 73 } elseif ( bp_is_single_item() ) { 74 add_filter( 'bp_get_buddypress_template', array( $this, 'single_template_hierarchy' ) ); 75 add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) ); 76 add_filter( 'bp_replace_the_content', array( $this, 'single_content' ) ); 68 77 } 69 78 } 70 79 … … class BP_Blogs_Theme_Compat { 198 207 public function create_content() { 199 208 return bp_buffer_template_part( 'blogs/create', null, false ); 200 209 } 210 211 /** Single ************************************************************/ 212 213 /** 214 * Add custom template hierarchy to theme compat for single site pages. 215 * 216 * This is to mirror how WordPress has 217 * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. 218 * 219 * @since 2.7.0 220 * 221 * @param string $templates The templates from bp_get_theme_compat_templates(). 222 * @return array $templates Array of custom templates to look for. 223 */ 224 public function single_template_hierarchy( $templates ) { 225 // Setup some variables we're going to reference in our custom templates 226 $site = bp_blogs_get_current_site(); 227 228 /** 229 * Filters the single site pages template hierarchy based on priority. 230 * 231 * @since 2.7.0 232 * 233 * @param array $value Array of default template files to use. 234 */ 235 $new_templates = apply_filters( 'bp_template_hierarchy_blogs_single_item', array( 236 'blogs/single/index-id-' . sanitize_file_name( $site->blog_id ) . '.php', 237 'blogs/single/index-slug-' . sanitize_file_name( $site->slug ) . '.php', 238 'blogs/single/index-action-' . sanitize_file_name( bp_current_action() ) . '.php', 239 'blogs/single/index.php' 240 ) ); 241 242 // Merge new templates with existing stack 243 // @see bp_get_theme_compat_templates() 244 $templates = array_merge( (array) $new_templates, $templates ); 245 246 return $templates; 247 } 248 249 /** 250 * Update the global $post with single blog data. 251 * 252 * @since 2.7.0 253 */ 254 public function single_dummy_post() { 255 bp_theme_compat_reset_post( array( 256 'ID' => 0, 257 'post_title' => bp_blogs_get_current_site_name(), 258 'post_author' => 0, 259 'post_date' => 0, 260 'post_content' => '', 261 'post_type' => 'page', 262 'post_status' => 'publish', 263 'is_page' => true, 264 'comment_status' => 'closed' 265 ) ); 266 } 267 268 /** 269 * Filter the_content with the single blog template part. 270 * 271 * @since 2.7.0 272 */ 273 public function single_content() { 274 return bp_buffer_template_part( 'blogs/single/home', null, false ); 275 } 201 276 } -
src/bp-blogs/classes/class-bp-site-query.php
diff --git src/bp-blogs/classes/class-bp-site-query.php src/bp-blogs/classes/class-bp-site-query.php index 0b92618..fdc515d 100644
class BP_Site_Query extends WP_Site_Query { 47 47 // Set BuddyPress specific query vars. 48 48 $this->set_bp_query( $query ); 49 49 50 // Get the matching sites 51 $this->get_sites(); 50 // If sites are not already set, run the query 51 if ( ! isset( $this->sites ) ) { 52 // Get the matching sites 53 $this->get_sites(); 52 54 53 // Get extra data for each found sites. 54 $this->get_site_extras(); 55 // Get extra data for each found sites. 56 $this->get_site_extras(); 57 } 55 58 } 56 59 57 60 /** … … class BP_Site_Query extends WP_Site_Query { 92 95 if ( ! empty( $this->query_vars['user_id'] ) ) { 93 96 $user_sites = BP_BLOGS_BLOG::get_blog_ids_for_user( $this->query_vars['user_id'] ); 94 97 98 if ( empty( $user_sites ) ) { 99 $this->sites = array(); 100 $this->found_sites = 0; 101 return; 102 } 103 95 104 if ( ! empty( $this->query_vars['site__in'] ) ) { 96 105 $intersect = array_intersect( $user_sites, $this->query_vars['site__in'] ); 97 106 … … class BP_Site_Query extends WP_Site_Query { 100 109 } 101 110 } 102 111 103 $this->query_vars['site__in'] = wp_parse_id_list( $user_sites );112 $this->query_vars['site__in'] = $user_sites; 104 113 } 105 114 106 115 /** -
src/bp-blogs/site/functions.php
diff --git src/bp-blogs/site/functions.php src/bp-blogs/site/functions.php index ebf6684..a79ec61 100644
11 11 defined( 'ABSPATH' ) || exit; 12 12 13 13 /** 14 * Return a default slug for the main site of the network. 15 * 16 * @since 2.7.0 17 * 18 * @param string $default The default slug for the root site 19 * @return string The main site's slug. 20 */ 21 function bp_blogs_get_root_site_slug( $default = 'root' ) { 22 /** 23 * Filters the root site's slug. 24 * 25 * @since 2.7.0 26 * 27 * @param string $default the default slug (root). 28 */ 29 return sanitize_title( apply_filters( 'bp_blogs_get_root_site_slug', $default ) ); 30 } 31 32 /** 33 * Get the community url for a site. 34 * 35 * @since 2.7.0 36 * 37 * @param string $slug The slug of the site. 38 * @return string The community url of the site. 39 */ 40 function bp_blogs_get_site_community_url( $slug = '' ) { 41 if ( ! $slug ) { 42 $slug = bp_blogs_get_current_site_slug(); 43 } 44 45 $url = trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/' . $slug ); 46 47 /** 48 * Filters the site's community url. 49 * 50 * @since 2.7.0 51 * 52 * @param string $url The community url of the site. 53 * @param string $slug The slug of the site. 54 */ 55 return apply_filters( 'bp_blogs_get_site_community_url', $url, $slug ); 56 } 57 58 /** 14 59 * Get a single site for the requested slug or ID. 15 60 * 16 61 * @since 2.7.0 … … function bp_blogs_get_site( $slug = '' ) { 49 94 return false; 50 95 } 51 96 52 return reset( $result['blogs'] ); 97 $site = reset( $result['blogs'] ); 98 99 if ( empty( $site->blog_id ) ) { 100 return false; 101 } 102 103 if ( ! is_a( $site, 'WP_Site' ) ) { 104 $bp_props = clone $site; 105 106 // Reset the site so that it's a WP_Site instance 107 $site = get_blog_details( $site->blog_id, false ); 108 109 foreach ( $bp_props as $bp_prop_key => $bp_prop ) { 110 if ( isset( $site->{$bp_prop_key} ) ) { 111 continue; 112 } 113 114 $site->{$bp_prop_key} = $bp_prop; 115 } 116 117 $site->site_admins = bp_blogs_get_blogmeta( $site->blog_id, 'site_admins' ); 118 $site->url = bp_blogs_get_blogmeta( $site->blog_id, 'url' ); 119 } 120 121 // Bail if the site is not showable. 122 if ( 1 === (int) $site->mature || 1 === (int) $site->spam || 1 === (int) $site->archived || 1 === (int) $site->deleted ) { 123 return false; 124 } 125 126 $site->slug = ''; 127 if ( (int) bp_get_root_blog_id() === (int) $site->blog_id ) { 128 $site->slug = bp_blogs_get_root_site_slug(); 129 } elseif ( is_subdomain_install() ) { 130 $site->slug = trim( str_replace( get_current_site()->domain, '', $site->domain ), '.' ); 131 } else { 132 $site->slug = trim( str_replace( get_current_site()->path, '', $site->path ), '/' ); 133 } 134 135 // How many users ? 136 $site->total_users = BP_Blogs_Blog::get_site_users_count( $site->blog_id ); 137 138 if ( ! bp_is_blogs_component() && ! bp_current_action() ) { 139 return $site; 140 } 141 142 // Check the current user caps for this site 143 if ( ! bp_is_root_blog() ) { 144 switch_to_blog( $site->blog_id ); 145 } 146 147 $site->is_member = bp_current_user_can( 'read' ); 148 149 if ( bp_current_user_can( 'manage_options' ) ) { 150 $site->is_admin = true; 151 } elseif ( bp_current_user_can( 'edit_posts' ) ) { 152 $site->is_contributor = true; 153 } 154 155 if ( ! bp_is_root_blog() ) { 156 restore_current_blog(); 157 } 158 159 return apply_filters( 'bp_blogs_get_site', $site ); 160 } 161 162 /** 163 * Get the current site displayed. 164 * 165 * @since 2.7.0 166 * 167 * @return WP_Site|object The displayed site object. 168 */ 169 function bp_blogs_get_current_site() { 170 $bp = buddypress(); 171 172 $current_site = false; 173 174 if ( isset( $bp->blogs->current_site ) ) { 175 $current_site = $bp->blogs->current_site; 176 } 177 178 /** 179 * Filters the Site object corresponding to the current site. 180 * 181 * @since 2.7.0 182 * 183 * @param WP_Site|object $current_site Current Site object. 184 */ 185 return apply_filters( 'bp_blogs_get_current_site', $current_site ); 186 } 187 188 /** 189 * Get a specific property of the current site object 190 * 191 * @since 2.7.0 192 * 193 * @param string $property The key of the property to get. 194 * @return mixed The value of the property. 195 */ 196 function bp_blogs_get_current_site_property( $property = '' ) { 197 $current_site = bp_blogs_get_current_site(); 198 199 if ( empty( $property ) || ! isset( $current_site->{$property} ) ) { 200 return false; 201 } 202 203 /** 204 * Dynamic Filter to edit the value of the specific property 205 * 206 * @since 2.7.0 207 * 208 * @param mixed $value The value of the property. 209 * @param WP_Site|object $current_site Current Site object. 210 */ 211 return apply_filters( "bp_blogs_current_site_{$property}", $current_site->{$property}, $current_site ); 212 } 213 214 /** 215 * Get the current site ID. 216 * 217 * @since 2.7.0 218 * 219 * @return int The current site ID. 220 */ 221 function bp_blogs_get_current_site_id() { 222 return (int) bp_blogs_get_current_site_property( 'blog_id' ); 223 } 224 225 /** 226 * Get the current site name. 227 * 228 * @since 2.7.0 229 * 230 * @return string The current site name. 231 */ 232 function bp_blogs_get_current_site_name() { 233 return esc_html( bp_blogs_get_current_site_property( 'name' ) ); 234 } 235 236 /** 237 * Get the current site slug. 238 * 239 * @since 2.7.0 240 * 241 * @return string The current site slug. 242 */ 243 function bp_blogs_get_current_site_slug() { 244 return sanitize_user( bp_blogs_get_current_site_property( 'slug' ) ); 245 } 246 247 /** 248 * Get the current site url. 249 * 250 * @since 2.7.0 251 * 252 * @return string The current site url. 253 */ 254 function bp_blogs_get_current_site_url() { 255 return esc_url( bp_blogs_get_current_site_property( 'url' ) ); 256 } 257 258 /** 259 * Get the public property of the current site. 260 * 261 * @since 2.7.0 262 * 263 * @return bool True if the site is public. False otherwise. 264 */ 265 function bp_blogs_current_site_is_public() { 266 return (bool) bp_blogs_get_current_site_property( 'public' ); 267 } 268 269 /** 270 * Does the current user can access to the displayed site? 271 * 272 * @since 2.7.0 273 * 274 * @return bool True if the user can access. False otherwise. 275 */ 276 function bp_blogs_current_site_has_access() { 277 return (bool) bp_blogs_get_current_site_property( 'user_has_access' ); 278 } 279 280 /** 281 * Return the list of Site Admin user ids. 282 * 283 * @since 2.7.0 284 * 285 * @return array The list of Site Admin user ids. 286 */ 287 function bp_blogs_current_site_get_admins() { 288 return (array) bp_blogs_get_current_site_property( 'site_admins' ); 289 } 290 291 /** 292 * Edit the BP User Query query vars to only get the site members 293 * 294 * @since 2.7.0 295 * 296 * @param BP_User_Query|null $site_user_query The BP User Query object 297 */ 298 function bp_blogs_set_site_user_query( BP_User_Query $site_user_query = null ) { 299 $bp = buddypress(); 300 301 // Bail if we're not in a site members loop. 302 if ( empty( $bp->blogs->site->members->loop_args['blog_id'] ) ) { 303 return; 304 } 305 306 $blog_id = $bp->blogs->site->members->loop_args['blog_id']; 307 308 $is_contributor = null; 309 if ( isset( $bp->blogs->site->members->loop_args['is_contributor'] ) ) { 310 $is_contributor = $bp->blogs->site->members->loop_args['is_contributor']; 311 } 312 313 $bp->blogs->site->members->extra = BP_Blogs_Blog::get_site_user_ids( $blog_id, $is_contributor ); 314 315 if ( empty( $bp->blogs->site->members->extra ) ) { 316 $user_ids = array( 0 ); 317 } else { 318 $user_ids = wp_list_pluck( $bp->blogs->site->members->extra, 'user_id' ); 319 } 320 321 // Only include site members 322 $site_user_query->query_vars_raw['include'] = $user_ids; 323 $site_user_query->query_vars['include'] = wp_parse_id_list( $user_ids ); 324 } 325 326 /** 327 * Add specific site extra to members fetched in the BP User Query 328 * 329 * @since 2.7.0 330 * 331 * @param BP_User_Query|null $site_user_query The BP User Query object 332 */ 333 function bp_blogs_user_query_site_populate_extras( BP_User_Query $site_user_query = null ) { 334 $bp = buddypress(); 335 336 if ( empty( $bp->blogs->site->members->extra ) ) { 337 return; 338 } 339 340 $admins = bp_blogs_current_site_get_admins(); 341 342 foreach ( (array) $bp->blogs->site->members->extra as $extra ) { 343 if ( isset( $site_user_query->results[ $extra->user_id ] ) ) { 344 $site_user_query->results[ $extra->user_id ]->is_contributor = (int) $extra->is_contributor; 345 346 if ( ! empty( $admins ) && in_array( $extra->user_id, $admins ) ) { 347 $site_user_query->results[ $extra->user_id ]->is_admin = 1; 348 } 349 } 350 } 53 351 } -
src/bp-blogs/site/screens.php
diff --git src/bp-blogs/site/screens.php src/bp-blogs/site/screens.php index 50d5c08..92c42f0 100644
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 // Put the code for the site screens here! 13 /** 14 * Set the site screens comparing the URI with the Site's navigation. 15 * And eventually set the active primary an secondary nav items. 16 * 17 * This function is hooked to `bp_template_redirect` before `bp_redirect_canonical` 18 * as we need to eventually edit the BuddyPress canonical stack according the Site's 19 * navigation. 20 * 21 * @since 2.7.0 22 */ 23 function bp_blogs_set_site_screens() { 24 if ( ! bp_is_site() ) { 25 return; 26 } 27 28 // Get BuddyPress instance. 29 $bp = buddypress(); 30 31 // Initialize the active nav 32 $active_nav = false; 33 34 // Default nav arguments are about primary nav. 35 $nav_args = array( 'slug' => bp_current_action() ); 36 37 // If we have an action variable, it's a secondary nav. 38 if ( bp_action_variable( 0 ) ) { 39 $nav_args = array( 'parent_slug' => bp_current_action(), 'slug' => bp_action_variable( 0 ) ); 40 } 41 42 // We need to try to get the corresponding primary nav item 43 if ( ! isset( $nav_args['parent_slug'] ) ) { 44 $active_nav = $bp->blogs->nav->get_primary( $nav_args, false ); 45 46 // Or the one of the secondary nav 47 } else { 48 $active_nav = $bp->blogs->nav->get_secondary( $nav_args, false ); 49 } 50 51 // No nav items matched. Redirect to Single site's home page. 52 if ( ! $active_nav ) { 53 if ( bp_is_current_item( bp_blogs_get_current_site_slug() ) ) { 54 bp_core_add_message( __( 'The page you requested is not available.', 'buddypress' ), 'error' ); 55 bp_core_redirect( $bp->canonical_stack['base_url'] ); 56 } 57 58 return; 59 } 60 61 // Get the matching screen function inside the active nav. 62 $nav_id = join( '/', $nav_args ); 63 $screen_function = $active_nav[ $nav_id ]->screen_function; 64 65 // If it's a secondary item nav, first check user has access to it 66 if ( ! empty( $active_nav[ $nav_id ]->parent_slug ) ) { 67 if ( ! $active_nav[ $nav_id ]->user_has_access ) { 68 if ( ! is_user_logged_in() ) { 69 bp_core_no_access(); 70 } elseif ( $active_nav[ $nav_id ]->no_access_url ) { 71 bp_core_add_message( __( 'You must be an admin of the site to access the page you requested.', 'buddypress' ), 'error' ); 72 bp_core_redirect( $active_nav[ $nav_id ]->no_access_url ); 73 } 74 75 return; 76 } 77 78 // Edit the parent nav to get it at the same time in order to eventually update the canonical stack. 79 $parent = bp_core_edit_nav_item( array( 80 'component' => 'blogs', 81 'slug' => $active_nav[ $nav_id ]->parent_slug, 82 'params' => array( 83 'item_css_class' => 'current selected', 84 ), 85 ) ); 86 87 if ( $parent->default_subnav_slug === $active_nav[ $nav_id ]->slug && ! bp_action_variable( 1 ) ) { 88 array_shift( $bp->canonical_stack['action_variables'] ); 89 } 90 91 // Finally edit the secondary item to set it as the active one. 92 bp_core_edit_nav_item( array( 93 'component' => 'blogs', 94 'slug' => $active_nav[ $nav_id ]->slug, 95 'parent_slug' => $active_nav[ $nav_id ]->parent_slug, 96 'params' => array( 97 'item_css_class' => 'current selected', 98 ), 99 ) ); 100 101 // It's a primary nav. 102 } else { 103 // Edit the primary nav to set it as the active one 104 bp_core_edit_nav_item( array( 105 'component' => 'blogs', 106 'slug' => $active_nav[ $nav_id ]->slug, 107 'params' => array( 108 'item_css_class' => 'current selected', 109 ), 110 ) ); 111 112 /** 113 * If it's a primary item and there's no secondary item active, 114 * set the default subnav slug as the first action variable. 115 */ 116 if ( ! empty( $active_nav[ $nav_id ]->default_subnav_slug ) && ! bp_action_variable( 0 ) ) { 117 $bp->action_variables = array( $active_nav[ $nav_id ]->default_subnav_slug ); 118 119 // Edit the secondary nav to set the active one. 120 bp_core_edit_nav_item( array( 121 'component' => 'blogs', 122 'slug' => $active_nav[ $nav_id ]->default_subnav_slug, 123 'parent_slug' => $active_nav[ $nav_id ]->slug, 124 'params' => array( 125 'item_css_class' => 'current selected', 126 ), 127 ) ); 128 } 129 } 130 131 // Finally hook the screen function. 132 if ( is_callable( $screen_function ) ) { 133 add_action( 'bp_screens', $screen_function, 3 ); 134 } 135 } 136 add_action( 'bp_template_redirect', 'bp_blogs_set_site_screens', 1 ); 137 138 /** 139 * Screen function for the site's pages. 140 * 141 * @since 2.7.0 142 */ 143 function bp_blogs_screen_site_home() { 144 if ( ! bp_is_single_item() ) { 145 return false; 146 } 147 148 /** 149 * Hook here to run specific actions juste before 150 * a blog's single page is displayed 151 * 152 * @since 2.7.0 153 */ 154 do_action( 'bp_blogs_screen_site_home' ); 155 156 /** 157 * Filter here to edit the template part to use for the Single site's home. 158 * 159 * @since 2.7.0 160 * 161 * @param string $value Relative path to the template part. 162 */ 163 bp_core_load_template( apply_filters( 'bp_blogs_screen_site_home_template', 'blogs/single/home' ) ); 164 } 165 166 /** 167 * Screen function for the site's manage pages. 168 * 169 * @since 2.7.0 170 */ 171 function bp_blogs_screen_site_manage() { 172 if ( ! bp_is_single_item() ) { 173 return false; 174 } 175 176 if ( bp_is_site_manage_screen( 'members' ) && 'remove' === bp_action_variable( 1 ) ) { 177 178 check_admin_referer( 'site_remove_member' ); 179 180 $blog_id = bp_blogs_get_current_site_id(); 181 $user_id = (int) bp_action_variable( 2 ); 182 183 $referer = wp_get_referer(); 184 $message = __( 'We were not able to perform this action, please try again later', 'buddypress' ); 185 $type = 'error'; 186 187 if ( ! bp_is_item_admin() || empty( $blog_id ) || empty( $user_id ) ) { 188 bp_core_add_message( $message, $type ); 189 bp_core_redirect( $referer ); 190 } 191 192 if ( bp_user_can( $user_id, 'edit_posts', array( 'site_id' => $blog_id ) ) ) { 193 $message = __( 'Only subscribers can be removed from this screen.', 'buddypress' ); 194 bp_core_add_message( $message, $type ); 195 bp_core_redirect( $referer ); 196 } 197 198 /** 199 * Fires before the user is removed from the blog 200 * 201 * @since 2.7.0 202 * 203 * @param int $user_id the ID of the current user 204 * @param int $blog_id the ID of the blog 205 */ 206 do_action( 'bp_blogs_before_remove_user_from_site', $user_id, $blog_id ); 207 208 /** 209 * Removing the user 210 */ 211 $removed = remove_user_from_blog( $user_id, $blog_id ); 212 213 if ( ! is_wp_error( $removed ) ) { 214 $message = __( 'Member successfully removed from the site.', 'buddypress' ); 215 $type = 'success'; 216 217 /** 218 * Fires after the user was removed from the blog 219 * 220 * @since 2.7.0 221 * 222 * @param int $user_id the ID of the current user 223 * @param int $blog_id the ID of the blog 224 */ 225 do_action( 'bp_blogs_after_remove_user_from_site', $user_id, $blog_id ); 226 227 } else { 228 $message = $removed->get_error_message(); 229 $type = 'error'; 230 } 231 232 bp_core_add_message( $message, $type ); 233 bp_core_redirect( $referer ); 234 } 235 236 /** 237 * Hook here to run specific actions juste before 238 * a single site's settings page is displayed 239 * 240 * @since 2.7.0 241 */ 242 do_action( 'bp_blogs_screen_site_manage' ); 243 244 /** 245 * Filter here to edit the template part to use for the Single site's settings page. 246 * 247 * @since 2.7.0 248 * 249 * @param string $value Relative path to the template part. 250 */ 251 bp_core_load_template( apply_filters( 'bp_blogs_screen_site_manage_template', 'blogs/single/home' ) ); 252 } -
src/bp-blogs/site/template.php
diff --git src/bp-blogs/site/template.php src/bp-blogs/site/template.php index 6c095a7..4a05676 100644
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 // Put the code for the site template here! 13 /** Blogs loop template tags **************************************************/ 14 15 /** 16 * Output the site's slug in a Blogs loop. 17 * 18 * @since 2.7.0. 19 */ 20 function bp_blogs_site_slug() { 21 echo bp_get_blogs_site_slug(); 22 } 23 24 /** 25 * Return the site's slug in a Blogs loop. 26 * 27 * @since 2.7.0. 28 * 29 * @return $slug The site's slug. 30 */ 31 function bp_get_blogs_site_slug() { 32 $slug = ''; 33 34 if ( ! empty( $GLOBALS['blogs_template'] ) ) { 35 $site = $GLOBALS['blogs_template']->blog; 36 } 37 38 if ( empty( $site->domain ) || empty( $site->path ) ) { 39 return; 40 } 41 42 if ( (int) bp_get_root_blog_id() === (int) bp_get_blog_id() ) { 43 $slug = bp_blogs_get_root_site_slug(); 44 } elseif ( is_subdomain_install() ) { 45 $slug = trim( str_replace( get_current_site()->domain, '', $site->domain ), '.' ); 46 } else { 47 $slug = trim( str_replace( get_current_site()->path, '', $site->path ), '/' ); 48 } 49 50 return apply_filters( 'bp_get_blogs_site_slug', $slug, $site ); 51 } 52 53 /** 54 * Output the button to display the site's community page. 55 * 56 * @see BP_Button for a the description of arguments and return 57 * value. 58 * 59 * @since 2.7.0 60 * 61 * @param array|string $args. 62 */ 63 function bp_blogs_site_discover_button( $args = '' ) { 64 echo bp_get_blogs_site_discover_button( $args ); 65 } 66 67 /** 68 * Get the arguments of the site's community button. 69 * 70 * @since 2.7.0 71 * 72 * @param array|string $args 73 * @return array The merged arguments. 74 */ 75 function bp_blogs_get_site_discover_button_args( $args = '' ) { 76 $r = wp_parse_args( $args, array( 77 'id' => 'discover_site', 78 'component' => 'blogs', 79 'must_be_logged_in' => false, 80 'block_self' => false, 81 'wrapper_class' => 'blog-button discover', 82 'link_href' => bp_blogs_get_site_community_url( bp_get_blogs_site_slug() ), 83 'link_class' => 'blog-button discover', 84 'link_text' => __( 'Discover Site', 'buddypress' ), 85 ) ); 86 87 return apply_filters( 'bp_blogs_get_site_discover_button_args', $r ); 88 } 89 /** 90 * Return button to display the site's community page. 91 * 92 * @see BP_Button for a the description of arguments and return 93 * value. 94 * 95 * @since 2.7.0 96 * 97 * @param array|string $args 98 * @return string The HTML for the Visit button. 99 */ 100 function bp_get_blogs_site_discover_button( $args = '' ) { 101 return bp_get_button( bp_blogs_get_site_discover_button_args( $args ) ); 102 } 103 104 /** Single Site template tags *************************************************/ 105 106 /** 107 * Load the appropriate current site's home page 108 * 109 * @since 2.7.0 110 * 111 * @param bool $require_once True to only include the template once. False otherwise. 112 * @param WP_Site|object $site The Site object. 113 */ 114 function bp_blogs_load_site_front_template( $require_once = false, $site = null ) { 115 $located = bp_blogs_get_site_front_template( $site ); 116 117 if ( false !== $located ) { 118 $slug = str_replace( '.php', '', $located ); 119 120 /** 121 * Let plugins adding an action to bp_get_template_part get it from here 122 * 123 * @param string $slug Template part slug requested. 124 * @param string $name Template part name requested. 125 */ 126 do_action( 'get_template_part_' . $slug, $slug, false ); 127 128 load_template( $located, $require_once ); 129 130 } elseif ( bp_is_active( 'activity' ) && bp_blogs_current_site_is_public() ) { 131 bp_get_template_part( 'blogs/single/activity' ); 132 133 } elseif ( bp_is_active( 'members' ) ) { 134 bp_get_template_part( 'blogs/single/members' ); 135 } 136 137 return $located; 138 } 139 140 /** 141 * Locate a site's custom front template if it exists. 142 * 143 * @since 2.7.0 144 * 145 * @param WP_Site|object $site The Site object. 146 */ 147 function bp_blogs_get_site_front_template( $site = null ) { 148 if ( ! is_object( $site ) ) { 149 $site = bp_blogs_get_current_site(); 150 } 151 152 if ( empty( $site->blog_id ) ) { 153 return false; 154 } 155 156 if ( isset( $site->front_template ) ) { 157 return $site->front_template; 158 } 159 160 $template_names = array( 161 'blogs/single/front-id-' . sanitize_file_name( $site->blog_id ) . '.php', 162 'blogs/single/front-slug-' . sanitize_file_name( $site->slug ) . '.php', 163 ); 164 165 $visibility = 'public'; 166 if ( ! $site->public ) { 167 $visibility = 'private'; 168 } 169 170 $template_names = array_merge( $template_names, array( 171 'blogs/single/front-visibility-' . $visibility . '.php', 172 'blogs/single/front.php' 173 ) ); 174 175 /** 176 * Filters the hierarchy of the site's front template. 177 * 178 * @since 2.7.0 179 * 180 * @param array $template_names Array of template paths. 181 * @param WP_Site|object $site Site object. 182 */ 183 return bp_locate_template( apply_filters( 'bp_blogs_get_site_front_template', $template_names, $site ), false, true ); 184 } 185 186 /** 187 * Generic function to get the output for a primary or a secondary nav. 188 * 189 * @since 2.7.0 190 * 191 * @param string $type Primary or Secondary? 192 * @return array List of li elements for the navigation. 193 */ 194 function bp_get_site_nav( $type = 'primary' ) { 195 $bp = buddypress(); 196 197 if ( 'secondary' === $type ) { 198 $parent_slug = bp_current_action(); 199 $nav_items = $bp->blogs->nav->get_secondary( array( 'parent_slug' => $parent_slug ) ); 200 } else { 201 $nav_items = $bp->blogs->nav->get_primary(); 202 } 203 204 if ( empty( $nav_items ) ) { 205 return; 206 } 207 208 $output = array(); 209 210 foreach ( $nav_items as $nav_item ) { 211 $selected = ''; 212 213 if ( ! empty( $nav_item->item_css_class ) ) { 214 $selected = ' class="' . esc_attr( $nav_item->item_css_class ) . '"'; 215 } 216 217 $output[ $nav_item->slug ] = sprintf( ' 218 <li id="%1$s-blogs-li"%2$s> 219 <a href="%3$s" id="site-%1$s">%4$s</a> 220 </li> 221 ', 222 esc_attr( $nav_item->css_id ), 223 $selected, 224 esc_url( $nav_item->link ), 225 wp_kses( $nav_item->name, array( 'span' => array( 'class' => true ) ) ) 226 ); 227 } 228 229 return apply_filters( 'bp_get_site_nav', $output, $nav_items, $type ); 230 } 231 232 /** 233 * Output the Site's primary nav. 234 * 235 * @since 2.7.0 236 * 237 * @return string HTML Output. 238 */ 239 function bp_site_primary_nav() { 240 echo join( "\n", bp_get_site_nav( 'primary' ) ); 241 } 242 243 /** 244 * Output the Site's secondary nav. 245 * 246 * @since 2.7.0 247 * 248 * @return string HTML Output. 249 */ 250 function bp_site_secondary_nav() { 251 echo join( "\n", bp_get_site_nav( 'secondary' ) ); 252 } 253 254 /** 255 * Does the current user has access to this site? 256 * 257 * @since 2.7.0 258 * 259 * @return bool True if the user has access. False otherwise. 260 */ 261 function bp_site_has_access() { 262 return bp_blogs_current_site_has_access(); 263 } 264 265 /** 266 * Is the current site public? 267 * 268 * @since 2.7.0 269 * 270 * @return bool True if the site is public. False otherwise. 271 */ 272 function bp_site_is_public() { 273 return bp_blogs_current_site_is_public(); 274 } 275 276 /** 277 * Prints a message if the user has no access to the blog's content 278 * 279 * @since 2.7.0 280 */ 281 function bp_site_visibility_message() { 282 $message = false; 283 284 // For now display a message if the blog is not public 285 if ( ! bp_blogs_current_site_is_public() ) { 286 $message = __( 'The details of this site are restricted to its members.', 'buddypress' ); 287 } 288 289 /** 290 * Filters a message if the blog is not public. 291 * 292 * @since 2.7.0 293 * 294 * @param string $message Message to display to the current user. 295 */ 296 echo esc_html( apply_filters( 'bp_site_visibility_message', $message ) ); 297 } 298 299 /** 300 * Template tag to allow plugins to add their 301 * specific content. 302 * 303 * @since 2.7.0 304 */ 305 function bp_site_plugins_content() { 306 /** 307 * Hook here to include your plugin's specific content 308 * 309 * @since 2.7.0 310 */ 311 do_action( 'bp_template_content' ); 312 } 313 314 /** 315 * Gets the current site manage action. 316 * 317 * @since 2.7.0 318 * 319 * @return string the current manage action. 320 */ 321 function bp_site_get_manage_action() { 322 return sanitize_key( bp_action_variable( 0 ) ); 323 } 324 325 /** Site members template tags ************************************************/ 326 327 /** 328 * Displays the available options to order site members. 329 * 330 * @since 2.7.0 331 * 332 * @return string HTML Output. 333 */ 334 function bp_site_members_filters() { 335 echo bp_get_site_members_filters(); 336 } 337 338 /** 339 * Returns the available options to order site members. 340 * 341 * @since 2.7.0 342 * 343 * @return string HTML Output. 344 */ 345 function bp_get_site_members_filters() { 346 $filters = apply_filters( 'bp_get_site_members_filters', array( 347 'active' => __( 'Last Active', 'buddypress' ), 348 'alphabetical' => __( 'Alphabetical', 'buddypress' ) 349 ) ); 350 351 if ( isset( $filters['alphabetical'] ) && ! bp_is_active( 'xprofile' ) ) { 352 unset( $filters['alphabetical'] ); 353 } 354 355 $output = ''; 356 357 foreach ( $filters as $kfilter => $vfilter ) { 358 $output .= sprintf( '<option value="%1$s">%2$s</option>', $kfilter, $vfilter ) . "\n"; 359 } 360 361 return $output; 362 } 363 364 /** 365 * Initialize a site member query loop. 366 * 367 * @since 2.7.0 368 * 369 * @param array|string $args { 370 * An array of optional arguments. 371 * @type int $blog_id ID of the site whose members are being queried. 372 * Default: current site ID. 373 * @type int $is_contributor Optional. Whether to get all members (null), contributors (1) 374 * or subscribers(0). Default: null. 375 * @type string $type Optional. Sort order of results. 'active', or 376 * 'alphabetical'. Default: 'active'. 377 * @type int $page Page of results to be queried. Default: 1. 378 * @type int $per_page Number of items to return per page of results. 379 * Default: 20. 380 * @type string $page_arg Optional. The page argument to use for pagination. 381 * Default: 'site_page'. 382 * @type int $user_id Optional. The specifc user to get using his ID. 383 * Default: 0. 384 * } 385 * 386 * @return bool 387 */ 388 function bp_site_has_members( $args = '' ) { 389 $bp = buddypress(); 390 391 // Initialize the site members global. 392 $bp->blogs->site->members = new stdClass; 393 394 $is_contributor = null; 395 if ( bp_is_site_manage_screen( 'members' ) ) { 396 $is_contributor = 0; 397 } 398 399 $bp->blogs->site->members->loop_args = bp_parse_args( $args, array( 400 'blog_id' => bp_blogs_get_current_site_id(), // Only return users recorded for the site. 401 'is_contributor' => $is_contributor, // Null to get all site members, 1 for contributors and 0 for subscribers 402 'type' => 'active', 403 'page' => 1, 404 'per_page' => 20, 405 'page_arg' => 'site_page', 406 'user_id' => 0, 407 ), 'site_has_members' ); 408 409 // Set up our query construct hook & populate_extras hook 410 add_action( 'bp_pre_user_query_construct', 'bp_blogs_set_site_user_query', 10, 1 ); 411 add_action( 'bp_user_query_populate_extras', 'bp_blogs_user_query_site_populate_extras', 10, 1 ); 412 413 if ( ! empty( $GLOBALS['members_template'] ) ) { 414 $reset_members_template = $GLOBALS['members_template']; 415 } 416 417 $has_site_members = bp_has_members( $bp->blogs->site->members->loop_args ); 418 $bp->blogs->site->members->template = clone $GLOBALS['members_template']; 419 420 if ( ! empty( $reset_members_template ) ) { 421 $GLOBALS['members_template'] = $reset_members_template; 422 } else { 423 $GLOBALS['members_template'] = null; 424 } 425 426 // Remove hooks 427 remove_action( 'bp_pre_user_query_construct', 'bp_blogs_set_site_user_query', 10, 1 ); 428 remove_action( 'bp_user_query_populate_extras', 'bp_blogs_user_query_site_populate_extras', 10, 1 ); 429 430 // Return the has members bool. 431 return $has_site_members; 432 } 433 434 /** 435 * Check whether there are more site members to iterate over. 436 * 437 * @since 2.7.0 438 * 439 * @return bool 440 */ 441 function bp_site_members() { 442 return buddypress()->blogs->site->members->template->members(); 443 } 444 445 /** 446 * Set up the current site member inside the loop. 447 * 448 * @since 2.7.0 449 * 450 * @return object 451 */ 452 function bp_site_the_member() { 453 return buddypress()->blogs->site->members->template->the_member(); 454 } 455 456 /** 457 * Displays the site members pagination count. 458 * 459 * @since 2.7.0 460 * 461 * @return string HTML Output. 462 */ 463 function bp_site_members_pagination_count() { 464 echo bp_get_site_members_pagination_count(); 465 } 466 467 /** 468 * Returns the site members pagination count. 469 * 470 * @since 2.7.0 471 * 472 * @return string HTML Output. 473 */ 474 function bp_get_site_members_pagination_count() { 475 $members_template = buddypress()->blogs->site->members->template; 476 477 $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1; 478 $from_num = bp_core_number_format( $start_num ); 479 $to_num = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) ); 480 $total = bp_core_number_format( $members_template->total_member_count ); 481 482 if ( 1 == $members_template->total_member_count ) { 483 $pag = __( 'Viewing 1 site member', 'buddypress' ); 484 } else { 485 $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s site member', 'Viewing %1$s - %2$s of %3$s site members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 486 } 487 488 /** 489 * Filters the site members pagination count. 490 * 491 * @since 2.7.0 492 * 493 * @param string $pag Pagination count string. 494 */ 495 return apply_filters( 'bp_get_site_members_pagination_count', $pag ); 496 } 497 498 /** 499 * Displays the site members pagination links. 500 * 501 * @since 2.7.0 502 * 503 * @return string HTML Output. 504 */ 505 function bp_site_members_pagination_links() { 506 echo bp_get_site_members_pagination_links(); 507 } 508 509 /** 510 * Returns the site members pagination links. 511 * 512 * @since 2.7.0 513 * 514 * @return string HTML Output. 515 */ 516 function bp_get_site_members_pagination_links() { 517 $members_template = buddypress()->blogs->site->members->template; 518 519 /** 520 * Filters the site members pagination link. 521 * 522 * @since 2.7.0 523 * 524 * @param string $pag_links HTML markup for pagination links. 525 */ 526 return apply_filters( 'bp_get_site_members_pagination_links', $members_template->pag_links ); 527 } 528 529 /** 530 * Returns the member ID being iterated on in the site members loop. 531 * 532 * @since 2.7.0 533 * 534 * @return int $value The member ID. 535 */ 536 function bp_get_site_member_user_id() { 537 $members_template = buddypress()->blogs->site->members->template; 538 539 return (int) $members_template->member->id; 540 } 541 542 /** 543 * Displays the permalink for the current site member in the loop. 544 * 545 * @since 2.7.0 546 * 547 * @return string HTML Output. 548 */ 549 function bp_site_member_permalink() { 550 echo esc_url( bp_get_site_member_permalink() ); 551 } 552 553 /** 554 * Get the permalink for the current site member in the loop. 555 * 556 * @since 2.7.0 557 * 558 * @return string HTML Output. 559 */ 560 function bp_get_site_member_permalink() { 561 $members_template = buddypress()->blogs->site->members->template; 562 563 /** 564 * Filters the permalink for the current site member in the loop. 565 * 566 * @since 2.7.0 567 * 568 * @param string $value Permalink for the current member in the loop. 569 */ 570 return apply_filters( 'bp_get_site_member_permalink', bp_core_get_user_domain( $members_template->member->id, $members_template->member->user_nicename, $members_template->member->user_login ) ); 571 } 572 573 /** 574 * Returns the member fullname being iterated on in the site members loop. 575 * 576 * @since 2.7.0 577 * 578 * @return int $fullname The member fullname. 579 */ 580 function bp_get_site_member_fullname() { 581 $members_template = buddypress()->blogs->site->members->template; 582 583 if ( ! empty( $members_template->member->fullname ) ) { 584 $fullname = $members_template->member->fullname; 585 } elseif ( ! empty( $members_template->member->display_name ) ) { 586 $fullname = $members_template->member->display_name; 587 } elseif ( ! empty( $members_template->member->user_nicename ) ) { 588 $fullname = $members_template->member->user_nicename; 589 } else { 590 $fullname = $members_template->member->user_login; 591 } 592 593 return $fullname; 594 } 595 596 /** 597 * Returns the site member avatar. 598 * 599 * @since 2.7.0 600 * 601 * @return string HTML Output. 602 */ 603 function bp_site_member_avatar() { 604 echo bp_get_site_member_avatar(); 605 } 606 607 /** 608 * Get a site member's avatar. 609 * 610 * @since 2.7.0 611 * 612 * @see bp_get_member_avatar() For a description of arguments and 613 * return values. 614 * 615 * @param array|string $args 616 * @return string User avatar string. 617 */ 618 function bp_get_site_member_avatar( $args = '' ) { 619 $members_template = buddypress()->blogs->site->members->template; 620 621 $r = wp_parse_args( $args, array( 622 'item_id' => (int) $members_template->member->id, 623 'email' => $members_template->member->user_email, 624 'type' => 'thumb', 625 'width' => false, 626 'height' => false, 627 'class' => 'avatar site-member-avatar', 628 'id' => false, 629 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), esc_attr( bp_get_site_member_fullname() ) ) 630 ) ); 631 632 /** 633 * Filters a site member avatar. 634 * 635 * @since 2.7.0 636 * 637 * @param string $value Formatted HTML <img> element, or raw avatar URL based on $html arg. 638 * @param array $r Array of parsed arguments. See {@link bp_get_member_avatar()}. 639 */ 640 return apply_filters( 'bp_get_site_member_avatar', bp_core_fetch_avatar( $r ), $r ); 641 } 642 643 /** 644 * Display the name of the current site member in the loop. 645 * 646 * @since 2.7.0 647 * 648 * @return string The user's fullname for display. 649 */ 650 function bp_site_member_name() { 651 echo bp_get_site_member_name(); 652 } 653 /** 654 * Get the display name of the current member in the loop. 655 * 656 * @see bp_get_member_name() for the long description 657 * 658 * @since 2.7.0 659 * 660 * @return string The user's fullname for display. 661 */ 662 function bp_get_site_member_name() { 663 // Sanitize the fullname. 664 $fullname = apply_filters( 'bp_get_member_name', bp_get_site_member_fullname() ); 665 666 /** 667 * Filters the display name of current site member in the loop. 668 * 669 * @since 2.7.0 670 * 671 * @param string $fullname Display name for current member. 672 */ 673 return apply_filters( 'bp_get_site_member_name', $fullname ); 674 } 675 676 /** 677 * Display the level of involvement of the current site member in the loop. 678 * 679 * @since 2.7.0 680 * 681 * @return string HTML Output. 682 */ 683 function bp_site_member_involvement() { 684 echo bp_get_site_member_involvement(); 685 } 686 687 /** 688 * Display the level of involvement of the current site member in the loop. 689 * 690 * @since 2.7.0 691 * 692 * @return string HTML Output. 693 */ 694 function bp_get_site_member_involvement() { 695 $members_template = buddypress()->blogs->site->members->template; 696 697 $involvement = esc_html__( 'Subscriber', 'buddypress' ); 698 if ( ! empty( $members_template->member->is_contributor ) ) { 699 $involvement = esc_html__( 'Contributor', 'buddypress' ); 700 } 701 702 return apply_filters( 'bp_get_site_member_involvement', $involvement ); 703 } 704 705 /** 706 * Display the action buttons of the current site member in the loop. 707 * 708 * @since 2.7.0 709 * 710 * @return string HTML Output. 711 */ 712 function bp_site_member_actions() { 713 echo join( ' ', bp_get_site_member_actions() ); 714 } 715 716 /** 717 * Checks if there are action buttons to display for the current site member in the loop. 718 * 719 * @since 2.7.0 720 * 721 * @return bool True if there are buttons. False otherwise. 722 */ 723 function bp_site_has_member_actions() { 724 $buttons = bp_get_site_member_actions(); 725 return ! empty( $buttons ); 726 } 727 728 /** 729 * Returns the action buttons of the current site member in the loop. 730 * 731 * @since 2.7.0 732 * 733 * @return array List of BP Buttons to output. 734 */ 735 function bp_get_site_member_actions() { 736 $members_template = buddypress()->blogs->site->members->template; 737 738 if ( ! empty( $members_template->member->action_buttons ) ) { 739 return $members_template->member->action_buttons; 740 } 741 742 $members_template->member->action_buttons = array(); 743 $user_id = bp_get_site_member_user_id(); 744 $screen = 'members'; 745 746 // Manage actions for the manage-members screen 747 if ( bp_is_site_manage_screen( 'members' ) ) { 748 $screen = 'manage-members'; 749 $involvement = (int) $members_template->member->is_contributor; 750 751 $members_template->member->action_buttons['remove'] = bp_get_site_manage_member_button( $user_id, $involvement ); 752 753 // Regular actions for members screen. 754 } else { 755 if ( bp_is_active( 'friends' ) ) { 756 $members_template->member->action_buttons['friends'] = bp_get_add_friend_button( $user_id ); 757 } 758 } 759 760 return apply_filters( 'bp_get_site_member_actions', $members_template->member->action_buttons, $user_id, $screen ); 761 } 762 763 /** 764 * Output the button to manage the member of the site. 765 * 766 * @see BP_Button for a the description of arguments and return 767 * value. 768 * 769 * @since 2.7.0 770 * 771 * @param int $user_id The ID of the user to manage 772 * @param int $involvement The level of involvement of the user (Only Subscriber for now). 773 */ 774 function bp_site_manage_member_button( $user_id = 0, $involvement = 0 ) { 775 echo bp_get_site_manage_member_button( $user_id, $involvement ); 776 } 777 778 /** 779 * Get the arguments of the site's community button. 780 * 781 * @since 2.7.0 782 * 783 * @param int $user_id The ID of the user to manage 784 * @param int $involvement The level of involvement of the user (Only Subscriber for now). 785 */ 786 function bp_get_site_manage_member_button_args( $user_id, $involvement ) { 787 if ( empty( $user_id ) ) { 788 return; 789 } 790 791 $button = array( 792 'component' => 'blogs', 793 'must_be_logged_in' => true, 794 'block_self' => false, 795 ); 796 797 switch ( $involvement ) { 798 case 1 : 799 return; 800 break; 801 case 0 : 802 default : 803 $button = array_merge( $button, array( 804 'id' => 'remove_member', 805 'wrapper_class' => 'site-button remove', 806 'link_href' => wp_nonce_url( bp_blogs_get_site_community_url() . 'manage/members/remove/' . $user_id . '/', 'site_remove_member' ), 807 'link_class' => 'site-button remove', 808 'link_text' => __( 'Remove', 'buddypress' ), 809 ) ); 810 811 break; 812 } 813 814 return apply_filters( 'bp_get_site_manage_member_button_args', $button ); 815 } 816 /** 817 * Return button to manage the member of the site 818 * 819 * @see BP_Button for a the description of arguments and return 820 * value. 821 * 822 * @since 2.7.0 823 * 824 * @param int $user_id The ID of the user to manage 825 * @param int $involvement The level of involvement of the user (Only Subscriber for now). 826 * @return string The HTML for the Manage button. 827 */ 828 function bp_get_site_manage_member_button( $user_id = 0, $involvement = 0 ) { 829 return bp_get_button( bp_get_site_manage_member_button_args( $user_id, $involvement ) ); 830 } -
src/bp-core/bp-core-buddybar.php
diff --git src/bp-core/bp-core-buddybar.php src/bp-core/bp-core-buddybar.php index 28f7a73..4e5a7fe 100644
function bp_core_create_nav_link( $args = '', $component = 'members' ) { 140 140 $r['item_css_id'] = $r['slug']; 141 141 } 142 142 143 $link = ''; 144 if ( 'members' === $component ) { 145 $link = bp_loggedin_user_domain(); 146 } elseif ( 'groups' === $component && bp_is_group() ) { 147 $link = bp_get_group_permalink( groups_get_current_group() ); 148 } elseif ( 'blogs' === $component && bp_is_site() ) { 149 $link = bp_blogs_get_site_community_url( bp_current_item() ); 150 } else { 151 /** 152 * Filter here to use a specific link for your primary nav. 153 * 154 * @since 2.7.0 155 * 156 * @param string $link The link for your primary nav (without the nav's slug). 157 * @param string $component The component your primary nav is attached to. 158 * @param array $r The list of nav arguments. 159 */ 160 $link = apply_filters( 'bp_core_create_nav_item_link', $link, $component, $r ); 161 } 162 143 163 $nav_item = array( 144 164 'name' => $r['name'], 145 165 'slug' => $r['slug'], 146 'link' => trailingslashit( bp_loggedin_user_domain(). $r['slug'] ),166 'link' => trailingslashit( $link . $r['slug'] ), 147 167 'css_id' => $r['item_css_id'], 148 168 'show_for_displayed_user' => $r['show_for_displayed_user'], 149 169 'position' => $r['position'], … … function bp_core_reset_subnav_items( $parent_slug, $component = 'members' ) { 895 915 } 896 916 } 897 917 918 /** 919 * Edit the parameters of a primary or a secondary nav item. 920 * 921 * NB: you can use this function to edit the position parameter of a specific nav for instance. 922 * 923 * @since 2.7.0 924 * 925 * @param array|string $args { 926 * @type string $component The component ID, the nav item is attached to (eg: members, groups, blogs). 927 * Default: 'members'. 928 * @type string $slug The slug of the nav item to edit. 929 * Default: ''. 930 * @type string $parent_slug The parent slug of the secondary nav item, to edit a secondary nav item. 931 * Leave empty to edit a primary nav item. Default: ''. 932 * @type string $params The secondary or primary params to edit. Default: an empty array. Required. 933 * {@see bp_core_new_nav_item() for the list of available params if you are 934 * editing a primary nav item}} 935 * {@see bp_core_new_subnav_item() for the list of available params if you are 936 * editing a secondary nav item}} 937 * } 938 * @return bool|BP_Core_Nav_Item The edited nav item on success. False otherwise. 939 */ 940 function bp_core_edit_nav_item( $args = array() ) { 941 $bp = buddypress(); 942 943 $r = wp_parse_args( $args, array( 944 'component' => 'members', // The component the nav item is attached to. 945 'slug' => '', // The slug of the nav item to edit. 946 'parent_slug' => '', // The parent slug to edit a seconday nav item. (For the current Group nav, use the Group's slug) 947 'params' => array(), // An associative array containing the keys and values of the nav params to edit. 948 // eg: array( 'position' => 5 ). 949 ) ); 950 951 if ( ! isset( $bp->{$r['component']}->nav ) || empty( $r['params'] ) ) { 952 return false; 953 } 954 955 return $bp->{$r['component']}->nav->edit_nav( $r['params'], $r['slug'], $r['parent_slug'] ); 956 } 898 957 899 958 /** 900 959 * Retrieve the Toolbar display preference of a user based on context. -
src/bp-core/bp-core-template.php
diff --git src/bp-core/bp-core-template.php src/bp-core/bp-core-template.php index 22bffd1..8ddfea6 100644
function bp_is_group_custom_front() { 2847 2847 return (bool) bp_is_group_home() && ! empty( $bp->groups->current_group->front_template ); 2848 2848 } 2849 2849 2850 /** Blogs ********************************************************************/ 2851 2850 2852 /** 2851 2853 * Is the current page the Create a Blog page? 2852 2854 * … … function bp_is_create_blog() { 2868 2870 * @return True if the current page is the blogs directory. 2869 2871 */ 2870 2872 function bp_is_blogs_directory() { 2871 if ( is_multisite() && bp_is_blogs_component() && ! bp_current_action() ) { 2873 if ( is_multisite() && bp_is_blogs_component() && ! bp_current_action() && ! bp_current_item() && ! bp_is_user() ) { 2874 return true; 2875 } 2876 2877 return false; 2878 } 2879 2880 /** 2881 * Does the current page belong to a single site ? 2882 * 2883 * Will return true for any subpage of a single site. 2884 * 2885 * @since 2.7.0 2886 * 2887 * @return bool True if the current page is part of a single site. 2888 */ 2889 function bp_is_site() { 2890 $retval = is_multisite() && bp_is_active( 'blogs', 'site' ); 2891 2892 if ( ! empty( $retval ) ) { 2893 $retval = bp_is_blogs_component() && bp_blogs_get_current_site(); 2894 } 2895 2896 return (bool) $retval; 2897 } 2898 2899 /** 2900 * Is the current page a site's single home page? 2901 * 2902 * URL will vary depending on which site tab is set to be the "home". By 2903 * default, it's the site's activity stream. 2904 * 2905 * @since 2.7.0 2906 * 2907 * @return bool True if the current page is a site's single home page. 2908 */ 2909 function bp_is_site_home() { 2910 if ( bp_is_single_item() && bp_is_blogs_component() && ( ! bp_current_action() || bp_is_current_action( 'home' ) ) ) { 2872 2911 return true; 2873 2912 } 2874 2913 2875 2914 return false; 2876 2915 } 2877 2916 2917 /** 2918 * Is the current site page a custom front? 2919 * 2920 * @since 2.7.0 2921 * 2922 * @return bool True if the current site page is a custom front. 2923 */ 2924 function bp_is_site_custom_front() { 2925 return (bool) bp_is_site_home() && ! empty( buddypress()->blogs->current_site->front_template ); 2926 } 2927 2928 /** 2929 * Is the current page a site's activity page? 2930 * 2931 * Eg http://example.com/sites/mysite/activity/. 2932 * 2933 * @since 2.7.0 2934 * 2935 * @return bool True if the current page is a site's activity page. 2936 */ 2937 function bp_is_site_activity() { 2938 $retval = false; 2939 2940 if ( bp_is_single_item() && bp_is_blogs_component() && bp_is_current_action( 'activity' ) ) { 2941 $retval = true; 2942 } 2943 2944 if ( bp_is_site_home() && bp_is_active( 'activity' ) && ! bp_is_site_custom_front() ) { 2945 $retval = true; 2946 } 2947 2948 return $retval; 2949 } 2950 2951 /** 2952 * Is the current page a site's members page? 2953 * 2954 * Eg http://example.com/sites/mysite/members/. 2955 * 2956 * @since 2.7.0 2957 * 2958 * @return bool True if the current page is a site's members page. 2959 */ 2960 function bp_is_site_members() { 2961 $retval = false; 2962 2963 if ( bp_is_single_item() && bp_is_blogs_component() && bp_is_current_action( 'members' ) ) { 2964 $retval = true; 2965 } 2966 2967 if ( bp_is_site_home() && ! bp_is_active( 'activity' ) && ! bp_is_site_custom_front() ) { 2968 $retval = true; 2969 } 2970 2971 return $retval; 2972 } 2973 2974 /** 2975 * Is the current page a site's manage page? 2976 * 2977 * Eg http://example.com/sites/mysite/manage/. 2978 * 2979 * @since 2.7.0 2980 * 2981 * @return bool True if the current page is a site's manage page. 2982 */ 2983 function bp_is_site_manage() { 2984 return (bool) ( bp_is_blogs_component() && bp_is_current_action( 'manage' ) ); 2985 } 2986 2987 /** 2988 * Is the current page a specific site manage screen? 2989 * 2990 * @since 2.7.0 2991 * 2992 * @param string $slug 2993 * @return bool 2994 */ 2995 function bp_is_site_manage_screen( $slug = '' ) { 2996 return (bool) ( bp_is_site_manage() && bp_is_action_variable( $slug ) ); 2997 } 2998 2999 /** 3000 * What is the current site manage action? 3001 * 3002 * @since 2.7.0 3003 * 3004 * @return string 3005 */ 3006 function bp_current_site_manage_action() { 3007 $retval = ''; 3008 3009 if ( bp_is_site_manage() && bp_action_variable( 0 ) ) { 3010 $retval = bp_action_variable( 0 ); 3011 } 3012 3013 return $retval; 3014 } 3015 3016 2878 3017 /** Messages ******************************************************************/ 2879 3018 2880 3019 /** … … function bp_get_title_parts( $seplocation = 'right' ) { 3095 3234 $component_id = bp_current_component(); 3096 3235 3097 3236 if ( ! empty( $bp->{$component_id}->nav ) ) { 3237 // Groups are using the secondary nav 3098 3238 $secondary_nav_item = $bp->{$component_id}->nav->get_secondary( array( 3099 3239 'parent_slug' => bp_current_item(), 3100 3240 'slug' => bp_current_action() … … function bp_get_title_parts( $seplocation = 'right' ) { 3102 3242 3103 3243 if ( $secondary_nav_item ) { 3104 3244 $secondary_nav_item = reset( $secondary_nav_item ); 3245 3246 // Sites are using the primary nav. 3247 } else { 3248 $primary_nav_item = $bp->{$component_id}->nav->get_primary( array( 3249 'slug' => bp_current_action() 3250 ), false ); 3251 3252 if ( $primary_nav_item ) { 3253 $primary_nav_item = reset( $primary_nav_item ); 3254 } 3105 3255 } 3106 3256 } 3107 3257 3108 $single_item_ subnav = '';3258 $single_item_nav = ''; 3109 3259 3110 3260 if ( ! empty( $secondary_nav_item->name ) ) { 3111 $single_item_subnav = $secondary_nav_item->name; 3261 $single_item_nav = $secondary_nav_item->name; 3262 } elseif ( ! empty( $primary_nav_item->name ) ) { 3263 $single_item_nav = $primary_nav_item->name; 3112 3264 } 3113 3265 3114 $bp_title_parts = array( $bp->bp_options_title, $single_item_ subnav );3266 $bp_title_parts = array( $bp->bp_options_title, $single_item_nav ); 3115 3267 3116 3268 // An index or directory. 3117 3269 } elseif ( bp_is_directory() ) { … … function bp_the_body_class() { 3363 3515 $bp_classes[] = 'activity-permalink'; 3364 3516 } 3365 3517 3518 /* Sites *************************************************************/ 3519 3520 if ( bp_is_site() ) { 3521 $bp_classes[] = 'site-' . bp_blogs_get_current_site_slug(); 3522 } 3523 3524 if ( bp_is_site_home() ) { 3525 $bp_classes[] = 'site-home'; 3526 } 3527 3528 if ( bp_is_site_members() ) { 3529 $bp_classes[] = 'site-members'; 3530 } 3531 3532 if ( bp_is_site_activity() ) { 3533 $bp_classes[] = 'site-activity'; 3534 } 3535 3536 if ( bp_is_site_manage() ) { 3537 $bp_classes[] = 'site-manage'; 3538 $bp_classes[] = 'site-manage-' . bp_current_site_manage_action(); 3539 } 3540 3366 3541 /* Registration ******************************************************/ 3367 3542 3368 3543 if ( bp_is_register_page() ) { -
src/bp-templates/bp-legacy/buddypress-functions.php
diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php index 436fcac..915d1c1 100644
class BP_Legacy extends BP_Theme_Compat { 113 113 114 114 // Blog button. 115 115 if ( bp_is_active( 'blogs' ) ) { 116 add_action( 'bp_directory_blogs_actions', 'bp_blogs_visit_blog_button' 116 add_action( 'bp_directory_blogs_actions', 'bp_blogs_visit_blog_button', 10 ); 117 117 add_action( 'bp_blogs_directory_blog_types', 'bp_legacy_theme_blog_create_nav', 999 ); 118 119 if ( bp_is_active( 'blogs', 'site' ) ) { 120 add_action( 'bp_directory_blogs_actions', 'bp_blogs_site_discover_button', 9 ); 121 } 118 122 } 119 123 } 120 124 -
src/bp-templates/bp-legacy/buddypress/blogs/single/activity.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/activity.php src/bp-templates/bp-legacy/buddypress/blogs/single/activity.php index e69de29..40ea85c 100644
1 <?php 2 /** 3 * BuddyPress - Site Activity 4 * 5 * @since 2.7.0 6 * 7 * @package BuddyPress 8 * @subpackage bp-legacy 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <div class="item-list-tabs no-ajax" id="subnav" role="navigation"> 15 <ul> 16 <li id="activity-filter-select" class="last"> 17 <label for="activity-filter-by"><?php _e( 'Show:', 'buddypress' ); ?></label> 18 <select id="activity-filter-by"> 19 <option value="-1"><?php _e( '— Everything —', 'buddypress' ); ?></option> 20 21 <?php bp_activity_show_filters( 'site' ); ?> 22 </select> 23 </li> 24 </ul> 25 </div><!-- .item-list-tabs --> 26 27 <div class="activity single-site" role="main"> 28 29 <?php if ( bp_site_is_public() ) : 30 bp_get_template_part( 'activity/activity-loop' ); 31 32 else : ?> 33 34 <div id="message" class="info"> 35 <p><?php _e( 'This site is private, no activity updates are available.', 'buddypress' ); ?></p> 36 </div> 37 38 <?php endif; ?> 39 40 </div><!-- .activity.single-site --> -
src/bp-templates/bp-legacy/buddypress/blogs/single/home.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/home.php src/bp-templates/bp-legacy/buddypress/blogs/single/home.php index e69de29..54384e0 100644
1 <?php 2 /** 3 * BuddyPress - Site Home 4 * 5 * @since 2.7.0 6 * 7 * @package BuddyPress 8 * @subpackage bp-legacy 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <div id="buddypress"> 15 16 <?php do_action( 'template_notices' ); ?> 17 18 <div id="item-nav"> 19 <div class="item-list-tabs no-ajax" id="object-nav" role="navigation"> 20 <ul> 21 22 <?php bp_site_primary_nav(); ?> 23 24 </ul> 25 </div> 26 </div><!-- #item-nav --> 27 28 <div id="item-body"> 29 30 <?php if ( bp_is_site_home() ) : 31 32 if ( bp_site_has_access() ) { 33 34 // Load the appropriate front template 35 bp_blogs_load_site_front_template(); 36 37 } else { 38 ?> 39 40 <div id="message" class="info"> 41 <p><?php bp_site_visibility_message(); ?></p> 42 </div> 43 44 <?php 45 } 46 47 // Not looking at home 48 else : 49 50 // Blog manage 51 if ( bp_is_site_manage() ) : bp_get_template_part( 'blogs/single/manage' ); 52 53 // Blog Activity 54 elseif ( bp_is_site_activity() ) : bp_get_template_part( 'blogs/single/activity' ); 55 56 // Blog Members 57 elseif ( bp_is_site_members() ) : bp_get_template_part( 'blogs/single/members' ); 58 59 // Anything else (plugins mostly) 60 else : bp_get_template_part( 'blogs/single/plugins' ); 61 62 endif; 63 64 endif; ?> 65 66 </div><!-- #item-body --> 67 68 </div><!-- #buddypress --> -
src/bp-templates/bp-legacy/buddypress/blogs/single/manage.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/manage.php src/bp-templates/bp-legacy/buddypress/blogs/single/manage.php index e69de29..e0f31de 100644
1 <?php 2 /** 3 * BuddyPress - Site Manage 4 * 5 * @since 2.7.0 6 * 7 * @package BuddyPress 8 * @subpackage bp-legacy 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <div class="item-list-tabs no-ajax" id="subnav" role="navigation"> 15 <ul> 16 17 <?php bp_site_secondary_nav();?> 18 19 </ul> 20 </div> 21 22 <?php switch ( bp_site_get_manage_action() ) : 23 case 'members' : 24 bp_get_template_part( 'blogs/single/members' ); 25 break; 26 default: 27 bp_get_template_part( 'blogs/single/plugins' ); 28 break; 29 endswitch; ?> -
src/bp-templates/bp-legacy/buddypress/blogs/single/members-loop.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/members-loop.php src/bp-templates/bp-legacy/buddypress/blogs/single/members-loop.php index e69de29..4ac0b95 100644
1 <?php 2 /** 3 * BuddyPress Blog single item members loop 4 * 5 * @since 2.7.0 6 * 7 * @package BuddyPress 8 * @subpackage bp-legacy 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <?php if ( bp_site_has_members( bp_ajax_querystring( 'site_members' ) ) ) : ?> 15 16 <div id="pag-top" class="pagination"> 17 18 <div class="pag-count" id="member-count-top"> 19 20 <?php bp_site_members_pagination_count(); ?> 21 22 </div> 23 24 <div class="pagination-links" id="member-pag-top"> 25 26 <?php bp_site_members_pagination_links(); ?> 27 28 </div> 29 30 </div> 31 32 <ul id="member-list" class="site_members item-list" role="main"> 33 34 <?php while ( bp_site_members() ) : bp_site_the_member(); ?> 35 36 <li> 37 <div class="item-avatar"> 38 <a href="<?php bp_site_member_permalink(); ?>"><?php bp_site_member_avatar(); ?></a> 39 </div> 40 41 <div class="item"> 42 <div class="item-title"> 43 <a href="<?php bp_site_member_permalink(); ?>"><?php bp_site_member_name(); ?></a> 44 </div> 45 46 <div class="item-meta"><span class="activity"><?php bp_site_member_involvement(); ?></span></div> 47 </div> 48 49 <?php if ( bp_site_has_member_actions() ) : ?> 50 <div class="action"> 51 52 <?php bp_site_member_actions(); ?> 53 54 </div> 55 <?php endif ; ?> 56 57 <div class="clear"></div> 58 </li> 59 60 <?php endwhile; ?> 61 62 </ul> 63 64 <div id="pag-bottom" class="pagination"> 65 66 <div class="pag-count" id="member-count-bottom"> 67 68 <?php bp_site_members_pagination_count(); ?> 69 70 </div> 71 72 <div class="pagination-links" id="member-pag-bottom"> 73 74 <?php bp_site_members_pagination_links(); ?> 75 76 </div> 77 78 </div> 79 80 <?php else: ?> 81 82 <div id="message" class="info"> 83 <p><?php _e( 'No site members were found.', 'buddypress' ); ?></p> 84 </div> 85 86 <?php endif; ?> -
src/bp-templates/bp-legacy/buddypress/blogs/single/members.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/members.php src/bp-templates/bp-legacy/buddypress/blogs/single/members.php index e69de29..a6002c3 100644
1 <?php 2 /** 3 * BuddyPress - Site Members 4 * 5 * @since 2.7.0 6 * 7 * @package BuddyPress 8 * @subpackage bp-legacy 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <form action="" method="post" id="members-site-form" class="dir-form"> 15 16 <div class="item-list-tabs" id="subnav" role="navigation"> 17 <ul> 18 <li id="site_members-order-select" class="last filter"> 19 <label for="site_members-order-by"><?php _e( 'Order By:', 'buddypress' ); ?></label> 20 <select id="site_members-order-by"> 21 <?php bp_site_members_filters(); ?> 22 </select> 23 </li> 24 </ul> 25 </div> 26 27 <div id="members-site-list" class="site_members dir-list"> 28 <?php bp_get_template_part( 'blogs/single/members-loop' ); ?> 29 </div><!-- #members-site-list --> 30 31 <?php wp_nonce_field( 'site_members', '_wpnonce-member-filter' ); ?> 32 33 </form><!-- #members-site-form --> 34 35 <?php bp_site_has_members(); ?> -
src/bp-templates/bp-legacy/buddypress/blogs/single/plugins.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/plugins.php src/bp-templates/bp-legacy/buddypress/blogs/single/plugins.php index e69de29..9e007f9 100644
1 <?php 2 /** 3 * BuddyPress - Site plugins 4 * 5 * @since 2.7.0 6 * 7 * @package BuddyPress 8 * @subpackage bp-legacy 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; 13 14 /** 15 * Template tag to allow plugins to add their 16 * specific content. 17 */ 18 bp_site_plugins_content(); -
src/bp-templates/bp-legacy/js/buddypress.js
diff --git src/bp-templates/bp-legacy/js/buddypress.js src/bp-templates/bp-legacy/js/buddypress.js index 40cfcaa..a1fdc58 100644
jq(document).ready( function() { 22 22 /* Activity filter and scope set */ 23 23 bp_init_activity(); 24 24 25 var objects = [ 'members', 'groups', 'blogs', 'forums', 'group_members' ],25 var objects = [ 'members', 'groups', 'blogs', 'forums', 'group_members', 'site_members' ], 26 26 $whats_new = jq('#whats-new'); 27 27 28 28 /* Object filter and scope set. */ … … jq(document).ready( function() { 934 934 template = 'groups/single/members'; 935 935 } 936 936 937 // On the Blogs single item Members page, we specify a template 938 if ( ( 'members' === object || 'manage' === object ) && 'blogs' === scope ) { 939 object = 'site_members'; 940 template = 'blogs/single/members-loop'; 941 } 942 937 943 if ( 'friends' === object ) { 938 944 object = 'members'; 939 945 } … … jq(document).ready( function() { 1014 1020 template = 'groups/single/members'; 1015 1021 } 1016 1022 1023 if ( ( 'members' === object || 'manage' === object ) && 'blogs' === css_id[1] ) { 1024 object = 'site_members'; 1025 template = 'blogs/single/members-loop'; 1026 } 1027 1017 1028 // On the Admin > Requests page, we need to reset the object, 1018 1029 // since "admin" isn't specific enough 1019 1030 if ( 'admin' === object && jq( 'body' ).hasClass( 'membership-requests' ) ) { … … jq(document).ready( function() { 1259 1270 }); 1260 1271 1261 1272 /* Add / Remove friendship buttons */ 1262 jq( '#members-dir-list, #members-group-list, #item-header ' ).on('click', '.friendship-button a', function() {1273 jq( '#members-dir-list, #members-group-list, #item-header, #members-site-list' ).on('click', '.friendship-button a', function() { 1263 1274 jq(this).parent().addClass('loading'); 1264 1275 var fid = jq(this).attr('id'), 1265 1276 nonce = jq(this).attr('href'), … … function bp_filter_request( object, filter, scope, target, search_terms, page, e 1924 1935 jq('.item-list-tabs li.selected').addClass('loading'); 1925 1936 jq('.item-list-tabs select option[value="' + filter + '"]').prop( 'selected', true ); 1926 1937 1927 if ( 'friends' === object || 'group_members' === object ) {1938 if ( 'friends' === object || 'group_members' === object || 'site_members' === object ) { 1928 1939 object = 'members'; 1929 1940 } 1930 1941