Ticket #6026: 6026.02.patch
File 6026.02.patch, 163.3 KB (added by , 10 years ago) |
---|
-
src/bp-activity/bp-activity-loader.php
diff --git src/bp-activity/bp-activity-loader.php src/bp-activity/bp-activity-loader.php index 8d4277b..a72f0e5 100644
class BP_Activity_Component extends BP_Component { 225 225 ); 226 226 } 227 227 228 // Additional menu if blogs is active 229 if ( bp_is_active( 'blogs' ) && ! bp_blogs_disable_single_items() ) { 230 $sub_nav[] = array( 231 'name' => _x( 'Sites', 'Profile activity screen sub nav', 'buddypress' ), 232 'slug' => bp_get_blogs_slug(), 233 'parent_url' => $activity_link, 234 'parent_slug' => $this->slug, 235 'screen_function' => 'bp_activity_screen_blogs', 236 'position' => 60, 237 'item_css_id' => 'activity-blogs' 238 ); 239 } 240 228 241 parent::setup_nav( $main_nav, $sub_nav ); 229 242 } 230 243 … … class BP_Activity_Component extends BP_Component { 322 335 'href' => trailingslashit( $activity_link . bp_get_groups_slug() ) 323 336 ); 324 337 } 338 339 // Blogs? 340 if ( bp_is_active( 'blogs' ) && ! bp_blogs_disable_single_items() ) { 341 $wp_admin_nav[] = array( 342 'parent' => 'my-account-' . $this->id, 343 'id' => 'my-account-' . $this->id . '-blogs', 344 'title' => _x( 'Sites', 'My Account Activity sub nav', 'buddypress' ), 345 'href' => trailingslashit( $activity_link . bp_get_blogs_slug() ) 346 ); 347 } 325 348 } 326 349 327 350 parent::setup_admin_bar( $wp_admin_nav ); -
src/bp-activity/bp-activity-screens.php
diff --git src/bp-activity/bp-activity-screens.php src/bp-activity/bp-activity-screens.php index d9cc9cf..e39d353 100644
function bp_activity_screen_groups() { 149 149 } 150 150 151 151 /** 152 * Load the 'My Blogs' activity page. 153 * 154 * @since BuddyPress (2.3.0) 155 */ 156 function bp_activity_screen_blogs() { 157 if ( ! bp_is_active( 'blogs' ) || bp_blogs_disable_single_items() ) { 158 return false; 159 } 160 161 bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' ); 162 163 /** 164 * Fires right before the loading of the "My Groups" screen template file. 165 * 166 * @since BuddyPress (2.3.0) 167 */ 168 do_action( 'bp_activity_screen_blogs' ); 169 170 /** 171 * Filters the template to load for the "My Blogs" screen. 172 * 173 * @since BuddyPress (2.3.0) 174 * 175 * @param string $template Path to the activity template to load. 176 */ 177 bp_core_load_template( apply_filters( 'bp_activity_template_blogs_activity', 'members/single/home' ) ); 178 } 179 180 /** 152 181 * Load the 'Favorites' activity page. 153 182 * 154 183 * @since BuddyPress (1.2.0) -
src/bp-activity/bp-activity-template.php
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php index 690c816..213457a 100644
function bp_has_activities( $args = '' ) { 626 626 $object = $bp->groups->id; 627 627 $primary_id = bp_get_current_group_id(); 628 628 $show_hidden = (bool) ( groups_is_user_member( bp_loggedin_user_id(), $primary_id ) || bp_current_user_can( 'bp_moderate' ) ); 629 } elseif ( bp_is_blog() ) { 630 $object = $bp->blogs->id; 631 $primary_id = bp_get_current_blog_id(); 632 $show_hidden = false; 629 633 } else { 630 634 $object = false; 631 635 $primary_id = false; … … function bp_activity_show_filters( $context = '' ) { 4416 4420 if ( bp_is_user() ) { 4417 4421 if ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) { 4418 4422 $context = 'member_groups'; 4423 } elseif ( bp_is_active( 'blogs' ) && bp_is_current_action( bp_get_blogs_slug() ) ) { 4424 $context = 'member_blogs'; 4419 4425 } else { 4420 4426 $context = 'member'; 4421 4427 } -
src/bp-blogs/bp-blogs-actions.php
diff --git src/bp-blogs/bp-blogs-actions.php src/bp-blogs/bp-blogs-actions.php index 2d77f11..a000eb4 100644
function bp_blogs_redirect_to_random_blog() { 32 32 } 33 33 } 34 34 add_action( 'bp_actions', 'bp_blogs_redirect_to_random_blog' ); 35 36 /** 37 * Check if the user needs to set an avatar for his just registered blog. 38 * 39 * @since BuddyPress (2.3.0) 40 */ 41 function bp_blogs_maybe_redirect_to_single_blog() { 42 if ( ! is_multisite() || ! is_user_logged_in() || ! bp_blogs_is_avatar_uploads_enabled() ) { 43 return; 44 } 45 46 $transient_key = sprintf( '_bp_activation_%d_redirect', bp_loggedin_user_id() ); 47 $blog_id = get_transient( $transient_key ); 48 49 if ( empty( $blog_id ) ) { 50 return; 51 } 52 53 // Delete the redirect transient 54 delete_transient( $transient_key ); 55 56 $single_blog = bp_blogs_get_blog( array( 'blog_id' => $blog_id ) ); 57 58 if ( empty( $single_blog->slug ) ) { 59 return; 60 } 61 62 $redirect = trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/' . $single_blog->slug . '/manage/edit-logo' ); 63 64 bp_core_add_message( __( 'Welcome to the profile area of your new site, please consider adding a site logo for your site', 'buddypress' ) ); 65 bp_core_redirect( esc_url( $redirect ) ); 66 } 67 add_action( 'bp_blogs_setup_nav', 'bp_blogs_maybe_redirect_to_single_blog' ); -
src/bp-blogs/bp-blogs-activity.php
diff --git src/bp-blogs/bp-blogs-activity.php src/bp-blogs/bp-blogs-activity.php index 1cace2a..0c73d1e 100644
function bp_blogs_register_activity_actions() { 32 32 __( 'New site created', 'buddypress' ), 33 33 'bp_blogs_format_activity_action_new_blog', 34 34 __( 'New Sites', 'buddypress' ), 35 035 array() 36 36 ); 37 37 } 38 38 … … function bp_blogs_register_activity_actions() { 44 44 __( 'New post comment posted', 'buddypress' ), 45 45 'bp_blogs_format_activity_action_new_blog_comment', 46 46 __( 'Comments', 'buddypress' ), 47 array( 'activity', 'member' ),47 array( 'activity', 'member', 'blog', 'member_blogs' ), 48 48 10 49 49 ); 50 50 } 51 51 52 52 /** 53 * Only add subscription actions if subscription are enabled 54 * for current blog, or when viewing the blogs activities on 55 * a user's profile 56 */ 57 if ( bp_current_blog_can_subscribe() || bp_is_user() || bp_is_activity_directory() ) { 58 bp_activity_set_action( 59 buddypress()->blogs->id, 60 'site_subscription', 61 __( 'New site subscription', 'buddypress' ), 62 'bp_blogs_format_activity_action_new_site_subscription', 63 __( 'Site Subscriptions', 'buddypress' ), 64 array( 'activity', 'member', 'blog', 'member_blogs' ), 65 20 66 ); 67 } 68 69 /** 53 70 * Fires after the registry of the default blog component activity actions. 54 71 * 55 72 * @since BuddyPress (1.1.0) … … function bp_blogs_format_activity_action_new_blog_comment( $action, $activity ) 281 298 } 282 299 283 300 /** 301 * Activity action callback for new site subscriptions 302 * 303 * @since BuddyPress (2.3.0) 304 * 305 * @param string $action the content of the action 306 * @param BP_Activity_Activity the activity object 307 * @return string $action the content of the action 308 */ 309 function bp_blogs_format_activity_action_new_site_subscription( $action = '', $activity = null ) { 310 if ( empty( $activity->item_id ) ) { 311 return $action; 312 } 313 314 $user_link = bp_core_get_userlink( $activity->user_id ); 315 $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' ); 316 $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' ); 317 $root_domain = trailingslashit( bp_get_root_domain() ); 318 319 if ( (int) $activity->item_id !== (int) get_current_site()->id ) { 320 $view_details_link = trailingslashit( $root_domain . bp_get_blogs_root_slug() . str_replace( $root_domain, '/', $blog_url ) ); 321 } else { 322 $view_details_link = trailingslashit( $root_domain . bp_get_blogs_root_slug() . '/' . apply_filters( 'bp_blogs_get_site_slug', 'root' ) ); 323 } 324 325 $action = sprintf( 326 __( '%1$s subscribed to the site %2$s', 'bp-blogs-extended' ), 327 $user_link, 328 '<a href="' . esc_url( $view_details_link ) . '">' . esc_html( $blog_name ) . '</a>' 329 ); 330 331 return apply_filters( 'bp_blogs_format_activity_action_new_site_subscription', $action, $activity ); 332 } 333 334 /** 284 335 * Fetch data related to blogs at the beginning of an activity loop. 285 336 * 286 337 * This reduces database overhead during the activity loop. … … function bp_blogs_prefetch_activity_object_data( $activities ) { 314 365 add_filter( 'bp_activity_prefetch_object_data', 'bp_blogs_prefetch_activity_object_data' ); 315 366 316 367 /** 368 * Set up activity arguments for use with the 'blogs' scope. 369 * 370 * @since BuddyPress (2.3.0) 371 * 372 * @param array $retval Empty array by default 373 * @param array $filter Current activity arguments 374 * @return array 375 */ 376 function bp_blogs_filter_activity_scope( $retval = array(), $filter = array() ) { 377 378 // Determine the user_id 379 if ( ! empty( $filter['user_id'] ) ) { 380 $user_id = $filter['user_id']; 381 } else { 382 $user_id = bp_displayed_user_id() 383 ? bp_displayed_user_id() 384 : bp_loggedin_user_id(); 385 } 386 387 // Determine blogs of user 388 $blogs = bp_blogs_get_blogs_for_user( $user_id ); 389 if ( empty( $blogs['blogs'] ) ) { 390 $blogs = array( 'blogs' => 0 ); 391 } else { 392 $blogs['blogs'] = array_keys( $blogs['blogs'] ); 393 } 394 395 // Should we show all items regardless of sitewide visibility? 396 $show_hidden = array(); 397 if ( ! empty( $user_id ) && ( $user_id !== bp_loggedin_user_id() ) ) { 398 $show_hidden = array( 399 'column' => 'hide_sitewide', 400 'value' => 0 401 ); 402 } 403 404 $retval = array( 405 'relation' => 'AND', 406 array( 407 'relation' => 'AND', 408 array( 409 'column' => 'component', 410 'value' => buddypress()->blogs->id 411 ), 412 array( 413 'column' => 'item_id', 414 'compare' => 'IN', 415 'value' => (array) $blogs['blogs'] 416 ), 417 ), 418 $show_hidden, 419 420 // overrides 421 'override' => array( 422 'filter' => array( 'user_id' => 0 ), 423 'show_hidden' => true 424 ), 425 ); 426 427 return $retval; 428 } 429 add_filter( 'bp_activity_set_blogs_scope_args', 'bp_blogs_filter_activity_scope', 10, 2 ); 430 431 /** 317 432 * Record blog-related activity to the activity stream. 318 433 * 319 434 * @since BuddyPress (1.0.0) -
src/bp-blogs/bp-blogs-cache.php
diff --git src/bp-blogs/bp-blogs-cache.php src/bp-blogs/bp-blogs-cache.php index df751d2..e66bcf2 100644
add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 56 56 add_action( 'wpmu_new_blog', 'bp_blogs_clear_blog_object_cache', 10, 2 ); 57 57 add_action( 'bp_blogs_remove_blog', 'bp_blogs_clear_blog_object_cache' ); 58 58 59 /** 60 * Bust blog caches when editing or deleting. 61 * 62 * @since BuddyPress (2.3.0) 63 * 64 * @param int $blog_id The blog being edited. 65 */ 66 function bp_blogs_delete_blog_cache( $blog_id = 0 ) { 67 wp_cache_delete( $blog_id, 'bp_blogs' ); 68 } 69 add_action( 'refresh_blog_details', 'bp_blogs_delete_blog_cache' ); 70 add_action( 'bp_blogs_remove_blog', 'bp_blogs_delete_blog_cache' ); 71 add_action( 'bp_blogs_remove_data_for_blog', 'bp_blogs_delete_blog_cache' ); 72 add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_delete_blog_cache' ); 73 74 /** 75 * Bust blogs caches when a user was deleted or marked as spam 76 * 77 * @since BuddyPress (2.3.0) 78 * 79 * @param int $blog_id The blog being edited. 80 */ 81 function bp_blogs_delete_blogs_cache( $user_id = 0 ) { 82 $blogs = get_blogs_of_user( $user_id ); 83 84 if ( empty( $blogs ) ) { 85 return; 86 } 87 88 foreach ( $blogs as $blog ) { 89 wp_cache_delete( $blog->userblog_id, 'bp_blogs' ); 90 } 91 } 92 add_action( 'bp_blogs_before_remove_data', 'bp_blogs_delete_blogs_cache' ); 93 94 /** 95 * Bust blog caches when a user or a blog option was edited 96 * 97 * @since BuddyPress (2.3.0) 98 * 99 * @param int $blog_id The blog being edited. 100 */ 101 function bp_blogs_delete_blog_cache_on_change() { 102 if ( ! is_multisite() ) { 103 return; 104 } 105 106 $blog_id = get_current_blog_id(); 107 108 wp_cache_delete( $blog_id, 'bp_blogs' ); 109 } 110 add_action( 'set_user_role', 'bp_blogs_delete_blog_cache_on_change' ); 111 add_action( 'update_option_blogname', 'bp_blogs_delete_blog_cache_on_change' ); 112 add_action( 'update_option_blogdescription', 'bp_blogs_delete_blog_cache_on_change' ); 113 add_action( 'update_option_thread_comments_depth', 'bp_blogs_delete_blog_cache_on_change' ); 114 add_action( 'update_option_thread_comments', 'bp_blogs_delete_blog_cache_on_change' ); 115 add_action( 'update_option_close_comments_days_old', 'bp_blogs_delete_blog_cache_on_change' ); 116 add_action( 'update_option_close_comments_for_old_posts', 'bp_blogs_delete_blog_cache_on_change' ); 117 59 118 // List actions to clear super cached pages on, if super cache is installed 60 119 add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' ); 61 120 add_action( 'bp_blogs_remove_comment', 'bp_core_clear_cache' ); -
src/bp-blogs/bp-blogs-functions.php
diff --git src/bp-blogs/bp-blogs-functions.php src/bp-blogs/bp-blogs-functions.php index d29e005..0bf6c83 100644
function bp_blogs_has_directory() { 23 23 } 24 24 25 25 /** 26 * Fetch a single blog object. 27 * 28 * @since BuddyPress (2.3.0) 29 * 30 * @param array $args { 31 * Array of arguments. 32 * @type int $blog_id ID of the blog. 33 * @type bool $populate_extras Whether to fetch extra information about the blog. 34 * Default: True. 35 * @return BP_Blogs_Blog $blog The blog object. 36 */ 37 function bp_blogs_get_blog( $args = '' ) { 38 // Parse query arguments 39 $r = bp_parse_args( $args, array( 40 'blog_id' => 0, 41 'populate_extras' => true // Whether to populate blogmeta 42 ), 'blogs_get_blog' ); 43 44 $blog_args = array( 45 'populate_extras' => $r['populate_extras'], 46 ); 47 48 if ( $r['populate_extras'] ) { 49 // Check cache for blog data 50 $blog = wp_cache_get( $r['blog_id'], 'bp_blogs' ); 51 52 // Got Cache 53 if ( false !== $blog ) { 54 return $blog; 55 } 56 } 57 58 $blog = new BP_Blogs_Blog( $r['blog_id'], $blog_args ); 59 60 if ( $r['populate_extras'] && ! empty( $blog->id ) ) { 61 wp_cache_set( $blog->id, $blog, 'bp_blogs' ); 62 } 63 64 /** 65 * Filters a single blog object. 66 * 67 * @since BuddyPress (2.3.0) 68 * 69 * @param BP_Blogs_Blog $blog Single blog object. 70 */ 71 return apply_filters( 'bp_blogs_get_blog', $blog ); 72 } 73 74 /** 75 * Get the BP_Blogs_Blog object corresponding to the current blog. 76 * 77 * @since BuddyPress (2.3.0) 78 * 79 * @return BP_Blogs_Blog The current blog object. 80 */ 81 function bp_blogs_get_current_blog() { 82 $bp = buddypress(); 83 84 $current_blog = false; 85 86 if ( isset( $bp->blogs->current_blog ) ) { 87 $current_blog = $bp->blogs->current_blog; 88 } 89 90 /** 91 * Filters the BP_Blogs_Blog object corresponding to the current blog. 92 * 93 * @since BuddyPress (2.3.0) 94 * 95 * @param BP_Blogs_Blog $current_blog Current BP_Blogs_Blog object. 96 */ 97 return apply_filters( 'bp_blogs_get_current_blog', $current_blog ); 98 } 99 100 /** 101 * Is the user able to access to single blog's content 102 * 103 * @since BuddyPress (2.3.0) 104 * @uses apply_filters() Filter bp_current_blog_has_access to modify the access to the blog 105 * 106 * @return bool true if the user can access, false otherwise 107 */ 108 function bp_current_blog_has_access() { 109 $current_blog = bp_blogs_get_current_blog(); 110 $has_access = false; 111 112 if ( isset( $current_blog->user_has_access ) ) { 113 $has_access = $current_blog->user_has_access; 114 } 115 116 /** 117 * Filters the access to the current blog 118 * 119 * @since BuddyPress (2.3.0) 120 * 121 * @param bool $has_access true if user can access, false otherwise. 122 * @param object $current_blog Instance holding the current blog. 123 */ 124 return (bool) apply_filters( 'bp_current_blog_has_access', $has_access, $current_blog ); 125 } 126 127 /** 128 * Is the current blog item public 129 * 130 * @since BuddyPress (2.3.0) 131 * @uses apply_filters() Filter bp_is_blog_public to edit the blog visibility 132 * 133 * @return bool true if the blog is public, false otherwise 134 */ 135 function bp_current_blog_is_public() { 136 $current_blog = bp_blogs_get_current_blog(); 137 $is_public = false; 138 139 if ( isset( $current_blog->blog_public ) ) { 140 $is_public = $current_blog->blog_public; 141 } 142 143 /** 144 * Filters activity visibility of the blog 145 * 146 * @since BuddyPress (2.3.0) 147 * 148 * @param bool $is_public true if blog is public, false otherwise. 149 * @param object $current_blog Instance holding the current blog. 150 */ 151 return (bool) apply_filters( 'bp_is_blog_public', $is_public, $current_blog ); 152 } 153 154 /** 155 * Can users subscribe to the current blog 156 * 157 * @since BuddyPress (2.3.0) 158 * @uses apply_filters() Filter bp_current_blog_can_subscribe to edit the ability to join the blog 159 * 160 * @return bool true if users can subscribe to the current blog, false otherwise 161 */ 162 function bp_current_blog_can_subscribe() { 163 $current_blog = bp_blogs_get_current_blog(); 164 165 // Defaults to site's visibility 166 $can_subscribe = bp_current_blog_is_public(); 167 168 169 if ( isset( $current_blog->disallow_subscriptions ) ) { 170 $can_subscribe = ! $current_blog->disallow_subscriptions; 171 } 172 173 /** 174 * Filters subscriptions setting for the blog 175 * 176 * @since BuddyPress (2.3.0) 177 * 178 * @param bool $can_subscribe true if subscription are enabled, false otherwise. 179 * @param object $current_blog Instance holding the current blog. 180 */ 181 return (bool) apply_filters( 'bp_current_blog_can_subscribe', $can_subscribe, $current_blog ); 182 } 183 184 /** 185 * Is current user a member of the current blog ? 186 * 187 * @since BuddyPress (2.3.0) 188 * @uses apply_filters() Filter bp_current_blog_is_member to edit the user membership 189 * 190 * @return bool true if the user is a member of the current blog, false otherwise 191 */ 192 function bp_current_blog_is_member() { 193 $current_blog = bp_blogs_get_current_blog(); 194 $is_member = false; 195 196 197 if ( isset( $current_blog->is_member ) ) { 198 $is_member = $current_blog->is_member; 199 } 200 201 /** 202 * Filters subscriptions setting for the blog 203 * 204 * @since BuddyPress (2.3.0) 205 * 206 * @param bool $is_member true if the user is a member of the current blog, false otherwise. 207 * @param object $current_blog Instance holding the current blog. 208 */ 209 return (bool) apply_filters( 'bp_current_blog_is_member', $is_member, $current_blog ); 210 } 211 212 /** 213 * Adds a relationship between a user and a blog 214 * 215 * We don't use bp_blogs_add_user_to_blog() to avoid recording blogmetas 216 * @see bp_blogs_record_blog() 217 * 218 * @since BuddyPress (2.3.0) 219 * 220 * @return bool true if the relationship was created, false otherwise 221 */ 222 function bp_blogs_link_user_to_blog( $user_id = 0, $blog_id = 0 ) { 223 if ( empty( $user_id ) || empty( $blog_id ) ) { 224 return false; 225 } 226 227 // Create the relationship between user & blog 228 $join_blog = new BP_Blogs_Blog; 229 $join_blog->user_id = $user_id; 230 $join_blog->blog_id = $blog_id; 231 232 if ( ! $join_blog->save() ) { 233 return false; 234 } 235 236 return true; 237 } 238 239 /** 240 * Subscribe a user to a blog 241 * 242 * @since BuddyPress (2.3.0) 243 * 244 * @return array the result in a feedback array 245 */ 246 function bp_blogs_join_blog() { 247 $blog = bp_blogs_get_current_blog(); 248 249 if ( ! bp_current_blog_can_subscribe() || empty( $blog->id ) ) { 250 return array( 251 'message' => __( 'We were not able to perform this action, please try again later', 'bp-blogs-extended' ), 252 'type' => 'error', 253 ); 254 } 255 256 /** 257 * Fires before the user joins the blog 258 */ 259 do_action( 'bp_blogs_before_join_blog', bp_loggedin_user_id(), $blog ); 260 261 // No need to use this action 262 remove_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 ); 263 264 // First WordPress 265 $subscribed = add_user_to_blog( $blog->id, bp_loggedin_user_id(), 'subscriber' ); 266 267 // Restore the action 268 add_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 ); 269 270 if ( is_wp_error( $subscribed ) ) { 271 $result = array( 272 'message' => $subscribed->get_error_message(), 273 'type' => 'error', 274 ); 275 } else { 276 // Then BuddyPress 277 bp_blogs_link_user_to_blog( bp_loggedin_user_id(), $blog->id ); 278 279 $result = array( 280 'message' => __( 'You successfully joined to the site.', 'bp-blogs-extended' ), 281 'type' => '', 282 ); 283 284 $user_link = bp_core_get_userlink( bp_loggedin_user_id() ); 285 286 $action = sprintf( 287 __( '%1$s subscribed to the site %2$s', 'bp-blogs-extended' ), 288 $user_link, 289 '<a href="' . esc_url( bp_get_blog_view_details_link() ) . '">' . esc_html( $blog->name ) . '</a>' 290 ); 291 292 bp_blogs_record_activity( array( 293 'action' => $action, 294 'type' => 'site_subscription', 295 'item_id' => $blog->id, 296 ) ); 297 298 // Update the blog's last activity. 299 bp_blogs_update_blogmeta( $blog->id, 'last_activity', bp_core_current_time() ); 300 301 /** 302 * Fires after the user joined the blog 303 */ 304 do_action( 'bp_blogs_joined_blog', bp_loggedin_user_id(), $blog ); 305 } 306 307 return $result; 308 } 309 310 /** 311 * Unsubscribe a user from a blog 312 * 313 * @since BuddyPress (2.3.0) 314 * 315 * @return array the result in a feedback array 316 */ 317 function bp_blogs_leave_blog() { 318 $blog = bp_blogs_get_current_blog(); 319 320 if ( empty( $blog->id ) || bp_is_item_admin() ) { 321 return array( 322 'message' => __( 'We were not able to perform this action, please try again later', 'bp-blogs-extended' ), 323 'type' => 'error', 324 ); 325 } 326 327 /** 328 * Fires before the user leaves the blog 329 */ 330 do_action( 'bp_blogs_before_leave_blog', bp_loggedin_user_id(), $blog ); 331 332 /** 333 * bp_blogs_remove_user_from_blog() will hook WordPress to remove 334 * the link between the user and the blog 335 */ 336 $unsubscribed = remove_user_from_blog( bp_loggedin_user_id(), $blog->id ); 337 338 if ( is_wp_error( $unsubscribed ) ) { 339 $result = array( 340 'message' => $unsubscribed->get_error_message(), 341 'type' => 'error', 342 ); 343 } else { 344 $result = array( 345 'message' => __( 'You successfully left the site.', 'buddypress' ), 346 'type' => '', 347 ); 348 349 bp_blogs_delete_activity( array( 350 'user_id' => bp_loggedin_user_id(), 351 'item_id' => $blog->id, 352 'type' => 'site_subscription', 353 ) ); 354 355 /** 356 * Fires after the user left the blog 357 */ 358 do_action( 'bp_blogs_left_blog', bp_loggedin_user_id(), $blog ); 359 } 360 361 return $result; 362 } 363 364 /** Blog Avatars ***************************************************************/ 365 366 /** 367 * Generate the avatar upload directory path for a given blog. 368 * 369 * @since BuddyPress (2.3.0) 370 * 371 * @param int $blog_id Optional. ID of the blog. Default: ID of the 372 * current blog. 373 * @return string 374 */ 375 function blogs_avatar_upload_dir( $blog_id = 0 ) { 376 377 if ( empty( $blog_id ) ) { 378 $blog_id = bp_get_current_blog_id(); 379 } 380 381 $directory = 'blog-avatars'; 382 $path = bp_core_avatar_upload_path() . '/' . $directory . '/' . $blog_id; 383 $newbdir = $path; 384 $newurl = bp_core_avatar_url() . '/' . $directory . '/' . $blog_id; 385 $newburl = $newurl; 386 $newsubdir = '/' . $directory . '/' . $blog_id; 387 388 /** 389 * Filters the avatar upload directory path for a given blog. 390 * 391 * @since BuddyPress (2.3.0) 392 * 393 * @param array $value Array of parts related to the blog avatar upload directory. 394 */ 395 return apply_filters( 'blogs_avatar_upload_dir', array( 396 'path' => $path, 397 'url' => $newurl, 398 'subdir' => $newsubdir, 399 'basedir' => $newbdir, 400 'baseurl' => $newburl, 401 'error' => false 402 ) ); 403 } 404 405 /** 406 * Check if avatar uploads are enabled 407 * 408 * @since BuddyPress (2.3.0) 409 * 410 * @return bool true if avatar uploads are enabled, false otherwise. 411 */ 412 function bp_blogs_is_avatar_uploads_enabled() { 413 $bp = buddypress(); 414 415 // If Blogs single items are disabled no need to carry on. 416 if ( bp_blogs_disable_single_items() ) { 417 return false; 418 } 419 420 /** 421 * Check if : 422 * - user can upload avatars 423 * - the WordPress show avatars setting is enabled 424 * - the new avatar UI is not disabled. 425 */ 426 $is_avatar_enabled = ! (int) $bp->site_options['bp-disable-avatar-uploads'] && $bp->avatar->show_avatars && false !== (bool) apply_filters( 'bp_avatar_is_front_edit', true ); 427 428 /** 429 * Filters the ability to set an avatar for a given blog. 430 * 431 * @since BuddyPress (2.3.0) 432 * 433 * @param bool $is_avatar_enabled true if avatar uploads are enabled, false otherwise. 434 */ 435 return (bool) apply_filters( 'bp_blogs_is_avatar_uploads_enabled', $is_avatar_enabled ); 436 } 437 438 /** 26 439 * Retrieve a set of blogs 27 440 * 28 441 * @see BP_Blogs_Blog::get() for a description of arguments and return value. … … function bp_blogs_remove_blog( $blog_id ) { 846 1259 'type' => 'new_blog' 847 1260 ) ); 848 1261 1262 // Remove the site logo. 1263 if ( is_multisite() && bp_blogs_is_avatar_uploads_enabled() ) { 1264 bp_core_delete_existing_avatar( array( 'item_id' => $blog_id, 'object' => 'blog' ) ); 1265 } 1266 849 1267 /** 850 1268 * Fires after a "blog created" item has been removed from blogs 851 1269 * tracker and activity stream. -
src/bp-blogs/bp-blogs-loader.php
diff --git src/bp-blogs/bp-blogs-loader.php src/bp-blogs/bp-blogs-loader.php index 36c2799..bb4f614 100644
class BP_Blogs_Component extends BP_Component { 77 77 // Setup the globals 78 78 parent::setup_globals( $args ); 79 79 80 /* 80 /** 81 81 * Set up the post post type to track. 82 82 * 83 83 * In case the config is not multisite, the blog_public option is ignored. … … class BP_Blogs_Component extends BP_Component { 100 100 101 101 // Filter the generic track parameters for the 'post' post type. 102 102 add_filter( 'bp_activity_get_post_type_tracking_args', array( $this, 'post_tracking_args' ), 10, 2 ); 103 104 /** Single Blog globals ***********************************************/ 105 106 if ( is_multisite() && bp_is_blogs_component() && bp_current_action() && ! bp_blogs_disable_single_items() ) { 107 108 /** 109 * Set the blogs single nav 110 * 111 * We need to do this early so that we can manage item access 112 * within the single nav 113 */ 114 $this->single_nav = array(); 115 $this->single_subnav = array(); 116 117 // Sort the single item nav 118 add_action( 'wp_head', array( $this, 'sort_single_item_nav' ) ); 119 120 /** 121 * Use this filter to define a new slug for the network root site 122 * 123 * @since BuddyPress (2.3.0) 124 * 125 * @param string $slug the alias for the network root slug 126 */ 127 if ( bp_is_current_action( apply_filters( 'bp_blogs_get_site_slug', 'root' ) ) ) { 128 $blog_id = get_current_site()->id; 129 } else { 130 $blog_id = get_id_from_blogname( bp_current_action() ); 131 } 132 133 // Set the current blog data 134 $this->current_blog = bp_blogs_get_blog( array( 'blog_id' => $blog_id ) ); 135 136 if ( empty( $this->current_blog->id ) ) { 137 $this->current_blog = 0; 138 bp_do_404(); 139 return; 140 } 141 142 // It's a blog single item 143 $bp->is_single_item = true; 144 $bp->current_item = $this->current_blog->slug; 145 $bp->current_action = bp_action_variable( 0 ); 146 array_shift( $bp->action_variables ); 147 148 // By Default grant access 149 $this->current_blog->user_has_access = true; 150 151 // If blog is not public, non members can't access 152 if ( ! $this->current_blog->blog_public && ! $this->current_blog->is_member ) { 153 $this->current_blog->user_has_access = false; 154 } 155 156 $admin_keys = array_flip( wp_list_pluck( $this->current_blog->admins, 'ID' ) ); 157 158 if ( is_super_admin() || isset( $admin_keys[ bp_loggedin_user_id() ] ) ) { 159 bp_update_is_item_admin( true, $bp->blogs->id ); 160 } 161 162 // Check once if the current blog has a custom front template 163 $this->current_blog->front_template = bp_blogs_get_blog_front_template( $this->current_blog ); 164 } 165 } 166 167 /** 168 * Set up canonical stack for this component. 169 * 170 * @since BuddyPress (2.3.0) 171 */ 172 public function setup_canonical_stack() { 173 $bp = buddypress(); 174 175 if ( ! bp_is_blogs_component() ) { 176 return; 177 } 178 179 if ( empty( $this->current_blog ) ) { 180 return; 181 } 182 183 if ( ! bp_current_action() ) { 184 $bp->current_action = 'home'; 185 } 186 187 // Prepare for a redirect to the canonical URL 188 $bp->canonical_stack['base_url'] = trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/'. $this->current_blog->slug ); 189 190 if ( bp_current_action() ) { 191 $bp->canonical_stack['action'] = bp_current_action(); 192 } 193 194 if ( ! empty( $bp->action_variables ) ) { 195 $bp->canonical_stack['action_variables'] = bp_action_variables(); 196 } 197 198 // When viewing the default extension, the canonical URL should not have 199 // that extension's slug, unless more has been tacked onto the URL via 200 // action variables 201 if ( bp_is_current_action( 'home' ) && empty( $bp->action_variables ) ) { 202 unset( $bp->canonical_stack['action'] ); 203 } 103 204 } 104 205 105 206 /** … … class BP_Blogs_Component extends BP_Component { 125 226 126 227 if ( is_multisite() ) { 127 228 $includes[] = 'widgets'; 229 230 if ( ! bp_blogs_disable_single_items() ) { 231 $includes[] = 'notifications'; 232 } 128 233 } 129 234 130 235 // Include the files … … class BP_Blogs_Component extends BP_Component { 153 258 return false; 154 259 } 155 260 156 // Add 'Sites' to the main navigation157 $count = (int) bp_get_total_blog_count_for_user();158 $class = ( 0 === $count ) ? 'no-count' : 'count';159 $nav_text = sprintf( __( 'Sites <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) );160 $main_nav = array(161 'name' => $nav_text,162 'slug' => $this->slug,163 'position' => 30,164 'screen_function' => 'bp_blogs_screen_my_blogs',165 'default_subnav_slug' => 'my-sites',166 'item_css_id' => $this->id167 );168 169 261 // Determine user to use 170 262 if ( bp_displayed_user_domain() ) { 171 263 $user_domain = bp_displayed_user_domain(); 172 264 } elseif ( bp_loggedin_user_domain() ) { 173 265 $user_domain = bp_loggedin_user_domain(); 174 266 } else { 175 return;267 $user_domain = false; 176 268 } 177 269 178 $parent_url = trailingslashit( $user_domain . bp_get_blogs_slug() ); 270 if ( ! empty( $user_domain ) ) { 271 // Add 'Sites' to the main navigation 272 $count = (int) bp_get_total_blog_count_for_user(); 273 $class = ( 0 === $count ) ? 'no-count' : 'count'; 274 $nav_text = sprintf( __( 'Sites <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) ); 275 $main_nav = array( 276 'name' => $nav_text, 277 'slug' => $this->slug, 278 'position' => 30, 279 'screen_function' => 'bp_blogs_screen_my_blogs', 280 'default_subnav_slug' => 'my-sites', 281 'item_css_id' => $this->id 282 ); 283 284 $parent_url = trailingslashit( $user_domain . bp_get_blogs_slug() ); 179 285 180 $sub_nav[] = array( 181 'name' => __( 'My Sites', 'buddypress' ), 182 'slug' => 'my-sites', 183 'parent_url' => $parent_url, 184 'parent_slug' => $bp->blogs->slug, 185 'screen_function' => 'bp_blogs_screen_my_blogs', 186 'position' => 10 187 ); 286 $sub_nav[] = array( 287 'name' => __( 'My Sites', 'buddypress' ), 288 'slug' => 'my-sites', 289 'parent_url' => $parent_url, 290 'parent_slug' => $bp->blogs->slug, 291 'screen_function' => 'bp_blogs_screen_my_blogs', 292 'position' => 10 293 ); 294 295 // Setup navigation 296 parent::setup_nav( $main_nav, $sub_nav ); 297 } 298 299 if ( bp_is_blogs_component() && bp_is_single_item() ) { 300 301 $main_nav_items = array( 302 array( 303 'name' => __( 'Home', 'buddypress' ), 304 'slug' => 'home', 305 'position' => 0, 306 'screen_function' => 'bp_blogs_screen_blog_home', 307 'default_subnav_slug' => false, 308 'item_css_id' => 'all', 309 'single_nav' => $this->id, 310 ), 311 ); 312 313 if ( bp_current_blog_has_access() ) { 314 315 if ( $this->current_blog->front_template || ( bp_is_active( 'activity' ) && bp_current_blog_is_public() ) ) { 316 /** 317 * Only add the members nav if it's not the home's nav 318 */ 319 $main_nav_items[] = array( 320 'name' => sprintf( _x( 'Members <span>%s</span>', 'Single Blog members screen nav', 'buddypress' ), $this->current_blog->total_member_count ), 321 'slug' => 'members', 322 'position' => 20, 323 'screen_function' => 'bp_blogs_screen_blog_home', 324 'default_subnav_slug' => false, 325 'item_css_id' => 'all', 326 'single_nav' => $this->id, 327 ); 328 329 /** 330 * If the theme is using a custom front, create 331 * an activity nav if the blog is public 332 */ 333 if ( $this->current_blog->front_template && bp_is_active( 'activity' ) && bp_current_blog_is_public() ) { 334 $main_nav_items[] = array( 335 'name' => _x( 'Activity', 'Single Blog activity screen nav', 'buddypress' ), 336 'slug' => 'activity', 337 'position' => 10, 338 'screen_function' => 'bp_blogs_screen_blog_home', 339 'default_subnav_slug' => false, 340 'item_css_id' => 'all', 341 'single_nav' => $this->id, 342 ); 343 } 344 } 345 346 if ( bp_is_item_admin() ) { 347 // Manage Main nav 348 $main_nav_items[] = array( 349 'name' => _x( 'Manage', 'Single Blog manage screen nav', 'buddypress' ), 350 'slug' => 'manage', 351 'position' => 1000, 352 'screen_function' => 'bp_blogs_screen_blog_settings', 353 'default_subnav_slug' => 'manage', 354 'single_nav' => $this->id, 355 ); 356 } 357 } 358 359 /** 360 * Use this filter if you want to add/remove nav items 361 * 362 * @since BuddyPress (2.3.0) 363 * 364 * @param array $main_nav_items the current blog subnav items 365 * @param BP_Blogs_Blog $current_blog the current blog object 366 */ 367 foreach ( (array) apply_filters( 'bp_blogs_current_blog_nav_items', $main_nav_items, $this->current_blog ) as $main_nav_item ) { 368 bp_core_new_nav_item( $main_nav_item ); 369 } 188 370 189 // Setup navigation 190 parent::setup_nav( $main_nav, $sub_nav ); 371 /** Sub nav items - only manage needs some for now */ 372 373 $sub_nav_items = array(); 374 $blog_link = trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/'. $this->current_blog->slug ); 375 376 if ( bp_is_item_admin() ) { 377 378 /** 379 * General settings 380 * 381 * Edit the preferences for the current blog 382 * Access is restricted to The blog admins 383 */ 384 $sub_nav_items[] = array( 385 'name' => _x( 'Edit Settings', 'Single Blog setting screen', 'buddypress' ), 386 'slug' => 'manage', 387 'parent_url' => trailingslashit( $blog_link . 'manage' ), 388 'parent_slug' => 'manage', 389 'screen_function' => 'bp_blogs_screen_blog_settings', 390 'position' => 0, 391 'user_has_access' => bp_is_item_admin(), 392 'single_subnav' => $this->id, 393 ); 394 395 /** 396 * Site logo 397 * 398 * Edit the logo for the current blog 399 * Access is restricted to The blog admins 400 */ 401 if ( bp_blogs_is_avatar_uploads_enabled() ) { 402 $sub_nav_items[] = array( 403 'name' => _x( 'Edit Logo', 'Single Blog photo screen', 'buddypress' ), 404 'slug' => 'edit-logo', 405 'parent_url' => trailingslashit( $blog_link . 'manage' ), 406 'parent_slug' => 'manage', 407 'screen_function' => 'bp_blogs_screen_blog_settings', 408 'position' => 10, 409 'user_has_access' => bp_is_item_admin(), 410 'single_subnav' => $this->id, 411 ); 412 } 413 414 /** 415 * Manage members (remove) 416 */ 417 $sub_nav_items[] = array( 418 'name' => _x( 'Members', 'Single Blog manage members screen', 'buddypress' ), 419 'slug' => 'members', 420 'parent_url' => trailingslashit( $blog_link . 'manage' ), 421 'parent_slug' => 'manage', 422 'screen_function' => 'bp_blogs_screen_blog_settings', 423 'position' => 20, 424 'user_has_access' => bp_is_item_admin(), 425 'single_subnav' => $this->id, 426 ); 427 } 428 429 /** 430 * Use this filter if you want to add/remove subnav items 431 * 432 * @since BuddyPress (2.3.0) 433 * 434 * @param array $sub_nav_items the current blog subnav items 435 * @param BP_Blogs_Blog $current_blog the current blog object 436 * @param string $blog_link the current blog view details link 437 */ 438 foreach ( (array) apply_filters( 'bp_blogs_current_blog_subnav_items', $sub_nav_items, $this->current_blog, $blog_link ) as $sub_nav_item ) { 439 bp_core_new_subnav_item( $sub_nav_item ); 440 } 441 } 191 442 } 192 443 193 444 /** … … class BP_Blogs_Component extends BP_Component { 260 511 $bp->bp_options_title = __( 'My Sites', 'buddypress' ); 261 512 } 262 513 514 // We are viewing a single blog, so set up the 515 // blog title tag using the $this->current_blog global. 516 } elseif ( bp_is_single_item() ) { 517 $bp->bp_options_title = $this->current_blog->name; 518 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 519 'item_id' => $this->current_blog->id, 520 'object' => 'blog', 521 'type' => 'thumb', 522 'avatar_dir' => 'blog-avatars', 523 'alt' => __( 'Site logo', 'buddypress' ) 524 ) ); 525 526 if ( empty( $bp->bp_options_avatar ) ) { 527 $bp->bp_options_avatar = '<img src="' . esc_url( bp_core_avatar_default_thumb() ) . '" alt="' . esc_attr__( 'No Site logo', 'buddypress' ) . '" class="avatar" />'; 528 } 529 263 530 // If we are not viewing the logged in user, set up the current 264 531 // users avatar and name 265 532 } else { … … class BP_Blogs_Component extends BP_Component { 284 551 285 552 // Global groups 286 553 wp_cache_add_global_groups( array( 287 'blog_meta' 554 'blog_meta', 555 'bp_blogs' 288 556 ) ); 289 557 290 558 parent::setup_cache_groups(); … … class BP_Blogs_Component extends BP_Component { 308 576 $params->admin_filter = __( 'New post published', 'buddypress' ); 309 577 $params->format_callback = 'bp_blogs_format_activity_action_new_blog_post'; 310 578 $params->front_filter = __( 'Posts', 'buddypress' ); 311 $params->contexts = array( 'activity', 'member' );579 $params->contexts = array( 'activity', 'member', 'blog', 'member_blogs' ); 312 580 $params->position = 5; 313 581 314 582 return $params; 315 583 } 584 585 /** 586 * Sort the current blog's nav 587 * 588 * @since BuddyPress (2.3.0) 589 */ 590 public function sort_single_item_nav() { 591 bp_core_sort_nav_items( $this->id ); 592 bp_core_sort_subnav_items( $this->id ); 593 } 316 594 } 317 595 318 596 /** -
src/bp-blogs/bp-blogs-notifications.php
diff --git src/bp-blogs/bp-blogs-notifications.php src/bp-blogs/bp-blogs-notifications.php index e69de29..240e253 100644
1 <?php 2 3 /** 4 * BuddyPress Blogs Notification Functions 5 * 6 * These functions handle the recording, deleting and formatting of notifications 7 * for the user and for this specific component. 8 * 9 * @package BuddyPress 10 * @subpackage BlogsNotifications 11 */ 12 13 // Exit if accessed directly 14 defined( 'ABSPATH' ) || exit; 15 16 /** 17 * Notify Site admins about a new subscription. 18 * 19 * @since BuddyPress (2.3.0) 20 * 21 * @param int $subscriber_id ID of the user who subscribed to a site. 22 * @param BP_Blogs_Blog $blog Blog object the user subscribed to 23 * @return bool|null False on failure. 24 */ 25 function bp_blogs_notification_new_subscription( $subscriber_id = 0, $blog = null ) { 26 if ( ! is_a( $blog, 'BP_Blogs_Blog' ) || empty( $subscriber_id ) ) { 27 return; 28 } 29 30 if ( empty( $blog->admins ) ) { 31 return; 32 } 33 34 // List of notified admins 35 $admin_notified = array(); 36 37 foreach ( $blog->admins as $admin ) { 38 39 // Trigger a BuddyPress Notification 40 if ( bp_is_active( 'notifications' ) ) { 41 bp_notifications_add_notification( array( 42 'user_id' => $admin->ID, 43 'item_id' => $blog->id, 44 'secondary_item_id' => $subscriber_id, 45 'component_name' => buddypress()->blogs->id, 46 'component_action' => 'new_site_subscription' 47 ) ); 48 } 49 50 // Bail if member opted out of receiving this email 51 if ( 'no' === bp_get_user_meta( $admin->ID, 'notification_blogs_new_subscription', true ) ) { 52 return false; 53 } 54 55 // Username of the subscriber: %1$s in mail 56 $subscriber_user_name = bp_core_get_user_displayname( $subscriber_id ); 57 58 // Blog's Manage members page 59 $manage_members = trailingslashit( bp_get_blog_view_details_link() . 'manage/members' ); 60 61 // Link to the user's profile who subscribed: %3$s in mail 62 $subscriber_profile_link = bp_core_get_user_domain( $subscriber_id ); 63 64 $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings'; 65 // Link to the site administrator email settings: %s in "disable notifications" part of the email 66 $settings_link = bp_core_get_user_domain( $admin->ID ) . $settings_slug . '/notifications/'; 67 68 // Set up and send the message 69 $to = $admin->user_email; 70 $subject = bp_get_email_subject( array( 'text' => sprintf( __( 'New subscription for the site: %s', 'buddypress' ), $blog->name ) ) ); 71 72 $message = sprintf( __( 73 '%1$s subscribed to the site "%2$s". 74 75 Because you are the administrator of this site, you are receiving this notifications. 76 77 To manage the members of your site, please visit: 78 %3$s 79 80 To view %4$s\'s profile: %5$s 81 82 --------------------- 83 ', 'buddypress' ), $subscriber_user_name, $blog->name, $manage_members, $subscriber_user_name, $subscriber_profile_link ); 84 85 // Only show the disable notifications line if the settings component is enabled 86 if ( bp_is_active( 'settings' ) ) { 87 $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); 88 } 89 90 /** 91 * Filters the user email that the site subscription notification will be sent to. 92 * 93 * @since BuddyPress (2.3.0) 94 * 95 * @param string $to User email the notification is being sent to. 96 */ 97 $to = apply_filters( 'bp_blogs_notification_new_site_subscription_to', $to ); 98 99 /** 100 * Filters the site subscription email subject that will be sent to user. 101 * 102 * @since BuddyPress (2.3.0) 103 * 104 * @param string $subject site subscription email subject text. 105 * @param BP_Blogs_Blog $blog Object holding the current blog instance. Passed by reference. 106 */ 107 $subject = apply_filters_ref_array( 'bp_blogs_notification_new_site_subscription_subject', array( $subject, $blog ) ); 108 109 /** 110 * Filters the site subscription notification message that will be sent to user. 111 * 112 * @since BuddyPress (2.3.0) 113 * 114 * @param string $message Email message text. 115 * @param BP_Blogs_Blog $blog Object holding the current blog instance. Passed by reference. 116 * @param string $subscriber_user_name Username of who subscribed. 117 * @param string $subscriber_profile_link URL permalink for the profile for the user requesting membership. 118 * @param string $manage_members URL permalink for the Blog's Manage members page 119 * @param string $settings_link URL permalink for the user's notification settings area. 120 */ 121 $message = apply_filters_ref_array( 'bp_blogs_notification_new_site_subscription_message', array( $message, $blog, $subscriber_user_name, $subscriber_profile_link, $manage_members, $settings_link ) ); 122 123 if ( wp_mail( $to, $subject, $message ) ) { 124 $admin_notified[] = $admin; 125 } 126 } 127 128 /** 129 * Fires after the notification is sent that a member subscribed to a site. 130 * 131 * @since BuddyPress (2.3.0) 132 * 133 * @param array $admin_notified list of Admin objects (ID, display name, user_login, user_nicename, user_email) 134 * who were notified 135 * @param string $subject Email notification subject text. 136 * @param string $message Email notification message text. 137 * @param int $subscriber_id ID of the user who subscribed. 138 * @param BP_Blogs_Blog $blog Object holding the current blog instance. Passed by reference. 139 */ 140 do_action( 'bp_blogs_sent_membership_request_email', $admin_notified, $subject, $message, $subscriber_id, $blog ); 141 } 142 add_action( 'bp_blogs_joined_blog', 'bp_blogs_notification_new_subscription', 10, 2 ); 143 144 /** 145 * Format notifications for the Blogs component. 146 * 147 * @since BuddyPress (2.3.0) 148 * 149 * @param string $action The kind of notification being rendered. 150 * @param int $item_id The primary item ID. 151 * @param int $secondary_item_id The secondary item ID. 152 * @param int $total_items The total number of messaging-related notifications 153 * waiting for the user. 154 * @param string $format 'string' for BuddyBar-compatible notifications; 'array' 155 * for WP Toolbar. Default: 'string'. 156 * @return string 157 */ 158 function bp_blogs_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { 159 160 switch ( $action ) { 161 case 'new_site_subscription': 162 $blog_id = $item_id; 163 $subscriber_id = $secondary_item_id; 164 $amount = 'single'; 165 166 // Set up the string and the filter 167 // Because different values are passed to the filters, we'll return the 168 // values inline 169 if ( (int) $total_items > 1 ) { 170 $text = sprintf( __( '%d new site subscriptions', 'buddypress' ), (int) $total_items ); 171 $amount = 'multiple'; 172 $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_blogs_slug() ) . '?n=1';; 173 174 if ( 'string' == $format ) { 175 176 /** 177 * Filters blogs multiple new subscription notification for string format. 178 * 179 * This is a dynamic filter that is dependent on item count and action. 180 * Complete filter - bp_blogs_multiple_new_site_subscriptions_notification. 181 * 182 * @since BuddyPress (2.3.0) 183 * 184 * @param string $string HTML anchor tag for request. 185 * @param int $total_items Total number of membership requests. 186 * @param string $text Notification content. 187 * @param string $notification_link The permalink for notification. 188 */ 189 return apply_filters( 'bp_blogs_' . $amount . '_' . $action . 's_notification', '<a href="' . $notification_link . '" title="' . __( 'Site Subscriptions', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link ); 190 } else { 191 192 /** 193 * Filters blogs multiple new subscription notification for any non-string format. 194 * 195 * This is a dynamic filter that is dependent on item count and action. 196 * Complete filter - bp_blogs_multiple_new_site_subscriptions_notification. 197 * 198 * @since BuddyPress (2.3.0) 199 * 200 * @param array $array Array holding permalink and content for notification. 201 * @param int $total_items Total number of membership requests. 202 * @param string $text Notification content. 203 * @param string $notification_link The permalink for notification. 204 */ 205 return apply_filters( 'bp_blogs_' . $amount . '_' . $action . 's_notification', array( 206 'link' => $notification_link, 207 'text' => $text 208 ), $total_items, $text, $notification_link ); 209 } 210 } else { 211 // Avoid switching blogs 212 $blog = get_blog_details( (int) $blog_id, false ); 213 $current_site = get_current_site(); 214 215 if ( (int) $current_site->id === (int) $blog_id ) { 216 $slug = apply_filters( 'bp_blogs_get_site_slug', 'root' ); 217 } else { 218 $slug = trim( str_replace( $current_site->path, '', $blog->path ), '/' ); 219 } 220 221 $blog_link = trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/' . $slug ); 222 $blog_name = bp_blogs_get_blogmeta( $blog_id, 'name' ); 223 $user_fullname = bp_core_get_user_displayname( $subscriber_id ); 224 $text = sprintf( __( '%1$s subscribed to the site "%2$s"', 'buddypress' ), $user_fullname, $blog_name ); 225 $notification_link = $blog_link . 'manage/members/?n=1'; 226 227 if ( 'string' == $format ) { 228 229 /** 230 * Filters blogs single new subscription notification for string format. 231 * 232 * This is a dynamic filter that is dependent on item count and action. 233 * Complete filter - bp_blogs_single_new_site_subscription_notification. 234 * 235 * @since BuddyPress (2.3.0) 236 * 237 * @param string $string HTML anchor tag for request. 238 * @param string $blog_link The permalink for the blog. 239 * @param string $user_fullname Full name of requesting user. 240 * @param string $blog_name Name of the blog. 241 * @param string $text Notification content. 242 * @param string $notification_link The permalink for notification. 243 */ 244 return apply_filters( 'bp_blogs_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '" title="' . sprintf( __( '%1$s subscribed to the site "%2$s"', 'buddypress' ), $user_fullname, $blog_name ) . '">' . $text . '</a>', $blog_link, $user_fullname, $blog_name, $text, $notification_link ); 245 } else { 246 247 /** 248 * Filters blogs single new subscription notification for any non-string format. 249 * 250 * This is a dynamic filter that is dependent on item count and action. 251 * Complete filter - bp_blogs_single_new_site_subscription_notification. 252 * 253 * @since BuddyPress (2.3.0) 254 * 255 * @param array $array Array holding permalink and content for notification. 256 * @param string $blog_link The permalink for the blog. 257 * @param string $user_fullname Full name of requesting user. 258 * @param string $blog_name Name of the blog. 259 * @param string $text Notification content. 260 * @param string $notification_link The permalink for notification. 261 */ 262 return apply_filters( 'bp_blogs_' . $amount . '_' . $action . '_notification', array( 263 'link' => $notification_link, 264 'text' => $text 265 ), $blog_link, $user_fullname, $blog_name, $text, $notification_link ); 266 } 267 } 268 269 break; 270 } 271 272 /** 273 * Fires right before returning the formatted blog notifications. 274 * 275 * @since BuddyPress (2.3.0) 276 * 277 * @param string $action The type of notification being rendered. 278 * @param int $item_id The primary item ID. 279 * @param int $secondary_item_id The secondary item ID. 280 * @param int $total_items Total amount of items to format. 281 */ 282 do_action( 'bp_blogs_format_notifications', $action, $item_id, $secondary_item_id, $total_items ); 283 284 return false; 285 } 286 287 /** 288 * Mark notifications read when a member views their blogs. 289 * 290 * @since BuddyPress (2.3.0) 291 */ 292 function bp_blogs_screen_my_blogs_mark_notifications() { 293 294 // Delete blog subscriptions for the user 295 if ( isset( $_GET['n'] ) && bp_is_active( 'notifications' ) ) { 296 297 // Get the necessary ID's 298 $component_id = buddypress()->blogs->id; 299 $user_id = bp_loggedin_user_id(); 300 301 // Mark notifications read 302 bp_notifications_mark_notifications_by_type( $user_id, $component_id, 'new_site_subscription' ); 303 } 304 } 305 add_action( 'bp_blogs_screen_my_blogs', 'bp_blogs_screen_my_blogs_mark_notifications', 10 ); 306 307 308 /** 309 * Mark notifications read when a member views the manage members screen of his site. 310 * 311 * @since BuddyPress (2.3.0) 312 */ 313 function bp_blogs_screen_manage_blog_members_mark_notifications() { 314 315 // Delete blog subscriptions for the user 316 if ( isset( $_GET['n'] ) && bp_is_active( 'notifications' ) ) { 317 bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), bp_get_current_blog_id(), buddypress()->blogs->id, 'new_site_subscription' ); 318 } 319 } 320 add_action( 'blogs_screen_blog_settings', 'bp_blogs_screen_manage_blog_members_mark_notifications', 10 ); 321 322 /** 323 * Delete notifications generated by a user who has been removed from the blog. 324 * 325 * @since BuddyPress (2.3.0) 326 */ 327 function bp_blogs_clean_notification_on_user_removed( $user_id = 0, $blog_id = 0 ) { 328 if ( bp_is_active( 'notifications' ) && ! empty( $user_id ) && ! empty( $blog_id ) ) { 329 bp_notifications_delete_notifications_by_item_id( false, $blog_id, buddypress()->blogs->id, 'new_site_subscription', $user_id ); 330 } 331 } 332 add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clean_notification_on_user_removed', 10, 2 ); 333 334 /** 335 * Delete all notifications about a blog who was removed. 336 * 337 * @since BuddyPress (2.3.0) 338 */ 339 function bp_blogs_clean_all_notifications_for_blog( $blog_id = 0 ) { 340 if ( bp_is_active( 'notifications' ) && ! empty( $blog_id ) ) { 341 bp_notifications_delete_all_notifications_by_type( $blog_id, buddypress()->blogs->id ); 342 } 343 } 344 add_action( 'bp_blogs_remove_blog', 'bp_blogs_clean_all_notifications_for_blog', 10, 1 ); -
src/bp-blogs/bp-blogs-screens.php
diff --git src/bp-blogs/bp-blogs-screens.php src/bp-blogs/bp-blogs-screens.php index 4b47ef5..ad77562 100644
function bp_blogs_screen_index() { 68 68 } 69 69 add_action( 'bp_screens', 'bp_blogs_screen_index', 2 ); 70 70 71 /** 72 * Home screen for the blogs single item 73 * 74 * @since BuddyPress (2.3.0) 75 */ 76 function bp_blogs_screen_blog_home() { 77 if ( ! bp_is_single_item() ) { 78 return false; 79 } 80 81 do_action( 'bp_blogs_screen_blog_home' ); 82 83 if ( ! empty( $_GET['action'] ) && ( 'join' === $_GET['action'] || 'leave' === $_GET['action'] ) ) { 84 $action = sanitize_key( $_GET['action'] ); 85 86 check_admin_referer( 'blogs_' . $action . '_blog' ); 87 88 $referer = wp_get_referer(); 89 $result = array( 90 'message' => __( 'We were not able to perform this action, please try again later', 'bp-blogs-extended' ), 91 'type' => 'error', 92 ); 93 94 if ( is_user_logged_in() && is_callable( 'bp_blogs_' . $action . '_blog' ) ) { 95 $result = call_user_func( 'bp_blogs_' . $action . '_blog' ); 96 } 97 98 bp_core_add_message( $result['message'], $result['type'] ); 99 bp_core_redirect( $referer ); 100 } 101 102 bp_core_load_template( apply_filters( 'bp_blogs_template_blog_home', 'blogs/single/home' ) ); 103 } 104 105 /** 106 * Settings screen for the blogs single item 107 * 108 * @since BuddyPress (2.3.0) 109 */ 110 function bp_blogs_screen_blog_settings() { 111 if ( ! bp_is_single_item() ) { 112 return false; 113 } 114 115 do_action( 'blogs_screen_blog_settings' ); 116 117 if ( bp_is_blog_manage() && ! bp_action_variables( 0 ) && ! empty( $_POST['bp_blog']['submit'] ) ) { 118 119 check_admin_referer( 'blog_settings_general' ); 120 121 unset( $_POST['bp_blog']['submit'] ); 122 $options = $_POST['bp_blog']; 123 124 if ( ! isset( $options['blog_public'] ) ) { 125 $options['blog_public'] = 0; 126 } 127 128 $blog_id = bp_get_current_blog_id(); 129 $referer = wp_unslash( $_POST['_wp_http_referer'] ); 130 $message = __( 'We were not able to perform this action, please try again later', 'buddypress' ); 131 132 if ( empty( $blog_id ) ) { 133 bp_core_add_message( $message, 'error' ); 134 bp_core_redirect( $referer ); 135 } 136 137 $success = 'error'; 138 139 // Update general settings 140 if ( bp_get_root_blog_id() !== $blog_id ) { 141 $needs_reset = true; 142 switch_to_blog( $blog_id ); 143 } 144 145 if ( current_user_can( 'manage_options' ) ) { 146 147 // This option will only be saved in BuddyPress blog metas 148 if ( isset( $options['disallow_subscriptions'] ) ) { 149 bp_blogs_update_blogmeta( $blog_id, 'disallow_subscriptions', intval( $options['disallow_subscriptions'] ) ); 150 unset( $options['disallow_subscriptions'] ); 151 } else { 152 bp_blogs_delete_blogmeta( $blog_id, 'disallow_subscriptions' ); 153 } 154 155 foreach ( $options as $key => $option ) { 156 $sanitized_option = sanitize_option( $key, $option ); 157 158 update_option( $key, $sanitized_option ); 159 } 160 $message = __( 'Settings saved.', 'buddypress' ); 161 $success = ''; 162 163 } else { 164 $message = __( 'You cannot update this site's options.', 'buddypress' ); 165 } 166 167 if ( isset( $needs_reset ) ) { 168 restore_current_blog(); 169 } 170 171 // Redirect the user once done 172 bp_core_add_message( $message, $success ); 173 bp_core_redirect( $referer ); 174 } 175 176 if ( bp_is_blog_manage_screen( 'members' ) && isset( $_GET['remove_member'] ) ) { 177 178 check_admin_referer( 'blogs_remove_member' ); 179 180 $blog_id = bp_get_current_blog_id(); 181 $user_id = intval( $_GET['remove_member'] ); 182 $referer = wp_get_referer(); 183 $message = __( 'We were not able to perform this action, please try again later', 'buddypress' ); 184 $type = 'error'; 185 186 if ( ! bp_is_item_admin() || empty( $blog_id ) || empty( $user_id ) ) { 187 bp_core_add_message( $message, $type ); 188 bp_core_redirect( $referer ); 189 } 190 191 /** 192 * Fires bofore the user is removed from the blog 193 */ 194 do_action( 'bp_blogs_before_remove_user_from_blog', $user_id, $blog_id ); 195 196 /** 197 * bp_blogs_remove_user_from_blog() will hook WordPress to remove 198 * the link between the user and the blog 199 */ 200 $removed = remove_user_from_blog( $user_id, $blog_id ); 201 202 if ( is_wp_error( $removed ) ) { 203 $message = $removed->get_error_message(); 204 } else { 205 $message = __( 'Member successfully removed from the site.', 'buddypress' ); 206 $type = 'success'; 207 208 bp_blogs_delete_activity( array( 209 'user_id' => $user_id, 210 'item_id' => $blog_id, 211 'type' => 'site_subscription', 212 ) ); 213 214 /** 215 * Fires after the user was removed from the blog 216 */ 217 do_action( 'bp_blogs_user_removed_from_blog', $user_id, $blog_id ); 218 219 bp_core_add_message( $message, $type ); 220 bp_core_redirect( $referer ); 221 } 222 } 223 224 bp_core_load_template( apply_filters( 'bp_blogs_template_blog_settings', 'blogs/single/home' ) ); 225 } 226 227 /** 228 * Render the blogs settings fields on the Notification Settings page. 229 * 230 * @since BuddyPress (2.3.0) 231 */ 232 function bp_blogs_screen_notification_settings() { 233 234 $new_subscription = bp_get_user_meta( bp_displayed_user_id(), 'notification_blogs_new_subscription', true ); 235 236 // Defaults to yes 237 if ( ! $new_subscription ) { 238 $new_subscription = 'yes'; 239 } 240 ; ?> 241 242 <table class="notification-settings" id="groups-notification-settings"> 243 <thead> 244 <tr> 245 <th class="icon"></th> 246 <th class="title"><?php _ex( 'Sites', 'Sites settings on notification settings page', 'buddypress' ) ?></th> 247 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 248 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 249 </tr> 250 </thead> 251 252 <tbody> 253 <tr id="blogs-notification-settings-subscription"> 254 <td></td> 255 <td><?php _ex( 'A member subscribe to a site you are an administrator of', 'Sites settings on notification settings page','buddypress' ) ?></td> 256 <td class="yes"><input type="radio" name="notifications[notification_blogs_new_subscription]" value="yes" <?php checked( $new_subscription, 'yes', true ) ?>/></td> 257 <td class="no"><input type="radio" name="notifications[notification_blogs_new_subscription]" value="no" <?php checked( $new_subscription, 'no', true ) ?>/></td> 258 </tr> 259 260 <?php 261 262 /** 263 * Fires at the end of the available group settings fields on Notification Settings page. 264 * 265 * @since BuddyPress (1.0.0) 266 */ 267 do_action( 'bp_blogs_screen_notification_settings' ); ?> 268 269 </tbody> 270 </table> 271 272 <?php 273 } 274 add_action( 'bp_notification_settings', 'bp_blogs_screen_notification_settings', 20 ); 275 71 276 /** Theme Compatibility *******************************************************/ 72 277 73 278 /** 74 279 * The main theme compat class for BuddyPress Blogs 75 280 * 76 281 * This class sets up the necessary theme compatibility actions to safely output 77 * grouptemplate parts to the_title and the_content areas of a theme.282 * blog template parts to the_title and the_content areas of a theme. 78 283 * 79 284 * @since BuddyPress (1.7.0) 80 285 */ … … class BP_Blogs_Theme_Compat { 96 301 */ 97 302 public function is_blogs() { 98 303 99 // Bail if not looking at a group304 // Bail if not looking at a blog 100 305 if ( ! bp_is_blogs_component() ) 101 306 return; 102 307 … … class BP_Blogs_Theme_Compat { 105 310 return; 106 311 107 312 // Blog Directory 108 if ( is_multisite() && ! bp_current_action() ) {313 if ( is_multisite() && ! bp_current_action() && ! bp_current_item() ) { 109 314 bp_update_is_directory( true, 'blogs' ); 110 315 111 316 /** … … class BP_Blogs_Theme_Compat { 121 326 add_filter( 'bp_replace_the_content', array( $this, 'directory_content' ) ); 122 327 123 328 // Create blog 124 } elseif ( is_user_logged_in() && bp_blog_signup_enabled() ) {329 } elseif ( is_user_logged_in() && bp_blog_signup_enabled() && bp_is_create_blog() ) { 125 330 add_filter( 'bp_get_buddypress_template', array( $this, 'create_template_hierarchy' ) ); 126 331 add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) ); 127 332 add_filter( 'bp_replace_the_content', array( $this, 'create_content' ) ); 333 } elseif ( bp_is_single_item() ) { 334 add_filter( 'bp_get_buddypress_template', array( $this, 'single_template_hierarchy' ) ); 335 add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) ); 336 add_filter( 'bp_replace_the_content', array( $this, 'single_content' ) ); 128 337 } 129 338 } 130 339 … … class BP_Blogs_Theme_Compat { 183 392 } 184 393 185 394 /** 186 * Filter the_content with the groups index template part.395 * Filter the_content with the blogs index template part. 187 396 * 188 397 * @since BuddyPress (1.7.0) 189 398 */ … … class BP_Blogs_Theme_Compat { 260 469 public function create_content() { 261 470 return bp_buffer_template_part( 'blogs/create', null, false ); 262 471 } 472 473 /** Single ************************************************************/ 474 475 /** 476 * Add custom template hierarchy to theme compat for blog pages. 477 * 478 * This is to mirror how WordPress has 479 * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}. 480 * 481 * @since BuddyPress (2.3.0) 482 * 483 * @param string $templates The templates from bp_get_theme_compat_templates(). 484 * @return array $templates Array of custom templates to look for. 485 */ 486 public function single_template_hierarchy( $templates ) { 487 // Setup some variables we're going to reference in our custom templates 488 $blog = bp_blogs_get_current_blog(); 489 490 /** 491 * Filters the Blogs single pages template hierarchy based on priority. 492 * 493 * @since BuddyPress (2.3.0) 494 * 495 * @param array $value Array of default template files to use. 496 */ 497 $new_templates = apply_filters( 'bp_template_hierarchy_blogs_single_item', array( 498 'blogs/single/index-id-' . sanitize_file_name( $blog->id ) . '.php', 499 'blogs/single/index-slug-' . sanitize_file_name( $blog->slug ) . '.php', 500 'blogs/single/index-action-' . sanitize_file_name( bp_current_action() ) . '.php', 501 'blogs/single/index.php' 502 ) ); 503 504 // Merge new templates with existing stack 505 // @see bp_get_theme_compat_templates() 506 $templates = array_merge( (array) $new_templates, $templates ); 507 508 return $templates; 509 } 510 511 /** 512 * Update the global $post with single blog data. 513 * 514 * @since BuddyPress (2.3.0) 515 */ 516 public function single_dummy_post() { 517 bp_theme_compat_reset_post( array( 518 'ID' => 0, 519 'post_title' => bp_get_current_blog_name(), 520 'post_author' => 0, 521 'post_date' => 0, 522 'post_content' => '', 523 'post_type' => 'page', 524 'post_status' => 'publish', 525 'is_page' => true, 526 'comment_status' => 'closed' 527 ) ); 528 } 529 530 /** 531 * Filter the_content with the single blog template part. 532 * 533 * @since BuddyPress (2.3.0) 534 */ 535 public function single_content() { 536 return bp_buffer_template_part( 'blogs/single/home', null, false ); 537 } 263 538 } 264 539 new BP_Blogs_Theme_Compat(); -
src/bp-blogs/bp-blogs-template.php
diff --git src/bp-blogs/bp-blogs-template.php src/bp-blogs/bp-blogs-template.php index bd5f62d..ec196b6 100644
class BP_Blogs_Template { 197 197 * queried blogs. 198 198 * @param array $include_blog_ids Array of blog IDs to include. 199 199 */ 200 public function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true, $include_blog_ids = false ) {200 public function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true, $include_blog_ids = false, $slug = '' ) { 201 201 202 202 $this->pag_arg = sanitize_key( $page_arg ); 203 203 $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $page ); 204 204 $this->pag_num = bp_sanitize_pagination_arg( 'num', $per_page ); 205 205 206 // A blog item is requested 207 if ( 'single-blog' === $type ) { 208 if ( bp_blogs_get_current_blog() ) { 209 $blog = bp_blogs_get_current_blog(); 210 211 } else { 212 $blog = bp_blogs_get_blog( array( 213 'blog_id' => get_id_from_blogname( $slug ), 214 ) ); 215 } 216 217 $this->blogs = array( $blog ); 218 206 219 // Backwards compatibility support for blogs by first letter 207 if ( ! empty( $_REQUEST['letter'] ) ) {220 } elseif ( ! empty( $_REQUEST['letter'] ) ) { 208 221 $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page ); 209 222 210 223 // Typical blogs query … … class BP_Blogs_Template { 220 233 ) ); 221 234 } 222 235 223 // Set the total blog count 224 if ( empty( $max ) || ( $max >= (int) $this->blogs['total'] ) ) { 225 $this->total_blog_count = (int) $this->blogs['total']; 236 if ( 'single-blog' === $type ) { 237 if ( empty( $blog->id ) ) { 238 $this->total_blog_count = 0; 239 $this->blog_count = 0; 240 } else { 241 $this->total_blog_count = 1; 242 $this->blog_count = 1; 243 } 244 226 245 } else { 227 $this->total_blog_count = (int) $max; 228 } 246 // Set the total blog count 247 if ( empty( $max ) || ( $max >= (int) $this->blogs['total'] ) ) { 248 $this->total_blog_count = (int) $this->blogs['total']; 249 } else { 250 $this->total_blog_count = (int) $max; 251 } 229 252 230 // Set the blogs array (to loop through later231 $this->blogs = $this->blogs['blogs'];253 // Set the blogs array (to loop through later 254 $this->blogs = $this->blogs['blogs']; 232 255 233 // Get the current blog count to compare maximum against234 $blog_count = count( $this->blogs );256 // Get the current blog count to compare maximum against 257 $blog_count = count( $this->blogs ); 235 258 236 // Set the current blog count 237 if ( empty( $max ) || ( $max >= (int) $blog_count ) ) { 238 $this->blog_count = (int) $blog_count; 239 } else { 240 $this->blog_count = (int) $max; 259 // Set the current blog count 260 if ( empty( $max ) || ( $max >= (int) $blog_count ) ) { 261 $this->blog_count = (int) $blog_count; 262 } else { 263 $this->blog_count = (int) $max; 264 } 241 265 } 242 266 243 267 // Build pagination links based on total blogs and current page number … … function bp_rewind_blogs() { 395 419 function bp_has_blogs( $args = '' ) { 396 420 global $blogs_template; 397 421 422 $type = 'active'; 423 $slug = ''; 424 $current_blog = bp_blogs_get_current_blog(); 425 426 if ( bp_get_current_blog_slug() ) { 427 $type = 'single-blog'; 428 $slug = bp_get_current_blog_slug(); 429 } 430 431 398 432 // Check for and use search terms 399 433 $search_terms = ! empty( $_REQUEST['s'] ) 400 434 ? $_REQUEST['s'] … … function bp_has_blogs( $args = '' ) { 402 436 403 437 // Parse arguments 404 438 $r = bp_parse_args( $args, array( 405 'type' => 'active',439 'type' => $type, 406 440 'page_arg' => 'bpage', // See https://buddypress.trac.wordpress.org/ticket/3679 407 441 'page' => 1, 408 442 'per_page' => 20, … … function bp_has_blogs( $args = '' ) { 410 444 'user_id' => bp_displayed_user_id(), // Pass a user_id to limit to only blogs this user is a member of 411 445 'include_blog_ids' => false, 412 446 'search_terms' => $search_terms, // Pass search terms to filter on the blog title or description. 413 'update_meta_cache' => true 447 'update_meta_cache' => true, 448 'slug' => $slug // Pass the slug of the blog in conjonction with a type set to 'single-blog' 414 449 ), 'has_blogs' ); 415 450 416 451 // Set per_page to maximum if max is enforced … … function bp_has_blogs( $args = '' ) { 419 454 } 420 455 421 456 // Get the blogs 422 $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'] );457 $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['slug'] ); 423 458 424 459 /** 425 460 * Filters whether or not there are blogs to list. … … function bp_blog_avatar( $args = '' ) { 555 590 'type' => 'full', 556 591 'width' => false, 557 592 'height' => false, 558 'class' => 'avatar ',593 'class' => 'avatar blog-' . $blogs_template->blog->blog_id . '-avatar', 559 594 'id' => false, 560 595 'alt' => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), bp_core_get_user_displayname( $blogs_template->blog->admin_user_id ) ), 561 596 'no_grav' => true, 562 597 ) ); 563 598 599 /** 600 * If the Blogs single items are allowed, as people can subscribe to 601 * sites, when a subsriber looks at my sites, he can see his avatar 602 * for a site he's not an admin off. That's because BP_Blogs_Blog::get() 603 * is not really getting the admin of a blog but any member linked to it 604 * in the bp_user_blogs table. 605 * 606 * So as Blogs can now set avatars, let's use the mystery man to avoid 607 * some confusions.. 608 */ 609 if ( ! bp_blogs_disable_single_items() ) { 610 $object = 'blog'; 611 $avatar_dir = 'blog-avatars'; 612 $item_id = $blogs_template->blog->blog_id; 613 $title = $blogs_template->blog->name; 614 $r['class'] = 'avatar'; 615 $r['alt'] = sprintf( __( 'Site logo of %s', 'buddypress' ), $blogs_template->blog->name ); 616 617 } else { 618 // Defaults to the admin avatar 619 $item_id = $blogs_template->blog->admin_user_id; 620 $title = $blogs_template->blog->admin_user_email; 621 $object = 'user'; 622 $avatar_dir = 'avatars'; 623 } 624 564 625 // Fetch the avatar 565 626 $avatar = bp_core_fetch_avatar( array( 566 'item_id' => $ blogs_template->blog->admin_user_id,567 'title' => $ blogs_template->blog->admin_user_email,568 //'avatar_dir' => 'blog-avatars',569 //'object' => 'blog',627 'item_id' => $item_id, 628 'title' => $title, 629 'avatar_dir' => $avatar_dir, 630 'object' => $object, 570 631 'type' => $r['type'], 571 632 'alt' => $r['alt'], 572 633 'css_id' => $r['id'], … … function bp_blog_avatar( $args = '' ) { 575 636 'height' => $r['height'] 576 637 ) ); 577 638 578 /***579 * In future BuddyPress versions you will be able to set the avatar for a blog.580 * Right now you can use a filter with the ID of the blog to change it if you wish.581 * By default it will return the avatar for the primary blog admin.582 *583 * This filter is deprecated as of BuddyPress 1.5 and may be removed in a future version.584 * Use the 'bp_get_blog_avatar' filter instead.585 */586 $avatar = apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, $avatar );587 588 639 /** 589 640 * Filters a blog's avatar. 590 641 * … … function bp_blog_avatar( $args = '' ) { 598 649 return apply_filters( 'bp_get_blog_avatar', $avatar, $blogs_template->blog->blog_id, $r ); 599 650 } 600 651 652 /** 653 * Output the link to the single blog item 654 * 655 * @since BuddyPress (2.3.0) 656 */ 657 function bp_blog_view_details_link() { 658 echo bp_get_blog_view_details_link(); 659 } 660 661 /** 662 * Return the link to the single blog item 663 * 664 * @since BuddyPress (2.3.0) 665 * 666 * @param object $blog the blog to get the view details link for 667 * @return string the link to the blog's single item 668 */ 669 function bp_get_blog_view_details_link() { 670 global $blogs_template; 671 $slug = false; 672 673 if ( isset( $blogs_template->blog ) ) { 674 $blog = $blogs_template->blog; 675 } else { 676 $blog = bp_blogs_get_current_blog(); 677 } 678 679 if ( isset( $blog->slug ) ) { 680 $slug = $blog->slug; 681 } elseif ( isset( $blog->path ) ) { 682 if ( (int) get_current_site()->id === (int) $blog->blog_id ) { 683 $slug = apply_filters( 'bp_blogs_get_site_slug', 'root' ); 684 } else { 685 $slug = trim( str_replace( get_current_site()->path, '', $blog->path ), '/' ); 686 } 687 } 688 689 $view_details_link = trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/' . $slug ); 690 691 /** 692 * Filters the blog view details link. 693 * 694 * @since BuddyPress (2.3.0) 695 * 696 * @param string $view_details_link Permalink URL to the profile of the blog. 697 */ 698 return apply_filters( 'bp_get_blog_view_details_link', $view_details_link ); 699 } 700 601 701 function bp_blog_permalink() { 602 702 echo bp_get_blog_permalink(); 603 703 } 604 704 function bp_get_blog_permalink() { 605 705 global $blogs_template; 606 706 607 if ( empty( $blogs_template->blog->domain ) ) 707 if ( empty( $blogs_template->blog->domain ) ) { 608 708 $permalink = bp_get_root_domain() . $blogs_template->blog->path; 609 else {709 } else { 610 710 $protocol = 'http://'; 611 711 if ( is_ssl() ) 612 712 $protocol = 'https://'; … … function bp_total_blog_count_for_user( $user_id = 0 ) { 1108 1208 } 1109 1209 add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' ); 1110 1210 1211 /** 1212 * Prints a message if the user has no access to the blog's content 1213 * 1214 * @since BuddyPress (2.3.0) 1215 * 1216 * @global BP_Blogs_Template $blogs_template Blogs template object 1217 * @param object $blog Blog to get status message for. Optional; defaults to current blog. 1218 */ 1219 function bp_blog_status_message( $blog = null ) { 1220 global $blogs_template; 1221 1222 // Blog not passed so look for loop 1223 if ( empty( $blog ) ) { 1224 $blog =& $blogs_template->blog; 1225 } 1226 1227 $message = false; 1228 1229 // For now display a message if the blog is not public 1230 if ( empty( $blog->blog_public ) ) { 1231 $message = __( 'The details of this site are restricted to its members.', 'buddypress' ); 1232 } 1233 1234 /** 1235 * Filters a message if the blog is not public. 1236 * 1237 * @since BuddyPress (2.3.0) 1238 * 1239 * @param string $message Message to display to the current user. 1240 * @param object $blog Blog to get status message for. 1241 */ 1242 echo apply_filters( 'bp_blog_status_message', $message, $blog ); 1243 } 1111 1244 1112 1245 /** Blog Registration ********************************************************/ 1113 1246 … … function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, 1371 1504 <?php printf(__( '<a href="%1$s">%2$s</a> is your new site. <a href="%3$s">Login</a> as "%4$s" using your existing password.', 'buddypress' ), $blog_url, $blog_url, $blog_url . "wp-login.php", $user_name ); ?> 1372 1505 </p> 1373 1506 1374 <?php 1507 <?php if ( bp_blogs_is_avatar_uploads_enabled() && is_user_logged_in() ) : 1508 $slug = trim( str_replace( get_current_site()->path, '', $path ), '/' ); 1509 $single_blog_link = trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/' . $slug . '/manage/edit-logo' ); 1510 ?> 1511 <p> 1512 <?php printf( __( 'You can also set a site logo for your site at any time from this <a href="%s">page</a>.', 'buddypress' ), $single_blog_link ); ?> 1513 </p> 1514 1515 <?php endif; 1375 1516 1376 1517 /** 1377 1518 * Fires after the default successful blog registration message markup. … … function bp_blog_backcompat_create_nav_item() { 1554 1695 add_action( 'bp_blogs_directory_blog_types', 'bp_blog_backcompat_create_nav_item', 1000 ); 1555 1696 1556 1697 /** 1698 * Output button to view the blogs single item details. 1699 * 1700 * @since BuddyPress (2.3.0) 1701 * 1702 * @see bp_get_blogs_view_details_blog_button() for description of arguments. 1703 * 1704 * @param array $args See {@link bp_get_blogs_view_details_blog_button()}. 1705 */ 1706 function bp_blogs_view_details_blog_button( $args = '' ) { 1707 echo bp_get_blogs_view_details_blog_button( $args ); 1708 } 1709 add_action( 'bp_directory_blogs_actions', 'bp_blogs_view_details_blog_button' ); 1710 1711 /** 1712 * Return button for viewing the blogs single item details. 1713 * 1714 * @since BuddyPress (2.3.0) 1715 * 1716 * @see BP_Button for a complete description of arguments and return 1717 * value. 1718 * 1719 * @param array $args { 1720 * Arguments are listed below, with their default values. For a 1721 * complete description of arguments, see {@link BP_Button}. 1722 * @type string $id Default: 'view_blog_profile'. 1723 * @type string $component Default: 'blogs'. 1724 * @type bool $must_be_logged_in Default: false. 1725 * @type bool $block_self Default: false. 1726 * @type string $wrapper_class Default: 'blog-button profile'. 1727 * @type string $link_href View details link of the current blog in the loop. 1728 * @type string $link_class Default: 'blog-button profile'. 1729 * @type string $link_text Default: 'View Details'. 1730 * @type string $link_title Default: 'View Details'. 1731 * } 1732 * @return string The HTML for the Visit button. 1733 */ 1734 function bp_get_blogs_view_details_blog_button( $args = '' ) { 1735 // Do not display the button if the single blog feature is disabled 1736 if ( bp_blogs_disable_single_items() ) { 1737 return; 1738 } 1739 1740 $button = wp_parse_args( $args, array( 1741 'id' => 'view_blog_profile', 1742 'component' => 'blogs', 1743 'must_be_logged_in' => false, 1744 'block_self' => false, 1745 'wrapper_class' => 'blog-button profile', 1746 'link_href' => esc_url( bp_get_blog_view_details_link() ), 1747 'link_class' => 'blog-button profile', 1748 'link_text' => __( 'View Details', 'buddypress' ), 1749 'link_title' => __( 'View Details', 'buddypress' ), 1750 ) ); 1751 1752 // Filter and return the HTML button 1753 return bp_get_button( apply_filters( 'bp_get_blogs_view_details_blog_button', $button ) ); 1754 } 1755 1756 /** 1557 1757 * Output button for visiting a blog in a loop. 1558 1758 * 1559 1759 * @see bp_get_blogs_visit_blog_button() for description of arguments. … … add_action( 'bp_blogs_directory_blog_types', 'bp_blog_backcompat_create_nav_item 1563 1763 function bp_blogs_visit_blog_button( $args = '' ) { 1564 1764 echo bp_get_blogs_visit_blog_button( $args ); 1565 1765 } 1766 add_action( 'bp_blog_header_actions', 'bp_blogs_visit_blog_button', 10 ); 1767 1566 1768 /** 1567 1769 * Return button for visiting a blog in a loop. 1568 1770 * … … function bp_blogs_visit_blog_button( $args = '' ) { 1609 1811 return bp_get_button( apply_filters( 'bp_get_blogs_visit_blog_button', $button ) ); 1610 1812 } 1611 1813 1814 /** 1815 * Add a subcribe button in blog's header 1816 * 1817 * @since BuddyPress (2.3.0) 1818 */ 1819 function bp_blogs_join_blog_button( $blog = null ) { 1820 echo bp_get_blogs_join_blog_button( $blog ); 1821 } 1822 add_action( 'bp_blog_header_actions', 'bp_blogs_join_blog_button', 5 ); 1823 1824 /** 1825 * Get the blog's subcribe button 1826 * 1827 * @since BuddyPress (2.3.0) 1828 */ 1829 function bp_get_blogs_join_blog_button( $blog = null ) { 1830 1831 if ( empty( $blog ) ) { 1832 $blog = bp_blogs_get_current_blog(); 1833 } 1834 1835 if ( ! is_user_logged_in() || ! isset( $blog->id ) || ! bp_current_blog_can_subscribe() ) { 1836 return false; 1837 } 1838 1839 // Already a member 1840 if ( bp_current_blog_is_member() ) { 1841 1842 if ( bp_is_item_admin() ) { 1843 return false; 1844 } 1845 1846 $button = array( 1847 'id' => 'leave_blog', 1848 'component' => 'blogs', 1849 'must_be_logged_in' => true, 1850 'block_self' => false, 1851 'wrapper_class' => 'blog-button leave', 1852 'wrapper_id' => 'blogbutton-' . $blog->id, 1853 'link_href' => esc_url( wp_nonce_url( bp_get_blog_view_details_link() . '?action=leave', 'blogs_leave_blog' ) ), 1854 'link_text' => __( 'Leave', 'buddypress' ), 1855 'link_title' => __( 'Leave', 'buddypress' ), 1856 'link_class' => 'blog-button leave-blog confirm', 1857 ); 1858 1859 // Not a member 1860 } else { 1861 1862 $button = array( 1863 'id' => 'join_blog', 1864 'component' => 'blogs', 1865 'must_be_logged_in' => true, 1866 'block_self' => false, 1867 'wrapper_class' => 'blog-button join', 1868 'wrapper_id' => 'blogbutton-' . $blog->id, 1869 'link_href' => esc_url( wp_nonce_url( bp_get_blog_view_details_link() . '?action=join', 'blogs_join_blog' ) ), 1870 'link_text' => __( 'Join', 'buddypress' ), 1871 'link_title' => __( 'Join', 'buddypress' ), 1872 'link_class' => 'blog-button join-blog', 1873 ); 1874 } 1875 1876 // Filter and return the HTML button 1877 return bp_get_button( apply_filters( 'bp_get_blogs_join_blog_button', $button ) ); 1878 } 1879 1612 1880 /** Stats **********************************************************************/ 1613 1881 1614 1882 /** … … function bp_blogs_get_profile_stats( $args = '' ) { 1669 1937 */ 1670 1938 return apply_filters( 'bp_blogs_get_profile_stats', $r['output'], $r ); 1671 1939 } 1940 1941 /** 1942 * Output the blogs single item sub nav 1943 * 1944 * @since BuddyPress (2.3.0) 1945 */ 1946 function bp_blogs_item_subnav() { 1947 $bp = buddypress(); 1948 1949 if ( $bp->blogs->id !== bp_current_component() || ! bp_is_single_item() ) { 1950 return; 1951 } 1952 1953 $component = bp_current_component(); 1954 $the_index = bp_current_action(); 1955 1956 // Default subnav 1957 $selected_item = bp_current_action(); 1958 1959 if ( bp_action_variable( 0 ) ) { 1960 $selected_item = bp_action_variable( 0 ); 1961 } 1962 1963 if ( empty( $bp->{$component}->single_subnav[ $the_index ] ) ) { 1964 return; 1965 } 1966 1967 return bp_component_options_nav( $bp->{$component}->single_subnav, $the_index, $selected_item, $component ); 1968 } 1969 1970 /** 1971 * Load the appropriate current blog's home page 1972 * 1973 * @since BuddyPress (2.3.0) 1974 */ 1975 function bp_blogs_load_blog_front_template( $require_once = false, $blog = null ) { 1976 $located = bp_blogs_get_blog_front_template( $blog ); 1977 1978 if ( false !== $located ) { 1979 $slug = str_replace( '.php', '', $located ); 1980 1981 /** 1982 * Let plugins adding an action to bp_get_template_part get it from here 1983 * 1984 * @param string $slug Template part slug requested. 1985 * @param string $name Template part name requested. 1986 */ 1987 do_action( 'get_template_part_' . $slug, $slug, false ); 1988 1989 load_template( $located, $require_once ); 1990 1991 } elseif ( bp_is_active( 'activity' ) && bp_current_blog_is_public() ) { 1992 bp_get_template_part( 'blogs/single/activity' ); 1993 1994 } elseif ( bp_is_active( 'members' ) ) { 1995 bp_get_template_part( 'blogs/single/members' ); 1996 } 1997 1998 return $located; 1999 } 2000 2001 /** 2002 * Locate a custom blog front template if it exsists 2003 * 2004 * @since BuddyPress (2.3.0) 2005 */ 2006 function bp_blogs_get_blog_front_template( $blog = null ) { 2007 if ( ! is_a( $blog, 'BP_Blogs_Blog' ) ) { 2008 $blog = bp_blogs_get_current_blog(); 2009 } 2010 2011 if ( ! isset( $blog->id ) ) { 2012 return false; 2013 } 2014 2015 if ( isset( $blog->front_template ) ) { 2016 return $blog->front_template; 2017 } 2018 2019 $template_names = apply_filters( 'bp_blogs_get_front_template', array( 2020 'blogs/single/front-id-' . sanitize_file_name( $blog->id ) . '.php', 2021 'blogs/single/front-slug-' . sanitize_file_name( $blog->slug ) . '.php', 2022 'blogs/single/front.php' 2023 ) ); 2024 2025 return bp_locate_template( $template_names, false, true ); 2026 } 2027 2028 /** 2029 * Is the current page a specific blog manage screen? 2030 * 2031 * @since BuddyPress (2.3.0) 2032 * 2033 * @param string $slug 2034 * @return bool 2035 */ 2036 function bp_is_blog_manage_screen( $slug = '' ) { 2037 return (bool) ( bp_is_blog_manage() && bp_is_action_variable( $slug ) ); 2038 } 2039 2040 /** 2041 * Return whether a blog has an avatar 2042 * 2043 * @since BuddyPress (2.3.0) 2044 * 2045 * @param int $blog_id 2046 * @return boolean 2047 */ 2048 function bp_get_blog_has_avatar( $blog_id = false ) { 2049 2050 if ( false === $blog_id ) { 2051 $blog_id = bp_get_current_blog_id(); 2052 } 2053 2054 $blog_avatar = bp_core_fetch_avatar( array( 2055 'item_id' => $blog_id, 2056 'object' => 'blog', 2057 'no_grav' => true, 2058 'html' => false, 2059 ) ); 2060 2061 if ( bp_core_avatar_default( 'local' ) === $blog_avatar ) { 2062 return false; 2063 } 2064 2065 return true; 2066 } 2067 2068 /** Current blog *************************************************************/ 2069 2070 /** 2071 * Echoes the output of bp_get_current_blog_id() 2072 * 2073 * @since BuddyPress (2.3.0) 2074 */ 2075 function bp_current_blog_id() { 2076 echo bp_get_current_blog_id(); 2077 } 2078 /** 2079 * Returns the ID of the current blog 2080 * 2081 * @since BuddyPress (2.3.0) 2082 * @uses apply_filters() Filter bp_get_current_blog_id to modify this output 2083 * 2084 * @return string The ID of the current blog, if there is one 2085 */ 2086 function bp_get_current_blog_id() { 2087 $current_blog = bp_blogs_get_current_blog(); 2088 $current_blog_id = ''; 2089 2090 if ( isset( $current_blog->id ) ) { 2091 $current_blog_id = $current_blog->id; 2092 } 2093 2094 /** 2095 * Filters the ID of the current blog 2096 * 2097 * @since BuddyPress (2.3.0) 2098 * 2099 * @param string $current_blog_id ID of the current blog. 2100 * @param object $current_blog Instance holding the current blog. 2101 */ 2102 return apply_filters( 'bp_get_current_blog_id', $current_blog_id, $current_blog ); 2103 } 2104 2105 /** 2106 * Echoes the output of bp_get_current_blog_name() 2107 * 2108 * @since BuddyPress (2.3.0) 2109 */ 2110 function bp_current_blog_name() { 2111 echo bp_get_current_blog_name(); 2112 } 2113 /** 2114 * Returns the name of the current blog 2115 * 2116 * @since BuddyPress (2.3.0) 2117 * @uses apply_filters() Filter bp_get_current_blog_name to modify this output 2118 * 2119 * @return string The name of the current blog, if there is one 2120 */ 2121 function bp_get_current_blog_name() { 2122 $current_blog = bp_blogs_get_current_blog(); 2123 $current_blog_name = ''; 2124 2125 if ( isset( $current_blog->name ) ) { 2126 $current_blog_name = $current_blog->name; 2127 } 2128 2129 /** 2130 * Filters the name of the current blog 2131 * 2132 * @since BuddyPress (2.3.0) 2133 * 2134 * @param string $current_blog_name Name of the current blog. 2135 * @param object $current_blog Instance holding the current blog. 2136 */ 2137 return apply_filters( 'bp_get_current_blog_name', $current_blog_name, $current_blog ); 2138 } 2139 2140 /** 2141 * Echoes the output of bp_get_current_blog_slug() 2142 * 2143 * @since BuddyPress (2.3.0) 2144 */ 2145 function bp_current_blog_slug() { 2146 echo bp_get_current_blog_slug(); 2147 } 2148 /** 2149 * Returns the slug of the current blog 2150 * 2151 * @since BuddyPress (2.3.0) 2152 * @uses apply_filters() Filter bp_get_current_blog_slug to modify this output 2153 * 2154 * @return string The slug of the current blog, if there is one 2155 */ 2156 function bp_get_current_blog_slug() { 2157 $current_blog = bp_blogs_get_current_blog(); 2158 $current_blog_slug = ''; 2159 2160 if ( isset( $current_blog->slug ) ) { 2161 $current_blog_slug = $current_blog->slug; 2162 } 2163 2164 /** 2165 * Filters the slug of the current blog 2166 * 2167 * @since BuddyPress (2.3.0) 2168 * 2169 * @param string $current_blog_slug Slug of the current blog. 2170 * @param object $current_blog Instance holding the current blog. 2171 */ 2172 return apply_filters( 'bp_get_current_blog_slug', $current_blog_slug, $current_blog ); 2173 } 2174 2175 /** 2176 * Display the admins in the blog's header 2177 * 2178 * @since BuddyPress (2.3.0) 2179 */ 2180 function bp_current_blog_admins() { 2181 echo bp_get_current_blog_admins(); 2182 } 2183 /** 2184 * Get the admins list 2185 * 2186 * @since BuddyPress (2.3.0) 2187 */ 2188 function bp_get_current_blog_admins() { 2189 $current_blog = bp_blogs_get_current_blog(); 2190 $pre_output = false; 2191 2192 // Do not display admins if the user has no access 2193 if ( ! bp_current_blog_has_access() ) { 2194 $pre_output = ''; 2195 } 2196 2197 /** 2198 * Use this filter if you need to hide the blog admins by returning false 2199 * 2200 * @since BuddyPress (2.3.0) 2201 * 2202 * @param boolean $pre_output whether to output the list of the current blog admins 2203 */ 2204 $pre_output = apply_filters( 'bp_pre_get_current_blog_admins', $pre_output, $current_blog ); 2205 if ( false !== $pre_output ) { 2206 return $pre_output; 2207 } 2208 2209 $output = '<h3>' . esc_html__( 'Site Admins', 'bp-blogs-extended' ) . '</h3>'; 2210 $output .= '<span class="activity">' . esc_html__( 'No Admins', 'bp-blogs-extended' ) . '</span>'; 2211 2212 if ( ! empty( $current_blog->admins ) ) { 2213 $output = '<ul id="blog-admins">'; 2214 2215 foreach( (array) $current_blog->admins as $admin ) { 2216 $output .= '<li>'; 2217 2218 if ( ! buddypress()->avatar->show_avatars ) { 2219 $output .= sprintf( 2220 '<a href="%s" title="%s">%s</a>', 2221 esc_url( bp_core_get_user_domain( $admin->ID, $admin->user_nicename, $admin->user_login ) ), 2222 sprintf( esc_attr__( 'Profile of %s', 'bp-blogs-extended' ), $admin->display_name ), 2223 esc_html( $admin->user_nicename ) 2224 ); 2225 } else { 2226 $output .= sprintf( 2227 '<a href="%s">%s</a>', 2228 esc_url( bp_core_get_user_domain( $admin->ID, $admin->user_nicename, $admin->user_login ) ), 2229 bp_core_fetch_avatar( array( 2230 'item_id' => esc_attr( $admin->ID ), 2231 'email' => esc_attr( $admin->user_email ), 2232 'alt' => sprintf( esc_attr__( 'Profile picture of %s', 'bp-blogs-extended' ), $admin->display_name ) 2233 ) ) 2234 ); 2235 } 2236 2237 $output .= '</li>'; 2238 } 2239 2240 $output .= '</ul>'; 2241 } 2242 2243 return apply_filters( 'bp_get_current_blog_admins', $output, $current_blog ); 2244 } 2245 2246 /** 2247 * Display the current blog type 2248 * 2249 * @since BuddyPress (2.3.0) 2250 */ 2251 function bp_current_blog_type() { 2252 echo bp_get_current_blog_type(); 2253 } 2254 2255 /** 2256 * Get the current blog type 2257 * 2258 * @since BuddyPress (2.3.0) 2259 */ 2260 function bp_get_current_blog_type() { 2261 $type = esc_html__( 'Private', 'buddypress' ); 2262 2263 if ( bp_current_blog_is_public() ) { 2264 $type = esc_html__( 'Public', 'buddypress' ); 2265 } 2266 2267 /** 2268 * Use this filter if you need to edit the blog type 2269 * 2270 * @since BuddyPress (2.3.0) 2271 * 2272 * @param string $type the blog type 2273 */ 2274 return apply_filters( 'bp_get_current_blog_type', $type ); 2275 } 2276 2277 /** Blog Members **************************************************************/ 2278 2279 /** 2280 * The following functions are wrapping some Members loop template functions 2281 * It might be interesting in the future to use a specific class to extend 2282 * BP_User_Query the same way the groups component is doing to add new filter 2283 * options. 2284 */ 2285 2286 /** 2287 * bp_has_members wrapper to fetch the current blog's members 2288 * 2289 * @since BuddyPress (2.3.0) 2290 * 2291 * @see bp_has_members() for detailed available arguments 2292 */ 2293 function bp_blog_has_members( $args = '' ) { 2294 global $wpdb; 2295 2296 $meta_key = $wpdb->get_blog_prefix( bp_get_current_blog_id() ) . 'capabilities'; 2297 2298 $r = bp_parse_args( $args, array( 2299 'type' => 'active', 2300 'page' => 1, 2301 'per_page' => 20, 2302 'max' => false, 2303 'page_arg' => 'blogpage', 2304 'user_id' => 0, 2305 'meta_key' => $meta_key, // Only return users of the current blog 2306 ), 'blog_has_members' ); 2307 2308 return bp_has_members( $r ); 2309 } 2310 2311 /** 2312 * bp_members wrapper for the current blog's 2313 * 2314 * @since BuddyPress (2.3.0) 2315 */ 2316 function bp_blog_members() { 2317 return bp_members(); 2318 } 2319 2320 /** 2321 * bp_the_member wrapper for the current blog's 2322 * 2323 * @since BuddyPress (2.3.0) 2324 */ 2325 function bp_blog_the_member() { 2326 return bp_the_member(); 2327 } 2328 2329 /** 2330 * bp_member_permalink wrapper for the current blog's 2331 * 2332 * @since BuddyPress (2.3.0) 2333 */ 2334 function bp_blog_member_permalink() { 2335 return bp_member_permalink(); 2336 } 2337 2338 /** 2339 * bp_member_avatar wrapper for the current blog's 2340 * 2341 * @since BuddyPress (2.3.0) 2342 */ 2343 function bp_blog_member_avatar() { 2344 return bp_member_avatar(); 2345 } 2346 2347 /** 2348 * bp_member_name wrapper for the current blog's 2349 * 2350 * @since BuddyPress (2.3.0) 2351 */ 2352 function bp_blog_member_name() { 2353 return bp_member_name(); 2354 } 2355 2356 /** 2357 * bp_get_member_latest_update wrapper for the current blog's 2358 * 2359 * @since BuddyPress (2.3.0) 2360 */ 2361 function bp_blog_get_member_latest_update() { 2362 return bp_get_member_latest_update(); 2363 } 2364 2365 /** 2366 * bp_member_latest_update wrapper for the current blog's 2367 * 2368 * @since BuddyPress (2.3.0) 2369 */ 2370 function bp_blog_member_latest_update() { 2371 return bp_member_latest_update(); 2372 } 2373 2374 /** 2375 * bp_member_last_active wrapper for the current blog's 2376 * 2377 * @since BuddyPress (2.3.0) 2378 */ 2379 function bp_blog_member_last_active() { 2380 return bp_member_last_active(); 2381 } 2382 2383 /** 2384 * Output button to remove a member from the site. 2385 * 2386 * @since BuddyPress (2.3.0) 2387 * 2388 * @see bp_get_blog_member_remove_button() for description of arguments. 2389 * 2390 * @param array $args See {@link bp_get_blog_member_remove_button()}. 2391 */ 2392 function bp_blog_member_remove_button( $args = '' ) { 2393 echo bp_get_blog_member_remove_button( $args ); 2394 } 2395 2396 /** 2397 * Return button to remove a member from the site. 2398 * 2399 * @since BuddyPress (2.3.0) 2400 * 2401 * @see BP_Button for a complete description of arguments and return 2402 * value. 2403 * 2404 * @param array $args { 2405 * Arguments are listed below, with their default values. For a 2406 * complete description of arguments, see {@link BP_Button}. 2407 * @type string $id Default: 'blog_remove_member'. 2408 * @type string $component Default: 'blogs'. 2409 * @type bool $must_be_logged_in Default: false. 2410 * @type bool $block_self Default: false. 2411 * @type string $wrapper_class Default: 'blog-button remove'. 2412 * @type string $link_href View details link of the current blog in the loop. 2413 * @type string $link_class Default: 'blog-button remove'. 2414 * @type string $link_text Default: 'Remove member'. 2415 * @type string $link_title Default: 'Remove member'. 2416 * } 2417 * @return string The HTML for the Visit button. 2418 */ 2419 function bp_get_blog_member_remove_button( $args = '' ) { 2420 // Do not display the button if the single blog feature is disabled 2421 if ( bp_blogs_disable_single_items() ) { 2422 return; 2423 } 2424 2425 $remove_link = trailingslashit( bp_get_blog_view_details_link() . 'manage/members' ); 2426 2427 $button = wp_parse_args( $args, array( 2428 'id' => 'blog_remove_member', 2429 'component' => 'blogs', 2430 'must_be_logged_in' => true, 2431 'block_self' => true, 2432 'wrapper_class' => 'blog-button remove', 2433 'link_href' => esc_url( wp_nonce_url( $remove_link . '?remove_member=' . bp_get_member_user_id(), 'blogs_remove_member' ) ), 2434 'link_class' => 'blog-button remove', 2435 'link_text' => __( 'Remove member', 'buddypress' ), 2436 'link_title' => __( 'Remove member', 'buddypress' ), 2437 ) ); 2438 2439 // Filter and return the HTML button 2440 return bp_get_button( apply_filters( 'bp_get_blog_member_remove_button', $button ) ); 2441 } -
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 5e88b89..7c516b1 100644
class BP_Blogs_Blog { 27 27 * 28 28 * @param int $id Optional. The ID of the blog. 29 29 */ 30 public function __construct( $id = null ) { 31 if ( !empty( $id ) ) { 30 public function __construct( $id = null, $args = array() ) { 31 $this->args = wp_parse_args( $args, array( 32 'populate_extras' => false, 33 ) ); 34 35 if ( ! empty( $id ) ) { 32 36 $this->id = $id; 33 37 $this->populate(); 34 38 } … … class BP_Blogs_Blog { 42 46 43 47 $bp = buddypress(); 44 48 45 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) ); 49 // Are we getting extra blog data? 50 if ( ! empty( $this->args['populate_extras'] ) ) { 51 52 // We need some of the blog details and it's a good 53 // way to check the blog is not moderated 54 $blog_details = get_blog_details( $this->id ); 55 56 if ( empty( $blog_details ) || 1 === (int) $blog_details->mature || 1 === (int) $blog_details->spam || 1 === (int) $blog_details->archived || 1 === (int) $blog_details->deleted ) { 57 $this->id = 0; 58 return; 59 } 60 61 // Set the blog id 62 $this->blog_id = $this->id; 63 64 // Populating BuddyPress blog metas for the requested blog 65 foreach ( bp_blogs_get_blogmeta( $this->id ) as $key => $meta ) { 66 // Don't fetch private blogmeta 67 if ( is_protected_meta( $key ) ) { 68 continue; 69 } 70 71 if ( count( $meta ) == 1 ) { 72 $this->{$key} = maybe_unserialize( $meta[0] ); 73 } else { 74 $this->{$key} = array_map( 'maybe_unserialize', $meta ); 75 } 76 } 77 78 if ( ! isset( $this->url ) ) { 79 $this->url = $blog_details->siteurl; 80 } 81 82 if ( ! isset( $this->name ) ) { 83 $this->name = $blog_details->blogname; 84 } 85 86 // The following properties are necessary for the blogs loop 87 $this->path = $blog_details->path; 88 $this->domain = $blog_details->domain; 89 $current_site = get_current_site(); 46 90 47 $this->user_id = $blog->user_id; 48 $this->blog_id = $blog->blog_id; 91 if ( (int) $current_site->id === (int) $this->blog_id ) { 92 $this->slug = apply_filters( 'bp_blogs_get_site_slug', 'root' ); 93 } else { 94 $this->slug = trim( str_replace( $current_site->path, '', $this->path ), '/' ); 95 } 96 97 if ( bp_get_root_blog_id() !== $this->id ) { 98 $needs_reset = true; 99 switch_to_blog( $this->id ); 100 } 101 102 // Who are the admins ? 103 $this->admins = get_users( array( 104 'role' => 'administrator', 105 'fields' => array( 'ID', 'display_name', 'user_login', 'user_nicename', 'user_email' ), 106 ) ); 107 108 $this->admin_user_id = $this->admins[0]->ID; 109 $this->admin_user_email = $this->admins[0]->user_email; 110 111 // How many users ? 112 $blog_users = count_users(); 113 $this->total_member_count = $blog_users['total_users']; 114 115 // How many posts ? 116 $this->post_count = $blog_details->post_count; 117 118 // Is current user a member of the blog ? 119 $this->is_member = current_user_can( 'read' ); 120 121 // Blog visibility 122 $this->blog_public = $blog_details->public; 123 124 if ( isset( $needs_reset ) ) { 125 restore_current_blog(); 126 } 127 128 } else { 129 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) ); 130 131 $this->user_id = $blog->user_id; 132 $this->blog_id = $blog->blog_id; 133 } 49 134 } 50 135 51 136 /** … … class BP_Blogs_Blog { 241 326 global $wpdb; 242 327 243 328 bp_blogs_delete_blogmeta( $blog_id ); 244 329 245 330 $bp = buddypress(); 246 331 247 332 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) ); -
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 e481184..9ddbd69 100644
function bp_admin_setting_callback_bbpress_configuration() { 218 218 <?php 219 219 } 220 220 221 /** Blogs Section ************************************************************/ 222 223 /** 224 * Blogs settings section description for the settings page 225 * 226 * @since BuddyPress (2.3.0) 227 */ 228 function bp_admin_setting_callback_blogs_section() { } 229 230 /** 231 * Disable the Blogs single items 232 * 233 * @since BuddyPress (2.3.0) 234 * 235 * @uses checked() To display the checked attribute 236 */ 237 function bp_admin_setting_callback_blog_single_item() { 238 ?> 239 240 <input id="bp-blogs-disable-single-items" name="bp-blogs-disable-single-items" type="checkbox"value="1" <?php checked( bp_blogs_disable_single_items() ); ?> /> 241 <label for="bp-blogs-disable-single-items"><?php _e( 'Disable single sites details', 'buddypress' ); ?></label> 242 <p class="description"><?php _e( 'Use this setting if you prefer to only use the sites directory.', 'buddypress' ); ?></p> 243 244 <?php 245 } 246 221 247 /** Settings Page *************************************************************/ 222 248 223 249 /** -
src/bp-core/bp-core-admin.php
diff --git src/bp-core/bp-core-admin.php src/bp-core/bp-core-admin.php index bd25184..8c3551c 100644
class BP_Admin { 401 401 add_settings_field( 'bp-disable-avatar-uploads', __( 'Profile Photo Uploads', 'buddypress' ), 'bp_admin_setting_callback_avatar_uploads', 'buddypress', $avatar_setting ); 402 402 register_setting ( 'buddypress', 'bp-disable-avatar-uploads', 'intval' ); 403 403 } 404 405 /** Blogs Section ****************************************************/ 406 407 if ( bp_is_active( 'blogs' ) && is_multisite() ) { 408 409 // Add the main section 410 add_settings_section( 'bp_blogs', __( 'Network Sites Settings', 'buddypress' ), 'bp_admin_setting_callback_blogs_section', 'buddypress' ); 411 412 // Allow subscriptions setting 413 add_settings_field( 'bp-blogs-disable-single-items', __( 'Single site details', 'buddypress' ), 'bp_admin_setting_callback_blog_single_item', 'buddypress', 'bp_blogs' ); 414 register_setting ( 'buddypress', 'bp-blogs-disable-single-items', 'intval' ); 415 } 404 416 } 405 417 406 418 /** -
src/bp-core/bp-core-attachments.php
diff --git src/bp-core/bp-core-attachments.php src/bp-core/bp-core-attachments.php index d454d88..5b0595a 100644
function bp_attachments_current_user_can( $capability, $args = array() ) { 312 312 // User profile photo 313 313 } elseif ( bp_is_active( 'xprofile' ) && 'user' === $args['object'] ) { 314 314 $can = bp_loggedin_user_id() === (int) $args['item_id'] || bp_current_user_can( 'bp_moderate' ); 315 // Site logo 316 } elseif ( bp_is_active( 'blogs' ) && 'blog' === $args['object'] ) { 317 $can = current_user_can_for_blog( (int) $args['item_id'], 'manage_options' ); 315 318 } 316 319 /** 317 320 * No avatar arguments, fallback to bp_user_can_create_groups() -
src/bp-core/bp-core-avatars.php
diff --git src/bp-core/bp-core-avatars.php src/bp-core/bp-core-avatars.php index 8457c03..fbfd3f4 100644
function bp_core_fetch_avatar( $args = '' ) { 213 213 switch ( $params['object'] ) { 214 214 215 215 case 'blog' : 216 $params['item_id'] = $current_blog->id; 216 if ( bp_is_active( 'blogs' ) ) { 217 $params['item_id'] = bp_get_current_blog_id(); 218 } else { 219 $params['item_id'] = false; 220 } 217 221 break; 218 222 219 223 case 'group' : … … function bp_core_delete_existing_avatar( $args = '' ) { 664 668 extract( $args, EXTR_SKIP ); 665 669 666 670 if ( empty( $item_id ) ) { 667 if ( 'user' == $object ) 671 if ( 'user' == $object ) { 668 672 $item_id = bp_displayed_user_id(); 669 elseif ( 'group' == $object )673 } elseif ( 'group' == $object && bp_is_active( 'groups' ) ) { 670 674 $item_id = buddypress()->groups->current_group->id; 671 elseif ( 'blog' == $object ) 672 $item_id = $current_blog->id; 675 } elseif ( 'blog' == $object && bp_is_active( 'blogs' ) ) { 676 $item_id = bp_get_current_blog_id(); 677 } 673 678 674 679 /** This filter is documented in bp-core/bp-core-avatars.php */ 675 680 $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object ); 676 681 677 if ( !$item_id ) return false; 682 if ( ! $item_id ) { 683 return false; 684 } 678 685 } 679 686 680 687 if ( empty( $avatar_dir ) ) { … … function bp_avatar_ajax_upload() { 920 927 'populate_extras' => false, 921 928 ) ); 922 929 } 930 } elseif ( 'blog' === $bp_params['object'] && bp_is_active( 'blogs' ) ) { 931 $bp_params['upload_dir_filter'] = 'blogs_avatar_upload_dir'; 932 933 if ( ! bp_get_current_blog_id() && ! empty( $bp_params['item_id'] ) ) { 934 $needs_reset = array( 'component' => 'blogs', 'key' => 'current_blog', 'value' => $bp->blogs->current_blog ); 935 $bp->blogs->current_blog = bp_blogs_get_blog( array( 936 'blog_id' => $bp_params['item_id'], 937 'populate_extras' => true, 938 ) ); 939 } 923 940 } else { 924 941 /** 925 942 * Filter here to deal with other components … … function bp_avatar_is_front_edit() { 1808 1825 } 1809 1826 } 1810 1827 1828 if ( bp_is_active( 'blogs' ) && bp_is_blog_manage_screen( 'edit-logo' ) ) { 1829 $retval = ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ); 1830 } 1831 1811 1832 /** 1812 1833 * Use this filter if you need to : 1813 1834 * - Load the avatar UI for a component that is !groups or !user (return true regarding your conditions) -
src/bp-core/bp-core-buddybar.php
diff --git src/bp-core/bp-core-buddybar.php src/bp-core/bp-core-buddybar.php index ca87d9a..ca0383c 100644
function bp_core_new_nav_item( $args = '' ) { 46 46 'site_admin_only' => false, // Can only site admins see this nav item? 47 47 'position' => 99, // Index of where this nav item should be positioned 48 48 'screen_function' => false, // The name of the function to run when clicked 49 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked 49 'default_subnav_slug' => false, // The slug of the default subnav item to select when clicked 50 'single_nav' => false, // The component id to create the single nav for 50 51 ); 51 52 52 53 $r = wp_parse_args( $args, $defaults ); 53 extract( $r, EXTR_SKIP );54 54 55 55 // If we don't have the required info we need, don't create this subnav item 56 if ( empty( $ name ) || empty( $slug ) )56 if ( empty( $r['name'] ) || empty( $r['slug'] ) ) { 57 57 return false; 58 } 58 59 59 60 // If this is for site admins only and the user is not one, don't create the subnav item 60 if ( ! empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) )61 if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { 61 62 return false; 63 } 62 64 63 if ( empty( $item_css_id ) ) 64 $item_css_id = $slug; 65 // Defaults to slug 66 $item_css_id = $r['slug']; 67 68 if ( ! empty( $r['item_css_id'] ) ) { 69 $item_css_id = $r['item_css_id']; 70 } 65 71 66 $ bp->bp_nav[$slug]= array(67 'name' => $ name,68 'slug' => $ slug,69 'link' => trailingslashit( bp_loggedin_user_domain() . $slug ),72 $nav_item = array( 73 'name' => $r['name'], 74 'slug' => $r['slug'], 75 'link' => '', 70 76 'css_id' => $item_css_id, 71 'show_for_displayed_user' => $ show_for_displayed_user,72 'position' => $ position,73 'screen_function' => &$ screen_function,74 'default_subnav_slug' => $default_subnav_slug77 'show_for_displayed_user' => $r['show_for_displayed_user'], 78 'position' => $r['position'], 79 'screen_function' => &$r['screen_function'], 80 'default_subnav_slug' => $r['default_subnav_slug'] 75 81 ); 76 82 83 $is_component_single_nav = ! empty( $r['single_nav'] ) && bp_is_active( $r['single_nav'] ) && isset( $bp->{$r['single_nav']}->single_nav ) && bp_is_current_component( $r['single_nav'] ); 84 85 // The component is managing its single items nav 86 if ( $is_component_single_nav ) { 87 $component = $r['single_nav']; 88 89 /** 90 * Filter here to add your custom function to build the component root slug 91 * 92 * @since BuddyPress (2.3.0) 93 * 94 * $callable string the function to use 95 * $component string the component id 96 */ 97 $callable = apply_filters( 'bp_core_new_nav_item_component_callable', 'bp_get_' . $component . '_root_slug', $component ); 98 99 if ( ! is_callable( $callable ) ) { 100 return false; 101 } 102 103 $nav_item['link'] = trailingslashit( bp_get_root_domain() . '/' . call_user_func( $callable ) . '/' . bp_current_item() . '/' . $r['slug'] ); 104 $bp->{$r['single_nav']}->single_nav[ $r['slug'] ] = $nav_item; 105 106 // Default nav is core nav 107 } else { 108 $nav_item['link'] = trailingslashit( bp_loggedin_user_domain() . $r['slug'] ); 109 $bp->bp_nav[ $r['slug'] ] = $nav_item; 110 } 111 77 112 /** 78 113 * If this nav item is hidden for the displayed user, and 79 114 * the logged in user is not the displayed user 80 115 * looking at their own profile, don't create the nav item. 81 116 */ 82 if ( empty( $ show_for_displayed_user ) && !bp_user_has_access() )117 if ( empty( $r['show_for_displayed_user'] ) && ! bp_user_has_access() ) { 83 118 return false; 119 } 84 120 85 121 /** 86 122 * If the nav item is visible, we are not viewing a user, and this is a root 87 123 * component, don't attach the default subnav function so we can display a 88 124 * directory or something else. 89 125 */ 90 if ( ( -1 != $ position ) && bp_is_root_component( $slug ) && !bp_displayed_user_id() )126 if ( ( -1 != $r['position'] ) && bp_is_root_component( $r['slug'] ) && ! bp_displayed_user_id() && ! $is_component_single_nav ) { 91 127 return; 128 } 129 130 // Manage the component's specific single nav 131 if ( $is_component_single_nav && bp_is_current_action( $r['slug'] ) ) { 132 if ( ! empty( $r['default_subnav_slug'] ) && bp_is_action_variable( $r['default_subnav_slug'], 0 ) && ! bp_action_variable( 1 ) ) { 133 unset( $bp->canonical_stack['action_variables'][0] ); 134 } elseif ( ! bp_action_variable( 0 ) ) { 92 135 93 // Look for current component 94 if ( bp_is_current_component( $slug ) || bp_is_current_item( $slug ) ) { 136 // Add our screen hook if screen function is callable 137 if ( is_callable( $r['screen_function'] ) ) { 138 add_action( 'bp_screens', $r['screen_function'], 3 ); 139 } 140 141 if ( ! empty( $r['default_subnav_slug'] ) ) { 142 /** 143 * Filters the component's single nav default subnav item. 144 * 145 * @since BuddyPress (2.3.0) 146 * 147 * @param string $default_subnav_slug The slug of the default subnav item 148 * to select when clicked. 149 * @param array $r Parsed arguments for the nav item. 150 */ 151 $bp->current_action = apply_filters( 'bp_default_component_single_subnav', $r['default_subnav_slug'], $r ); 152 } 153 } 154 155 // Look for current component in core nav 156 } elseif ( bp_is_current_component( $r['slug'] ) || bp_is_current_item( $r['slug'] ) ) { 95 157 96 158 // The requested URL has explicitly included the default subnav 97 159 // (eg: http://example.com/members/membername/activity/just-me/) 98 160 // The canonical version will not contain this subnav slug. 99 if ( ! empty( $default_subnav_slug ) && bp_is_current_action( $default_subnav_slug ) && !bp_action_variable( 0 ) ) {161 if ( ! empty( $r['default_subnav_slug'] ) && bp_is_current_action( $r['default_subnav_slug'] ) && ! bp_action_variable( 0 ) ) { 100 162 unset( $bp->canonical_stack['action'] ); 101 163 } elseif ( ! bp_current_action() ) { 102 164 103 165 // Add our screen hook if screen function is callable 104 if ( is_callable( $ screen_function) ) {105 add_action( 'bp_screens', $ screen_function, 3 );166 if ( is_callable( $r['screen_function'] ) ) { 167 add_action( 'bp_screens', $r['screen_function'], 3 ); 106 168 } 107 169 108 if ( ! empty( $default_subnav_slug) ) {170 if ( ! empty( $r['default_subnav_slug'] ) ) { 109 171 110 172 /** 111 173 * Filters the default component subnav item. … … function bp_core_new_nav_item( $args = '' ) { 116 178 * to select when clicked. 117 179 * @param array $r Parsed arguments for the nav item. 118 180 */ 119 $bp->current_action = apply_filters( 'bp_default_component_subnav', $ default_subnav_slug, $r );181 $bp->current_action = apply_filters( 'bp_default_component_subnav', $r['default_subnav_slug'], $r ); 120 182 } 121 183 } 122 184 } … … function bp_core_new_nav_default( $args = '' ) { 212 274 * 213 275 * @return bool|null Returns false on failure. 214 276 */ 215 function bp_core_sort_nav_items( ) {277 function bp_core_sort_nav_items( $component = '' ) { 216 278 $bp = buddypress(); 217 279 218 if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) ) 280 if ( empty( $component ) || ! bp_is_active( $component ) ) { 281 $nav = $bp->bp_nav; 282 } else { 283 $nav = $bp->{$component}->single_nav; 284 } 285 286 if ( empty( $nav ) || ! is_array( $nav ) ) { 219 287 return false; 288 } 220 289 221 290 $temp = array(); 222 291 223 foreach ( (array) $ bp->bp_nav as $slug => $nav_item ) {292 foreach ( (array) $nav as $slug => $nav_item ) { 224 293 if ( empty( $temp[$nav_item['position']]) ) { 225 294 $temp[$nav_item['position']] = $nav_item; 226 295 } else { … … function bp_core_sort_nav_items() { 234 303 } 235 304 236 305 ksort( $temp ); 237 $bp->bp_nav = &$temp; 306 $nav = &$temp; 307 308 if ( empty( $component ) || ! bp_is_active( $component ) ) { 309 $bp->bp_nav = $nav; 310 } else { 311 $bp->{$component}->single_nav = $nav; 312 } 238 313 } 239 314 add_action( 'wp_head', 'bp_core_sort_nav_items' ); 240 315 add_action( 'admin_head', 'bp_core_sort_nav_items' ); … … function bp_core_new_subnav_item( $args = '' ) { 286 361 'screen_function' => false, // The name of the function to run when clicked 287 362 'link' => '', // The link for the subnav item; optional, not usually required. 288 363 'show_in_admin_bar' => false, // Show the Manage link in the current group's "Edit" Admin Bar menu 364 'single_subnav' => false, // The component id to create the single subnav for 289 365 ) ); 290 366 291 extract( $r, EXTR_SKIP );292 293 367 // If we don't have the required info we need, don't create this subnav item 294 if ( empty( $ name ) || empty( $slug ) || empty( $parent_slug ) || empty( $parent_url ) || empty( $screen_function ) )368 if ( empty( $r['name'] ) || empty( $r['slug'] ) || empty( $r['parent_slug'] ) || empty( $r['parent_url'] ) || empty( $r['screen_function'] ) ) { 295 369 return false; 370 } 371 372 $parent_default_subnav = ''; 373 $parent_screen_function = ''; 374 $is_component_subnav = ! empty( $r['single_subnav'] ) && bp_is_active( $r['single_subnav'] ) && isset( $bp->{$r['single_subnav']}->single_subnav ); 375 376 // The component is managing its single items subnav 377 if ( $is_component_subnav && isset( $bp->{$r['single_subnav']}->single_nav ) ) { 378 if ( ! empty( $bp->{$r['single_subnav']}->single_nav[ $r['parent_slug'] ]['default_subnav_slug'] ) ) { 379 $parent_default_subnav = $bp->{$r['single_subnav']}->single_nav[ $r['parent_slug'] ]['default_subnav_slug']; 380 } 381 382 if ( ! empty( $bp->{$r['single_subnav']}->single_nav[ $r['parent_slug'] ]['screen_function'] ) ) { 383 $parent_screen_function = $bp->{$r['single_subnav']}->single_nav[ $r['parent_slug'] ]['screen_function']; 384 } 385 386 // Default nav is core nav 387 } else { 388 if ( ! empty( $bp->bp_nav[ $r['parent_slug'] ]['default_subnav_slug'] ) ) { 389 $parent_default_subnav = $bp->bp_nav[ $r['parent_slug'] ]['default_subnav_slug']; 390 } 391 392 if ( ! empty( $bp->bp_nav[ $r['parent_slug'] ]['screen_function'] ) ) { 393 $parent_screen_function = $bp->bp_nav[ $r['parent_slug'] ]['screen_function']; 394 } 395 } 296 396 297 397 // Link was not forced, so create one 298 if ( empty( $ link) ) {299 $link = trailingslashit( $ parent_url . $slug);398 if ( empty( $r['link'] ) ) { 399 $link = trailingslashit( $r['parent_url'] . $r['slug'] ); 300 400 301 401 // If this sub item is the default for its parent, skip the slug 302 if ( ! empty( $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) && $slug == $bp->bp_nav[$parent_slug]['default_subnav_slug']) {303 $link = trailingslashit( $ parent_url);402 if ( $r['slug'] == $parent_default_subnav ) { 403 $link = trailingslashit( $r['parent_url'] ); 304 404 } 405 } else { 406 $link = $r['link']; 305 407 } 306 408 307 409 // If this is for site admins only and the user is not one, don't create the subnav item 308 if ( ! empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) )410 if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { 309 411 return false; 412 } 413 414 // Defaults to slug 415 $item_css_id = $r['slug']; 310 416 311 if ( empty( $item_css_id ) ) 312 $item_css_id = $slug; 417 if ( ! empty( $r['item_css_id'] ) ) { 418 $item_css_id = $r['item_css_id']; 419 } 313 420 314 421 $subnav_item = array( 315 'name' => $ name,422 'name' => $r['name'], 316 423 'link' => $link, 317 'slug' => $ slug,424 'slug' => $r['slug'], 318 425 'css_id' => $item_css_id, 319 'position' => $ position,320 'user_has_access' => $ user_has_access,321 'no_access_url' => $ no_access_url,322 'screen_function' => &$ screen_function,426 'position' => $r['position'], 427 'user_has_access' => $r['user_has_access'], 428 'no_access_url' => $r['no_access_url'], 429 'screen_function' => &$r['screen_function'], 323 430 'show_in_admin_bar' => (bool) $r['show_in_admin_bar'], 324 431 ); 325 432 326 $bp->bp_options_nav[$parent_slug][$slug] = $subnav_item; 433 // The component is managing its single items nav 434 if ( $is_component_subnav ) { 435 $bp->{$r['single_subnav']}->single_subnav[ $r['parent_slug'] ][ $r['slug'] ] = $subnav_item; 327 436 328 /** 329 * The last step is to hook the screen function for the added subnav item. But this only 330 * needs to be done if this subnav item is the current view, and the user has access to the 331 * subnav item. We figure out whether we're currently viewing this subnav by checking the 332 * following two conditions: 333 * (1) Either: 334 * (a) the parent slug matches the current_component, or 335 * (b) the parent slug matches the current_item 336 * (2) And either: 337 * (a) the current_action matches $slug, or 338 * (b) there is no current_action (ie, this is the default subnav for the parent nav) 339 * and this subnav item is the default for the parent item (which we check by 340 * comparing this subnav item's screen function with the screen function of the 341 * parent nav item in $bp->bp_nav). This condition only arises when viewing a 342 * user, since groups should always have an action set. 343 */ 437 if ( ! bp_is_current_component( $r['single_subnav'] ) && ! bp_is_current_action( $r['parent_slug'] ) ) { 438 return; 439 } 344 440 345 // If we *don't* meet condition (1), return 346 if ( ! bp_is_current_component( $parent_slug ) && ! bp_is_current_item( $parent_slug ) ) 347 return; 441 if ( bp_action_variable( 0 ) && bp_is_action_variable( $r['slug'], 0 ) ) { 442 443 $hooked = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ); 444 445 // If redirect args have been returned, perform the redirect now 446 if ( ! empty( $hooked['status'] ) && 'failure' === $hooked['status'] && isset( $hooked['redirect_args'] ) ) { 447 bp_core_no_access( $hooked['redirect_args'] ); 448 } 449 } 450 451 // Default nav is core nav 452 } else { 453 $bp->bp_options_nav[ $r['parent_slug'] ][ $r['slug'] ] = $subnav_item; 454 455 /** 456 * The last step is to hook the screen function for the added subnav item. But this only 457 * needs to be done if this subnav item is the current view, and the user has access to the 458 * subnav item. We figure out whether we're currently viewing this subnav by checking the 459 * following two conditions: 460 * (1) Either: 461 * (a) the parent slug matches the current_component, or 462 * (b) the parent slug matches the current_item 463 * (2) And either: 464 * (a) the current_action matches $slug, or 465 * (b) there is no current_action (ie, this is the default subnav for the parent nav) 466 * and this subnav item is the default for the parent item (which we check by 467 * comparing this subnav item's screen function with the screen function of the 468 * parent nav item in $bp->bp_nav). This condition only arises when viewing a 469 * user, since groups should always have an action set. 470 */ 471 472 // If we *don't* meet condition (1), return 473 if ( ! bp_is_current_component( $r['parent_slug'] ) && ! bp_is_current_item( $r['parent_slug'] ) ) { 474 return; 475 } 348 476 349 // If we *do* meet condition (2), then the added subnav item is currently being requested350 if ( ( bp_current_action() && bp_is_current_action( $slug ) ) || ( bp_is_user() && ! bp_current_action() && ( $screen_function == $bp->bp_nav[$parent_slug]['screen_function']) ) ) {477 // If we *do* meet condition (2), then the added subnav item is currently being requested 478 if ( ( bp_current_action() && bp_is_current_action( $r['slug'] ) ) || ( bp_is_user() && ! bp_current_action() && ( $r['screen_function'] == $parent_screen_function ) ) ) { 351 479 352 $hooked = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );480 $hooked = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ); 353 481 354 // If redirect args have been returned, perform the redirect now 355 if ( ! empty( $hooked['status'] ) && 'failure' === $hooked['status'] && isset( $hooked['redirect_args'] ) ) { 356 bp_core_no_access( $hooked['redirect_args'] ); 482 // If redirect args have been returned, perform the redirect now 483 if ( ! empty( $hooked['status'] ) && 'failure' === $hooked['status'] && isset( $hooked['redirect_args'] ) ) { 484 bp_core_no_access( $hooked['redirect_args'] ); 485 } 357 486 } 358 487 } 359 488 } … … function bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) { 454 583 * 455 584 * @return bool|null Returns false on failure. 456 585 */ 457 function bp_core_sort_subnav_items( ) {586 function bp_core_sort_subnav_items( $component = '' ) { 458 587 $bp = buddypress(); 459 588 460 if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) ) 589 if ( empty( $component ) || ! bp_is_active( $component ) ) { 590 $subnav = $bp->bp_options_nav; 591 } else { 592 $subnav = $bp->{$component}->single_subnav; 593 } 594 595 if ( empty( $subnav ) || ! is_array( $subnav ) ) { 461 596 return false; 597 } 462 598 463 foreach ( (array) $ bp->bp_options_nav as $parent_slug => $subnav_items ) {599 foreach ( (array) $subnav as $parent_slug => $subnav_items ) { 464 600 if ( !is_array( $subnav_items ) ) 465 601 continue; 466 602 … … function bp_core_sort_subnav_items() { 477 613 } 478 614 } 479 615 ksort( $temp ); 480 $ bp->bp_options_nav[$parent_slug] = &$temp;616 $subnav[$parent_slug] = &$temp; 481 617 unset( $temp ); 482 618 } 619 620 if ( empty( $component ) || ! bp_is_active( $component ) ) { 621 $bp->bp_options_nav = $subnav; 622 } else { 623 $bp->{$component}->single_subnav = $subnav; 624 } 483 625 } 484 626 add_action( 'wp_head', 'bp_core_sort_subnav_items' ); 485 627 add_action( 'admin_head', 'bp_core_sort_subnav_items' ); -
src/bp-core/bp-core-filters.php
diff --git src/bp-core/bp-core-filters.php src/bp-core/bp-core-filters.php index cb1bcb9..f63d40b 100644
function bp_modify_page_title( $title = '', $sep = '»', $seplocation = 'ri 731 731 732 732 // A single item from a component other than groups 733 733 } elseif ( bp_is_single_item() ) { 734 $title_parts = array( $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'] ); 734 if ( isset( $bp->{$bp->current_component}->single_nav ) ) { 735 $component_nav_section = ''; 736 737 // Get the component nav section name 738 foreach ( $bp->{$bp->current_component}->single_nav as $component_nav_item ) { 739 if ( bp_current_action() !== $component_nav_item['slug'] ) { 740 continue; 741 } 742 743 $component_nav_section = $component_nav_item['name']; 744 } 745 746 $title_parts = array( $bp->bp_options_title, $component_nav_section ); 747 } else { 748 $title_parts = array( $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'] ); 749 } 735 750 736 751 // An index or directory 737 752 } elseif ( bp_is_directory() ) { -
src/bp-core/bp-core-options.php
diff --git src/bp-core/bp-core-options.php src/bp-core/bp-core-options.php index 646ff07..bf381da 100644
function bp_get_default_options() { 44 44 // Used to decide if blogs need indexing 45 45 'bp-blogs-first-install' => false, 46 46 47 // Disable the blogs single items 48 'bp-blogs-disable-single-items' => false, 49 47 50 /** Settings **********************************************************/ 48 51 49 52 // Disable the WP to BP profile sync … … function bp_disable_blogforum_comments( $default = false ) { 630 633 } 631 634 632 635 /** 636 * Are blogs single items disabled? 637 * 638 * @since BuddyPress (2.3.0) 639 * 640 * @param bool $default Optional. Fallback value if not found in the database. 641 * Default: false. 642 * @return bool True if blogs single items are disabled, otherwise false. 643 */ 644 function bp_blogs_disable_single_items( $default = false ) { 645 646 /** 647 * Filters whether or not blogs single items are disabled. 648 * 649 * @since BuddyPress (2.3.0) 650 * 651 * @param bool $value Whether or not blogs single items are disabled. 652 */ 653 return (bool) apply_filters( 'bp_blogs_disable_single_items', (bool) bp_get_option( 'bp-blogs-disable-single-items', $default ) ); 654 } 655 656 /** 633 657 * Is group creation turned off? 634 658 * 635 659 * @since BuddyPress (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 641b7fe..b3f8571 100644
10 10 defined( 'ABSPATH' ) || exit; 11 11 12 12 /** 13 * Output a component's single item main nav 14 * 15 * @since BuddyPress (2.3.0) 16 * 17 * @param string $component the component id 18 */ 19 function bp_component_main_nav( $component = '' ) { 20 $bp = buddypress(); 21 22 if ( empty( $component ) ) { 23 $component = bp_is_user() ? $bp->members->id : bp_current_component(); 24 } 25 26 if ( ! isset( $bp->{$component}->single_nav ) || ! is_array( $bp->{$component}->single_nav ) ) { 27 return; 28 } 29 30 foreach ( (array) $bp->{$component}->single_nav as $main_nav_item ) { 31 32 $selected = ''; 33 34 if ( bp_is_current_action( $main_nav_item['slug'] ) ) { 35 $selected = ' class="current selected"'; 36 } 37 38 echo apply_filters_ref_array( 'bp_component_main_nav_' . $main_nav_item['css_id'], array( '<li id="' . esc_attr( $main_nav_item['slug'] ) . '-' . esc_attr( $main_nav_item['css_id'] ) . '-li" ' . $selected . '><a id="' . esc_attr( $component ) . '-' . esc_attr( $main_nav_item['slug'] ) . '" href="' . esc_url( $main_nav_item['link'] ) . '">' . $main_nav_item['name'] . '</a></li>', &$main_nav_item['slug'] ) ); 39 } 40 } 41 42 /** 43 * Output a component's single item options nav 44 * 45 * @since BuddyPress (2.3.0) 46 * 47 * @param array $subnav the subnav containing the nav items to output 48 * @param string $the_index the subnav index containing the nav items 49 * @param string $selected_item the current item displayed 50 * @param string $list_type extra css attribute 51 */ 52 function bp_component_options_nav( $subnav, $the_index = '', $selected_item = '', $list_type = '' ) { 53 $bp = buddypress(); 54 55 if ( empty( $subnav ) || ! is_array( $subnav ) ) { 56 return false; 57 } 58 59 // Defaults to bp_option_nav 60 $filter_prefix = 'bp_get_options_nav'; 61 62 if ( ! empty( $list_type ) && 'group' !== $list_type && 'personal' !== $list_type && bp_current_component() ) { 63 $filter_prefix = 'bp_' . bp_current_component() . '_single_subnav'; 64 } 65 66 // Loop through each navigation item 67 foreach ( (array) $subnav[$the_index] as $subnav_item ) { 68 if ( empty( $subnav_item['user_has_access'] ) ) { 69 continue; 70 } 71 72 // If the current action or an action variable matches the nav item id, then add a highlight CSS class. 73 if ( $subnav_item['slug'] == $selected_item ) { 74 $selected = ' class="current selected"'; 75 } else { 76 $selected = ''; 77 } 78 79 /** 80 * Filters the "options nav", the secondary-level single item navigation menu. 81 * 82 * This is a dynamic filter that is dependent on the provided css_id value. 83 * 84 * @since BuddyPress (1.1.0) 85 * 86 * @param string $value HTML list item for the submenu item. 87 * @param array $subnav_item Submenu array item being displayed. 88 * @param string $selected_item Current action. 89 */ 90 echo apply_filters( $filter_prefix . '_' . $subnav_item['css_id'], '<li id="' . esc_attr( $subnav_item['css_id'] . '-' . $list_type . '-li' ) . '" ' . $selected . '><a id="' . esc_attr( $subnav_item['css_id'] ) . '" href="' . esc_url( $subnav_item['link'] ) . '">' . $subnav_item['name'] . '</a></li>', $subnav_item, $selected_item ); 91 } 92 } 93 94 /** 13 95 * Output the "options nav", the secondary-level single item navigation menu. 14 96 * 15 97 * Uses the $bp->bp_options_nav global to render out the sub navigation for the … … function bp_get_options_nav( $parent_slug = '' ) { 55 137 } 56 138 } 57 139 58 // Loop through each navigation item 59 foreach ( (array) $bp->bp_options_nav[$the_index] as $subnav_item ) { 60 if ( empty( $subnav_item['user_has_access'] ) ) { 61 continue; 62 } 140 // List type depends on our current component 141 $list_type = bp_is_group() ? 'groups' : 'personal'; 63 142 64 // If the current action or an action variable matches the nav item id, then add a highlight CSS class. 65 if ( $subnav_item['slug'] == $selected_item ) { 66 $selected = ' class="current selected"'; 67 } else { 68 $selected = ''; 69 } 70 71 // List type depends on our current component 72 $list_type = bp_is_group() ? 'groups' : 'personal'; 73 74 /** 75 * Filters the "options nav", the secondary-level single item navigation menu. 76 * 77 * This is a dynamic filter that is dependent on the provided css_id value. 78 * 79 * @since BuddyPress (1.1.0) 80 * 81 * @param string $value HTML list item for the submenu item. 82 * @param array $subnav_item Submenu array item being displayed. 83 * @param string $selected_item Current action. 84 */ 85 echo apply_filters( 'bp_get_options_nav_' . $subnav_item['css_id'], '<li id="' . esc_attr( $subnav_item['css_id'] . '-' . $list_type . '-li' ) . '" ' . $selected . '><a id="' . esc_attr( $subnav_item['css_id'] ) . '" href="' . esc_url( $subnav_item['link'] ) . '">' . $subnav_item['name'] . '</a></li>', $subnav_item, $selected_item ); 86 } 143 return bp_component_options_nav( $bp->bp_options_nav, $the_index, $selected_item, $list_type ); 87 144 } 88 145 89 146 /** … … function bp_is_create_blog() { 2544 2601 * @return True if the current page is the blogs directory. 2545 2602 */ 2546 2603 function bp_is_blogs_directory() { 2547 if ( is_multisite() && bp_is_blogs_component() && ! bp_current_action() ) { 2604 if ( is_multisite() && bp_is_blogs_component() && ! bp_current_action() && ! bp_current_item() ) { 2605 return true; 2606 } 2607 2608 return false; 2609 } 2610 2611 /** 2612 * Does the current page belong to a single blog ? 2613 * 2614 * Will return true for any subpage of a single blog. 2615 * 2616 * @since BuddyPress (2.3.0) 2617 * 2618 * @return bool True if the current page is part of a single blog. 2619 */ 2620 function bp_is_blog() { 2621 $retval = bp_is_active( 'blogs' ); 2622 2623 if ( ! empty( $retval ) ) { 2624 $retval = bp_is_blogs_component() && bp_blogs_get_current_blog(); 2625 } 2626 2627 return (bool) $retval; 2628 } 2629 2630 /** 2631 * Is the current page a single blog's home page? 2632 * 2633 * URL will vary depending on which blog tab is set to be the "home". By 2634 * default, it's the blog's recent activity. 2635 * 2636 * @since BuddyPress (2.3.0) 2637 * 2638 * @return bool True if the current page is a single blog's home page. 2639 */ 2640 function bp_is_blog_home() { 2641 if ( bp_is_single_item() && bp_is_blogs_component() && ( ! bp_current_action() || bp_is_current_action( 'home' ) ) ) { 2548 2642 return true; 2549 2643 } 2550 2644 2551 2645 return false; 2552 2646 } 2553 2647 2648 /** 2649 * Is the current page a blog's activity page? 2650 * 2651 * Eg http://example.com/sites/mysite/activity/. 2652 * 2653 * @since BuddyPress (2.3.0) 2654 * 2655 * @return bool True if the current page is a blog's activity page. 2656 */ 2657 function bp_is_blog_activity() { 2658 return (bool) ( bp_is_blogs_component() && bp_is_current_action( 'activity' ) ); 2659 } 2660 2661 /** 2662 * Is the current page a blog's members page? 2663 * 2664 * Eg http://example.com/sites/mysite/members/. 2665 * 2666 * @since BuddyPress (2.3.0) 2667 * 2668 * @return bool True if the current page is a blog's members page. 2669 */ 2670 function bp_is_blog_members() { 2671 return (bool) ( bp_is_blogs_component() && bp_is_current_action( 'members' ) ); 2672 } 2673 2674 /** 2675 * Is the current page a blog's manage page? 2676 * 2677 * Eg http://example.com/sites/mysite/manage/. 2678 * 2679 * @since BuddyPress (2.3.0) 2680 * 2681 * @return bool True if the current page is a blog's manage page. 2682 */ 2683 function bp_is_blog_manage() { 2684 return (bool) ( bp_is_blogs_component() && bp_is_current_action( 'manage' ) ); 2685 } 2686 2554 2687 /** Messages ******************************************************************/ 2555 2688 2556 2689 /** -
src/bp-core/classes/class-bp-attachment-avatar.php
diff --git src/bp-core/classes/class-bp-attachment-avatar.php src/bp-core/classes/class-bp-attachment-avatar.php index 389e546..0fe5785 100644
class BP_Attachment_Avatar extends BP_Attachment { 297 297 } 298 298 299 299 /** 300 * Get the blog id to set its avatar 301 * 302 * @since BuddyPress (2.3.0) 303 * 304 * @return integer the blog id 305 */ 306 private function get_blog_id() { 307 $blog_id = 0; 308 309 if ( bp_is_blog() ) { 310 $blog_id = bp_get_current_blog_id(); 311 } 312 313 return $blog_id; 314 } 315 316 /** 300 317 * Build script datas for the Uploader UI 301 318 * 302 319 * @since BuddyPress (2.3.0) … … class BP_Attachment_Avatar extends BP_Attachment { 316 333 // Get the possible item ids 317 334 $user_id = $this->get_user_id(); 318 335 $group_id = $this->get_group_id(); 336 $blog_id = $this->get_blog_id(); 319 337 320 338 if ( ! empty( $user_id ) ) { 321 339 // Should we load the the Webcam Avatar javascript file … … class BP_Attachment_Avatar extends BP_Attachment { 358 376 3 => __( 'There was a problem deleting the group profile photo. Please try again.', 'buddypress' ), 359 377 4 => __( 'The group profile photo was deleted successfully!', 'buddypress' ), 360 378 ); 379 } elseif( ! empty( $blog_id ) ) { 380 $script_data['bp_params'] = array( 381 'object' => 'blog', 382 'item_id' => $blog_id, 383 'has_avatar' => bp_get_blog_has_avatar( $blog_id ), 384 'nonces' => array( 385 'set' => wp_create_nonce( 'bp_avatar_cropstore' ), 386 'remove' => wp_create_nonce( 'bp_delete_avatar_link' ), 387 ), 388 ); 389 390 // Set feedback messages 391 $script_data['feedback_messages'] = array( 392 1 => __( 'There was a problem cropping the site logo.', 'buddypress' ), 393 2 => __( 'The site logo was uploaded successfully.', 'buddypress' ), 394 3 => __( 'There was a problem deleting the site logo. Please try again.', 'buddypress' ), 395 4 => __( 'The site logo was deleted successfully!', 'buddypress' ), 396 ); 361 397 } else { 362 398 /** 363 399 * Use this filter to include specific BuddyPress params for your object 364 * e.g. Blavatar365 400 * 366 401 * @since BuddyPress (2.3.0) 367 402 * -
src/bp-friends/bp-friends-template.php
diff --git src/bp-friends/bp-friends-template.php src/bp-friends/bp-friends-template.php index 41821d8..165ccf6 100644
function bp_member_add_friend_button() { 211 211 bp_add_friend_button( bp_get_member_user_id() ); 212 212 } 213 213 add_action( 'bp_directory_members_actions', 'bp_member_add_friend_button' ); 214 add_action( 'bp_blog_members_actions', 'bp_member_add_friend_button' ); 214 215 215 216 /** 216 217 * Output the friend count for the current member in the loop. -
src/bp-members/bp-members-functions.php
diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php index 2f4acc9..ed0c7d0 100644
function bp_core_activate_signup( $key ) { 1901 1901 1902 1902 $user_id = $user['user_id']; 1903 1903 1904 /** 1905 * If it's a blog signup and site logos are enabled 1906 * save a transient so that the user once loggedin will 1907 * be redirected to the edit-logo manage page of his site 1908 */ 1909 if ( ! empty( $user['blog_id'] ) && bp_is_active( 'blogs' ) ) { 1910 // Taking no risk 1911 if ( bp_blogs_is_avatar_uploads_enabled() ) { 1912 $transient_key = sprintf( '_bp_activation_%d_redirect', $user_id ); 1913 1914 // Five minutes should be ok. 1915 set_transient( $transient_key, intval( $user['blog_id'] ), 300 ); 1916 } 1917 } 1918 1904 1919 } else { 1905 1920 $signups = BP_Signup::get( array( 1906 1921 'activation_key' => $key, -
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 fb29224..3719eb0 100644
do_action( 'bp_before_directory_activity' ); ?> 86 86 87 87 <?php endif; ?> 88 88 89 <?php if ( bp_is_active( 'blogs' ) && ! bp_blogs_disable_single_items() ) : ?> 90 91 <?php if ( bp_get_total_blog_count_for_user( bp_loggedin_user_id() ) ) : ?> 92 93 <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 am a member of.', 'buddypress' ); ?>"><?php printf( __( 'My Sites <span>%s</span>', 'buddypress' ), bp_get_total_blog_count_for_user( bp_loggedin_user_id() ) ); ?></a></li> 94 95 <?php endif; ?> 96 97 <?php endif; ?> 98 89 99 <?php 90 100 91 101 /** -
src/bp-templates/bp-legacy/buddypress/assets/_attachments/avatars/index.php
diff --git src/bp-templates/bp-legacy/buddypress/assets/_attachments/avatars/index.php src/bp-templates/bp-legacy/buddypress/assets/_attachments/avatars/index.php index 82c401f..0656495 100644
do_action( 'bp_attachments_avatar_check_template' ); 39 39 <# } else if ( 'group' === data.object ) { #> 40 40 <p><?php _e( "If you'd like to remove the existing group profile photo but not upload a new one, please use the delete group profile photo button.", 'buddypress' ); ?></p> 41 41 <p><a class="button edit" id="bp-delete-avatar" href="#" title="<?php esc_attr_e( 'Delete Group Profile Photo', 'buddypress' ); ?>"><?php esc_html_e( 'Delete Group Profile Photo', 'buddypress' ); ?></a></p> 42 <# } else if ( 'blog' === data.object ) { #> 43 <p><?php _e( "If you'd like to remove the existing site logo but not upload a new one, please use the delete site logo button.", 'buddypress' ); ?></p> 44 <p><a class="button edit" id="bp-delete-avatar" href="#" title="<?php esc_attr_e( 'Delete Site Logo', 'buddypress' ); ?>"><?php esc_html_e( 'Delete Site Logo', 'buddypress' ); ?></a></p> 42 45 <# } else { #> 43 46 <?php do_action( 'bp_attachments_avatar_delete_template' ); ?> 44 47 <# } #> -
src/bp-templates/bp-legacy/buddypress/blogs/single/activity.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/activity.php src/bp-templates/bp-legacy/buddypress/blogs/single/activity.php index e69de29..b2c06f6 100644
1 <?php 2 /** 3 * BuddyPress Blog single item activity 4 * 5 * @since 2.3 6 * 7 * @package BuddyPress 8 * @subpackage blogs 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <div class="item-list-tabs no-ajax" id="subnav" role="navigation"> 15 <ul> 16 <?php do_action( 'bp_blog_activity_syndication_options' ); ?> 17 18 <li id="activity-filter-select" class="last"> 19 <label for="activity-filter-by"><?php _e( 'Show:', 'buddypress' ); ?></label> 20 <select id="activity-filter-by"> 21 <option value="-1"><?php _e( '— Everything —', 'buddypress' ); ?></option> 22 23 <?php bp_activity_show_filters( 'blog' ); ?> 24 </select> 25 </li> 26 </ul> 27 </div><!-- .item-list-tabs --> 28 29 <?php do_action( 'bp_before_blog_activity_content' ); ?> 30 31 <div class="activity single-blog" role="main"> 32 33 <?php if ( bp_current_blog_is_public() ) : 34 bp_get_template_part( 'activity/activity-loop' ); 35 36 else : ?> 37 38 <div id="message" class="info"> 39 <p><?php _e( 'Sorry, as this site is private, no activity are available.', 'buddypress' ); ?></p> 40 </div> 41 42 <?php endif; ?> 43 44 </div><!-- .activity.single-blog --> 45 46 <?php do_action( 'bp_after_blog_activity_content' ); ?> -
src/bp-templates/bp-legacy/buddypress/blogs/single/blog-header.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/blog-header.php src/bp-templates/bp-legacy/buddypress/blogs/single/blog-header.php index e69de29..73cce09 100644
1 <?php 2 /** 3 * BuddyPress Blog single item header 4 * 5 * @since 2.3 6 * 7 * @package BuddyPress 8 * @subpackage blogs 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <?php do_action( 'bp_before_blog_header' ); ?> 15 16 <div id="item-actions"> 17 18 <?php bp_current_blog_admins(); 19 20 do_action( 'bp_after_blog_menu_admins' ); ?> 21 22 </div><!-- #item-actions --> 23 24 <div id="item-header-avatar"> 25 <a href="<?php bp_blog_view_details_link(); ?>" title="<?php bp_blog_name(); ?>"> 26 27 <?php bp_blog_avatar(); ?> 28 29 </a> 30 </div><!-- #item-header-avatar --> 31 32 <div id="item-header-content"> 33 <span class="highlight"><?php bp_current_blog_type(); ?></span> 34 <span class="activity"><?php bp_blog_last_active(); ?></span> 35 36 <?php do_action( 'bp_before_blog_header_meta' ); ?> 37 38 <div id="item-meta"> 39 40 <?php bp_blog_description(); ?> 41 42 <div id="item-buttons"> 43 44 <?php do_action( 'bp_blog_header_actions' ); ?> 45 46 </div><!-- #item-buttons --> 47 48 <?php do_action( 'bp_blog_header_meta' ); ?> 49 50 </div> 51 </div><!-- #item-header-content --> 52 53 <?php 54 do_action( 'bp_after_blog_header' ); 55 do_action( 'template_notices' ); 56 ?> -
src/bp-templates/bp-legacy/buddypress/blogs/single/home.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/home.php src/bp-templates/bp-legacy/buddypress/blogs/single/home.php index e69de29..2181c5a 100644
1 <?php 2 /** 3 * BuddyPress Blog single item home page 4 * 5 * @since 2.3 6 * 7 * @package BuddyPress 8 * @subpackage blogs 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <div id="buddypress"> 15 16 <?php if ( bp_has_blogs() ) : while ( bp_blogs() ) : bp_the_blog(); ?> 17 18 <?php do_action( 'bp_before_blog_home_content' ); ?> 19 20 <div id="item-header" role="complementary"> 21 22 <?php bp_get_template_part( 'blogs/single/blog-header' ); ?> 23 24 </div><!-- #item-header --> 25 26 <div id="item-nav"> 27 <div class="item-list-tabs no-ajax" id="object-nav" role="navigation"> 28 <ul> 29 30 <?php bp_component_main_nav( 'blogs' ); ?> 31 32 <?php do_action( 'bp_blog_main_nav' ); ?> 33 34 </ul> 35 </div> 36 </div><!-- #item-nav --> 37 38 <div id="item-body"> 39 40 <?php do_action( 'bp_before_blog_body' ); 41 42 /** 43 * Does this next bit look familiar? If not, go check out WordPress's 44 */ 45 46 // Looking at home location 47 if ( bp_is_blog_home() ) : 48 49 if ( bp_current_blog_has_access() ) { 50 51 // Load the appropriate front template 52 bp_blogs_load_blog_front_template(); 53 54 } else { 55 56 /** 57 * Fires before the display of the blog status message. 58 * 59 * @since BuddyPress (2.3.0) 60 */ 61 do_action( 'bp_before_blog_status_message' ); ?> 62 63 <div id="message" class="info"> 64 <p><?php bp_blog_status_message(); ?></p> 65 </div> 66 67 <?php 68 69 /** 70 * Fires after the display of the blog status message. 71 * 72 * @since BuddyPress (2.3.0) 73 */ 74 do_action( 'bp_after_blog_status_message' ); 75 76 } 77 78 // Not looking at home 79 else : 80 81 // Blog manage 82 if ( bp_is_blog_manage() ) : bp_get_template_part( 'blogs/single/manage' ); 83 84 // Blog Activity 85 elseif ( bp_is_blog_activity() ) : bp_get_template_part( 'blogs/single/activity' ); 86 87 // Blog Members 88 elseif ( bp_is_blog_members() ) : bp_get_template_part( 'blogs/single/members' ); 89 90 // Anything else (plugins mostly) 91 else : bp_get_template_part( 'blogs/single/plugins' ); 92 93 endif; 94 95 endif; 96 97 do_action( 'bp_after_blog_body' ); ?> 98 99 </div><!-- #item-body --> 100 101 <?php do_action( 'bp_after_blog_home_content' ); ?> 102 103 <?php endwhile; endif; ?> 104 105 </div><!-- #buddypress --> -
src/bp-templates/bp-legacy/buddypress/blogs/single/manage.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/manage.php src/bp-templates/bp-legacy/buddypress/blogs/single/manage.php index e69de29..b787722 100644
1 <?php 2 /** 3 * BuddyPress Blog single item manage page 4 * 5 * @since 2.3 6 * 7 * @package BuddyPress 8 * @subpackage blogs 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <div class="item-list-tabs no-ajax" id="subnav" role="navigation"> 15 <ul> 16 <?php if ( bp_is_item_admin() ) : ?> 17 18 <?php bp_blogs_item_subnav();?> 19 20 <?php endif; ?> 21 </ul> 22 </div> 23 24 <?php 25 $action = bp_action_variable( 0 ) ? bp_action_variable( 0 ) : bp_current_action(); 26 27 switch ( $action ) : 28 case 'manage' : 29 bp_get_template_part( 'blogs/single/settings/general' ); 30 break; 31 case 'edit-logo' : 32 bp_get_template_part( 'blogs/single/settings/logo' ); 33 break; 34 case 'members' : 35 bp_get_template_part( 'blogs/single/settings/members' ); 36 break; 37 default: 38 bp_get_template_part( 'blogs/single/plugins' ); 39 break; 40 endswitch; -
src/bp-templates/bp-legacy/buddypress/blogs/single/members-loop.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/members-loop.php src/bp-templates/bp-legacy/buddypress/blogs/single/members-loop.php index e69de29..4854c72 100644
1 <?php 2 /** 3 * BuddyPress Blog single item members loop 4 * 5 * @since 2.3 6 * 7 * @package BuddyPress 8 * @subpackage blogs 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <?php if ( bp_blog_has_members( bp_ajax_querystring( 'blog_members' ) ) ) : ?> 15 16 <?php 17 18 /** 19 * Fires before the display of the blog members content. 20 * 21 * @since BuddyPress (2.3.0) 22 */ 23 do_action( 'bp_before_blog_members_content' ); ?> 24 25 <div id="pag-top" class="pagination"> 26 27 <div class="pag-count" id="member-count-top"> 28 29 <?php bp_members_pagination_count(); ?> 30 31 </div> 32 33 <div class="pagination-links" id="member-pag-top"> 34 35 <?php bp_members_pagination_links(); ?> 36 37 </div> 38 39 </div> 40 41 <?php 42 43 /** 44 * Fires before the display of the blog members list. 45 * 46 * @since BuddyPress (2.3.0) 47 */ 48 do_action( 'bp_before_blog_members_list' ); ?> 49 50 <ul id="member-list" class="item-list" role="main"> 51 52 <?php while ( bp_blog_members() ) : bp_blog_the_member(); ?> 53 54 <li> 55 <div class="item-avatar"> 56 <a href="<?php bp_blog_member_permalink(); ?>"><?php bp_blog_member_avatar(); ?></a> 57 </div> 58 59 <div class="item"> 60 <div class="item-title"> 61 <a href="<?php bp_blog_member_permalink(); ?>"><?php bp_blog_member_name(); ?></a> 62 63 <?php if ( bp_blog_get_member_latest_update() ) : ?> 64 65 <span class="update"> <?php bp_blog_member_latest_update(); ?></span> 66 67 <?php endif; ?> 68 69 </div> 70 71 <div class="item-meta"><span class="activity"><?php bp_blog_member_last_active(); ?></span></div> 72 73 <?php do_action( 'bp_blog_members_item' ); ?> 74 </div> 75 76 <div class="action"> 77 78 <?php do_action( 'bp_blog_members_actions' ); ?> 79 80 </div> 81 82 <div class="clear"></div> 83 </li> 84 85 <?php endwhile; ?> 86 87 </ul> 88 89 <?php 90 91 /** 92 * Fires after the display of the blog members list. 93 * 94 * @since BuddyPress (2.3.0) 95 */ 96 do_action( 'bp_after_blog_members_list' ); ?> 97 98 <div id="pag-bottom" class="pagination"> 99 100 <div class="pag-count" id="member-count-bottom"> 101 102 <?php bp_members_pagination_count(); ?> 103 104 </div> 105 106 <div class="pagination-links" id="member-pag-bottom"> 107 108 <?php bp_members_pagination_links(); ?> 109 110 </div> 111 112 </div> 113 114 <?php 115 116 /** 117 * Fires after the display of the blog members content. 118 * 119 * @since BuddyPress (2.3.0) 120 */ 121 do_action( 'bp_after_blog_members_content' ); ?> 122 123 <?php else: ?> 124 125 <div id="message" class="info"> 126 <p><?php _e( 'No members were found.', 'buddypress' ); ?></p> 127 </div> 128 129 <?php endif; ?> -
src/bp-templates/bp-legacy/buddypress/blogs/single/members.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/members.php src/bp-templates/bp-legacy/buddypress/blogs/single/members.php index e69de29..1d0819d 100644
1 <?php 2 /** 3 * BuddyPress Blog single item members 4 * 5 * @since 2.3 6 * 7 * @package BuddyPress 8 * @subpackage blogs 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <form action="" method="post" id="members-blog-form" class="dir-form"> 15 16 <div class="item-list-tabs" id="subnav" role="navigation"> 17 <ul> 18 <?php bp_blogs_item_subnav();?> 19 20 <?php do_action( 'bp_members_blog_member_sub_types' ); ?> 21 22 <li id="members-order-select" class="last filter"> 23 <label for="members-order-by"><?php _e( 'Order By:', 'buddypress' ); ?></label> 24 <select id="members-order-by"> 25 <option value="active"><?php _e( 'Last Active', 'buddypress' ); ?></option> 26 27 <?php if ( bp_is_active( 'xprofile' ) ) : ?> 28 <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option> 29 <?php endif; ?> 30 31 <?php do_action( 'bp_members_blog_order_options' ); ?> 32 </select> 33 </li> 34 </ul> 35 </div> 36 37 <div id="blog-list" class="members item-list"> 38 <?php bp_get_template_part( 'blogs/single/members-loop' ); ?> 39 </div><!-- #members-dir-list --> 40 41 <?php do_action( 'bp_blog_members_content' ); ?> 42 43 <?php wp_nonce_field( 'blog_members', '_wpnonce-member-filter' ); ?> 44 45 <?php do_action( 'bp_after_blog_members_content' ); ?> 46 47 </form><!-- #members-directory-form --> 48 49 <?php do_action( 'bp_after_blog_members' ); ?> -
src/bp-templates/bp-legacy/buddypress/blogs/single/plugins.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/plugins.php src/bp-templates/bp-legacy/buddypress/blogs/single/plugins.php index e69de29..df2fc1b 100644
1 <?php 2 /** 3 * BuddyPress Blog single item plugins 4 * 5 * @since 2.3 6 * 7 * @package BuddyPress 8 * @subpackage blogs 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <?php do_action( 'bp_before_blog_plugin_template' ); ?> 15 16 <div class="item-list-tabs no-ajax" id="subnav"> 17 <ul> 18 <?php bp_blogs_item_subnav();?> 19 20 <?php do_action( 'bp_blog_plugin_sub_nav' ); ?> 21 </ul> 22 </div><!-- .item-list-tabs --> 23 24 <h3><?php do_action( 'bp_template_title' ); ?></h3> 25 26 <?php do_action( 'bp_template_content' ); ?> 27 28 <?php do_action( 'bp_after_blog_plugin_template' ); ?> -
src/bp-templates/bp-legacy/buddypress/blogs/single/settings/general.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/settings/general.php src/bp-templates/bp-legacy/buddypress/blogs/single/settings/general.php index e69de29..7b0de96 100644
1 <?php 2 /** 3 * BuddyPress Blog single item settings 4 * 5 * @since 2.3 6 * 7 * @package BuddyPress 8 * @subpackage blogs 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <?php do_action( 'bp_before_blog_settings_template' ); ?> 15 16 <form action="" method="post" class="standard-form" id="settings-form"> 17 18 <h4><?php esc_html_e( 'General settings', 'buddypress' ); ?></h4> 19 20 <label for="blog_name"><?php esc_html_e( 'Site Name', 'buddypress' ); ?></label> 21 <input type="text" name="bp_blog[blogname]" id="blog_name" value="<?php echo esc_attr( bp_get_blog_name() ); ?>" class="settings-input" /> 22 <p class="description"><?php esc_html_e( 'This setting is synchronized with the corresponding WordPress setting.', 'buddypress' ); ?></p> 23 24 <label for="blog_description"><?php esc_html_e( 'Site Description', 'buddypress' ); ?></label> 25 <input type="text" name="bp_blog[blogdescription]" id="blog_description" value="<?php echo esc_html( bp_get_blog_description() ); ?>" class="settings-input" /> 26 <p class="description"><?php esc_html_e( 'This setting is synchronized with the corresponding WordPress setting.', 'buddypress' ); ?></p> 27 28 <label for="blog_public"> 29 <input type="checkbox" name="bp_blog[blog_public]" id="blog_public" value="1" <?php checked( true, bp_current_blog_is_public() ); ?> /> 30 <?php esc_html_e( 'Public site', 'buddypress' ); ?> 31 </label> 32 <p class="description"><?php esc_html_e( 'This setting is synchronized with the "Discourage search engines from indexing this site" WordPress setting.', 'buddypress' ); ?></p> 33 <p class="description"><?php esc_html_e( 'If you deactivate this option, post types tracking and subscriptions will not be available for your site.', 'buddypress' ); ?></p> 34 35 <?php if ( bp_current_blog_is_public() ) : ?> 36 <label for="blog_disallow_subscriptions"> 37 <input type="checkbox" name="bp_blog[disallow_subscriptions]" id="blog_disallow_subscriptions" value="1" <?php checked( true, ! bp_current_blog_can_subscribe() ); ?> /> 38 <?php esc_html_e( 'Disallow subscritions', 'buddypress' ); ?> 39 </label> 40 <p class="description"><?php esc_html_e( 'Subscriptions are only available for public sites', 'buddypress' ); ?></p> 41 <?php endif ; ?> 42 43 <?php do_action( 'bp_blog_settings_after_general' ); ?> 44 45 <div class="submit"> 46 <input type="submit" name="bp_blog[submit]" value="<?php esc_attr_e( 'Save Changes', 'buddypress' ); ?>" id="submit" class="auto" /> 47 </div> 48 49 <?php do_action( 'bp_blog_settings_after_submit' ); ?> 50 51 <?php wp_nonce_field( 'blog_settings_general' ); ?> 52 53 </form> 54 55 <?php do_action( 'bp_after_blog_settings_template' ); ?> -
src/bp-templates/bp-legacy/buddypress/blogs/single/settings/logo.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/settings/logo.php src/bp-templates/bp-legacy/buddypress/blogs/single/settings/logo.php index e69de29..91257ae 100644
1 <?php 2 /** 3 * BuddyPress Blog single item edit logo 4 * 5 * @since 2.3 6 * 7 * @package BuddyPress 8 * @subpackage blogs 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <?php do_action( 'bp_before_blog_avatar_upload_content' ); ?> 15 16 <p><?php esc_html_e( "Upload an image to use as a logo for this site. The image will be shown on the site's details page, and in search results.", 'buddypress' ); ?></p> 17 18 <?php bp_avatar_get_templates(); ?> 19 20 <?php do_action( 'bp_after_blog_avatar_upload_content' ); ?> -
src/bp-templates/bp-legacy/buddypress/blogs/single/settings/members.php
diff --git src/bp-templates/bp-legacy/buddypress/blogs/single/settings/members.php src/bp-templates/bp-legacy/buddypress/blogs/single/settings/members.php index e69de29..e0554e7 100644
1 <?php 2 /** 3 * BuddyPress Blog single item manage members 4 * 5 * @since 2.3 6 * 7 * @package BuddyPress 8 * @subpackage blogs 9 */ 10 11 // Exit if accessed directly 12 defined( 'ABSPATH' ) or die; ?> 13 14 <form action="" method="post" id="members-blog-form" class="dir-form"> 15 16 <div class="item-list-tabs" id="subnav" role="navigation"> 17 <ul> 18 19 <?php do_action( 'bp_members_blog_member_sub_types' ); ?> 20 21 <li id="members-order-select" class="last filter"> 22 <label for="members-order-by"><?php _e( 'Order By:', 'buddypress' ); ?></label> 23 <select id="members-order-by"> 24 <option value="active"><?php _e( 'Last Active', 'buddypress' ); ?></option> 25 26 <?php if ( bp_is_active( 'xprofile' ) ) : ?> 27 <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option> 28 <?php endif; ?> 29 30 <?php do_action( 'bp_members_blog_order_options' ); ?> 31 </select> 32 </li> 33 </ul> 34 </div> 35 36 <div id="blog-list" class="members item-list"> 37 38 <?php if ( bp_blog_has_members( bp_ajax_querystring( 'blog_members' ) ) ) : ?> 39 40 <?php 41 42 /** 43 * Fires before the display of the blog members content. 44 * 45 * @since BuddyPress (2.3.0) 46 */ 47 do_action( 'bp_before_blog_members_manage_content' ); ?> 48 49 <div id="pag-top" class="pagination"> 50 51 <div class="pag-count" id="member-count-top"> 52 53 <?php bp_members_pagination_count(); ?> 54 55 </div> 56 57 <div class="pagination-links" id="member-pag-top"> 58 59 <?php bp_members_pagination_links(); ?> 60 61 </div> 62 63 </div> 64 65 <?php 66 67 /** 68 * Fires before the display of the blog members list. 69 * 70 * @since BuddyPress (2.3.0) 71 */ 72 do_action( 'bp_before_blog_members_manage_list' ); ?> 73 74 <ul id="member-list" class="item-list" role="main"> 75 76 <?php while ( bp_blog_members() ) : bp_blog_the_member(); ?> 77 78 <li> 79 <div class="item-avatar"> 80 <a href="<?php bp_blog_member_permalink(); ?>"><?php bp_blog_member_avatar(); ?></a> 81 </div> 82 83 <div class="item"> 84 <div class="item-title"> 85 <a href="<?php bp_blog_member_permalink(); ?>"><?php bp_blog_member_name(); ?></a> 86 </div> 87 88 <div class="item-meta"><span class="activity"><?php bp_blog_member_last_active(); ?></span></div> 89 90 <?php do_action( 'bp_blog_members_manage_item' ); ?> 91 </div> 92 93 <div class="action"> 94 95 <?php bp_blog_member_remove_button() ;?> 96 97 <?php do_action( 'bp_blog_members__manage_actions' ); ?> 98 99 </div> 100 101 <div class="clear"></div> 102 </li> 103 104 <?php endwhile; ?> 105 106 </ul> 107 108 <?php 109 110 /** 111 * Fires after the display of the blog members list. 112 * 113 * @since BuddyPress (2.3.0) 114 */ 115 do_action( 'bp_after_blog_members_manage_list' ); ?> 116 117 <div id="pag-bottom" class="pagination"> 118 119 <div class="pag-count" id="member-count-bottom"> 120 121 <?php bp_members_pagination_count(); ?> 122 123 </div> 124 125 <div class="pagination-links" id="member-pag-bottom"> 126 127 <?php bp_members_pagination_links(); ?> 128 129 </div> 130 131 </div> 132 133 <?php 134 135 /** 136 * Fires after the display of the blog members content. 137 * 138 * @since BuddyPress (2.3.0) 139 */ 140 do_action( 'bp_after_blog_members_manage_content' ); ?> 141 142 <?php else: ?> 143 144 <div id="message" class="info"> 145 <p><?php _e( 'No members were found.', 'buddypress' ); ?></p> 146 </div> 147 148 <?php endif; ?> 149 150 </div><!-- #members-dir-list --> 151 152 <?php do_action( 'bp_blog_members_manage_content' ); ?> 153 154 <?php wp_nonce_field( 'blog_members', '_wpnonce-member-filter' ); ?> 155 156 <?php do_action( 'bp_after_blog_members_manage_content' ); ?> 157 158 </form><!-- #members-directory-form --> 159 160 <?php do_action( 'bp_after_blog_members_manage' ); ?> -
src/bp-templates/bp-legacy/css/buddypress.css
diff --git src/bp-templates/bp-legacy/css/buddypress.css src/bp-templates/bp-legacy/css/buddypress.css index 9a64410..a0549f1 100644
a.bp-title-button { 796 796 text-decoration: none; 797 797 } 798 798 799 #buddypress div.blog-button { 800 display: inline-block; 801 margin-left: 5px; 802 } 803 799 804 #buddypress form.standard-form .left-menu { 800 805 float: left; 801 806 } -
tests/phpunit/testcases/core/nav.php
diff --git tests/phpunit/testcases/core/nav.php tests/phpunit/testcases/core/nav.php index 92a7ebd..f391809 100644
5 5 * @group nav 6 6 */ 7 7 class BP_Tests_Core_Nav extends BP_UnitTestCase { 8 9 /** 10 * @group bp_core_new_nav_item 11 */ 12 public function test_bp_core_new_nav_item_user_nav() { 13 $bp_nav = buddypress()->bp_nav; 14 15 $u = $this->factory->user->create(); 16 $old_current_user = get_current_user_id(); 17 $this->set_current_user( $u ); 18 19 $this->go_to( bp_core_get_user_domain( $u ) ); 20 21 bp_core_new_nav_item( array( 22 'name' => 'Foo', 23 'slug' => 'foo', 24 'position' => 25, 25 'screen_function' => 'foo_screen_function', 26 'default_subnav_slug' => 'foo-sub' 27 ) ); 28 29 $expected = array( 30 'name' => 'Foo', 31 'slug' => 'foo', 32 'link' => trailingslashit( bp_core_get_user_domain( $u ) . 'foo' ), 33 'css_id' => 'foo', 34 'show_for_displayed_user' => true, 35 'position' => 25, 36 'screen_function' => 'foo_screen_function', 37 'default_subnav_slug' => 'foo-sub' 38 ); 39 40 $this->assertSame( buddypress()->bp_nav['foo'], $expected ); 41 42 // Clean up 43 buddypress()->bp_nav = $bp_nav; 44 $this->set_current_user( $old_current_user ); 45 } 46 47 /** 48 * @group bp_core_new_nav_item 49 */ 50 public function test_bp_core_new_nav_item_group_nav() { 51 $bp_nav = buddypress()->bp_nav; 52 53 $u = $this->factory->user->create(); 54 $g = $this->factory->group->create(); 55 $old_current_user = get_current_user_id(); 56 $this->set_current_user( $u ); 57 58 $group = groups_get_group( array( 59 'group_id' => $g, 60 ) ); 61 62 $this->go_to( bp_get_group_permalink( $group ) ); 63 64 $this->assertTrue( buddypress()->bp_nav[ $group->slug ]['position'] === -1 ); 65 66 // Clean up 67 buddypress()->bp_nav = $bp_nav; 68 $this->set_current_user( $old_current_user ); 69 } 70 71 /** 72 * @group bp_core_new_nav_item 73 */ 74 public function test_bp_core_new_nav_item_foo_nav() { 75 $bp = buddypress(); 76 $reset_active_components = $bp->active_components; 77 $reset_current_component = $bp->current_component; 78 $reset_current_item = $bp->current_item; 79 $bp_nav = buddypress()->bp_nav; 80 81 if ( ! function_exists( 'bp_get_foo_root_slug') ) { 82 function bp_get_foo_root_slug() { 83 return 'foo'; 84 } 85 } 86 87 // Create and activate the foo component 88 $bp->foo = new BP_Component; 89 $bp->foo->id = 'foo'; 90 $bp->foo->slug = 'foo'; 91 $bp->foo->name = 'Foo'; 92 $bp->foo->single_nav = array(); 93 $bp->active_components[ $bp->foo->id ] = 1; 94 95 $bp->current_component = 'foo'; 96 $bp->current_item = 'single-foo'; 97 98 bp_core_new_nav_item( array( 99 'name' => 'Bar', 100 'slug' => 'bar', 101 'position' => 10, 102 'screen_function' => 'bar_screen_function', 103 'default_subnav_slug' => 'bar-sub', 104 'single_nav' => $bp->foo->id 105 ) ); 106 107 $expected = array( 108 'name' => 'Bar', 109 'slug' => 'bar', 110 'link' => trailingslashit( bp_get_root_domain() . '/foo/single-foo/bar' ), 111 'css_id' => 'bar', 112 'show_for_displayed_user' => true, 113 'position' => 10, 114 'screen_function' => 'bar_screen_function', 115 'default_subnav_slug' => 'bar-sub' 116 ); 117 118 $this->assertTrue( empty( $bp->bp_nav['bar'] ) ); 119 $this->assertSame( $bp->foo->single_nav['bar'], $expected ); 120 121 // Clean up 122 $bp->foo->single_nav = array(); 123 $bp->active_components = $reset_active_components; 124 $bp->current_component = $reset_current_component; 125 $bp->current_item = $reset_current_item; 126 } 127 128 /** 129 * @group bp_core_sort_nav_items 130 */ 131 public function test_bp_core_sort_nav_items() { 132 $bp_nav = buddypress()->bp_nav; 133 134 $u = $this->factory->user->create(); 135 $old_current_user = get_current_user_id(); 136 $this->set_current_user( $u ); 137 138 $this->go_to( bp_core_get_user_domain( $u ) ); 139 140 bp_core_new_nav_item( array( 141 'name' => 'Foo', 142 'slug' => 'foo', 143 'position' => 25, 144 'screen_function' => 'foo_screen_function', 145 'default_subnav_slug' => 'foo-sub' 146 ) ); 147 148 $expected = array( 149 'name' => 'Foo', 150 'slug' => 'foo', 151 'link' => trailingslashit( bp_core_get_user_domain( $u ) . 'foo' ), 152 'css_id' => 'foo', 153 'show_for_displayed_user' => true, 154 'position' => 25, 155 'screen_function' => 'foo_screen_function', 156 'default_subnav_slug' => 'foo-sub' 157 ); 158 159 bp_core_sort_nav_items(); 160 161 $this->assertSame( buddypress()->bp_nav[25], $expected ); 162 163 // Clean up 164 buddypress()->bp_nav = $bp_nav; 165 $this->set_current_user( $old_current_user ); 166 } 167 168 /** 169 * @group bp_core_new_subnav_item 170 */ 171 public function test_bp_core_new_subnav_item_user_subnav() { 172 $bp_options_nav = buddypress()->bp_options_nav; 173 174 $u = $this->factory->user->create(); 175 $old_current_user = get_current_user_id(); 176 $this->set_current_user( $u ); 177 178 $user_domain = bp_core_get_user_domain( $u ); 179 180 $this->go_to( $user_domain ); 181 182 bp_core_new_subnav_item( array( 183 'name' => 'Foo', 184 'slug' => 'foo', 185 'parent_url' => trailingslashit( $user_domain . 'foo' ), 186 'parent_slug' => 'foo', 187 'screen_function' => 'foo_screen_function', 188 'position' => 10 189 ) ); 190 191 $expected = array( 192 'name' => 'Foo', 193 'link' => trailingslashit( $user_domain . 'foo/foo' ), 194 'slug' => 'foo', 195 'css_id' => 'foo', 196 'position' => 10, 197 'user_has_access' => true, 198 'no_access_url' => '', 199 'screen_function' => 'foo_screen_function', 200 'show_in_admin_bar' => false, 201 ); 202 203 $this->assertSame( buddypress()->bp_options_nav['foo']['foo'], $expected ); 204 205 // Clean up 206 buddypress()->bp_options_nav = $bp_options_nav; 207 $this->set_current_user( $old_current_user ); 208 } 209 210 /** 211 * @group bp_core_new_nav_item 212 */ 213 public function test_bp_core_new_subnav_item_foo_subnav() { 214 $bp = buddypress(); 215 $reset_active_components = $bp->active_components; 216 217 // Create and activate the foo component 218 $bp->foo = new BP_Component; 219 $bp->foo->id = 'foo'; 220 $bp->foo->slug = 'foo'; 221 $bp->foo->name = 'Foo'; 222 $bp->foo->single_nav = array(); 223 $bp->foo->single_subnav = array(); 224 $bp->active_components[ $bp->foo->id ] = 1; 225 226 bp_core_new_subnav_item( array( 227 'name' => 'Bar', 228 'slug' => 'bar', 229 'parent_url' => trailingslashit( bp_get_root_domain() . '/foo/single-foo/bar' ), 230 'parent_slug' => 'bar', 231 'screen_function' => 'bar_screen_function', 232 'position' => 10, 233 'single_subnav' => $bp->foo->id 234 ) ); 235 236 $expected = array( 237 'name' => 'Bar', 238 'link' => trailingslashit( bp_get_root_domain() . '/foo/single-foo/bar/bar' ), 239 'slug' => 'bar', 240 'css_id' => 'bar', 241 'position' => 10, 242 'user_has_access' => true, 243 'no_access_url' => '', 244 'screen_function' => 'bar_screen_function', 245 'show_in_admin_bar' => false, 246 ); 247 248 $this->assertTrue( empty( $bp->bp_options_nav['bar'] ) ); 249 $this->assertSame( $bp->foo->single_subnav['bar']['bar'], $expected ); 250 251 // Clean up 252 $bp->foo->single_subnav = array(); 253 $bp->active_components = $reset_active_components; 254 } 255 256 8 257 /** 9 258 * @group bp_core_new_subnav_item 10 259 */ … … class BP_Tests_Core_Nav extends BP_UnitTestCase { 400 649 401 650 $this->assertSame( $link, buddypress()->bp_options_nav['foo']['bar']['link'] ); 402 651 } 652 653 /** 654 * @group bp_core_sort_subnav_items 655 */ 656 public function test_bp_core_sort_subnav_items() { 657 $bp_options_nav = buddypress()->bp_options_nav; 658 659 $u = $this->factory->user->create(); 660 $old_current_user = get_current_user_id(); 661 $this->set_current_user( $u ); 662 663 $user_domain = bp_core_get_user_domain( $u ); 664 665 $this->go_to( $user_domain ); 666 667 bp_core_new_subnav_item( array( 668 'name' => 'Foo', 669 'slug' => 'foo', 670 'parent_url' => trailingslashit( $user_domain . 'foo' ), 671 'parent_slug' => 'foo', 672 'screen_function' => 'foo_screen_function', 673 'position' => 10 674 ) ); 675 676 bp_core_sort_subnav_items(); 677 678 $expected = array( 679 'name' => 'Foo', 680 'link' => trailingslashit( $user_domain . 'foo/foo' ), 681 'slug' => 'foo', 682 'css_id' => 'foo', 683 'position' => 10, 684 'user_has_access' => true, 685 'no_access_url' => '', 686 'screen_function' => 'foo_screen_function', 687 'show_in_admin_bar' => false, 688 ); 689 690 $this->assertSame( buddypress()->bp_options_nav['foo'][10], $expected ); 691 692 // Clean up 693 buddypress()->bp_options_nav = $bp_options_nav; 694 $this->set_current_user( $old_current_user ); 695 } 403 696 }