Ticket #6026: 6026.smaller-steps.03.patch
File 6026.smaller-steps.03.patch, 104.6 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 c425666..9d20cba 100644
function bp_has_activities( $args = '' ) { 236 236 ? $bp->loaded_components[ bp_current_action() ] 237 237 : bp_current_action(); 238 238 239 // Specific case for the sites subscriptions 240 if ( 'blogs' === $scope && bp_is_user_blogs_activity() && bp_action_variable( 0 ) ) { 241 $scope = 'site_' . sanitize_key( bp_action_variable( 0 ) ); 242 } 243 239 244 // Support for permalinks on single item pages: /groups/my-group/activity/124/. 240 245 $include = bp_is_current_action( bp_get_activity_slug() ) 241 246 ? bp_action_variable( 0 ) … … function bp_activity_show_filters( $context = '' ) { 3804 3809 if ( empty( $context ) ) { 3805 3810 3806 3811 // On member pages, default to 'member', unless this 3807 // is a user's Groups activity.3812 // is a user's Groups or a user's Blogs activity. 3808 3813 if ( bp_is_user() ) { 3814 // Groups 3809 3815 if ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) { 3810 3816 $context = 'member_groups'; 3817 3818 // Sites 3819 } elseif ( bp_is_active( 'blogs' ) && bp_is_current_action( bp_get_blogs_slug() ) ) { 3820 $context = 'member_sites'; 3811 3821 } else { 3812 3822 $context = 'member'; 3813 3823 } -
src/bp-activity/classes/class-bp-activity-component.php
diff --git src/bp-activity/classes/class-bp-activity-component.php src/bp-activity/classes/class-bp-activity-component.php index 4f85efb..4052f1d 100644
class BP_Activity_Component extends BP_Component { 233 233 ); 234 234 } 235 235 236 // Additional menu if blogs is active 237 if ( bp_is_active( 'blogs' ) ) { 238 $sub_nav[] = array( 239 'name' => _x( 'Sites', 'Profile activity screen sub nav', 'buddypress' ), 240 'slug' => bp_get_blogs_slug(), 241 'parent_url' => $activity_link, 242 'parent_slug' => $this->slug, 243 'screen_function' => 'bp_blogs_activity_screen', 244 'position' => 60, 245 'item_css_id' => 'activity-blogs' 246 ); 247 } 248 236 249 parent::setup_nav( $main_nav, $sub_nav ); 237 250 } 238 251 … … class BP_Activity_Component extends BP_Component { 329 342 'position' => 50 330 343 ); 331 344 } 345 346 // Blogs ? 347 if ( bp_is_active( 'blogs' ) ) { 348 $wp_admin_nav[] = array( 349 'parent' => 'my-account-' . $this->id, 350 'id' => 'my-account-' . $this->id . '-blogs', 351 'title' => _x( 'Sites', 'My Account Activity sub nav', 'buddypress' ), 352 'href' => trailingslashit( $activity_link . bp_get_blogs_slug() ) 353 ); 354 } 332 355 } 333 356 334 357 parent::setup_admin_bar( $wp_admin_nav ); -
src/bp-blogs/bp-blogs-activity.php
diff --git src/bp-blogs/bp-blogs-activity.php src/bp-blogs/bp-blogs-activity.php index c259897..30d8054 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', 'site' ),28 array( 'activity', 'member', 'site', 'member_sites' ), 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', 'site' );80 $params->contexts = array( 'activity', 'member', 'site', 'member_sites' ); 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', 'site' );108 $params->comments_tracking->contexts = array( 'activity', 'member', 'site', 'member_sites' ); 109 109 $params->comments_tracking->position = 10; 110 110 } 111 111 } … … function bp_blogs_activity_comment_single_action( $retval, $activity ) { 1425 1425 return $retval; 1426 1426 } 1427 1427 add_filter( 'bp_get_activity_action_pre_meta', 'bp_blogs_activity_comment_single_action', 10, 2 ); 1428 1429 /** 1430 * Set up activity arguments to use for the 'blogs' scope. 1431 * 1432 * @since 2.7.0 1433 * 1434 * @param array $retval Empty array by default 1435 * @param array $filter Current activity arguments 1436 * @return array 1437 */ 1438 function bp_blogs_blog_activity_scope( $retval = array(), $filter = array() ) { 1439 1440 // Determine the user_id 1441 if ( ! empty( $filter['user_id'] ) ) { 1442 $user_id = $filter['user_id']; 1443 } else { 1444 $user_id = bp_displayed_user_id() 1445 ? bp_displayed_user_id() 1446 : bp_loggedin_user_id(); 1447 } 1448 1449 // Determine blogs of user 1450 $blogs = bp_blogs_get_blogs_for_user( $user_id ); 1451 if ( empty( $blogs['blogs'] ) ) { 1452 $blogs = array( 'blogs' => 0 ); 1453 } else { 1454 $blogs['blogs'] = array_keys( $blogs['blogs'] ); 1455 } 1456 1457 // Should we show all items regardless of sitewide visibility? 1458 $show_hidden = array(); 1459 if ( ! empty( $user_id ) && ( $user_id !== bp_loggedin_user_id() ) ) { 1460 $show_hidden = array( 1461 'column' => 'hide_sitewide', 1462 'value' => 0 1463 ); 1464 } 1465 1466 $retval = array( 1467 'relation' => 'AND', 1468 array( 1469 'relation' => 'AND', 1470 array( 1471 'column' => 'component', 1472 'value' => buddypress()->blogs->id 1473 ), 1474 array( 1475 'column' => 'item_id', 1476 'compare' => 'IN', 1477 'value' => (array) $blogs['blogs'] 1478 ), 1479 ), 1480 $show_hidden, 1481 1482 // overrides 1483 'override' => array( 1484 'filter' => array( 'user_id' => 0 ), 1485 'show_hidden' => true 1486 ), 1487 ); 1488 1489 return $retval; 1490 } 1491 add_filter( 'bp_activity_set_blogs_scope_args', 'bp_blogs_blog_activity_scope', 10, 2 ); -
src/bp-blogs/bp-blogs-cache.php
diff --git src/bp-blogs/bp-blogs-cache.php src/bp-blogs/bp-blogs-cache.php index 19e3391..8510497 100644
function bp_blogs_update_meta_cache( $blog_ids = false ) { 44 44 */ 45 45 function bp_blogs_clear_blog_object_cache( $blog_id = 0, $user_id = 0 ) { 46 46 if ( ! empty( $user_id ) ) { 47 wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' ); 48 wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' ); 47 wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' ); 48 wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' ); 49 wp_cache_delete( 'bp_total_site_subscriptions_for_user_' . $user_id, 'bp' ); 49 50 } 50 51 51 52 wp_cache_delete( 'bp_total_blogs', 'bp' ); -
src/bp-blogs/bp-blogs-filters.php
diff --git src/bp-blogs/bp-blogs-filters.php src/bp-blogs/bp-blogs-filters.php index 1d0d71b..2826c02 100644
function bp_blogs_post_pre_publish( $return = true, $blog_id = 0, $post_id = 0, 121 121 } 122 122 add_filter( 'bp_activity_post_pre_publish', 'bp_blogs_post_pre_publish', 10, 4 ); 123 123 add_filter( 'bp_activity_post_pre_comment', 'bp_blogs_post_pre_publish', 10, 4 ); 124 125 /** 126 * Use the mystery site avatar for sites. 127 * 128 * @since 2.7.0 129 * 130 * @param string $avatar Current avatar src. 131 * @param array $params Avatar params. 132 * @return string 133 */ 134 function bp_blogs_default_avatar( $avatar, $params ) { 135 if ( isset( $params['object'] ) && 'blog' === $params['object'] ) { 136 $avatar = buddypress()->plugin_url . "bp-core/images/mystery-site.svg"; 137 } 138 139 return $avatar; 140 } 141 add_filter( 'bp_core_avatar_default', 'bp_blogs_default_avatar', 10, 3 ); 142 add_filter( 'bp_core_avatar_default_thumb', 'bp_blogs_default_avatar', 10, 3 ); -
src/bp-blogs/bp-blogs-functions.php
diff --git src/bp-blogs/bp-blogs-functions.php src/bp-blogs/bp-blogs-functions.php index 1aee053..c980454 100644
function bp_blogs_has_directory() { 38 38 * @type int $per_page Default: 20. 39 39 * @type int $page Default: 1. 40 40 * @type bool $update_meta_cache Whether to pre-fetch blogmeta. Default: true. 41 * @type int $is_contributor Whether to get sites user is at least a contributor (1) 42 * or the sites he subscribed to (0). Default: 1. 41 43 * } 42 44 * @return array See {@link BP_Blogs_Blog::get()}. 43 45 */ … … function bp_blogs_get_blogs( $args = '' ) { 51 53 'search_terms' => false, // Limit to blogs matching these search terms 52 54 'per_page' => 20, // The number of results to return per page 53 55 'page' => 1, // The page to return if limiting per page 54 'update_meta_cache' => true // Whether to pre-fetch blogmeta 56 'update_meta_cache' => true, // Whether to pre-fetch blogmeta, 57 'is_contributor' => 1, 55 58 ), 'blogs_get_blogs' ); 56 59 57 60 // Get the blogs. … … function bp_blogs_get_blogs( $args = '' ) { 62 65 $r['user_id'], 63 66 $r['search_terms'], 64 67 $r['update_meta_cache'], 65 $r['include_blog_ids'] 68 $r['include_blog_ids'], 69 $r['is_contributor'] 66 70 ); 67 71 68 72 // Filter and return. … … add_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_com 814 818 function bp_blogs_add_user_to_blog( $user_id, $role = false, $blog_id = 0 ) { 815 819 global $wpdb; 816 820 821 /** 822 * WordPress is removing the user from the main blog just after 823 * creating it on it. So we need to do the same with blog association. 824 */ 825 if ( doing_action( 'wpmu_new_user' ) ) { 826 BP_Blogs_Blog::delete_blog_for_user( get_current_site()->blog_id, $user_id ); 827 828 // No need to carry on. 829 return false; 830 } 831 817 832 // If no blog ID was passed, use the root blog ID. 818 833 if ( empty( $blog_id ) ) { 819 834 $blog_id = isset( $wpdb->blogid ) ? $wpdb->blogid : bp_get_root_blog_id(); … … function bp_blogs_add_user_to_blog( $user_id, $role = false, $blog_id = 0 ) { 866 881 bp_blogs_record_blog( $blog_id, $user_id, true ); 867 882 } 868 883 add_action( 'set_user_role', 'bp_blogs_add_user_to_blog', 10, 2 ); 884 add_action( 'wpmu_new_user', 'bp_blogs_add_user_to_blog', 10, 1 ); 869 885 870 886 /** 871 887 * The allowed blog roles a member must have to be recorded into the … … function bp_blogs_total_blogs() { 1144 1160 * Get the total number of blogs being tracked by BP for a specific user. 1145 1161 * 1146 1162 * @since 1.2.0 1163 * @since 2.7.0 Now this function also gets/caches the site subscriptions count. 1164 * Adds the $is_contributor parameter. 1147 1165 * 1148 1166 * @param int $user_id ID of the user being queried. Default: on a user page, 1149 1167 * the displayed user. Otherwise, the logged-in user. 1150 1168 * @return int $count Total blog count for the user. 1151 1169 */ 1152 function bp_blogs_total_blogs_for_user( $user_id = 0 ) {1170 function bp_blogs_total_blogs_for_user( $user_id = 0, $is_contributor = 1 ) { 1153 1171 if ( empty( $user_id ) ) { 1154 1172 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 1155 1173 } … … function bp_blogs_total_blogs_for_user( $user_id = 0 ) { 1159 1177 return 0; 1160 1178 } 1161 1179 1162 $count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ); 1180 $cache = 'bp_total_blogs_for_user_' . $user_id; 1181 if ( 0 === $is_contributor ) { 1182 $cache = 'bp_total_site_subscriptions_for_user_' . $user_id; 1183 } 1184 1185 $count = wp_cache_get( $cache, 'bp' ); 1163 1186 if ( false === $count ) { 1164 $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );1165 wp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' );1187 $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id, $is_contributor ); 1188 wp_cache_set( $cache, $count, 'bp' ); 1166 1189 } 1167 1190 1168 1191 return $count; … … function bp_blogs_restore_data( $user_id = 0 ) { 1428 1451 } 1429 1452 } 1430 1453 add_action( 'bp_make_ham_user', 'bp_blogs_restore_data', 10, 1 ); 1454 1455 /** 1456 * Checks if we safely use sites subscriptions. 1457 * 1458 * @since 2.7.0 1459 * 1460 * @return bool True if Site subscriptions are active. False otherwise. 1461 */ 1462 function bp_blogs_is_site_subscriptions_active() { 1463 return bp_is_active( 'blogs', 'site' ) && ! bp_disable_site_subscriptions(); 1464 } -
src/bp-blogs/bp-blogs-screens.php
diff --git src/bp-blogs/bp-blogs-screens.php src/bp-blogs/bp-blogs-screens.php index 371f401..bc2d8a3 100644
function bp_blogs_screen_index() { 72 72 } 73 73 add_action( 'bp_screens', 'bp_blogs_screen_index', 2 ); 74 74 75 /** 76 * Load the User's activity page. 77 * 78 * @since 2.7.0 79 */ 80 function bp_blogs_activity_screen() { 81 bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' ); 82 83 /** 84 * Fires right before the loading of the "My Sites" activities screen template file. 85 * 86 * @since 2.7.0 87 */ 88 do_action( 'bp_blogs_activity_screen' ); 89 90 /** 91 * Filters the template to load for the "My Sites" activities screen. 92 * 93 * @since 2.7.0 94 * 95 * @param string $template Path to the activity template to load. 96 */ 97 bp_core_load_template( apply_filters( 'bp_blogs_activity_screen_template', 'members/single/home' ) ); 98 } 99 75 100 /** Theme Compatibility *******************************************************/ 76 101 77 102 new BP_Blogs_Theme_Compat(); -
src/bp-blogs/bp-blogs-site.php
diff --git src/bp-blogs/bp-blogs-site.php src/bp-blogs/bp-blogs-site.php index 1a8e445..5e16d87 100644
require dirname( __FILE__ ) . '/site/functions.php'; 14 14 require dirname( __FILE__ ) . '/site/screens.php'; 15 15 require dirname( __FILE__ ) . '/site/template.php'; 16 16 require dirname( __FILE__ ) . '/site/adminbar.php'; 17 require dirname( __FILE__ ) . '/site/filters.php'; 17 18 18 19 if ( bp_is_active( 'activity' ) ) { 19 20 require dirname( __FILE__ ) . '/site/activity.php'; -
src/bp-blogs/bp-blogs-template.php
diff --git src/bp-blogs/bp-blogs-template.php src/bp-blogs/bp-blogs-template.php index cbe37ed..890f7e4 100644
function bp_rewind_blogs() { 143 143 * @type int $user_id The ID of the user whose blogs should be retrieved. 144 144 * When viewing a user profile page, 'user_id' defaults to the 145 145 * ID of the displayed user. Otherwise the default is false. 146 * @type int $is_contributor Whether to get sites user is at least a contributor (1) 147 * or the sites he subscribed to (0). Default: 1. 146 148 * } 147 149 * @return bool Returns true when blogs are found, otherwise false. 148 150 */ 149 151 function bp_has_blogs( $args = '' ) { 150 152 global $blogs_template; 151 153 154 $is_contributor = 1; 155 if ( bp_is_active( 'blogs', 'site' ) && bp_is_user() && bp_is_current_action( 'my-subscriptions' ) ) { 156 $is_contributor = 0; 157 } 158 152 159 // Check for and use search terms. 153 160 $search_terms_default = false; 154 161 $search_query_arg = bp_core_get_component_search_query_arg( 'blogs' ); … … function bp_has_blogs( $args = '' ) { 168 175 'user_id' => bp_displayed_user_id(), // Pass a user_id to limit to only blogs this user is a member of. 169 176 'include_blog_ids' => false, 170 177 'search_terms' => $search_terms_default, 171 'update_meta_cache' => true 178 'update_meta_cache' => true, 179 'is_contributor' => $is_contributor, 172 180 ), 'has_blogs' ); 173 181 174 182 // Set per_page to maximum if max is enforced. … … function bp_has_blogs( $args = '' ) { 177 185 } 178 186 179 187 // Get the blogs. 180 $blogs_template = new BP_Blogs_Template( $r['type'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['search_terms'], $r['page_arg'], $r['update_meta_cache'], $r['include_blog_ids'] );188 $blogs_template = new BP_Blogs_Template( $r['type'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['search_terms'], $r['page_arg'], $r['update_meta_cache'], $r['include_blog_ids'], $r['is_contributor'] ); 181 189 182 190 /** 183 191 * Filters whether or not there are blogs to list. … … function bp_blogs_pagination_links() { 287 295 } 288 296 289 297 /** 298 * Returns the Site's avatar. 299 * 300 * @since 2.7.0 301 * 302 * @param array|string $args { 303 * For more information about the arguments, see 304 * {@link bp_core_fetch_avatar()}. 305 * } 306 * @return string HTML output for the site's avatar. 307 */ 308 function bp_blogs_get_site_avatar( $args = array() ) { 309 $r = wp_parse_args( $args, array( 310 'item_id' => 0, 311 'title' => '', 312 'avatar_dir' => 'blog-avatars', 313 'object' => 'blog', 314 'type' => 'full', 315 'alt' => __( 'Site Photo', 'buddypress' ), 316 'css_id' => 0, 317 'class' => 'avatar site-avatar', 318 'width' => false, 319 'height' => false, 320 'site_name' => '', 321 ) ); 322 323 if ( ! empty( $r['site_name'] ) ) { 324 $r['alt'] = sprintf( __( 'Site Photo of %s', 'buddypress' ), $r['site_name'] ); 325 326 // Only replace the title if not set. 327 if ( ! $r['title'] ) { 328 $r['title'] = $r['alt']; 329 } 330 331 unset( $r['site_name'] ); 332 333 // Only set the default title if not already set. 334 } elseif ( ! $r['title'] ) { 335 $r['title'] = __( 'Site Photo', 'buddypress' ); 336 } 337 338 return bp_core_fetch_avatar( $r ); 339 } 340 341 /** 290 342 * Output a blog's avatar. 291 343 * 292 344 * @see bp_get_blog_avatar() for description of arguments. … … function bp_blog_avatar( $args = '' ) { 299 351 /** 300 352 * Get a blog's avatar. 301 353 * 302 * At the moment, blog avatars are simply the user avatars of the blog303 * admin. Filter 'bp_get_blog_avatar_' . $blog_id to customize.304 *305 354 * @since 2.4.0 Introduced `$title` argument. 306 355 * 307 356 * @see bp_core_fetch_avatar() For a description of arguments and 308 357 * return values. 309 358 * 310 359 * @param array|string $args { 311 * Arguments are listed here with an explanation of their defaults.312 360 * For more information about the arguments, see 313 361 * {@link bp_core_fetch_avatar()}. 314 * @type string $alt Default: 'Profile picture of site author [user name]'.315 * @type string $class Default: 'avatar'.316 * @type string $title Default: 'Profile picture of site author [user name]'.317 * @type string $type Default: 'full'.318 * @type int|bool $width Default: false.319 * @type int|bool $height Default: false.320 * @type bool $id Currently unused.321 * @type bool $no_grav Default: true.322 362 * } 323 * @return string Useravatar string.363 * @return string Site avatar string. 324 364 */ 325 365 function bp_get_blog_avatar( $args = '' ) { 326 366 global $blogs_template; … … function bp_blog_avatar( $args = '' ) { 331 371 return false; 332 372 } 333 373 334 $author_displayname = bp_core_get_user_displayname( $blogs_template->blog->admin_user_id );335 336 374 // Parse the arguments. 337 375 $r = bp_parse_args( $args, array( 338 'type' => 'full', 339 'width' => false, 340 'height' => false, 341 'class' => 'avatar', 342 'title' => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), esc_attr( $author_displayname ) ), 343 'id' => false, 344 'alt' => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), esc_attr( $author_displayname ) ), 345 'no_grav' => true, 346 ) ); 376 'item_id' => $blogs_template->blog->blog_id, 377 'type' => 'thumb', 378 'site_name' => esc_attr( bp_get_blog_name() ), 379 'title' => '', 380 ), 'get_blog_avatar' ); 347 381 348 382 // Fetch the avatar. 349 $avatar = bp_core_fetch_avatar( array( 350 'item_id' => $blogs_template->blog->admin_user_id, 351 'title' => $r['title'], 352 // 'avatar_dir' => 'blog-avatars', 353 // 'object' => 'blog', 354 'type' => $r['type'], 355 'alt' => $r['alt'], 356 'css_id' => $r['id'], 357 'class' => $r['class'], 358 'width' => $r['width'], 359 'height' => $r['height'] 360 ) ); 361 362 /** 363 * In future BuddyPress versions you will be able to set the avatar for a blog. 364 * Right now you can use a filter with the ID of the blog to change it if you wish. 365 * By default it will return the avatar for the primary blog admin. 366 * 367 * This filter is deprecated as of BuddyPress 1.5 and may be removed in a future version. 368 * Use the 'bp_get_blog_avatar' filter instead. 369 */ 370 $avatar = apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, $avatar ); 383 $avatar = bp_blogs_get_site_avatar( $r ); 371 384 372 385 /** 373 386 * Filters a blog's avatar. … … function bp_blog_permalink() { 388 401 function bp_get_blog_permalink() { 389 402 global $blogs_template; 390 403 404 if ( is_null( $blogs_template ) ) { 405 return; 406 } 407 391 408 if ( empty( $blogs_template->blog->domain ) ) 392 409 $permalink = bp_get_root_domain() . $blogs_template->blog->path; 393 410 else { … … function bp_total_blog_count_for_user( $user_id = 0 ) { 900 917 } 901 918 add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' ); 902 919 920 /** 921 * Output the total number of site subscriptions for a given user. 922 * 923 * @since 2.7.0 924 * 925 * @param int $user_id ID of the user. 926 */ 927 function bp_total_site_subscriptions_for_user( $user_id = 0 ) { 928 echo bp_get_total_site_subscriptions_for_user( $user_id ); 929 } 930 /** 931 * Return the total number of site subscriptions for a given user. 932 * 933 * @since 2.7.0 934 * 935 * @param int $user_id ID of the user. 936 * @return int Total number of site subscriptions for the user. 937 */ 938 function bp_get_total_site_subscriptions_for_user( $user_id = 0 ) { 939 940 /** 941 * Filters the total number of site subscriptions for a given user. 942 * 943 * @since 2.7.0 944 * 945 * @param int $value Total number of site subscriptions for a given user. 946 * @param int $user_id ID of the queried user. 947 */ 948 return apply_filters( 'bp_get_total_site_subscriptions_for_user', bp_blogs_total_blogs_for_user( $user_id, 0 ), $user_id ); 949 } 950 add_filter( 'bp_get_total_site_subscriptions_for_user', 'bp_core_number_format' ); 951 903 952 904 953 /** Blog Registration ********************************************************/ 905 954 … … function bp_blogs_get_profile_stats( $args = '' ) { 1483 1532 */ 1484 1533 return apply_filters( 'bp_blogs_get_profile_stats', $r['output'], $r ); 1485 1534 } 1535 1536 /** 1537 * Displays Tabs to filter the Site's activities of the member. 1538 * 1539 * My sites: the activities of the sites he is at least a contributor. 1540 * My Subscriptions: the activities of the sites he subscribed to. 1541 * 1542 * @since 2.7.0 1543 * 1544 * @return string HTML Output. 1545 */ 1546 function bp_blogs_member_tabs() { 1547 echo join( "\n", bp_get_blogs_member_tabs() ); 1548 } 1549 1550 /** 1551 * Gets Tabs to filter the Site's activities of the member. 1552 * 1553 * @since 2.7.0 1554 * 1555 * @return array The list of tabs. 1556 */ 1557 function bp_get_blogs_member_tabs() { 1558 /** 1559 * Filter here to disable/edit the tabs 1560 * 1561 * @since 2.7.0 1562 * 1563 * @param array The list of User's tabs for the activity of their Sites. 1564 */ 1565 $tabs = apply_filters( 'bp_get_blogs_member_tabs', array( 1566 'blogs' => __( 'My Sites', 'buddypress' ), 1567 'subscriptions' => __( 'My Subscriptions', 'buddypress' ), 1568 ) ); 1569 1570 // The site's feature or the Subscriptions one is disable, remove the tabs! 1571 if ( ! bp_blogs_is_site_subscriptions_active() ) { 1572 unset( $tabs['subscriptions'] ); 1573 1574 // Nobody used the filter to add tabs, let's remove everything! 1575 if ( 1 === count( $tabs ) ) { 1576 unset( $tabs['blogs'] ); 1577 } 1578 } 1579 1580 $output = array(); 1581 1582 if ( empty( $tabs ) ) { 1583 return $output; 1584 } 1585 1586 $current_action = bp_action_variable( 0 ); 1587 1588 foreach ( $tabs as $action => $tab ) { 1589 $selected = ''; 1590 $link_parts = array( trim( bp_displayed_user_domain(), '/' ), bp_get_activity_slug(), bp_get_blogs_slug() ); 1591 1592 if ( ! $current_action && 'blogs' === $action || $current_action === $action ) { 1593 $selected = ' current selected'; 1594 } 1595 1596 if ( 'blogs' !== $action ) { 1597 $link_parts[] = $action; 1598 } 1599 1600 $output[ $action ] = sprintf( '<li class="activity-%1$s%2$s"><a href="%3$s" class="no-ajax">%4$s</a></li>', 1601 esc_attr( $action ), 1602 $selected, 1603 esc_url( trailingslashit( join( '/', $link_parts ) ) ), 1604 esc_html( $tab ) 1605 ); 1606 } 1607 1608 /** 1609 * Filter here to edit the output 1610 * 1611 * @since 2.7.0 1612 * 1613 * @param array An associative array containing the links to filter the member's sites activity 1614 */ 1615 return apply_filters( 'bp_get_blogs_member_tabs_output', $output, $tabs ); 1616 } -
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 556d4c1..a7909d8 100644
class BP_Blogs_Blog { 188 188 * @param bool $update_meta_cache Whether to pre-fetch metadata for 189 189 * blogs. Default: true. 190 190 * @param array|bool $include_blog_ids Array of blog IDs to include. 191 * @param int $is_contributor Whether to get sites user is at least a contributor (1) 192 * or the sites he subscribed to (0). Default: 1. 191 193 * @return array Multidimensional results array, structured as follows: 192 194 * 'blogs' - Array of located blog objects 193 195 * 'total' - A count of the total blogs matching the filter params 194 196 */ 195 public static function get( $type, $limit = false, $page = false, $user_id = 0, $search_terms = false, $update_meta_cache = true, $include_blog_ids = false ) {197 public static function get( $type, $limit = false, $page = false, $user_id = 0, $search_terms = false, $update_meta_cache = true, $include_blog_ids = false, $is_contributor = 1 ) { 196 198 // Default query vars 197 199 $query_vars = array( 198 200 'public' => 1, … … class BP_Blogs_Blog { 214 216 215 217 if ( ! empty( $user_id ) ) { 216 218 $query_vars['user_id'] = (int) $user_id; 219 220 if ( ! is_null( $is_contributor ) ) { 221 $query_vars['is_contributor'] = (int) $is_contributor; 222 } 217 223 } 218 224 219 225 switch ( $type ) { … … class BP_Blogs_Blog { 323 329 $sql['where']['user_id'] = $wpdb->prepare( 'b.user_id = %d', $query_vars['user_id'] ); 324 330 325 331 // Defaults to blogs user is a least a contributor of 326 if ( ! isset( $query_vars[' only_contributors'] ) ) {332 if ( ! isset( $query_vars['is_contributor'] ) ) { 327 333 $sql['where']['is_contributor'] = 'b.is_contributor = 1'; 328 334 } else { 329 $sql['where']['is_contributor'] = $wpdb->prepare( 'b.is_contributor = %d', $query_vars[' only_contributors'] );335 $sql['where']['is_contributor'] = $wpdb->prepare( 'b.is_contributor = %d', $query_vars['is_contributor'] ); 330 336 } 331 337 } 332 338 … … class BP_Blogs_Blog { 828 834 * 829 835 * @since 2.7.0 830 836 * 831 * @param int $blog_id The blog ID to get users for. 832 * @param int $is_contributor Get only contributors (1) or subscribers (0). 837 * @param int $blog_id The blog ID to get users for. 838 * @param int|null $is_contributor Get only contributors (1) or subscribers (0). 839 * @param string|null $order Null for no order, DESC or ASC. 833 840 * @return array The list of users of the blog 834 841 */ 835 public static function get_site_user_ids( $blog_id, $is_contributor = null ) {842 public static function get_site_user_ids( $blog_id, $is_contributor = null, $order = null ) { 836 843 global $wpdb; 837 844 838 845 $bp = buddypress(); … … class BP_Blogs_Blog { 848 855 $sql['where']['is_contributor'] = $wpdb->prepare( 'is_contributor = %d', $is_contributor ); 849 856 } 850 857 858 if ( 'DESC' === $order || 'ASC' === $order ) { 859 $sql['order'] = sprintf( 'ORDER BY id %s', $order ); 860 } 861 851 862 $sql['where'] = 'WHERE ' . join( ' AND ', $sql['where'] ); 852 863 $query = join( ' ', $sql ); 853 864 -
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 6ccb129..0780650 100644
class BP_Blogs_Component extends BP_Component { 112 112 113 113 if ( is_multisite() && bp_is_blogs_component() && bp_current_action() && bp_is_active( $this->id, 'site' ) ) { 114 114 // Initialize a global placeholder for the site. 115 $this->site = new stdClass; 115 $this->site = new stdClass; 116 $this->site->settings = array(); 116 117 117 118 // Set the current Site object 118 119 if ( bp_is_current_action( bp_blogs_get_root_site_slug() ) ) { … … class BP_Blogs_Component extends BP_Component { 150 151 // Initialize the nav for the current site. 151 152 $this->nav = new BP_Core_Nav( $this->current_site->blog_id ); 152 153 154 /** 155 * Hook here to add your custom globals for the site feature. 156 * Use it to add specific settings using bp_blogs_register_site_settings() 157 * 158 * @since 2.7.0 159 * 160 * @param int $value The current site id. 161 */ 162 do_action( "bp_{$this->id}_setup_site_globals", $this->current_site->blog_id ); 163 153 164 // Set current_site to 0 to prevent debug errors. 154 165 } else { 155 166 $this->current_site = 0; … … class BP_Blogs_Component extends BP_Component { 300 311 'screen_function' => 'bp_blogs_screen_my_blogs', 301 312 'position' => 10 302 313 ); 314 315 if ( bp_blogs_is_site_subscriptions_active() ) { 316 $sub_nav[] = array( 317 'name' => __( 'My Subscriptions', 'buddypress' ), 318 'slug' => 'my-subscriptions', 319 'parent_url' => $parent_url, 320 'parent_slug' => $slug, 321 'screen_function' => 'bp_blogs_screen_my_blogs', 322 'position' => 20 323 ); 324 } 303 325 } 304 326 305 327 // Setup navigation. … … class BP_Blogs_Component extends BP_Component { 429 451 * Access is restricted to the site admins. 430 452 */ 431 453 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' ); 454 if ( bp_blogs_current_site_can_subscribe() ) { 455 /** 456 * Manage members. 457 * 458 * Eventually remove subscriptions. 459 */ 460 bp_core_new_subnav_item( array( 461 'name' => _x( 'Members', 'Single Site manage members screen', 'buddypress' ), 462 'slug' => 'members', 463 'parent_url' => trailingslashit( $site_link . 'manage' ), 464 'parent_slug' => 'manage', 465 'screen_function' => 'bp_blogs_screen_site_manage', 466 'position' => 20, 467 'user_has_access' => bp_is_item_admin(), 468 'no_access_url' => $site_link, 469 'show_in_admin_bar' => true, 470 ), 'blogs' ); 471 } 448 472 } 449 473 450 474 /** … … class BP_Blogs_Component extends BP_Component { 507 531 'position' => 10 508 532 ); 509 533 534 if ( bp_blogs_is_site_subscriptions_active() ) { 535 $wp_admin_nav[] = array( 536 'parent' => 'my-account-' . $this->id, 537 'id' => 'my-account-' . $this->id . '-my-subscriptions', 538 'title' => __( 'My Subscriptions', 'buddypress' ), 539 'href' => trailingslashit( $blogs_link . 'my-subscriptions' ) 540 ); 541 } 542 510 543 // Create a Site. 511 544 if ( bp_blog_signup_enabled() ) { 512 545 $wp_admin_nav[] = array( -
src/bp-blogs/classes/class-bp-blogs-template.php
diff --git src/bp-blogs/classes/class-bp-blogs-template.php src/bp-blogs/classes/class-bp-blogs-template.php index b203c89..710d869 100644
class BP_Blogs_Template { 96 96 * @param bool $update_meta_cache Whether to pre-fetch metadata for 97 97 * queried blogs. 98 98 * @param array|bool $include_blog_ids Array of blog IDs to include. 99 * @param int $is_contributor Whether to get sites user is at least a contributor (1) 100 * or the sites he subscribed to (0). Default: 1. 99 101 */ 100 public function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true, $include_blog_ids = false ) {102 public function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true, $include_blog_ids = false, $is_contributor = 1 ) { 101 103 102 104 $this->pag_arg = sanitize_key( $page_arg ); 103 105 $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $page ); … … class BP_Blogs_Template { 117 119 'search_terms' => $search_terms, 118 120 'update_meta_cache' => $update_meta_cache, 119 121 'include_blog_ids' => $include_blog_ids, 122 'is_contributor' => $is_contributor, 120 123 ) ); 121 124 } 122 125 -
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 fdc515d..60e973d 100644
class BP_Site_Query extends WP_Site_Query { 93 93 * is a contributor or a subscriber of. 94 94 */ 95 95 if ( ! empty( $this->query_vars['user_id'] ) ) { 96 $user_sites = BP_BLOGS_BLOG::get_blog_ids_for_user( $this->query_vars['user_id'] ); 96 $is_contributor = 1; 97 98 if ( isset( $this->query_vars['is_contributor'] ) ) { 99 $is_contributor = (int) $this->query_vars['is_contributor']; 100 } 101 102 $user_sites = BP_Blogs_Blog::get_blog_ids_for_user( $this->query_vars['user_id'], $is_contributor ); 97 103 98 104 if ( empty( $user_sites ) ) { 99 105 $this->sites = array(); -
src/bp-blogs/site/activity.php
diff --git src/bp-blogs/site/activity.php src/bp-blogs/site/activity.php index a522230..f8825c3 100644
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 // Put the code for the site activity here! 13 /** 14 * Register activity actions for the site subscriptions feature. 15 * 16 * @since 2.7.0 17 */ 18 function bp_blogs_site_register_subscription_activity_action() { 19 if ( bp_disable_site_subscriptions() ) { 20 return; 21 } 22 23 /** 24 * Only add subscription actions if subscription are enabled 25 * for current blog, or when viewing the blogs activities on 26 * a user's profile or on the activity directory 27 */ 28 if ( ( bp_is_site() && bp_blogs_current_site_can_subscribe() ) || bp_is_user() || bp_is_activity_directory() ) { 29 bp_activity_set_action( 30 buddypress()->blogs->id, 31 'site_subscription', 32 __( 'New site subscription', 'buddypress' ), 33 'bp_blogs_site_format_activity_action_new_subscription', 34 __( 'Site Subscriptions', 'buddypress' ), 35 array( 'activity', 'member', 'site', 'member_sites' ), 36 20 37 ); 38 } 39 } 40 add_action( 'bp_blogs_register_activity_actions', 'bp_blogs_site_register_subscription_activity_action' ); 41 42 /** 43 * Activity action callback for new site subscriptions 44 * 45 * @since 2.7.0 46 * 47 * @param string $action The content of the action. 48 * @param BP_Activity_Activity|null $activity The activity object. 49 * @return string The content of the action. 50 */ 51 function bp_blogs_site_format_activity_action_new_subscription( $action = '', $activity = null ) { 52 if ( empty( $activity->item_id ) ) { 53 return $action; 54 } 55 56 $user_link = bp_core_get_userlink( $activity->user_id ); 57 $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' ); 58 $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' ); 59 $root_url = trailingslashit( bp_get_root_domain() ); 60 $root_domain = get_current_site()->domain; 61 $protocol = 'http://'; 62 if ( is_ssl() ) { 63 $protocol = 'https://'; 64 } 65 66 if ( (int) $activity->item_id !== (int) get_current_site()->blog_id ) { 67 if ( is_subdomain_install() ) { 68 $slug = trim( str_replace( $root_domain, '', $blog_url ), '.' ); 69 $slug = str_replace( $protocol, '', $slug ); 70 } else { 71 $slug = trim( str_replace( $root_url, '', $blog_url ), '/' ); 72 } 73 74 $community_link = bp_blogs_get_site_community_url( $slug ); 75 } else { 76 $community_link = bp_blogs_get_site_community_url( bp_blogs_get_root_site_slug() ); 77 } 78 79 $action = sprintf( 80 __( '%1$s subscribed to the site %2$s', 'buddypress' ), 81 $user_link, 82 '<a href="' . esc_url( $community_link ) . '">' . esc_html( $blog_name ) . '</a>' 83 ); 84 85 return apply_filters( 'bp_blogs_site_format_activity_action_new_subscription', $action, $activity ); 86 } 87 88 /** 89 * Add an activity once the user subscribed to the site. 90 * 91 * @since 2.7.0 92 * 93 * @param int $user_id The user id who subscribed. 94 * @param WP_Site|object $site The site object he subscribed to. 95 */ 96 function bp_blogs_site_activity_user_subcribed( $user_id, $site ) { 97 $action = sprintf( 98 __( '%1$s subscribed to the site %2$s', 'buddypress' ), 99 bp_core_get_userlink( $user_id ), 100 '<a href="' . esc_url( bp_blogs_get_site_community_url( $site->slug ) ) . '">' . esc_html( $site->name ) . '</a>' 101 ); 102 103 bp_blogs_record_activity( array( 104 'action' => $action, 105 'type' => 'site_subscription', 106 'item_id' => $site->blog_id, 107 ) ); 108 109 // Update the blog's last activity. 110 bp_blogs_update_blogmeta( $site->blog_id, 'last_activity', bp_core_current_time() ); 111 } 112 add_action( 'bp_blogs_after_site_subscribed', 'bp_blogs_site_activity_user_subcribed', 10, 2 ); 113 114 /** 115 * Remove an activity once the user unsubscribed to the site. 116 * 117 * @since 2.7.0 118 * 119 * @param int $user_id The user id who unsubscribed. 120 * @param WP_Site|object $site The site object he unsubscribed to. 121 */ 122 function bp_blogs_site_activity_user_unsubscribed( $user_id, $site ) { 123 bp_blogs_delete_activity( array( 124 'user_id' => $user_id, 125 'item_id' => $site->blog_id, 126 'type' => 'site_subscription', 127 ) ); 128 } 129 add_action( 'bp_blogs_after_site_unsubscribed', 'bp_blogs_site_activity_user_unsubscribed', 10, 2 ); -
src/bp-blogs/site/filters.php
diff --git src/bp-blogs/site/filters.php src/bp-blogs/site/filters.php index e69de29..707b6f2 100644
1 <?php 2 /** 3 * BuddyPress Blogs Site Filters 4 * 5 * @package BuddyPress 6 * @subpackage BlogsSiteFilters 7 * @since 2.7.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 add_filter( 'bp_get_site_description', 'wptexturize' ); 14 add_filter( 'bp_get_sitename', 'wptexturize' ); 15 add_filter( 'bp_get_site_description', 'convert_smilies' ); 16 add_filter( 'bp_get_site_description', 'convert_chars' ); 17 add_filter( 'bp_get_sitename', 'convert_chars' ); 18 add_filter( 'bp_get_site_description', 'wpautop' ); 19 add_filter( 'bp_get_site_description', 'make_clickable', 9 ); 20 add_filter( 'bp_get_sitename', 'wp_filter_kses', 1 ); 21 add_filter( 'bp_get_site_description', 'wp_filter_kses', 1 ); 22 add_filter( 'bp_get_site_description', 'stripslashes' ); 23 add_filter( 'bp_get_site_description_editable', 'stripslashes' ); 24 add_filter( 'bp_get_sitename', 'stripslashes' ); 25 add_filter( 'bp_get_site_name_editable', 'stripslashes' ); -
src/bp-blogs/site/functions.php
diff --git src/bp-blogs/site/functions.php src/bp-blogs/site/functions.php index a79ec61..4bf23fe 100644
function bp_blogs_get_site( $slug = '' ) { 139 139 return $site; 140 140 } 141 141 142 // Check if we need to switch the blog. 143 $needs_switch = ! bp_is_root_blog( (int) $site->blog_id ); 144 142 145 // Check the current user caps for this site 143 if ( ! bp_is_root_blog()) {146 if ( $needs_switch ) { 144 147 switch_to_blog( $site->blog_id ); 145 148 } 146 149 147 $site->is_member = bp_current_user_can( 'read' );150 $site->is_member = current_user_can( 'read' ); 148 151 149 if ( bp_current_user_can( 'manage_options' ) ) {152 if ( current_user_can( 'manage_options' ) ) { 150 153 $site->is_admin = true; 151 } elseif ( bp_current_user_can( 'edit_posts' ) ) {154 } elseif ( current_user_can( 'edit_posts' ) ) { 152 155 $site->is_contributor = true; 153 156 } 154 157 155 if ( ! bp_is_root_blog() ) { 158 // Most of the time, there will be only one admin. 159 if ( 1 === count( $site->site_admins ) ) { 160 $user_id = reset( $site->site_admins ); 161 $site->admins_list = array( get_user_by( 'id', $user_id ) ); 162 163 // NB: WordPress introduced the 'role__in' parameter in 4.4 164 } else { 165 $site->admins_list = get_users( array( 166 'include' => $site->site_admins, 167 'orderby' => 'ID', 168 'order' => 'ASC', 169 ) ); 170 } 171 172 if ( $needs_switch ) { 156 173 restore_current_blog(); 157 174 } 158 175 … … function bp_blogs_current_site_get_admins() { 289 306 } 290 307 291 308 /** 309 * Can users subscribe to the site? 310 * 311 * @since 2.7.0 312 * 313 * @return bool True if subscriptions are enabled. False otherwise. 314 */ 315 function bp_blogs_current_site_can_subscribe() { 316 if ( bp_disable_site_subscriptions() ) { 317 return false; 318 } 319 320 $can = bp_blogs_current_site_is_public(); 321 322 if ( $can ) { 323 $can = ! bp_blogs_get_current_site_property( 'disallow_subscriptions' ); 324 } 325 326 /** 327 * Filters subscriptions setting for the site 328 * 329 * @since 2.7.0 330 * 331 * @param bool $can True if subscriptions are enabled. False otherwise. 332 */ 333 return (bool) apply_filters( 'bp_get_site_can_subscribe', $can ); 334 } 335 336 /** 292 337 * Edit the BP User Query query vars to only get the site members 293 338 * 294 339 * @since 2.7.0 … … function bp_blogs_set_site_user_query( BP_User_Query $site_user_query = null ) { 310 355 $is_contributor = $bp->blogs->site->members->loop_args['is_contributor']; 311 356 } 312 357 313 $bp->blogs->site->members->extra = BP_Blogs_Blog::get_site_user_ids( $blog_id, $is_contributor ); 358 $order = null; 359 if ( 'last_joined' === $bp->blogs->site->members->loop_args['type'] ) { 360 $order = 'DESC'; 361 } elseif ( 'first_joined' === $bp->blogs->site->members->loop_args['type'] ) { 362 $order = 'ASC'; 363 } 364 365 $bp->blogs->site->members->extra = BP_Blogs_Blog::get_site_user_ids( $blog_id, $is_contributor, $order ); 314 366 315 367 if ( empty( $bp->blogs->site->members->extra ) ) { 316 368 $user_ids = array( 0 ); 317 369 } else { 318 370 $user_ids = wp_list_pluck( $bp->blogs->site->members->extra, 'user_id' ); 371 372 if ( ! is_null( $order ) ) { 373 $bp->blogs->site->members->order_by = array_merge( array( 'u.id' ), wp_parse_id_list( $user_ids ) ); 374 } 319 375 } 320 376 321 377 // Only include site members … … function bp_blogs_set_site_user_query( BP_User_Query $site_user_query = null ) { 324 380 } 325 381 326 382 /** 383 * Edit the order of the BP User Query clause if needed. 384 * 385 * @since 2.7.0 386 * 387 * @param BP_User_Query|null $site_user_query The BP User Query object 388 */ 389 function bp_blogs_pre_site_user_query( BP_User_Query $site_user_query = null ) { 390 $bp = buddypress(); 391 392 if ( empty( $bp->blogs->site->members->order_by ) ) { 393 return; 394 } 395 396 $site_user_query->uid_clauses['orderby'] = "ORDER BY FIELD(" . join( ',', $bp->blogs->site->members->order_by ) . ")"; 397 } 398 399 /** 327 400 * Add specific site extra to members fetched in the BP User Query 328 401 * 329 402 * @since 2.7.0 … … function bp_blogs_user_query_site_populate_extras( BP_User_Query $site_user_quer 349 422 } 350 423 } 351 424 } 425 426 /** 427 * BuddyPress Restricted Blogmetas. 428 * 429 * @since 2.7.0 430 * 431 * @return array The list of restricted Blogmetas. 432 */ 433 function bp_blogs_get_restricted_options() { 434 return array( 435 'name', 436 'description', 437 'last_activity', 438 'close_comments_for_old_posts', 439 'close_comments_days_old', 440 'thread_comments_depth', 441 'site_admins', 442 'url', 443 'disallow_subscriptions', 444 ); 445 } 446 447 /** 448 * Register custom settings for the site's manage settings screen. 449 * 450 * @since 2.7.0 451 * 452 * @param string $option_name The 'meta_key' you choose for the blogmeta 453 * @param array|string $args { 454 * An array of required arguments. 455 * @type string $display_function Required. The name of the function to use 456 * for the setting display. 457 * @type string $sanitize_function Required. The name of the function to use 458 * to sanitize the value of the option. 459 * } 460 * @return bool True if the setting has been registered. False otherwise. 461 */ 462 function bp_blogs_register_site_settings( $option_name, $args = array() ) { 463 if ( ! doing_action( 'bp_blogs_setup_site_globals' ) ) { 464 return false; 465 } 466 467 $bp = buddypress(); 468 $core_options = bp_blogs_get_restricted_options(); 469 $option_name = sanitize_key( $option_name ); 470 471 $restricted = array_flip( array_merge( $core_options, wp_list_pluck( $bp->blogs->site->settings, 'option_name' ) ) ); 472 473 if ( empty( $option_name ) || isset( $restricted[ $option_name ] ) ) { 474 return false; 475 } 476 477 $option_args = wp_parse_args( $args, array( 478 'display_function' => '', 479 'sanitize_function' => '', 480 ) ); 481 482 $option_args['option_name'] = $option_name; 483 484 $bp->blogs->site->settings[ $option_name ] = (object) $option_args; 485 486 // Settings is registered. 487 return true; 488 } 489 490 /** 491 * Get all or a specific site custom setting. 492 * 493 * @since 2.7.0 494 * 495 * @param string $option The 'meta_key' of the custom option. 496 * @return array|object|false The list of all registered settings. 497 * The specific requested setting object. 498 * False or an empty array if no settings were found. 499 */ 500 function bp_blogs_get_site_settings( $option = '' ) { 501 $settings = buddypress()->blogs->site->settings; 502 503 if ( empty( $option ) ) { 504 return $settings; 505 } elseif ( ! isset( $settings[ $option ] ) || ! $settings[ $option ]->display_function || ! $settings[ $option ]->sanitize_function ) { 506 return false; 507 } 508 509 return $settings[ $option ]; 510 } -
src/bp-blogs/site/screens.php
diff --git src/bp-blogs/site/screens.php src/bp-blogs/site/screens.php index 92c42f0..7e96336 100644
function bp_blogs_screen_site_manage() { 173 173 return false; 174 174 } 175 175 176 if ( bp_is_site_manage_s creen( 'members' ) && 'remove' === bp_action_variable( 1) ) {176 if ( bp_is_site_manage_settings() ) { 177 177 178 check_admin_referer( 'site_remove_member' ); 178 // Update settings. 179 if ( ! empty( $_POST['bp_site']['submit'] ) ) { 179 180 180 $blog_id = bp_blogs_get_current_site_id(); 181 $user_id = (int) bp_action_variable( 2 ); 181 check_admin_referer( 'site_manage_settings' ); 182 182 183 $referer = wp_get_referer(); 184 $message = __( 'We were not able to perform this action, please try again later', 'buddypress' ); 185 $type = 'error'; 183 unset( $_POST['bp_site']['submit'] ); 184 $options = $_POST['bp_site']; 186 185 187 if ( ! bp_is_item_admin() || empty( $blog_id ) || empty( $user_id ) ) { 188 bp_core_add_message( $message, $type ); 186 $blog_id = bp_blogs_get_current_site_id(); 187 $referer = wp_unslash( $_POST['_wp_http_referer'] ); 188 $message = __( 'We were not able to perform this action, please try again later', 'buddypress' ); 189 $type = 'error'; 190 $name_check = empty( $options['blogname'] ); 191 192 if ( ! bp_is_item_admin() || empty( $blog_id ) || $name_check ) { 193 if ( $name_check ) { 194 $message = __( 'The site title is required.', 'buddypress' ); 195 } 196 197 bp_core_add_message( $message, $type ); 198 bp_core_redirect( $referer ); 199 } 200 201 if ( ! isset( $options['blog_public'] ) ) { 202 $options['blog_public'] = 0; 203 } 204 205 // This option will only be saved in BuddyPress blog metas 206 if ( isset( $options['disallow_subscriptions'] ) ) { 207 bp_blogs_update_blogmeta( $blog_id, 'disallow_subscriptions', (int) $options['disallow_subscriptions'] ); 208 unset( $options['disallow_subscriptions'] ); 209 } else { 210 bp_blogs_delete_blogmeta( $blog_id, 'disallow_subscriptions' ); 211 } 212 213 $needs_switch = ! bp_is_root_blog( (int) $blog_id ); 214 215 if ( $needs_switch ) { 216 switch_to_blog( $blog_id ); 217 } 218 219 $whitelist_options = array( 220 'blogname' => true, 221 'blogdescription' => true, 222 'blog_public' => true, 223 ); 224 225 foreach ( $options as $key => $option ) { 226 if ( empty( $whitelist_options[ $key ] ) ) { 227 continue; 228 } 229 230 $sanitized_option = sanitize_option( $key, $option ); 231 232 update_option( $key, $sanitized_option ); 233 } 234 235 if ( isset( $needs_reset ) ) { 236 restore_current_blog(); 237 } 238 239 $options = array_diff_key( $options, $whitelist_options ); 240 241 // Now manage the options plugins can eventually add, if any. 242 $plugin_settings = bp_blogs_get_site_settings(); 243 244 if ( ! empty( $plugin_settings ) ) { 245 foreach ( $plugin_settings as $plugin_setting ) { 246 if ( empty( $plugin_setting->sanitize_function ) || ! is_callable( $plugin_setting->sanitize_function ) ) { 247 continue; 248 } 249 250 if ( isset( $options[ $plugin_setting->option_name ] ) ) { 251 $plugin_option = call_user_func_array( $plugin_setting->sanitize_function, array( $options[ $plugin_setting->option_name ] ) ); 252 253 bp_blogs_update_blogmeta( $blog_id, $plugin_setting->option_name, $plugin_option ); 254 } else { 255 bp_blogs_delete_blogmeta( $blog_id, $plugin_setting->option_name ); 256 } 257 } 258 } 259 260 // Redirect the user once done 261 bp_core_add_message( __( 'Settings saved.', 'buddypress' ) ); 189 262 bp_core_redirect( $referer ); 190 263 } 191 264 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' ); 265 } elseif ( bp_is_site_manage_members() ) { 266 267 if ( 'remove' === bp_action_variable( 1 ) ) { 268 check_admin_referer( 'site_remove_member' ); 269 270 $blog_id = bp_blogs_get_current_site_id(); 271 $user_id = (int) bp_action_variable( 2 ); 272 273 $referer = wp_get_referer(); 274 $message = __( 'We were not able to perform this action, please try again later', 'buddypress' ); 275 $type = 'error'; 276 277 if ( ! bp_is_item_admin() || empty( $blog_id ) || empty( $user_id ) ) { 278 bp_core_add_message( $message, $type ); 279 bp_core_redirect( $referer ); 280 } 281 282 if ( bp_user_can( $user_id, 'delete_published_posts', array( 'site_id' => $blog_id ) ) ) { 283 $message = __( 'Only subscribers or contributors can be removed from this screen.', 'buddypress' ); 284 bp_core_add_message( $message, $type ); 285 bp_core_redirect( $referer ); 286 } 287 288 /** 289 * Fires before the user is removed from the blog 290 * 291 * @since 2.7.0 292 * 293 * @param int $user_id the ID of the current user 294 * @param int $blog_id the ID of the blog 295 */ 296 do_action( 'bp_blogs_before_remove_user_from_site', $user_id, $blog_id ); 297 298 /** 299 * Removing the user 300 */ 301 $removed = remove_user_from_blog( $user_id, $blog_id ); 302 303 if ( ! is_wp_error( $removed ) ) { 304 $message = __( 'Member successfully removed from the site.', 'buddypress' ); 305 $type = ''; 306 307 /** 308 * Fires after the user was removed from the blog 309 * 310 * @since 2.7.0 311 * 312 * @param int $user_id the ID of the current user 313 * @param int $blog_id the ID of the blog 314 */ 315 do_action( 'bp_blogs_after_remove_user_from_site', $user_id, $blog_id ); 316 317 } else { 318 $message = $removed->get_error_message(); 319 $type = 'error'; 320 } 321 194 322 bp_core_add_message( $message, $type ); 195 323 bp_core_redirect( $referer ); 196 }197 324 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 ); 325 // Toggle involvement 326 } elseif ( 'promote' === bp_action_variable( 1 ) || 'demote' === bp_action_variable( 1 ) ) { 327 $action = sanitize_key( bp_action_variable( 1 ) ); 207 328 208 /** 209 * Removing the user 210 */ 211 $removed = remove_user_from_blog( $user_id, $blog_id ); 329 check_admin_referer( "site_{$action}_member" ); 330 331 $blog_id = bp_blogs_get_current_site_id(); 332 $user_id = (int) bp_action_variable( 2 ); 333 334 $referer = wp_get_referer(); 335 $message = __( 'We were not able to perform this action, please try again later', 'buddypress' ); 336 $type = 'error'; 337 338 if ( ! bp_is_item_admin() || empty( $blog_id ) || empty( $user_id ) ) { 339 bp_core_add_message( $message, $type ); 340 bp_core_redirect( $referer ); 341 } 212 342 213 if ( ! is_wp_error( $removed ) ) { 214 $message = __( 'Member successfully removed from the site.', 'buddypress' ); 215 $type = 'success'; 343 $needs_switch = ! bp_is_root_blog( (int) $blog_id ); 344 345 if ( $needs_switch ) { 346 switch_to_blog( $blog_id ); 347 } 348 349 if ( user_can( $user_id, 'delete_published_posts' ) ) { 350 $message = __( 'Only subscribers or contributors can be managed from this screen. Please use your Site Administration to manage the role of this specific member.', 'buddypress' ); 351 bp_core_add_message( $message, $type ); 352 bp_core_redirect( $referer ); 353 } 216 354 217 355 /** 218 * Fires after the user was removed from the blog356 * Fires before the user is promoted or demoted 219 357 * 220 358 * @since 2.7.0 221 359 * 222 360 * @param int $user_id the ID of the current user 223 361 * @param int $blog_id the ID of the blog 224 362 */ 225 do_action( 'bp_blogs_after_remove_user_from_site', $user_id, $blog_id );363 do_action( "bp_blogs_before_{$action}_user_from_site", $user_id, $blog_id ); 226 364 227 } else { 228 $message = $removed->get_error_message(); 229 $type = 'error'; 230 } 365 $message = __( 'Member successfully promoted to contributor.', 'buddypress' ); 366 $userdata = array( 'ID' => $user_id, 'role' => 'contributor' ); 367 368 if ( 'demote' === $action ) { 369 $message = __( 'Member successfully demoted to subscriber.', 'buddypress' ); 370 $userdata['role'] = 'subscriber'; 371 } 372 373 /** 374 * Updating the user role 375 */ 376 $updated = wp_update_user( $userdata ); 231 377 232 bp_core_add_message( $message, $type ); 233 bp_core_redirect( $referer ); 378 if ( $needs_switch ) { 379 restore_current_blog(); 380 } 381 382 if ( is_wp_error( $updated ) ) { 383 $message = $updated->get_error_message(); 384 $type = 'error'; 385 } else { 386 $type = ''; 387 388 /** 389 * Fires after the user was promoted or demoted. 390 * 391 * @since 2.7.0 392 * 393 * @param int $user_id the ID of the current user 394 * @param int $blog_id the ID of the blog 395 */ 396 do_action( "bp_blogs_after_{$action}_user_from_site", $user_id, $blog_id ); 397 } 398 399 bp_core_add_message( $message, $type ); 400 bp_core_redirect( $referer ); 401 } 234 402 } 235 403 236 404 /** -
src/bp-blogs/site/subscriptions.php
diff --git src/bp-blogs/site/subscriptions.php src/bp-blogs/site/subscriptions.php index c6debc5..8be8ce3 100644
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 // Put the code for the front-end site subscriptions feature here! 13 /** 14 * Displays a subscribe button for the current site. 15 * 16 * @since 2.7.0 17 * 18 * @param WP_Site|object $site The site object. 19 * @return string HTML Output. 20 */ 21 function bp_site_subscribe_button( $site = null ) { 22 if ( empty( $site ) ) { 23 $site = bp_blogs_get_current_site(); 24 } 25 26 echo bp_get_site_subscribe_button( $site ); 27 } 28 29 /** 30 * Builds the arguments of the subscribe button for the current site. 31 * 32 * @since 2.7.0 33 * 34 * @param WP_Site|object $site The site object. 35 * @return array The button arguments. 36 */ 37 function bp_get_site_subscribe_button_args( $site = null ) { 38 if ( empty( $site->blog_id ) ) { 39 $site = bp_blogs_get_current_site(); 40 } 41 42 if ( ! $site || ! empty( $site->is_admin ) ) { 43 return; 44 } 45 46 $start_button = array( 47 'id' => 'subscribe_unsubscribe', 48 'component' => 'blogs', 49 'must_be_logged_in' => true, 50 'block_self' => false, 51 ); 52 53 if ( ! $site->is_member ) { 54 $end_button = array( 55 'wrapper_class' => 'site-button subscribe', 56 'link_href' => esc_url( wp_nonce_url( 57 add_query_arg( 'action', 'subscribe', bp_blogs_get_site_community_url() ), 58 'site_subscribe' 59 ) ), 60 'link_class' => 'site-button subscribe', 61 'link_text' => __( 'Subscribe', 'buddypress' ), 62 ); 63 } else { 64 $link_text = __( 'Unsubscribe', 'buddypress' ); 65 66 // To avoid any confusion 67 if ( ! empty( $site->is_contributor ) ) { 68 $link_text = __( 'Leave', 'buddypress' ); 69 } 70 71 $end_button = array( 72 'wrapper_class' => 'site-button unsubscribe', 73 'link_href' => esc_url( wp_nonce_url( 74 add_query_arg( 'action', 'unsubscribe', bp_blogs_get_site_community_url() ), 75 'site_unsubscribe' 76 ) ), 77 'link_class' => 'site-button unsubscribe confirm', 78 'link_text' => $link_text, 79 ); 80 } 81 82 $button = array_merge( $start_button, $end_button ); 83 84 /** 85 * Filter here to edit button arguments. 86 * 87 * @since 2.7.0 88 * 89 * @param array $button The Button arguments. 90 * @param object $site The site object. 91 */ 92 return apply_filters( 'bp_get_site_subscribe_button_args', $button, $site ); 93 } 94 95 /** 96 * Gets the Subscribe Button for the current site. 97 * 98 * @since 2.7.0 99 * 100 * @param WP_Site|object $site The site object. 101 * @return string HTML Output. 102 */ 103 function bp_get_site_subscribe_button( $site = null ) { 104 return bp_get_button( bp_get_site_subscribe_button_args( $site ) ); 105 } 106 107 /** 108 * Listen to the subscribe/unsubscribe actions and handle them. 109 * 110 * @since 2.7.0 111 */ 112 function bp_blogs_site_subscriptions_handle_actions() { 113 if ( empty( $_GET['action'] ) || ( 'subscribe' !== $_GET['action'] && 'unsubscribe' !== $_GET['action'] ) ) { 114 return; 115 } 116 117 $action = sanitize_key( $_GET['action'] ); 118 119 check_admin_referer( 'site_' . $action ); 120 121 $referer = wp_get_referer(); 122 $result = array( 123 'message' => __( 'We were not able to perform this action, please try again later', 'buddypress' ), 124 'type' => 'error', 125 ); 126 127 if ( is_user_logged_in() && is_callable( 'bp_blogs_site_' . $action ) ) { 128 $result = call_user_func( 'bp_blogs_site_' . $action ); 129 } 130 131 bp_core_add_message( $result['message'], $result['type'] ); 132 bp_core_redirect( $referer ); 133 } 134 add_action( 'bp_blogs_screen_site_home', 'bp_blogs_site_subscriptions_handle_actions' ); 135 136 /** 137 * Subscribes a user to a site. 138 * 139 * @since 2.7.0 140 * 141 * @param int $user_id The ID of the user. 142 * @param int $site_id The ID of the site. 143 * @return array The feedback message and type. 144 */ 145 function bp_blogs_site_subscribe( $user_id = 0, $site_id = 0 ) { 146 if ( empty( $user_id ) ) { 147 $user_id = bp_loggedin_user_id(); 148 } 149 150 if ( empty( $site_id ) ) { 151 $site = bp_blogs_get_current_site(); 152 } else { 153 $site = bp_blogs_get_site( $site_id ); 154 } 155 156 // Default result 157 $result = array( 158 'message' => __( 'We were not able to perform this action, please try again later', 'buddypress' ), 159 'type' => 'error', 160 ); 161 162 if ( bp_disable_site_subscriptions() || empty( $site->blog_id ) || empty( $site->public ) || ! empty( $site->disallow_subscriptions ) ) { 163 return $result; 164 } 165 166 // First make sure not to add a user that is already a subscriber of the blog. 167 if ( bp_user_can( $user_id, 'read', array( 'site_id' => $site->blog_id ) ) ) { 168 $result['message'] = __( 'You already subcribed to this site.', 'buddypress' ); 169 return $result; 170 } 171 172 /** 173 * Fires before the user subcribes to the site. 174 * 175 * @since 2.7.0 176 * 177 * @param int $user_id the ID of the user. 178 * @param WP_Site|object $site The Site object. 179 */ 180 do_action( 'bp_blogs_before_site_subscribe', $user_id, $site ); 181 182 $subscribed = add_user_to_blog( $site->blog_id, $user_id, 'subscriber' ); 183 184 if ( is_wp_error( $subscribed ) ) { 185 $result = array( 186 'message' => $subscribed->get_error_message(), 187 'type' => 'error', 188 ); 189 } else { 190 // Update Site object 191 $site->is_member = true; 192 193 $result = array( 194 'message' => __( 'You successfully subscribed to the site.', 'buddypress' ), 195 'type' => '', 196 ); 197 198 /** 199 * Fires after the user subcribed to the site. 200 * 201 * @since 2.7.0 202 * 203 * @param int $user_id the ID of the user. 204 * @param WP_Site|object $site The Site object. 205 */ 206 do_action( 'bp_blogs_after_site_subscribed', $user_id, $site ); 207 } 208 209 return $result; 210 } 211 212 /** 213 * Unsubscribes a user to a site. 214 * 215 * @since 2.7.0 216 * 217 * @param int $user_id The ID of the user. 218 * @param int $site_id The ID of the site. 219 * @return array The feedback message and type. 220 */ 221 function bp_blogs_site_unsubscribe( $user_id = 0, $site_id = 0 ) { 222 if ( empty( $user_id ) ) { 223 $user_id = bp_loggedin_user_id(); 224 } 225 226 if ( empty( $site_id ) ) { 227 $site = bp_blogs_get_current_site(); 228 } else { 229 $site = bp_blogs_get_site( $site_id ); 230 } 231 232 // Default result 233 $result = array( 234 'message' => __( 'We were not able to perform this action, please try again later', 'buddypress' ), 235 'type' => 'error', 236 ); 237 238 if ( bp_disable_site_subscriptions() || empty( $site->blog_id ) || empty( $site->public ) || ! empty( $site->disallow_subscriptions ) ) { 239 return $result; 240 } 241 242 // First check the user is a subscriber. 243 if ( ! bp_user_can( $user_id, 'read', array( 'site_id' => $site->blog_id ) ) ) { 244 $result['message'] = __( 'You already unsubcribed to this site.', 'buddypress' ); 245 return $result; 246 } 247 248 /** 249 * Fires before the user unsubscribes to the site. 250 * 251 * @since 2.7.0 252 * 253 * @param int $user_id The ID of the user. 254 * @param WP_Site|object $site The site object. 255 */ 256 do_action( 'bp_blogs_before_site_unsubscribe', $user_id, $site ); 257 258 $unsubscribed = remove_user_from_blog( $user_id, $site->blog_id ); 259 260 if ( is_wp_error( $unsubscribed ) ) { 261 $result = array( 262 'message' => $unsubscribed->get_error_message(), 263 'type' => 'error', 264 ); 265 } else { 266 // Update Site object 267 $site->is_member = false; 268 269 $result = array( 270 'message' => __( 'You successfully unsubscribed to the site.', 'buddypress' ), 271 'type' => 'success', 272 ); 273 274 /** 275 * Fires after the user unsubscribed to the site. 276 * 277 * @since 2.7.0 278 * 279 * @param int $user_id The ID of the user. 280 * @param WP_Site|object $site The site object. 281 */ 282 do_action( 'bp_blogs_after_site_unsubscribed', $user_id, $site ); 283 } 284 285 return $result; 286 } 287 -
src/bp-blogs/site/template.php
diff --git src/bp-blogs/site/template.php src/bp-blogs/site/template.php index 4a05676..364710f 100644
function bp_get_site_nav( $type = 'primary' ) { 237 237 * @return string HTML Output. 238 238 */ 239 239 function bp_site_primary_nav() { 240 /** 241 * Fires before the site primary nav 242 * 243 * (inside an <ul> tag) 244 * 245 * @since 2.7.0 246 */ 247 do_action( 'bp_before_site_primary_nav' ); 248 240 249 echo join( "\n", bp_get_site_nav( 'primary' ) ); 250 251 /** 252 * Fires after the site primary nav 253 * 254 * (inside an <ul> tag) 255 * 256 * @since 2.7.0 257 */ 258 do_action( 'bp_after_site_primary_nav' ); 241 259 } 242 260 243 261 /** … … function bp_site_primary_nav() { 248 266 * @return string HTML Output. 249 267 */ 250 268 function bp_site_secondary_nav() { 269 /** 270 * Fires before the site secondary nav 271 * 272 * (inside an <ul> tag) 273 * 274 * @since 2.7.0 275 */ 276 do_action( 'bp_before_site_secondary_nav' ); 277 251 278 echo join( "\n", bp_get_site_nav( 'secondary' ) ); 279 280 /** 281 * Fires after the site secondary nav 282 * 283 * (inside an <ul> tag) 284 * 285 * @since 2.7.0 286 */ 287 do_action( 'bp_after_site_secondary_nav' ); 252 288 } 253 289 254 290 /** … … function bp_site_visibility_message() { 297 333 } 298 334 299 335 /** 336 * Display the site name. 337 * 338 * @since 2.7.0 339 * 340 * @return string The site name. 341 */ 342 function bp_sitename() { 343 echo bp_get_sitename(); 344 } 345 346 /** 347 * Get the site name to display. 348 * 349 * @since 2.7.0 350 * 351 * @return string The site name. 352 */ 353 function bp_get_sitename() { 354 return apply_filters( 'bp_get_sitename', bp_blogs_get_current_site_property( 'name' ) ); 355 } 356 357 /** 358 * Display the site description. 359 * 360 * @since 2.7.0 361 * 362 * @return string The site name. 363 */ 364 function bp_site_description() { 365 /** 366 * Fires before the site description 367 * 368 * @since 2.7.0 369 */ 370 do_action( 'bp_before_site_description' ); 371 372 echo bp_get_site_description(); 373 374 /** 375 * Fires after the site description 376 * 377 * @since 2.7.0 378 */ 379 do_action( 'bp_after_site_description' ); 380 } 381 382 /** 383 * Get the site description to display. 384 * 385 * @since 2.7.0 386 * 387 * @return string The site description. 388 */ 389 function bp_get_site_description() { 390 return apply_filters( 'bp_get_site_description', bp_blogs_get_current_site_property( 'description' ) ); 391 } 392 393 /** 394 * Display the site's avatar 395 * 396 * @since 2.7.0 397 * 398 * @return string The site's avatar. 399 */ 400 function bp_site_avatar() { 401 echo bp_blogs_get_site_avatar( array( 402 'item_id' => bp_blogs_get_current_site_id(), 403 'type' => 'full', 404 'site_name' => esc_attr( bp_get_sitename() ), 405 ) ); 406 } 407 408 /** 409 * Display the admins in the site's header 410 * 411 * @since 2.7.0 412 * 413 * @return string HTML output 414 */ 415 function bp_site_list_admins() { 416 /** 417 * Fires before the site admins list 418 * 419 * @since 2.7.0 420 */ 421 do_action( 'bp_before_site_list_admins' ); 422 423 echo bp_get_site_list_admins(); 424 425 /** 426 * Fires after the site admins list 427 * 428 * @since 2.7.0 429 */ 430 do_action( 'bp_after_site_list_admins' ); 431 } 432 /** 433 * Get the admins list 434 * 435 * @since 2.7.0 436 * 437 * @return string HTML output 438 */ 439 function bp_get_site_list_admins() { 440 $admins_list = bp_blogs_get_current_site_property( 'admins_list' ); 441 $pre_output = false; 442 443 /** 444 * Use this filter if you need to override the content of the admins list 445 * 446 * @since 2.7.0 447 * 448 * @param string $pre_output The new content. 449 * @param array $site admins 450 */ 451 $pre_output = apply_filters( 'bp_pre_get_site_list_admins', $pre_output, $admins_list ); 452 if ( false !== $pre_output ) { 453 return $pre_output; 454 } 455 456 $output = '<h2>' . esc_html__( 'Site Admins', 'buddypress' ) . '</h2>'; 457 458 if ( ! empty( $admins_list ) ) { 459 $output .= '<ul id="site-admins">'; 460 461 foreach( (array) $admins_list as $admin ) { 462 $output .= '<li>'; 463 464 if ( bp_disable_avatar_uploads() ) { 465 $output .= sprintf( 466 '<a href="%1$s" title="%2$s">%3$s</a>', 467 esc_url( bp_core_get_user_domain( $admin->ID, $admin->user_nicename, $admin->user_login ) ), 468 sprintf( esc_attr__( 'Profile of %s', 'buddypress' ), $admin->display_name ), 469 esc_html( $admin->user_nicename ) 470 ); 471 } else { 472 $output .= sprintf( 473 '<a href="%1$s">%2$s</a>', 474 esc_url( bp_core_get_user_domain( $admin->ID, $admin->user_nicename, $admin->user_login ) ), 475 bp_core_fetch_avatar( array( 476 'item_id' => esc_attr( $admin->ID ), 477 'email' => esc_attr( $admin->user_email ), 478 'alt' => sprintf( esc_attr__( 'Profile picture of %s', 'buddypress' ), $admin->display_name ) 479 ) ) 480 ); 481 } 482 483 $output .= '</li>'; 484 } 485 486 $output .= '</ul>'; 487 } else { 488 $output .= '<span class="activity">' . esc_html__( 'No Admins', 'buddypress' ) . '</span>'; 489 } 490 491 return apply_filters( 'bp_get_site_list_admins', $output, $admins_list ); 492 } 493 494 /** 495 * Display action buttons inside the header of the current site. 496 * 497 * @since 2.7.0 498 * 499 * @return string HTML Output. 500 */ 501 function bp_site_header_actions() { 502 echo join( ' ', bp_get_site_header_actions() ); 503 } 504 505 /** 506 * Checks if there are action buttons to display in the header of the current site. 507 * 508 * @since 2.7.0 509 * 510 * @return bool True if there are buttons. False otherwise. 511 */ 512 function bp_site_has_header_actions() { 513 $buttons = bp_get_site_header_actions(); 514 return ! empty( $buttons ); 515 } 516 517 /** 518 * Returns the action buttons of the current site member in the loop. 519 * 520 * @since 2.7.0 521 * 522 * @return array List of BP Buttons to output. 523 */ 524 function bp_get_site_header_actions() { 525 $bp = buddypress(); 526 527 if ( ! empty( $bp->blogs->site->header_action_buttons ) ) { 528 return $bp->blogs->site->header_action_buttons; 529 } 530 531 $bp->blogs->site->header_action_buttons = array( 532 'visit' => bp_get_blogs_visit_blog_button( array( 'link_href' => bp_blogs_get_current_site_url() ) ), 533 ); 534 535 // Add the join/leave button 536 if ( bp_blogs_current_site_can_subscribe() ) { 537 $bp->blogs->site->header_action_buttons['subscrive_unsubscribe'] = bp_get_site_subscribe_button(); 538 } 539 540 return apply_filters( 'bp_get_site_member_actions', $bp->blogs->site->header_action_buttons ); 541 } 542 543 /** 300 544 * Template tag to allow plugins to add their 301 545 * specific content. 302 546 * … … function bp_site_members_filters() { 344 588 */ 345 589 function bp_get_site_members_filters() { 346 590 $filters = apply_filters( 'bp_get_site_members_filters', array( 591 'last_joined' => __( 'Newest', 'buddypress' ), 592 'first_joined' => __( 'Oldest', 'buddypress' ), 347 593 'active' => __( 'Last Active', 'buddypress' ), 348 'alphabetical' => __( 'Alphabetical', 'buddypress' ) 594 'alphabetical' => __( 'Alphabetical', 'buddypress' ), 349 595 ) ); 350 596 351 597 if ( isset( $filters['alphabetical'] ) && ! bp_is_active( 'xprofile' ) ) { … … function bp_site_members_filters() { 355 601 $output = ''; 356 602 357 603 foreach ( $filters as $kfilter => $vfilter ) { 358 $output .= sprintf( '<option value="%1$s">%2$s</option>', $kfilter, $vfilter) . "\n";604 $output .= sprintf( '<option value="%1$s">%2$s</option>', $kfilter, esc_html( $vfilter ) ) . "\n"; 359 605 } 360 606 361 607 return $output; … … function bp_site_has_members( $args = '' ) { 392 638 $bp->blogs->site->members = new stdClass; 393 639 394 640 $is_contributor = null; 395 if ( bp_is_site_manage_screen( 'members' ) ) { 396 $is_contributor = 0; 641 if ( bp_is_site_manage_members() ) { 642 $involvement_type = bp_action_variable( 1 ); 643 644 if ( 'contributors' === $involvement_type ) { 645 $is_contributor = 1; 646 } elseif ( 'subscribers' === $involvement_type ) { 647 $is_contributor = 0; 648 } 397 649 } 398 650 399 651 $bp->blogs->site->members->loop_args = bp_parse_args( $args, array( 400 652 'blog_id' => bp_blogs_get_current_site_id(), // Only return users recorded for the site. 401 653 'is_contributor' => $is_contributor, // Null to get all site members, 1 for contributors and 0 for subscribers 402 'type' => ' active',654 'type' => 'newest', 403 655 'page' => 1, 404 656 'per_page' => 20, 405 657 'page_arg' => 'site_page', … … function bp_site_has_members( $args = '' ) { 408 660 409 661 // Set up our query construct hook & populate_extras hook 410 662 add_action( 'bp_pre_user_query_construct', 'bp_blogs_set_site_user_query', 10, 1 ); 663 add_action( 'bp_pre_user_query', 'bp_blogs_pre_site_user_query', 10, 1 ); 411 664 add_action( 'bp_user_query_populate_extras', 'bp_blogs_user_query_site_populate_extras', 10, 1 ); 412 665 413 666 if ( ! empty( $GLOBALS['members_template'] ) ) { … … function bp_site_has_members( $args = '' ) { 425 678 426 679 // Remove hooks 427 680 remove_action( 'bp_pre_user_query_construct', 'bp_blogs_set_site_user_query', 10, 1 ); 681 remove_action( 'bp_pre_user_query', 'bp_blogs_pre_site_user_query', 10, 1 ); 428 682 remove_action( 'bp_user_query_populate_extras', 'bp_blogs_user_query_site_populate_extras', 10, 1 ); 429 683 430 684 // Return the has members bool. … … function bp_site_has_member_actions() { 744 998 $screen = 'members'; 745 999 746 1000 // Manage actions for the manage-members screen 747 if ( bp_is_site_manage_ screen( 'members') ) {1001 if ( bp_is_site_manage_members() ) { 748 1002 $screen = 'manage-members'; 749 1003 $involvement = (int) $members_template->member->is_contributor; 750 1004 751 $members_template->member->action_buttons['remove'] = bp_get_site_manage_member_button( $user_id, $involvement ); 1005 $members_template->member->action_buttons = array( 1006 'involve' => bp_get_site_involvement_member_button(), 1007 'remove' => bp_get_site_remove_member_button(), 1008 ); 752 1009 753 1010 // Regular actions for members screen. 754 1011 } else { … … function bp_site_has_member_actions() { 761 1018 } 762 1019 763 1020 /** 764 * Output the button to manage the member of the site.1021 * Output the button to remove the member of the site. 765 1022 * 766 1023 * @see BP_Button for a the description of arguments and return 767 1024 * value. 768 1025 * 769 1026 * @since 2.7.0 770 *771 * @param int $user_id The ID of the user to manage772 * @param int $involvement The level of involvement of the user (Only Subscriber for now).773 1027 */ 774 function bp_site_ manage_member_button( $user_id = 0, $involvement = 0) {775 echo bp_get_site_ manage_member_button( $user_id, $involvement);1028 function bp_site_remove_member_button() { 1029 echo bp_get_site_remove_member_button(); 776 1030 } 777 1031 778 1032 /** 779 * Get the arguments of the site's communitybutton.1033 * Get the arguments of the remove site member button. 780 1034 * 781 1035 * @since 2.7.0 782 *783 * @param int $user_id The ID of the user to manage784 * @param int $involvement The level of involvement of the user (Only Subscriber for now).785 1036 */ 786 function bp_get_site_manage_member_button_args( $user_id, $involvement ) { 787 if ( empty( $user_id ) ) { 788 return; 1037 function bp_get_site_remove_member_button_args() { 1038 $members_template = buddypress()->blogs->site->members->template; 1039 1040 if ( empty( $members_template->member ) || ! empty( $members_template->member->is_admin ) ) { 1041 return false; 789 1042 } 790 1043 791 1044 $button = array( 1045 'id' => 'remove_member', 792 1046 'component' => 'blogs', 793 1047 'must_be_logged_in' => true, 794 'block_self' => false, 1048 'block_self' => true, 1049 'wrapper_class' => 'site-button remove', 1050 'link_href' => wp_nonce_url( bp_blogs_get_site_community_url() . 'manage/members/remove/' . $members_template->member->id . '/', 'site_remove_member' ), 1051 'link_class' => 'site-button remove confirm', 1052 'link_text' => __( 'Remove', 'buddypress' ), 1053 ); 1054 1055 /** 1056 * Filter here to edit button arguments. 1057 * 1058 * @since 2.7.0 1059 * 1060 * @param array $button The Button arguments. 1061 * @param object $value The site member object. 1062 */ 1063 return apply_filters( 'bp_get_site_remove_member_button_args', $button, $members_template->member ); 1064 } 1065 /** 1066 * Return button to remove the member from the site 1067 * 1068 * @see BP_Button for a the description of arguments and return 1069 * value. 1070 * 1071 * @since 2.7.0 1072 * @return string The HTML for the Manage button. 1073 */ 1074 function bp_get_site_remove_member_button() { 1075 // Make sure the block self button will do its job. 1076 add_filter( 'bp_get_member_user_id', 'bp_get_site_member_user_id' ); 1077 1078 $button = bp_get_button( bp_get_site_remove_member_button_args() ); 1079 1080 remove_filter( 'bp_get_member_user_id', 'bp_get_site_member_user_id' ); 1081 1082 return $button; 1083 } 1084 1085 /** 1086 * Output the button to promote the member to contributor or demote him to subscriber. 1087 * 1088 * @see BP_Button for a the description of arguments and return 1089 * value. 1090 * 1091 * @since 2.7.0 1092 */ 1093 function bp_site_involvement_member_button() { 1094 echo bp_get_site_involvement_member_button(); 1095 } 1096 1097 /** 1098 * Get the arguments of the site member involvement button. 1099 * 1100 * @since 2.7.0 1101 */ 1102 function bp_get_site_involvement_member_button_args() { 1103 $members_template = buddypress()->blogs->site->members->template; 1104 1105 if ( empty( $members_template->member ) || ! empty( $members_template->member->is_admin ) ) { 1106 return false; 1107 } 1108 1109 $start_button = array( 1110 'id' => 'toggle_involvment', 1111 'component' => 'blogs', 1112 'must_be_logged_in' => true, 1113 'block_self' => true, 795 1114 ); 796 1115 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; 1116 if ( 1 === (int) $members_template->member->is_contributor ) { 1117 $end_button = array( 1118 'wrapper_class' => 'site-button demote', 1119 'link_href' => wp_nonce_url( bp_blogs_get_site_community_url() . 'manage/members/demote/' . $members_template->member->id . '/', 'site_demote_member' ), 1120 'link_class' => 'site-button demote confirm', 1121 'link_text' => __( 'Demote to Subscriber', 'buddypress' ), 1122 ); 1123 } else { 1124 $end_button = array( 1125 'wrapper_class' => 'site-button promote', 1126 'link_href' => wp_nonce_url( bp_blogs_get_site_community_url() . 'manage/members/promote/' . $members_template->member->id . '/', 'site_promote_member' ), 1127 'link_class' => 'site-button promote', 1128 'link_text' => __( 'Promote to Contributor', 'buddypress' ), 1129 ); 812 1130 } 813 1131 814 return apply_filters( 'bp_get_site_manage_member_button_args', $button ); 1132 $button = array_merge( $start_button, $end_button ); 1133 1134 /** 1135 * Filter here to edit button arguments. 1136 * 1137 * @since 2.7.0 1138 * 1139 * @param array $button The Button arguments. 1140 * @param object $value The site member object. 1141 */ 1142 return apply_filters( 'bp_get_site_involvement_member_button_args', $button, $members_template->member ); 815 1143 } 816 1144 /** 817 * Return button to manage the member of the site1145 * Return button to promote or demote the member of the site. 818 1146 * 819 1147 * @see BP_Button for a the description of arguments and return 820 1148 * value. 821 1149 * 822 1150 * @since 2.7.0 1151 * @return string The HTML for the button. 1152 */ 1153 function bp_get_site_involvement_member_button() { 1154 // Make sure the block self button will do its job. 1155 add_filter( 'bp_get_member_user_id', 'bp_get_site_member_user_id' ); 1156 1157 $button = bp_get_button( bp_get_site_involvement_member_button_args() ); 1158 1159 remove_filter( 'bp_get_member_user_id', 'bp_get_site_member_user_id' ); 1160 1161 return $button; 1162 } 1163 1164 /** 1165 * Output Links to filter members according to their involvement levels. 1166 * 1167 * @since 2.7.0 1168 * 1169 * @return string HTML output. 1170 */ 1171 function bp_site_manage_members_subnav() { 1172 echo join( "\n", bp_get_site_manage_members_subnav() ); 1173 } 1174 1175 /** 1176 * Get the links to filter members according to their involvement levels. 823 1177 * 824 * @ param int $user_id The ID of the user to manage825 * @param int $involvement The level of involvement of the user (Only Subscriber for now).826 * @return string The HTML for the Manage button.1178 * @since 2.7.0 1179 * 1180 * @return array The list of tabs. 827 1181 */ 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 ) ); 1182 function bp_get_site_manage_members_subnav() { 1183 /** 1184 * Filter here to disable/edit the links 1185 * 1186 * @since 2.7.0 1187 * 1188 * @param array The list of BuddyPress involvement levels. 1189 */ 1190 $involvement_types = apply_filters( 'bp_get_site_involvement_types', array( 1191 'all' => __( 'All Members', 'buddypress' ), 1192 'contributors' => __( 'Contributors', 'buddypress' ), 1193 'subscribers' => __( 'Subscribers', 'buddypress' ), 1194 ) ); 1195 1196 $output = array(); 1197 1198 if ( empty( $involvement_types ) ) { 1199 return $output; 1200 } 1201 1202 $current_action = bp_action_variable( 1 ); 1203 1204 foreach ( $involvement_types as $type => $label ) { 1205 $selected = ''; 1206 $link = trailingslashit( bp_blogs_get_site_community_url() . 'manage/members' ); 1207 1208 if ( ! $current_action && 'all' === $type || $current_action === $type ) { 1209 $selected = ' current selected'; 1210 } 1211 1212 1213 if ( 'all' !== $type ) { 1214 $link .= trailingslashit( $type ); 1215 } 1216 1217 $output[ $type ] = sprintf( '<li class="site-members-%1$s%2$s"><a href="%3$s" class="no-ajax">%4$s</a></li>', 1218 esc_attr( $type ), 1219 $selected, 1220 esc_url( $link ), 1221 esc_html( $label ) 1222 ); 1223 } 1224 1225 /** 1226 * Filter here to edit the output 1227 * 1228 * @since 2.7.0 1229 * 1230 * @param array An associative array containing the links to filter the members 1231 * according to their involvement levels. 1232 */ 1233 return apply_filters( 'bp_get_site_manage_members_subnav', $output, $involvement_types ); 830 1234 } 1235 1236 /** 1237 * Get the site name to edit inside the settings screen. 1238 * 1239 * @since 2.7.0 1240 * 1241 * @return string The site name. 1242 */ 1243 function bp_get_site_name_editable() { 1244 return apply_filters( 'bp_get_site_name_editable', bp_blogs_get_current_site_property( 'name' ) ); 1245 } 1246 1247 /** 1248 * Get the site description to edit inside the settings screen. 1249 * 1250 * @since 2.7.0 1251 * 1252 * @return string The site description. 1253 */ 1254 function bp_get_site_description_editable() { 1255 return apply_filters( 'bp_get_site_description_editable', bp_blogs_get_current_site_property( 'description' ) ); 1256 } 1257 1258 /** 1259 * Can users subscribe to this site? 1260 * 1261 * @since 2.7.0 1262 * 1263 * @return bool True if users can subscribe. False otherwise. 1264 */ 1265 function bp_site_can_subscribe() { 1266 return bp_blogs_current_site_can_subscribe(); 1267 } 1268 1269 /** 1270 * Output custom setting fields in the site's settings screen. 1271 * 1272 * @see bp_blogs_register_site_settings() to register your custom settings. 1273 * NB: make sure to use a name attribute looking like this `bp_site[option_name]` 1274 * for the input used in your display function. 1275 * 1276 * @since 2.7.0 1277 * 1278 * @return string HTML output. 1279 */ 1280 function bp_site_plugin_settings() { 1281 $plugin_settings = bp_blogs_get_site_settings(); 1282 1283 if ( empty( $plugin_settings ) ) { 1284 return; 1285 } 1286 1287 foreach ( $plugin_settings as $plugin_setting ) { 1288 if ( empty( $plugin_setting->display_function ) || ! is_callable( $plugin_setting->display_function ) ) { 1289 continue; 1290 } 1291 1292 add_action( 'bp_site_plugin_settings_output', $plugin_setting->display_function ); 1293 } 1294 1295 printf( "<fieldset class=\"site-other-settings\">\n<legend>%s</legend>\n", esc_html__( 'Other settings', 'buddypress' ) ); 1296 1297 do_action( 'bp_site_plugin_settings_output' ); 1298 1299 print( "\n<fieldset>\n" ); 1300 } -
src/bp-core/admin/bp-core-admin-settings.php
diff --git src/bp-core/admin/bp-core-admin-settings.php src/bp-core/admin/bp-core-admin-settings.php index d17ff83..a79335c 100644
function bp_admin_setting_callback_blogs_section() { } 262 262 * Disable front-end site subscriptions. 263 263 * 264 264 * @since 2.7.0 265 *266 265 */ 267 266 function bp_admin_setting_callback_blog_subscriptions() { 268 267 ?> … … function bp_admin_setting_callback_blog_subscriptions() { 273 272 <?php 274 273 } 275 274 275 /** 276 * Disable the site's avatar uploads 277 * 278 * @since 2.7.0 279 */ 280 function bp_admin_setting_callback_blog_avatar_uploads() { 281 ?> 282 283 <input id="bp-disable-site-avatar-uploads" name="bp-disable-site-avatar-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_site_avatar_uploads() ); ?> /> 284 <label for="bp-disable-site-avatar-uploads"><?php _e( 'Allow customizable avatars for sites', 'buddypress' ); ?></label> 285 <?php 286 } 287 276 288 /** Settings Page *************************************************************/ 277 289 278 290 /** … … function bp_core_admin_settings_save() { 341 353 'bp-disable-group-cover-image-uploads', 342 354 'bp_disable_blogforum_comments', 343 355 'bp-disable-site-subscriptions', 356 'bp-disable-site-avatar-uploads', 344 357 'bp-disable-profile-sync', 345 358 'bp_restrict_group_creation', 346 359 'hide-loggedout-adminbar', -
src/bp-core/bp-core-avatars.php
diff --git src/bp-core/bp-core-avatars.php src/bp-core/bp-core-avatars.php index f03b9d1..b542544 100644
function bp_core_fetch_avatar( $args = '' ) { 566 566 567 567 // By default, Gravatar is not pinged for groups. 568 568 if ( null === $params['no_grav'] ) { 569 $params['no_grav'] = 'group' === $params['object'] ;569 $params['no_grav'] = 'group' === $params['object'] || 'blog' === $params['object']; 570 570 } 571 571 572 572 /** -
src/bp-core/bp-core-options.php
diff --git src/bp-core/bp-core-options.php src/bp-core/bp-core-options.php index cb73d93..cf974dd 100644
function bp_get_default_options() { 73 73 // Disallow members to subscribe to sites. 74 74 'bp-disable-site-subscriptions' => false, 75 75 76 // Blog Profile Photos 77 'bp-disable-site-avatar-uploads' => false, 78 76 79 // The ID for the current theme package. 77 80 '_bp_theme_package_id' => 'legacy', 78 81 … … function bp_disable_site_subscriptions( $default = false ) { 721 724 } 722 725 723 726 /** 727 * Are site avatars disabled? 728 * 729 * @since 2.7.0 730 * 731 * @param bool $default Optional. Fallback value if not found in the database. 732 * Defaults: False. 733 * @return bool True if site avatar uploads are disabled, otherwise false. 734 */ 735 function bp_disable_site_avatar_uploads( $default = false ) { 736 /** 737 * Filters whether or not members are able to upload site avatars. 738 * 739 * @since BuddyPress (2.4.0) 740 * 741 * @param bool $disabled Whether or not members are able to upload their site avatars. 742 * @param bool $default Default value passed to the function. 743 */ 744 return (bool) apply_filters( 'bp_disable_site_avatar_uploads', (bool) bp_get_option( 'bp-disable-site-avatar-uploads', $default ) ); 745 } 746 747 /** 724 748 * Is group creation turned off? 725 749 * 726 750 * @since 1.6.0 -
src/bp-core/bp-core-template.php
diff --git src/bp-core/bp-core-template.php src/bp-core/bp-core-template.php index 8ddfea6..3fbe1a5 100644
function bp_is_user_groups_activity() { 2356 2356 } 2357 2357 2358 2358 /** 2359 * Is the current page a user's Blogs activity stream? 2360 * 2361 * Eg http://example.com/members/joe/activity/blogs/ 2362 * 2363 * @since 2.7.0 2364 * 2365 * @return bool True if the current page is a user's Groups activity stream. 2366 */ 2367 function bp_is_user_blogs_activity() { 2368 2369 if ( ! bp_is_active( 'blogs' ) ) { 2370 return false; 2371 } 2372 2373 $slug = 'blogs'; 2374 if ( bp_get_blogs_slug() ) { 2375 $slug = bp_get_blogs_slug(); 2376 } 2377 2378 if ( bp_is_user_activity() && bp_is_current_action( $slug ) ) { 2379 return true; 2380 } 2381 2382 return false; 2383 } 2384 2385 /** 2359 2386 * Is the current page part of a user's extended profile? 2360 2387 * 2361 2388 * Eg http://example.com/members/joe/profile/ (or a subpage thereof). … … function bp_is_site_manage_screen( $slug = '' ) { 2997 3024 } 2998 3025 2999 3026 /** 3027 * Is the current page a the manage members screen? 3028 * 3029 * @since 2.7.0 3030 * 3031 * @return bool 3032 */ 3033 function bp_is_site_manage_members() { 3034 return bp_is_site_manage_screen( 'members' ); 3035 } 3036 3037 /** 3038 * Is the current page a the manage settings screen? 3039 * 3040 * @since 2.7.0 3041 * 3042 * @return bool 3043 */ 3044 function bp_is_site_manage_settings() { 3045 return bp_is_site_manage_screen( 'settings' ); 3046 } 3047 3048 /** 3000 3049 * What is the current site manage action? 3001 3050 * 3002 3051 * @since 2.7.0 -
src/bp-core/classes/class-bp-admin.php
diff --git src/bp-core/classes/class-bp-admin.php src/bp-core/classes/class-bp-admin.php index be89886..4e65e93 100644
class BP_Admin { 478 478 // Add the main section. 479 479 add_settings_section( 'bp_blogs', __( 'Sites Settings', 'buddypress' ), 'bp_admin_setting_callback_blogs_section', 'buddypress' ); 480 480 481 // Activity commenting on blog and forum posts.481 // Disable site subscriptions. 482 482 add_settings_field( 'bp-disable-site-subscriptions', __( 'Site subscriptions.', 'buddypress' ), 'bp_admin_setting_callback_blog_subscriptions', 'buddypress', 'bp_blogs' ); 483 483 register_setting( 'buddypress', 'bp-disable-site-subscriptions', 'intval' ); 484 485 // Disable site avatars 486 add_settings_field( 'bp-disable-site-avatar-uploads', __( 'Site Photo Uploads', 'buddypress' ), 'bp_admin_setting_callback_blog_avatar_uploads', 'buddypress', 'bp_blogs' ); 487 register_setting( 'buddypress', 'bp-disable-site-avatar-uploads', 'intval' ); 484 488 } 485 489 } 486 490 -
src/bp-core/images/mystery-site.svg
diff --git src/bp-core/images/mystery-site.svg src/bp-core/images/mystery-site.svg index e69de29..47bfb8b 100644
1 <?xml version="1.0" encoding="utf-8"?> 2 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 3 <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" height="20" viewBox="0 0 20 20"> 4 <rect x="0" y="0" width="20" height="20" fill="#fff"/><g fill="#ccc"><g><path d="M18 14v-10c0-0.55-0.45-1-1-1h-14c-0.55 0-1 0.45-1 1v10c0 0.55 0.45 1 1 1h14c0.55 0 1-0.45 1-1zM10 6c2.3 0 4.4 1.14 6 3-1.6 1.86-3.7 3-6 3s-4.4-1.14-6-3c1.6-1.86 3.7-3 6-3zM12 9c0-1.1-0.9-2-2-2s-2 0.9-2 2 0.9 2 2 2 2-0.9 2-2zM14 17h3v1h-14v-1h3v-1h8v1z"></path></g></g> 5 </svg> -
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 915d1c1..703badd 100644
function bp_legacy_theme_ajax_querystring( $query_string, $object ) { 681 681 } 682 682 683 683 if ( ! empty( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) { 684 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 685 684 686 if ( 'personal' == $_BP_COOKIE['bp-' . $object . '-scope'] ) { 685 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();686 687 $qs[] = 'user_id=' . $user_id; 688 689 // Blogs directory, list sites the user subscribed to 690 } elseif ( 'blogs' === $object && 'subscriptions' === $_BP_COOKIE['bp-' . $object . '-scope'] ) { 691 $qs[] = 'user_id=' . $user_id; 692 $qs[] = 'is_contributor=0'; 687 693 } 688 694 689 695 // Activity stream scope only on activity directory. -
src/bp-templates/bp-legacy/buddypress/activity/index.php
diff --git src/bp-templates/bp-legacy/buddypress/activity/index.php src/bp-templates/bp-legacy/buddypress/activity/index.php index f6f6805..fd433b1 100644
do_action( 'bp_before_directory_activity' ); ?> 124 124 125 125 <?php endif; ?> 126 126 127 <?php if ( bp_is_active( 'blogs' ) && bp_get_total_blog_count_for_user( bp_loggedin_user_id() ) ) : ?> 128 129 <li id="activity-blogs"><a href="<?php echo bp_loggedin_user_domain() . bp_get_activity_slug() . '/' . bp_get_blogs_slug() . '/'; ?>" title="<?php esc_attr_e( 'The activity of sites I contribute to.', 'buddypress' ); ?>"><?php printf( __( 'My Sites <span>%s</span>', 'buddypress' ), bp_get_total_blog_count_for_user( bp_loggedin_user_id() ) ); ?></a></li> 130 131 <?php endif; ?> 132 127 133 <?php endif; ?> 128 134 129 135 <?php -
src/bp-templates/bp-legacy/buddypress/blogs/index.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/index.php src/bp-templates/bp-legacy/buddypress/blogs/index.php index c8460d9..f8272d3 100644
do_action( 'bp_before_directory_blogs_page' ); ?> 58 58 59 59 <?php endif; ?> 60 60 61 <?php if ( bp_blogs_is_site_subscriptions_active() && is_user_logged_in() && bp_get_total_site_subscriptions_for_user( bp_loggedin_user_id() ) ) : ?> 62 63 <li id="blogs-subscriptions"><a href="<?php echo esc_url( bp_loggedin_user_domain() . bp_get_blogs_slug() . '/my-subscriptions/' ); ?>"><?php printf( __( 'My Subscriptions %s', 'buddypress' ), '<span>' . bp_get_total_site_subscriptions_for_user( bp_loggedin_user_id() ) . '</span>' ); ?></a></li> 64 65 <?php endif; ?> 66 61 67 <?php 62 68 63 69 /** -
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 54384e0..c72e2f6 100644
defined( 'ABSPATH' ) or die; ?> 13 13 14 14 <div id="buddypress"> 15 15 16 <?php do_action( 'template_notices' ); ?> 16 <div id="item-header" role="complementary"> 17 18 <?php bp_get_template_part( 'blogs/single/site-header' ); ?> 19 20 </div><!-- #item-header --> 17 21 18 22 <div id="item-nav"> 19 23 <div class="item-list-tabs no-ajax" id="object-nav" role="navigation"> -
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 e0f31de..ec83266 100644
defined( 'ABSPATH' ) or die; ?> 20 20 </div> 21 21 22 22 <?php switch ( bp_site_get_manage_action() ) : 23 case 'settings' : 24 bp_get_template_part( 'blogs/single/manage/settings' ); 25 break; 23 26 case 'members' : 24 27 bp_get_template_part( 'blogs/single/members' ); 25 28 break; -
src/bp-templates/bp-legacy/buddypress/blogs/single/manage/edit-avatar.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/manage/edit-avatar.php src/bp-templates/bp-legacy/buddypress/blogs/single/manage/edit-avatar.php index e69de29..56ee23c 100644
1 <?php 2 /** 3 * BuddyPress Site Edit Avatar 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; ?> -
src/bp-templates/bp-legacy/buddypress/blogs/single/manage/edit-cover-image.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/manage/edit-cover-image.php src/bp-templates/bp-legacy/buddypress/blogs/single/manage/edit-cover-image.php index e69de29..a77fc01 100644
1 <?php 2 /** 3 * BuddyPress Site Edit Cover Image 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 No newline at end of file -
src/bp-templates/bp-legacy/buddypress/blogs/single/manage/settings.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/manage/settings.php src/bp-templates/bp-legacy/buddypress/blogs/single/manage/settings.php index e69de29..4773622 100644
1 <?php 2 /** 3 * BuddyPress Site Manage settings 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" class="standard-form" id="settings-form"> 15 16 <fieldset class="site-general-settings"> 17 18 <legend><?php esc_html_e( 'General', 'buddypress' ); ?></legend> 19 20 <label for="site_name"><?php esc_html_e( 'Site Name (required)', 'buddypress' ); ?></label> 21 <input type="text" name="bp_site[blogname]" id="site_name" value="<?php echo esc_attr( bp_get_site_name_editable() ); ?>" class="settings-input" /> 22 23 <label for="site_description"><?php esc_html_e( 'Site Description', 'buddypress' ); ?></label> 24 <input type="text" name="bp_site[blogdescription]" id="site_description" value="<?php echo esc_attr( bp_get_site_description_editable() ); ?>" class="settings-input" /> 25 26 <label for="site_public"> 27 <input type="checkbox" name="bp_site[blog_public]" id="site_public" value="1" <?php checked( true, bp_site_is_public() ); ?> /> 28 <?php esc_html_e( 'Public site', 'buddypress' ); ?> 29 </label> 30 <p class="description"><?php esc_html_e( 'If you choose to deactivate this option, post types tracking and subscriptions will not be available for your site.', 'buddypress' ); ?></p> 31 32 <?php if ( bp_site_is_public() ) : ?> 33 <label for="site_disallow_subscriptions"> 34 <input type="checkbox" name="bp_site[disallow_subscriptions]" id="site_disallow_subscriptions" value="1" <?php checked( true, ! bp_site_can_subscribe() ); ?> /> 35 <?php esc_html_e( 'Disallow subscriptions', 'buddypress' ); ?> 36 </label> 37 <p class="description"><?php esc_html_e( 'Subscriptions are only available for public sites', 'buddypress' ); ?></p> 38 <?php endif ; ?> 39 40 </fieldset> 41 42 <?php bp_site_plugin_settings(); ?> 43 44 <div class="submit"> 45 <input type="submit" name="bp_site[submit]" value="<?php esc_attr_e( 'Save Changes', 'buddypress' ); ?>" id="submit" class="auto" /> 46 </div> 47 48 <?php wp_nonce_field( 'site_manage_settings' ); ?> 49 50 </form> -
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 a6002c3..d47ea9a 100644
defined( 'ABSPATH' ) or die; ?> 15 15 16 16 <div class="item-list-tabs" id="subnav" role="navigation"> 17 17 <ul> 18 <?php if ( bp_is_site_manage_members() ) : 19 20 bp_site_manage_members_subnav(); 21 22 endif; ?> 23 18 24 <li id="site_members-order-select" class="last filter"> 19 25 <label for="site_members-order-by"><?php _e( 'Order By:', 'buddypress' ); ?></label> 20 26 <select id="site_members-order-by"> -
src/bp-templates/bp-legacy/buddypress/blogs/single/site-header.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/site-header.php src/bp-templates/bp-legacy/buddypress/blogs/single/site-header.php index e69de29..ae99210 100644
1 <?php 2 /** 3 * BuddyPress Site Manage settings 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="item-actions"> 15 16 <?php if ( bp_site_has_access() ) : ?> 17 18 <?php bp_site_list_admins(); 19 20 endif; ?> 21 22 </div><!-- #item-actions --> 23 24 <?php if ( ! bp_disable_site_avatar_uploads() ) : ?> 25 <div id="item-header-avatar"> 26 <a href="<?php echo esc_url( bp_blogs_get_site_community_url() ); ?>" title="<?php echo esc_attr( bp_get_sitename() ); ?>"> 27 28 <?php bp_site_avatar(); ?> 29 30 </a> 31 </div><!-- #item-header-avatar --> 32 <?php endif; ?> 33 34 <div id="item-header-content"> 35 36 <div id="item-meta"> 37 38 <?php bp_site_description(); ?> 39 40 <?php if ( bp_site_has_header_actions() ) : ?> 41 <div id="item-buttons"> 42 43 <?php bp_site_header_actions() ;?> 44 45 </div><!-- #item-buttons --> 46 <?php endif; ?> 47 48 </div> 49 50 </div><!-- #item-header-content --> 51 52 <?php 53 54 /** This action is documented in bp-templates/bp-legacy/buddypress/activity/index.php */ 55 do_action( 'template_notices' ); ?> -
src/bp-templates/bp-legacy/buddypress/members/single/activity.php
diff --git src/bp-templates/bp-legacy/buddypress/members/single/activity.php src/bp-templates/bp-legacy/buddypress/members/single/activity.php index b80ec02..11b17a3 100644
34 34 </ul> 35 35 </div><!-- .item-list-tabs --> 36 36 37 <?php if ( bp_is_user_blogs_activity() ) : 38 39 bp_get_template_part( 'members/single/blogs/site-tabs' ); 40 41 endif; ?> 42 37 43 <?php 38 44 39 45 /** -
src/bp-templates/bp-legacy/buddypress/members/single/blogs.php
diff --git src/bp-templates/bp-legacy/buddypress/members/single/blogs.php src/bp-templates/bp-legacy/buddypress/members/single/blogs.php index bad9c4b..1d5a257 100644
8 8 9 9 ?> 10 10 11 <div class="item-list-tabs " id="subnav" role="navigation">11 <div class="item-list-tabs no-ajax" id="subnav" role="navigation"> 12 12 <ul> 13 13 14 14 <?php bp_get_options_nav(); ?> … … 39 39 switch ( bp_current_action() ) : 40 40 41 41 // Home/My Blogs 42 case 'my-sites' : 42 case 'my-sites' : 43 case 'my-subscriptions' : 43 44 44 45 /** 45 46 * Fires before the display of member blogs content. -
src/bp-templates/bp-legacy/buddypress/members/single/blogs/site-tabs.php
diff --git src/bp-templates/bp-legacy/buddypress/members/single/blogs/site-tabs.php src/bp-templates/bp-legacy/buddypress/members/single/blogs/site-tabs.php index e69de29..6d24476 100644
1 <?php 2 /** 3 * BuddyPress - Site Tabs 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="subsubnav" role="navigation"> 15 <ul> 16 17 <?php bp_blogs_member_tabs(); ?> 18 19 </ul> 20 </div><!-- .item-list-tabs --> -
tests/phpunit/testcases/blogs/site.php
diff --git tests/phpunit/testcases/blogs/site.php tests/phpunit/testcases/blogs/site.php index e42cc22..9b36b4f 100644
class BP_Tests_Blogs_Site_TestCases extends BP_UnitTestCase { 35 35 } 36 36 37 37 $this->set_current_user( $this->current_user ); 38 39 /** 40 * Workaround till #7150 is fixed 41 * 42 * @see https://buddypress.trac.wordpress.org/ticket/7150 43 */ 44 $bp_pages = array_keys( bp_get_option( 'bp-pages' ) ); 45 if ( ! isset( $bp_pages['blogs'] ) && bp_is_active( 'blogs' ) ) { 46 bp_core_add_root_component( 'blogs' ); 47 bp_core_create_root_component_page(); 48 } 49 50 add_action( 'bp_init', array( $this, 'set_early_setting' ) ); 51 add_action( 'bp_blogs_setup_site_globals', array( $this, 'set_site_settings' ) ); 38 52 } 39 53 40 54 public function tearDown() { 41 55 parent::tearDown(); 42 56 43 57 $this->set_current_user( $this->old_user ); 58 59 remove_action( 'bp_init', array( $this, 'set_early_setting' ) ); 60 remove_action( 'bp_blogs_setup_site_globals', array( $this, 'set_site_settings' ) ); 44 61 } 45 62 46 63 /** … … class BP_Tests_Blogs_Site_TestCases extends BP_UnitTestCase { 76 93 remove_filter( 'bp_blogs_use_bp_site_query', '__return_false' ); 77 94 } 78 95 } 96 97 public function set_early_setting() { 98 bp_blogs_register_site_settings( 'foobar', array( 99 'display_function' => 'foobar_display', 100 'sanitize_function' => 'foobar_sanitize', 101 ) ); 102 } 103 104 public function set_site_settings() { 105 bp_blogs_register_site_settings( 'barfoo', array( 106 'display_function' => 'barfoo_display', 107 'sanitize_function' => 'barfoo_sanitize', 108 ) ); 109 110 bp_blogs_register_site_settings( 'name', array( 111 'display_function' => 'name_display', 112 'sanitize_function' => 'name_sanitize', 113 ) ); 114 } 115 116 /** 117 * @group site_settings 118 */ 119 public function test_bp_blogs_register_site_settings() { 120 $bp = buddypress(); 121 122 $single_site = bp_blogs_get_site( 'foobar' ); 123 124 $this->go_to( bp_blogs_get_site_community_url( $single_site->slug ) ); 125 126 $this->assertNotEmpty( $bp->blogs->site->settings['barfoo'] ); 127 $this->assertTrue( 1 === count( $bp->blogs->site->settings ) ); 128 } 129 130 /** 131 * @group site_settings 132 */ 133 public function test_bp_blogs_get_site_settings() { 134 $bp = buddypress(); 135 136 $this->go_to( bp_blogs_get_site_community_url( 'barfoo' ) ); 137 138 $this->assertNotEmpty( bp_blogs_get_site_settings( 'barfoo' ) ); 139 140 $bp->blogs->site->settings['barfoo']->display_function = ''; 141 142 $this->assertEmpty( bp_blogs_get_site_settings( 'barfoo' ) ); 143 } 144 145 /** 146 * @group subscriptions 147 */ 148 public function test_bp_blogs_site_subscribe() { 149 $bp = buddypress(); 150 151 $u = $this->factory->user->create(); 152 153 // Trying to subscribe to a private site 154 $result = bp_blogs_site_subscribe( $u, 'tazfoo' ); 155 $this->assertTrue( 'error' === $result['type'] ); 156 157 // Trying to subscribe to a site when subscription are disabled 158 add_filter( 'bp_disable_site_subscriptions', '__return_true' ); 159 160 $result = bp_blogs_site_subscribe( $u, 'barfoo' ); 161 $this->assertTrue( 'error' === $result['type'] ); 162 163 remove_filter( 'bp_disable_site_subscriptions', '__return_true' ); 164 165 // Trying to subscribe to a site when it disabled subscriptions 166 bp_blogs_update_blogmeta( $this->sites['bar']['id'], 'disallow_subscriptions', 1 ); 167 168 $result = bp_blogs_site_subscribe( $u, 'barfoo' ); 169 $this->assertTrue( 'error' === $result['type'] ); 170 171 bp_blogs_delete_blogmeta( $this->sites['bar']['id'], 'disallow_subscriptions' ); 172 173 // Finally subscribe to foobar! 174 $result = bp_blogs_site_subscribe( $u, 'foobar' ); 175 $this->assertFalse( 'error' === $result['type'] ); 176 177 $user_blogs = BP_Blogs_Blog::get_user_blog( $u, $this->sites['foo']['id'] ); 178 $this->assertInternalType( 'integer', $user_blogs ); 179 } 180 181 /** 182 * @group subscriptions 183 */ 184 public function test_bp_blogs_site_unsubscribe() { 185 $bp = buddypress(); 186 187 $u = $this->factory->user->create(); 188 189 // Never subscribed! 190 $result = bp_blogs_site_unsubscribe( $u, 'foobar' ); 191 $this->assertTrue( 'error' === $result['type'] ); 192 193 add_user_to_blog( $this->sites['bar']['id'], $u, 'subscriber' ); 194 195 $user_blogs = BP_Blogs_Blog::get_user_blog( $u, $this->sites['bar']['id'] ); 196 $this->assertInternalType( 'integer', $user_blogs ); 197 198 // Finally unsubscribe to barfoo! 199 $result = bp_blogs_site_unsubscribe( $u, 'barfoo' ); 200 $this->assertFalse( 'error' === $result['type'] ); 201 202 $user_blogs = BP_Blogs_Blog::get_user_blog( $u, $this->sites['bar']['id'] ); 203 $this->assertEmpty( $user_blogs ); 204 } 79 205 } -
tests/phpunit/testcases/blogs/template.php
diff --git tests/phpunit/testcases/blogs/template.php tests/phpunit/testcases/blogs/template.php index 987c2a4..c032c90 100644
class BP_Tests_Blogs_Template extends BP_UnitTestCase { 384 384 $blogs_template->blog->blog_id = get_current_blog_id(); 385 385 $blogs_template->blog->admin_user_id = $user->ID; 386 386 $blogs_template->blog->admin_user_email = $user->user_email; 387 $blogs_template->blog->name = 'Site name'; 387 388 388 389 $actual = bp_get_blog_avatar( array( 389 390 'title' => 'Foo', … … class BP_Tests_Blogs_Template extends BP_UnitTestCase { 401 402 /** 402 403 * @ticket BP6519 403 404 */ 404 public function test_bp_blog_get_avatar_title_attribute_should_default_to_ user_displayname() {405 public function test_bp_blog_get_avatar_title_attribute_should_default_to_site_name() { 405 406 global $blogs_template; 406 407 407 408 if ( isset( $blogs_template ) ) { … … class BP_Tests_Blogs_Template extends BP_UnitTestCase { 415 416 $blogs_template->blog->blog_id = get_current_blog_id(); 416 417 $blogs_template->blog->admin_user_id = $user->ID; 417 418 $blogs_template->blog->admin_user_email = $user->user_email; 419 $blogs_template->blog->name = 'Site name'; 418 420 419 421 $actual = bp_get_blog_avatar(); 420 422 … … class BP_Tests_Blogs_Template extends BP_UnitTestCase { 424 426 unset( $blogs_template ); 425 427 } 426 428 427 $this->assertContains( 'title=" Profile picture of site author ' . bp_core_get_user_displayname( $user->ID ) . '"', $actual );429 $this->assertContains( 'title="Site Photo of Site name"', $actual ); 428 430 } 429 431 }