[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Members functions 4 * 5 * @since 3.0.0 6 * @version 10.0.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Register Scripts for the Members component 14 * 15 * @since 8.0.0 16 * 17 * @param array $scripts Optional. The array of scripts to register. 18 * @return array The same array with the specific members scripts. 19 */ 20 function bp_nouveau_members_register_scripts( $scripts = array() ) { 21 if ( ! isset( $scripts['bp-nouveau'] ) || ! bp_get_members_invitations_allowed() ) { 22 return $scripts; 23 } 24 25 return array_merge( $scripts, array( 26 'bp-nouveau-member-invites' => array( 27 'file' => 'js/buddypress-member-invites%s.js', 28 'dependencies' => array(), 29 'footer' => true, 30 ), 31 ) ); 32 } 33 34 /** 35 * Enqueue the members scripts 36 * 37 * @since 3.0.0 38 */ 39 function bp_nouveau_members_enqueue_scripts() { 40 // Neutralize Ajax when using BuddyPress Groups & member widgets on default front page 41 if ( bp_is_user_front() && bp_nouveau_get_appearance_settings( 'user_front_page' ) ) { 42 wp_add_inline_style( 43 'bp-nouveau', 44 '#member-front-widgets #groups-list-options, 45 #member-front-widgets #members-list-options, 46 #member-front-widgets #friends-list-options { 47 display: none; 48 }' 49 ); 50 } 51 52 if ( bp_is_user_members_invitations_list() ) { 53 wp_enqueue_script( 'bp-nouveau-member-invites' ); 54 } 55 } 56 57 /** 58 * Get the nav items for the Members directory 59 * 60 * @since 3.0.0 61 * 62 * @return array An associative array of nav items. 63 */ 64 function bp_nouveau_get_members_directory_nav_items() { 65 $nav_items = array(); 66 67 $nav_items['all'] = array( 68 'component' => 'members', 69 'slug' => 'all', // slug is used because BP_Core_Nav requires it, but it's the scope 70 'li_class' => array(), 71 'link' => bp_get_members_directory_permalink(), 72 'text' => __( 'All Members', 'buddypress' ), 73 'count' => bp_get_total_member_count(), 74 'position' => 5, 75 ); 76 77 if ( is_user_logged_in() ) { 78 // If friends component is active and the user has friends 79 if ( bp_is_active( 'friends' ) && bp_get_total_friend_count( bp_loggedin_user_id() ) ) { 80 $nav_items['personal'] = array( 81 'component' => 'members', 82 'slug' => 'personal', // slug is used because BP_Core_Nav requires it, but it's the scope 83 'li_class' => array(), 84 'link' => bp_loggedin_user_domain() . bp_nouveau_get_component_slug( 'friends' ) . '/my-friends/', 85 'text' => __( 'My Friends', 'buddypress' ), 86 'count' => bp_get_total_friend_count( bp_loggedin_user_id() ), 87 'position' => 15, 88 ); 89 } 90 } 91 92 // Check for the deprecated hook : 93 $extra_nav_items = bp_nouveau_parse_hooked_dir_nav( 'bp_members_directory_member_types', 'members', 20 ); 94 if ( ! empty( $extra_nav_items ) ) { 95 $nav_items = array_merge( $nav_items, $extra_nav_items ); 96 } 97 98 /** 99 * Use this filter to introduce your custom nav items for the members directory. 100 * 101 * @since 3.0.0 102 * 103 * @param array $nav_items The list of the members directory nav items. 104 */ 105 return apply_filters( 'bp_nouveau_get_members_directory_nav_items', $nav_items ); 106 } 107 108 /** 109 * Get Dropdown filters for the members component 110 * 111 * @since 3.0.0 112 * 113 * @param string $context Optional. 114 * 115 * @return array the filters 116 */ 117 function bp_nouveau_get_members_filters( $context = '' ) { 118 if ( 'group' !== $context ) { 119 $filters = array( 120 'active' => __( 'Last Active', 'buddypress' ), 121 'newest' => __( 'Newest Registered', 'buddypress' ), 122 ); 123 124 if ( bp_is_active( 'xprofile' ) ) { 125 $filters['alphabetical'] = __( 'Alphabetical', 'buddypress' ); 126 } 127 128 $action = 'bp_members_directory_order_options'; 129 130 if ( 'friends' === $context ) { 131 $action = 'bp_member_friends_order_options'; 132 } 133 } else { 134 $filters = array( 135 'last_joined' => __( 'Newest', 'buddypress' ), 136 'first_joined' => __( 'Oldest', 'buddypress' ), 137 ); 138 139 if ( bp_is_active( 'activity' ) ) { 140 $filters['group_activity'] = __( 'Group Activity', 'buddypress' ); 141 } 142 143 $filters['alphabetical'] = __( 'Alphabetical', 'buddypress' ); 144 $action = 'bp_groups_members_order_options'; 145 } 146 147 /** 148 * Recommended, filter here instead of adding an action to 'bp_members_directory_order_options' 149 * 150 * @since 3.0.0 151 * 152 * @param array the members filters. 153 * @param string the context. 154 */ 155 $filters = apply_filters( 'bp_nouveau_get_members_filters', $filters, $context ); 156 157 return bp_nouveau_parse_hooked_options( $action, $filters ); 158 } 159 160 /** 161 * Catch the arguments for buttons 162 * 163 * @since 3.0.0 164 * 165 * @param array $buttons The arguments of the button that BuddyPress is about to create. 166 * 167 * @return array An empty array to stop the button creation process. 168 */ 169 function bp_nouveau_members_catch_button_args( $button = array() ) { 170 /* 171 * Globalize the arguments so that we can use it 172 * in bp_nouveau_get_member_header_buttons(). 173 */ 174 bp_nouveau()->members->button_args = $button; 175 176 // return an empty array to stop the button creation process 177 return array(); 178 } 179 180 /** 181 * Catch the content hooked to the do_action hooks in single member header 182 * and in the members loop. 183 * 184 * @since 3.0.0 185 * @since 6.0.0 Replace wrongly positioned `bp_directory_members_item` 186 * with `bp_directory_members_item_meta` 187 * 188 * @return string|false HTML Output if hooked. False otherwise. 189 */ 190 function bp_nouveau_get_hooked_member_meta() { 191 ob_start(); 192 193 if ( ! empty( $GLOBALS['members_template'] ) ) { 194 /** 195 * Fires inside the display of metas in the directory member item. 196 * 197 * @since 6.0.0 198 */ 199 do_action( 'bp_directory_members_item_meta' ); 200 201 // It's the user's header 202 } else { 203 /** 204 * Fires after the group header actions section. 205 * 206 * If you'd like to show specific profile fields here use: 207 * bp_member_profile_data( 'field=About Me' ); -- Pass the name of the field 208 * 209 * @since 1.2.0 210 */ 211 do_action( 'bp_profile_header_meta' ); 212 } 213 214 $output = ob_get_clean(); 215 216 if ( ! empty( $output ) ) { 217 return $output; 218 } 219 220 return false; 221 } 222 223 /** 224 * Add the default user front template to the front template hierarchy 225 * 226 * @since 3.0.0 227 * 228 * @param array $templates The list of templates for the front.php template part. 229 * 230 * @return array The same list with the default front template if needed. 231 */ 232 function bp_nouveau_member_reset_front_template( $templates = array() ) { 233 $use_default_front = bp_nouveau_get_appearance_settings( 'user_front_page' ); 234 235 // Setting the front template happens too early, so we need this! 236 if ( is_customize_preview() ) { 237 $use_default_front = bp_nouveau_get_temporary_setting( 'user_front_page', $use_default_front ); 238 } 239 240 if ( ! empty( $use_default_front ) ) { 241 array_push( $templates, 'members/single/default-front.php' ); 242 } 243 244 /** 245 * Filters the BuddyPress Nouveau template hierarchy after resetting front template for members. 246 * 247 * @since 3.0.0 248 * 249 * @param array $templates Array of templates. 250 */ 251 return apply_filters( '_bp_nouveau_member_reset_front_template', $templates ); 252 } 253 254 /** 255 * Only locate global user's front templates 256 * 257 * @since 3.0.0 258 * 259 * @param array $templates The User's front template hierarchy. 260 * 261 * @return array Only the global front templates. 262 */ 263 function bp_nouveau_member_restrict_user_front_templates( $templates = array() ) { 264 return array_intersect( array( 265 'members/single/front.php', 266 'members/single/default-front.php', 267 ), $templates ); 268 } 269 270 /** 271 * Locate a single member template into a specific hierarchy. 272 * 273 * @since 3.0.0 274 * 275 * @param string $template The template part to get (eg: activity, groups...). 276 * 277 * @return string The located template. 278 */ 279 function bp_nouveau_member_locate_template_part( $template = '' ) { 280 $displayed_user = bp_get_displayed_user(); 281 $bp_nouveau = bp_nouveau(); 282 283 if ( ! $template || empty( $displayed_user->id ) ) { 284 return ''; 285 } 286 287 // Use a global to avoid requesting the hierarchy for each template 288 if ( ! isset( $bp_nouveau->members->displayed_user_hierarchy ) ) { 289 $bp_nouveau->members->displayed_user_hierarchy = array( 290 'members/single/%s-id-' . (int) $displayed_user->id . '.php', 291 'members/single/%s-nicename-' . sanitize_file_name( $displayed_user->userdata->user_nicename ) . '.php', 292 ); 293 294 /* 295 * Check for member types and add it to the hierarchy 296 * 297 * Make sure to register your member 298 * type using the hook 'bp_register_member_types' 299 */ 300 if ( bp_get_member_types() ) { 301 $displayed_user_member_type = bp_get_member_type( $displayed_user->id ); 302 if ( ! $displayed_user_member_type ) { 303 $displayed_user_member_type = 'none'; 304 } 305 306 $bp_nouveau->members->displayed_user_hierarchy[] = 'members/single/%s-member-type-' . sanitize_file_name( $displayed_user_member_type ) . '.php'; 307 } 308 309 // And the regular one 310 $bp_nouveau->members->displayed_user_hierarchy[] = 'members/single/%s.php'; 311 } 312 313 $templates = array(); 314 315 // Loop in the hierarchy to fill it for the requested template part 316 foreach ( $bp_nouveau->members->displayed_user_hierarchy as $part ) { 317 $templates[] = sprintf( $part, $template ); 318 } 319 320 /** 321 * Filters the found template parts for the member template part locating functionality. 322 * 323 * @since 3.0.0 324 * 325 * @param array $templates Array of found templates. 326 */ 327 return bp_locate_template( apply_filters( 'bp_nouveau_member_locate_template_part', $templates ), false, true ); 328 } 329 330 /** 331 * Load a single member template part 332 * 333 * @since 3.0.0 334 * 335 * @param string $template The template part to get (eg: activity, groups...). 336 * 337 * @return string HTML output. 338 */ 339 function bp_nouveau_member_get_template_part( $template = '' ) { 340 $located = bp_nouveau_member_locate_template_part( $template ); 341 342 if ( false !== $located ) { 343 $slug = str_replace( '.php', '', $located ); 344 $name = null; 345 346 /** 347 * Let plugins adding an action to bp_get_template_part get it from here. 348 * 349 * @since 3.0.0 350 * 351 * @param string $slug Template part slug requested. 352 * @param string $name Template part name requested. 353 */ 354 do_action( 'get_template_part_' . $slug, $slug, $name ); 355 356 load_template( $located, true ); 357 } 358 359 return $located; 360 } 361 362 /** 363 * Display the User's WordPress bio info into the default front page? 364 * 365 * @since 3.0.0 366 * 367 * @return bool True to display. False otherwise. 368 */ 369 function bp_nouveau_members_wp_bio_info() { 370 $user_settings = bp_nouveau_get_appearance_settings(); 371 372 return ! empty( $user_settings['user_front_page'] ) && ! empty( $user_settings['user_front_bio'] ); 373 } 374 375 /** 376 * Are we inside the Current user's default front page sidebar? 377 * 378 * @since 3.0.0 379 * 380 * @return bool True if in the group's home sidebar. False otherwise. 381 */ 382 function bp_nouveau_member_is_home_widgets() { 383 return ( true === bp_nouveau()->members->is_user_home_sidebar ); 384 } 385 386 /** 387 * Filter the Latest activities Widget to only keep the one of displayed user 388 * 389 * @since 3.0.0 390 * 391 * @param array $args The Activities Template arguments. 392 * 393 * @return array The Activities Template arguments. 394 */ 395 function bp_nouveau_member_activity_widget_overrides( $args = array() ) { 396 return array_merge( $args, array( 397 'user_id' => bp_displayed_user_id(), 398 ) ); 399 } 400 401 /** 402 * Filter the Groups widget to only keep the groups the displayed user is a member of. 403 * 404 * @since 3.0.0 405 * 406 * @param array $args The Groups Template arguments. 407 * 408 * @return array The Groups Template arguments. 409 */ 410 function bp_nouveau_member_groups_widget_overrides( $args = array() ) { 411 return array_merge( $args, array( 412 'user_id' => bp_displayed_user_id(), 413 ) ); 414 } 415 416 /** 417 * Filter the Members widgets to only keep members of the displayed group. 418 * 419 * @since 3.0.0 420 * 421 * @param array $args The Members Template arguments. 422 * 423 * @return array The Members Template arguments. 424 */ 425 function bp_nouveau_member_members_widget_overrides( $args = array() ) { 426 // Do nothing for the friends widget 427 if ( ! empty( $args['user_id'] ) && (int) $args['user_id'] === (int) bp_displayed_user_id() ) { 428 return $args; 429 } 430 431 return array_merge( $args, array( 432 'include' => bp_displayed_user_id(), 433 ) ); 434 } 435 436 /** 437 * Init the Member's default front page filters as we're in the sidebar 438 * 439 * @since 3.0.0 440 */ 441 function bp_nouveau_members_add_home_widget_filters() { 442 add_filter( 'bp_nouveau_activity_widget_query', 'bp_nouveau_member_activity_widget_overrides', 10, 1 ); 443 add_filter( 'bp_before_has_groups_parse_args', 'bp_nouveau_member_groups_widget_overrides', 10, 1 ); 444 add_filter( 'bp_before_has_members_parse_args', 'bp_nouveau_member_members_widget_overrides', 10, 1 ); 445 446 /** 447 * Fires after Nouveau adds its members home widget filters. 448 * 449 * @since 3.0.0 450 */ 451 do_action( 'bp_nouveau_members_add_home_widget_filters' ); 452 } 453 454 /** 455 * Remove the Member's default front page filters as we're no more in the sidebar 456 * 457 * @since 3.0.0 458 */ 459 function bp_nouveau_members_remove_home_widget_filters() { 460 remove_filter( 'bp_nouveau_activity_widget_query', 'bp_nouveau_member_activity_widget_overrides', 10, 1 ); 461 remove_filter( 'bp_before_has_groups_parse_args', 'bp_nouveau_member_groups_widget_overrides', 10, 1 ); 462 remove_filter( 'bp_before_has_members_parse_args', 'bp_nouveau_member_members_widget_overrides', 10, 1 ); 463 464 /** 465 * Fires after Nouveau removes its members home widget filters. 466 * 467 * @since 3.0.0 468 */ 469 do_action( 'bp_nouveau_members_remove_home_widget_filters' ); 470 } 471 472 /** 473 * Get the WP Profile fields for all or a specific user 474 * 475 * @since 3.0.0 476 * 477 * @param WP_User $user The user object. Optional. 478 * 479 * @return array The list of WP Profile fields 480 */ 481 function bp_nouveau_get_wp_profile_fields( $user = null ) { 482 /** 483 * Filters the contact methods to be included in the WP Profile fields for a specific user. 484 * 485 * Provide a chance for plugins to avoid showing the contact methods they're adding on front end. 486 * 487 * @since 3.0.0 488 * 489 * @param array $value Array of user contact methods. 490 * @param WP_User $user WordPress user to get contact methods for. 491 */ 492 $contact_methods = (array) apply_filters( 'bp_nouveau_get_wp_profile_field', wp_get_user_contact_methods( $user ), $user ); 493 494 $wp_fields = array( 495 'display_name' => __( 'Name', 'buddypress' ), 496 'user_description' => __( 'About Me', 'buddypress' ), 497 'user_url' => __( 'Website', 'buddypress' ), 498 ); 499 500 return array_merge( $wp_fields, $contact_methods ); 501 } 502 503 /** 504 * Build the Member's nav for the our customizer control. 505 * 506 * @since 3.0.0 507 * 508 * @return array The Members single item primary nav ordered. 509 */ 510 function bp_nouveau_member_customizer_nav() { 511 add_filter( '_bp_nouveau_member_reset_front_template', 'bp_nouveau_member_restrict_user_front_templates', 10, 1 ); 512 513 if ( bp_displayed_user_get_front_template( buddypress()->loggedin_user ) ) { 514 buddypress()->members->nav->add_nav( 515 array( 516 'name' => _x( 'Home', 'Member Home page', 'buddypress' ), 517 'slug' => 'front', 518 'position' => 5, 519 ) 520 ); 521 } 522 523 remove_filter( '_bp_nouveau_member_reset_front_template', 'bp_nouveau_member_restrict_user_front_templates', 10, 1 ); 524 525 $nav = buddypress()->members->nav; 526 527 // Eventually reset the order. 528 bp_nouveau_set_nav_item_order( $nav, bp_nouveau_get_appearance_settings( 'user_nav_order' ) ); 529 530 return $nav->get_primary(); 531 } 532 533 /** 534 * Includes additional information about the Members loop Ajax response. 535 * 536 * @since 10.0.0 537 * 538 * @param array $additional_info An associative array with additional information to include in the Ajax response. 539 * @param array $args The Ajax query arguments. 540 * @return array Additional information about the members loop. 541 */ 542 function bp_nouveau_members_loop_additional_info( $additional_info = array(), $args = array() ) { 543 if ( ! isset( $GLOBALS['members_template'] ) || ! $GLOBALS['members_template'] ) { 544 return $additional_info; 545 } 546 547 $members_template = $GLOBALS['members_template']; 548 549 if ( isset( $members_template->member_count ) && 'all' === $args['scope'] ) { 550 $additional_info['totalItems'] = bp_core_number_format( $members_template->member_count ); 551 $additional_info['navLabel'] = esc_html__( 'All Members', 'buddypress' ); 552 553 $nav_labels = array( 554 'active' => esc_html__( 'Active Members', 'buddypress' ), 555 'newest' => esc_html__( 'Newest Members', 'buddypress' ), 556 ); 557 558 if ( isset( $nav_labels[ $args['filter'] ] ) ) { 559 $additional_info['navLabel'] = $nav_labels[ $args['filter'] ]; 560 } 561 } 562 563 return $additional_info; 564 } 565 add_filter( 'bp_nouveau_members_ajax_object_template_response', 'bp_nouveau_members_loop_additional_info', 10, 2 );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |