[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Member Template Tags. 4 * 5 * Functions that are safe to use inside your template files and themes. 6 * 7 * @package BuddyPress 8 * @subpackage MembersTemplate 9 * @since 1.5.0 10 */ 11 12 // Exit if accessed directly. 13 defined( 'ABSPATH' ) || exit; 14 15 /** 16 * Output the profile component slug. 17 * 18 * @since 2.4.0 19 */ 20 function bp_profile_slug() { 21 echo bp_get_profile_slug(); 22 } 23 /** 24 * Return the profile component slug. 25 * 26 * @since 2.4.0 27 * 28 * @return string 29 */ 30 function bp_get_profile_slug() { 31 32 /** 33 * Filters the profile component slug. 34 * 35 * @since 2.4.0 36 * 37 * @param string $slug Profile component slug. 38 */ 39 return apply_filters( 'bp_get_profile_slug', buddypress()->profile->slug ); 40 } 41 42 /** 43 * Output the members component slug. 44 * 45 * @since 1.5.0 46 */ 47 function bp_members_slug() { 48 echo bp_get_members_slug(); 49 } 50 /** 51 * Return the members component slug. 52 * 53 * @since 1.5.0 54 * 55 * @return string 56 */ 57 function bp_get_members_slug() { 58 59 /** 60 * Filters the Members component slug. 61 * 62 * @since 1.5.0 63 * 64 * @param string $slug Members component slug. 65 */ 66 return apply_filters( 'bp_get_members_slug', buddypress()->members->slug ); 67 } 68 69 /** 70 * Output the members component root slug. 71 * 72 * @since 1.5.0 73 */ 74 function bp_members_root_slug() { 75 echo bp_get_members_root_slug(); 76 } 77 /** 78 * Return the members component root slug. 79 * 80 * @since 1.5.0 81 * 82 * @return string 83 */ 84 function bp_get_members_root_slug() { 85 86 /** 87 * Filters the Members component root slug. 88 * 89 * @since 1.5.0 90 * 91 * @param string $root_slug Members component root slug. 92 */ 93 return apply_filters( 'bp_get_members_root_slug', buddypress()->members->root_slug ); 94 } 95 96 /** 97 * Output the member type base slug. 98 * 99 * @since 2.5.0 100 */ 101 function bp_members_member_type_base() { 102 echo esc_url( bp_get_members_member_type_base() ); 103 } 104 /** 105 * Get the member type URL base. 106 * 107 * The base slug is the string used as the base prefix when generating member type directory URLs. 108 * For example, in example.com/members/type/foo/, 'foo' is the member type and 'type' is the 109 * base slug. 110 * 111 * @since 2.5.0 112 * 113 * @return string 114 */ 115 function bp_get_members_member_type_base() { 116 117 /** 118 * Filters the member type URL base. 119 * 120 * @since 2.3.0 121 * 122 * @param string $base Base slug for the member type. 123 */ 124 return apply_filters( 'bp_members_member_type_base', _x( 'type', 'member type URL base', 'buddypress' ) ); 125 } 126 127 /** 128 * Output member directory permalink. 129 * 130 * @since 1.5.0 131 */ 132 function bp_members_directory_permalink() { 133 echo esc_url( bp_get_members_directory_permalink() ); 134 } 135 /** 136 * Return member directory permalink. 137 * 138 * @since 1.5.0 139 * 140 * @return string 141 */ 142 function bp_get_members_directory_permalink() { 143 144 /** 145 * Filters the member directory permalink. 146 * 147 * @since 1.5.0 148 * 149 * @param string $value Members directory permalink. 150 */ 151 return apply_filters( 'bp_get_members_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() ) ); 152 } 153 154 /** 155 * Output member type directory permalink. 156 * 157 * @since 2.5.0 158 * 159 * @param string $member_type Optional. Member type. Defaults to current member type. 160 */ 161 function bp_member_type_directory_permalink( $member_type = '' ) { 162 echo esc_url( bp_get_member_type_directory_permalink( $member_type ) ); 163 } 164 /** 165 * Return member type directory permalink. 166 * 167 * @since 2.5.0 168 * 169 * @param string $member_type Optional. Member type. Defaults to current member type. 170 * @return string Member type directory URL on success, an empty string on failure. 171 */ 172 function bp_get_member_type_directory_permalink( $member_type = '' ) { 173 174 if ( $member_type ) { 175 $_member_type = $member_type; 176 } else { 177 // Fall back on the current member type. 178 $_member_type = bp_get_current_member_type(); 179 } 180 181 $type = bp_get_member_type_object( $_member_type ); 182 183 // Bail when member type is not found or has no directory. 184 if ( ! $type || ! $type->has_directory ) { 185 return ''; 186 } 187 188 /** 189 * Filters the member type directory permalink. 190 * 191 * @since 2.5.0 192 * 193 * @param string $value Member type directory permalink. 194 * @param object $type Member type object. 195 * @param string $member_type Member type name, as passed to the function. 196 */ 197 return apply_filters( 'bp_get_member_type_directory_permalink', trailingslashit( bp_get_members_directory_permalink() . bp_get_members_member_type_base() . '/' . $type->directory_slug ), $type, $member_type ); 198 } 199 200 /** 201 * Output the sign-up slug. 202 * 203 * @since 1.5.0 204 */ 205 function bp_signup_slug() { 206 echo bp_get_signup_slug(); 207 } 208 /** 209 * Return the sign-up slug. 210 * 211 * @since 1.5.0 212 * 213 * @global BuddyPress $bp The one true BuddyPress instance. 214 * 215 * @return string 216 */ 217 function bp_get_signup_slug() { 218 $bp = buddypress(); 219 220 if ( ! empty( $bp->pages->register->slug ) ) { 221 $slug = $bp->pages->register->slug; 222 } elseif ( defined( 'BP_REGISTER_SLUG' ) ) { 223 $slug = BP_REGISTER_SLUG; 224 } else { 225 $slug = 'register'; 226 } 227 228 /** 229 * Filters the sign-up slug. 230 * 231 * @since 1.5.0 232 * 233 * @param string $slug Sign-up slug. 234 */ 235 return apply_filters( 'bp_get_signup_slug', $slug ); 236 } 237 238 /** 239 * Output the activation slug. 240 * 241 * @since 1.5.0 242 */ 243 function bp_activate_slug() { 244 echo bp_get_activate_slug(); 245 } 246 /** 247 * Return the activation slug. 248 * 249 * @since 1.5.0 250 * 251 * @global BuddyPress $bp The one true BuddyPress instance. 252 * 253 * @return string 254 */ 255 function bp_get_activate_slug() { 256 $bp = buddypress(); 257 258 if ( ! empty( $bp->pages->activate->slug ) ) { 259 $slug = $bp->pages->activate->slug; 260 } elseif ( defined( 'BP_ACTIVATION_SLUG' ) ) { 261 $slug = BP_ACTIVATION_SLUG; 262 } else { 263 $slug = 'activate'; 264 } 265 266 /** 267 * Filters the activation slug. 268 * 269 * @since 1.5.0 270 * 271 * @param string $slug Activation slug. 272 */ 273 return apply_filters( 'bp_get_activate_slug', $slug ); 274 } 275 276 /** 277 * Output the members invitation pane slug. 278 * 279 * @since 8.0.0 280 */ 281 function bp_members_invitations_slug() { 282 echo bp_get_members_invitations_slug(); 283 } 284 /** 285 * Return the members invitations root slug. 286 * 287 * @since 8.0.0 288 * 289 * @return string 290 */ 291 function bp_get_members_invitations_slug() { 292 293 /** 294 * Filters the Members invitations pane root slug. 295 * 296 * @since 8.0.0 297 * 298 * @param string $slug Members invitations pane root slug. 299 */ 300 return apply_filters( 'bp_get_members_invitations_slug', _x( 'invitations', 'Member profile invitations pane URL base', 'buddypress' ) ); 301 } 302 303 /** 304 * Initialize the members loop. 305 * 306 * Based on the $args passed, bp_has_members() populates the $members_template 307 * global, enabling the use of BuddyPress templates and template functions to 308 * display a list of members. 309 * 310 * @since 1.2.0 311 * @since 7.0.0 Added `xprofile_query` parameter. Added `user_ids` parameter. 312 * @since 10.0.0 Added `date_query` parameter. 313 * 314 * @global BP_Core_Members_Template $members_template 315 * 316 * @param array|string $args { 317 * Arguments for limiting the contents of the members loop. Most arguments 318 * are in the same format as {@link BP_User_Query}. However, because 319 * the format of the arguments accepted here differs in a number of ways, 320 * and because bp_has_members() determines some default arguments in a 321 * dynamic fashion, we list all accepted arguments here as well. 322 * 323 * Arguments can be passed as an associative array, or as a URL query 324 * string (eg, 'user_id=4&per_page=3'). 325 * 326 * @type int $type Sort order. Accepts 'active', 'random', 'newest', 'popular', 327 * 'online', 'alphabetical'. Default: 'active'. 328 * @type int|bool $page Page of results to display. Default: 1. 329 * @type int|bool $per_page Number of results per page. Default: 20. 330 * @type int|bool $max Maximum number of results to return. Default: false (unlimited). 331 * @type string $page_arg The string used as a query parameter in pagination links. 332 * Default: 'bpage'. 333 * @type array|int|string|bool $include Limit results by a list of user IDs. Accepts an array, a 334 * single integer, a comma-separated list of IDs, or false (to 335 * disable this limiting). Accepts 'active', 'alphabetical', 336 * 'newest', or 'random'. Default: false. 337 * @type array|int|string|bool $exclude Exclude users from results by ID. Accepts an array, a single 338 * integer, a comma-separated list of IDs, or false (to disable 339 * this limiting). Default: false. 340 * @type array|string|bool $user_ids An array or comma-separated list of IDs, or false (to 341 * disable this limiting). Default: false. 342 * @type int $user_id If provided, results are limited to the friends of the specified 343 * user. When on a user's Friends page, defaults to the ID of the 344 * displayed user. Otherwise defaults to 0. 345 * @type string|array $member_type Array or comma-separated list of member types to limit 346 * results to. 347 * @type string|array $member_type__in Array or comma-separated list of member types to limit 348 * results to. 349 * @type string|array $member_type__not_in Array or comma-separated list of member types to exclude 350 * from results. 351 * @type string $search_terms Limit results by a search term. Default: value of 352 * `$_REQUEST['members_search']` or `$_REQUEST['s']`, if present. 353 * Otherwise false. 354 * @type string $meta_key Limit results by the presence of a usermeta key. 355 * Default: false. 356 * @type mixed $meta_value When used with meta_key, limits results by the a matching 357 * usermeta value. Default: false. 358 * @type array $xprofile_query Filter results by xprofile data. Requires the xprofile 359 * component. See {@see BP_XProfile_Query} for details. 360 * @type array $date_query Filter results by member last activity date. See first parameter of 361 * {@link WP_Date_Query::__construct()} for syntax. Only applicable if 362 * $type is either 'active', 'random', 'newest', or 'online'. 363 * @type bool $populate_extras Whether to fetch optional data, such as friend counts. 364 * Default: true. 365 * } 366 * @return bool Returns true when blogs are found, otherwise false. 367 */ 368 function bp_has_members( $args = '' ) { 369 global $members_template; 370 371 // Default user ID. 372 $user_id = 0; 373 374 // User filtering. 375 if ( bp_is_user_friends() && ! bp_is_user_friend_requests() ) { 376 $user_id = bp_displayed_user_id(); 377 } 378 379 $member_type = bp_get_current_member_type(); 380 if ( ! $member_type && ! empty( $_GET['member_type'] ) ) { 381 if ( is_array( $_GET['member_type'] ) ) { 382 $member_type = $_GET['member_type']; 383 } else { 384 // Can be a comma-separated list. 385 $member_type = explode( ',', $_GET['member_type'] ); 386 } 387 } 388 389 $search_terms_default = null; 390 $search_query_arg = bp_core_get_component_search_query_arg( 'members' ); 391 if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) { 392 $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] ); 393 } 394 395 // Type: active ( default ) | random | newest | popular | online | alphabetical. 396 $r = bp_parse_args( 397 $args, 398 array( 399 'type' => 'active', 400 'page' => 1, 401 'per_page' => 20, 402 'max' => false, 403 404 'page_arg' => 'upage', // See https://buddypress.trac.wordpress.org/ticket/3679. 405 406 'include' => false, // Pass a user_id or a list (comma-separated or array) of user_ids to only show these users. 407 'exclude' => false, // Pass a user_id or a list (comma-separated or array) of user_ids to exclude these users. 408 'user_ids' => false, 409 410 'user_id' => $user_id, // Pass a user_id to only show friends of this user. 411 'member_type' => $member_type, 412 'member_type__in' => '', 413 'member_type__not_in' => '', 414 'search_terms' => $search_terms_default, 415 416 'meta_key' => false, // Only return users with this usermeta. 417 'meta_value' => false, // Only return users where the usermeta value matches. Requires meta_key. 418 419 'xprofile_query' => false, 420 'date_query' => false, // Filter members by last activity. 421 'populate_extras' => true, // Fetch usermeta? Friend count, last active etc. 422 ), 423 'has_members' 424 ); 425 426 // Pass a filter if ?s= is set. 427 if ( is_null( $r['search_terms'] ) ) { 428 if ( !empty( $_REQUEST['s'] ) ) { 429 $r['search_terms'] = $_REQUEST['s']; 430 } else { 431 $r['search_terms'] = false; 432 } 433 } 434 435 // Set per_page to max if max is larger than per_page. 436 if ( !empty( $r['max'] ) && ( $r['per_page'] > $r['max'] ) ) { 437 $r['per_page'] = $r['max']; 438 } 439 440 // Query for members and populate $members_template global. 441 $members_template = new BP_Core_Members_Template( $r ); 442 443 /** 444 * Filters whether or not BuddyPress has members to iterate over. 445 * 446 * @since 1.2.4 447 * @since 2.6.0 Added the `$r` parameter 448 * 449 * @param bool $value Whether or not there are members to iterate over. 450 * @param BP_Core_Members_Template $members_template Populated $members_template global. 451 * @param array $r Array of arguments passed into the BP_Core_Members_Template class. 452 */ 453 return apply_filters( 'bp_has_members', $members_template->has_members(), $members_template, $r ); 454 } 455 456 /** 457 * Set up the current member inside the loop. 458 * 459 * @since 1.2.0 460 * 461 * @global BP_Core_Members_Template $members_template 462 * 463 * @return object 464 */ 465 function bp_the_member() { 466 global $members_template; 467 return $members_template->the_member(); 468 } 469 470 /** 471 * Check whether there are more members to iterate over. 472 * 473 * @since 1.2.0 474 * 475 * @global BP_Core_Members_Template $members_template 476 * 477 * @return bool 478 */ 479 function bp_members() { 480 global $members_template; 481 return $members_template->members(); 482 } 483 484 /** 485 * Output the members pagination count. 486 * 487 * @since 1.2.0 488 */ 489 function bp_members_pagination_count() { 490 echo bp_get_members_pagination_count(); 491 } 492 /** 493 * Generate the members pagination count. 494 * 495 * @since 1.5.0 496 * 497 * @global BP_Core_Members_Template $members_template 498 * 499 * @return string 500 */ 501 function bp_get_members_pagination_count() { 502 global $members_template; 503 504 if ( empty( $members_template->type ) ) { 505 $members_template->type = ''; 506 } 507 508 $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1; 509 $from_num = bp_core_number_format( $start_num ); 510 $to_num = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) ); 511 $total = bp_core_number_format( $members_template->total_member_count ); 512 513 if ( 'active' == $members_template->type ) { 514 if ( 1 == $members_template->total_member_count ) { 515 $pag = __( 'Viewing 1 active member', 'buddypress' ); 516 } else { 517 /* translators: 1: active member from number. 2: active member to number. 3: total active members. */ 518 $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s active member', 'Viewing %1$s - %2$s of %3$s active members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 519 } 520 } elseif ( 'popular' == $members_template->type ) { 521 if ( 1 == $members_template->total_member_count ) { 522 $pag = __( 'Viewing 1 member with friends', 'buddypress' ); 523 } else { 524 /* translators: 1: member with friends from number. 2: member with friends to number. 3: total members with friends. */ 525 $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s member with friends', 'Viewing %1$s - %2$s of %3$s members with friends', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 526 } 527 } elseif ( 'online' == $members_template->type ) { 528 if ( 1 == $members_template->total_member_count ) { 529 $pag = __( 'Viewing 1 online member', 'buddypress' ); 530 } else { 531 /* translators: 1: online member from number. 2: online member to number. 3: total online members. */ 532 $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s online member', 'Viewing %1$s - %2$s of %3$s online members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 533 } 534 } else { 535 if ( 1 == $members_template->total_member_count ) { 536 $pag = __( 'Viewing 1 member', 'buddypress' ); 537 } else { 538 /* translators: 1: member from number. 2: member to number. 3: total members. */ 539 $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s member', 'Viewing %1$s - %2$s of %3$s members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 540 } 541 } 542 543 /** 544 * Filters the members pagination count. 545 * 546 * @since 1.5.0 547 * 548 * @param string $pag Pagination count string. 549 */ 550 return apply_filters( 'bp_members_pagination_count', $pag ); 551 } 552 553 /** 554 * Output the members pagination links. 555 * 556 * @since 1.2.0 557 */ 558 function bp_members_pagination_links() { 559 echo bp_get_members_pagination_links(); 560 } 561 /** 562 * Fetch the members pagination links. 563 * 564 * @since 1.2.0 565 * 566 * @global BP_Core_Members_Template $members_template 567 * 568 * @return string 569 */ 570 function bp_get_members_pagination_links() { 571 global $members_template; 572 573 /** 574 * Filters the members pagination link. 575 * 576 * @since 1.2.0 577 * 578 * @param string $pag_links HTML markup for pagination links. 579 */ 580 return apply_filters( 'bp_get_members_pagination_links', $members_template->pag_links ); 581 } 582 583 /** 584 * Output the ID of the current member in the loop. 585 * 586 * @since 1.2.0 587 */ 588 function bp_member_user_id() { 589 echo bp_get_member_user_id(); 590 } 591 /** 592 * Get the ID of the current member in the loop. 593 * 594 * @since 1.2.0 595 * 596 * @global BP_Core_Members_Template $members_template 597 * 598 * @return int Member ID. 599 */ 600 function bp_get_member_user_id() { 601 global $members_template; 602 603 $member_id = isset( $members_template->member->id ) 604 ? (int) $members_template->member->id 605 : 0; 606 607 /** 608 * Filters the ID of the current member in the loop. 609 * 610 * @since 1.2.0 611 * 612 * @param int $member_id ID of the member being iterated over. 613 */ 614 return apply_filters( 'bp_get_member_user_id', (int) $member_id ); 615 } 616 617 /** 618 * Output the row class of the current member in the loop. 619 * 620 * @since 1.7.0 621 * 622 * @param array $classes Array of custom classes. 623 */ 624 function bp_member_class( $classes = array() ) { 625 echo bp_get_member_class( $classes ); 626 } 627 /** 628 * Return the row class of the current member in the loop. 629 * 630 * @since 1.7.0 631 * 632 * @global BP_Core_Members_Template $members_template 633 * 634 * @param array $classes Array of custom classes. 635 * 636 * @return string Row class of the member 637 */ 638 function bp_get_member_class( $classes = array() ) { 639 global $members_template; 640 641 // Add even/odd classes, but only if there's more than 1 member. 642 if ( $members_template->member_count > 1 ) { 643 $pos_in_loop = (int) $members_template->current_member; 644 $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd'; 645 646 // If we've only one member in the loop, don't bother with odd and even. 647 } else { 648 $classes[] = 'bp-single-member'; 649 } 650 651 // Maybe add 'is-online' class. 652 if ( ! empty( $members_template->member->last_activity ) ) { 653 654 // Calculate some times. 655 $current_time = bp_core_current_time( true, 'timestamp' ); 656 $last_activity = strtotime( $members_template->member->last_activity ); 657 $still_online = strtotime( '+5 minutes', $last_activity ); 658 659 // Has the user been active recently? 660 if ( $current_time <= $still_online ) { 661 $classes[] = 'is-online'; 662 } 663 } 664 665 // Add current user class. 666 if ( bp_loggedin_user_id() === (int) $members_template->member->id ) { 667 $classes[] = 'is-current-user'; 668 } 669 670 // Add current user member types. 671 if ( $member_types = bp_get_member_type( $members_template->member->id, false ) ) { 672 foreach ( $member_types as $member_type ) { 673 $classes[] = sprintf( 'member-type-%s', esc_attr( $member_type ) ); 674 } 675 } 676 677 /** 678 * Filters the determined classes to add to the HTML element. 679 * 680 * @since 1.7.0 681 * 682 * @param string $classes Classes to be added to the HTML element. 683 */ 684 $classes = apply_filters( 'bp_get_member_class', $classes ); 685 $classes = array_merge( $classes, array() ); 686 $retval = 'class="' . join( ' ', $classes ) . '"'; 687 688 return $retval; 689 } 690 691 /** 692 * Output nicename of current member in the loop. 693 * 694 * @since 1.2.5 695 */ 696 function bp_member_user_nicename() { 697 echo bp_get_member_user_nicename(); 698 } 699 /** 700 * Get the nicename of the current member in the loop. 701 * 702 * @since 1.2.5 703 * 704 * @global BP_Core_Members_Template $members_template 705 * 706 * @return string Members nicename. 707 */ 708 function bp_get_member_user_nicename() { 709 global $members_template; 710 711 /** 712 * Filters the nicename of the current member in the loop. 713 * 714 * @since 1.2.5 715 * 716 * @param string $user_nicename Nicename for the current member. 717 */ 718 return apply_filters( 'bp_get_member_user_nicename', $members_template->member->user_nicename ); 719 } 720 721 /** 722 * Output login for current member in the loop. 723 * 724 * @since 1.2.5 725 */ 726 function bp_member_user_login() { 727 echo bp_get_member_user_login(); 728 } 729 /** 730 * Get the login of the current member in the loop. 731 * 732 * @since 1.2.5 733 * 734 * @global BP_Core_Members_Template $members_template 735 * 736 * @return string Member's login. 737 */ 738 function bp_get_member_user_login() { 739 global $members_template; 740 741 /** 742 * Filters the login of the current member in the loop. 743 * 744 * @since 1.2.5 745 * 746 * @param string $user_login Login for the current member. 747 */ 748 return apply_filters( 'bp_get_member_user_login', $members_template->member->user_login ); 749 } 750 751 /** 752 * Output the email address for the current member in the loop. 753 * 754 * @since 1.2.5 755 */ 756 function bp_member_user_email() { 757 echo bp_get_member_user_email(); 758 } 759 /** 760 * Get the email address of the current member in the loop. 761 * 762 * @since 1.2.5 763 * 764 * @global BP_Core_Members_Template $members_template 765 * 766 * @return string Member's email address. 767 */ 768 function bp_get_member_user_email() { 769 global $members_template; 770 771 /** 772 * Filters the email address of the current member in the loop. 773 * 774 * @since 1.2.5 775 * 776 * @param string $user_email Email address for the current member. 777 */ 778 return apply_filters( 'bp_get_member_user_email', $members_template->member->user_email ); 779 } 780 781 /** 782 * Check whether the current member in the loop is the logged-in user. 783 * 784 * @since 1.2.5 785 * @since 10.0.0 Updated to get member ID from `bp_get_member_user_id`. 786 * 787 * @return bool 788 */ 789 function bp_member_is_loggedin_user() { 790 791 /** 792 * Filters whether the current member in the loop is the logged-in user. 793 * 794 * @since 1.2.5 795 * 796 * @param bool $value Whether current member in the loop is logged in. 797 */ 798 return apply_filters( 'bp_member_is_loggedin_user', ( bp_loggedin_user_id() === bp_get_member_user_id() ) ); 799 } 800 801 /** 802 * Output a member's avatar. 803 * 804 * @since 1.2.0 805 * 806 * @see bp_get_member_avatar() for description of arguments. 807 * 808 * @param array|string $args See {@link bp_get_member_avatar()}. 809 */ 810 function bp_member_avatar( $args = '' ) { 811 812 /** 813 * Filters a members avatar. 814 * 815 * @since 1.2.0 816 * @since 2.6.0 Added the `$args` parameter. 817 * 818 * @param string $value Formatted HTML <img> element, or raw avatar URL based on $html arg. 819 * @param array|string $args See {@link bp_get_member_avatar()}. 820 */ 821 echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ), $args ); 822 } 823 /** 824 * Get a member's avatar. 825 * 826 * @since 1.2.0 827 * 828 * @global BP_Core_Members_Template $members_template 829 * 830 * @see bp_core_fetch_avatar() For a description of arguments and 831 * return values. 832 * 833 * @param array|string $args { 834 * Arguments are listed here with an explanation of their defaults. 835 * For more information about the arguments, see 836 * {@link bp_core_fetch_avatar()}. 837 * @type string $alt Default: 'Profile picture of [user name]'. 838 * @type string $class Default: 'avatar'. 839 * @type string $type Default: 'thumb'. 840 * @type int|bool $width Default: false. 841 * @type int|bool $height Default: false. 842 * @type bool $no_grav Default: false. 843 * @type bool $id Currently unused. 844 * } 845 * @return string User avatar string. 846 */ 847 function bp_get_member_avatar( $args = '' ) { 848 global $members_template; 849 850 $fullname = ! empty( $members_template->member->fullname ) 851 ? $members_template->member->fullname 852 : $members_template->member->display_name; 853 854 $r = bp_parse_args( 855 $args, 856 array( 857 'type' => 'thumb', 858 'width' => false, 859 'height' => false, 860 'class' => 'avatar', 861 'id' => false, 862 'no_grav' => false, 863 /* translators: %s: member name */ 864 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname ), 865 ) 866 ); 867 868 $avatar = bp_core_fetch_avatar( 869 array( 870 'email' => bp_get_member_user_email(), 871 'item_id' => bp_get_member_user_id(), 872 'type' => $r['type'], 873 'alt' => $r['alt'], 874 'no_grav' => $r['no_grav'], 875 'css_id' => $r['id'], 876 'class' => $r['class'], 877 'width' => $r['width'], 878 'height' => $r['height'], 879 ) 880 ); 881 882 /** 883 * Filters a member's avatar. 884 * 885 * @since 1.2.0 886 * @since 2.6.0 Added the `$r` parameter. 887 * 888 * @param string $value Formatted HTML <img> element, or raw avatar URL based on $html arg. 889 * @param array $r Array of parsed arguments. See {@link bp_get_member_avatar()}. 890 */ 891 return apply_filters( 'bp_get_member_avatar', $avatar, $r ); 892 } 893 894 /** 895 * Output the permalink for the current member in the loop. 896 * 897 * @since 1.2.0 898 */ 899 function bp_member_permalink() { 900 echo esc_url( bp_get_member_permalink() ); 901 } 902 /** 903 * Get the permalink for the current member in the loop. 904 * 905 * @since 1.2.0 906 * 907 * @global BP_Core_Members_Template $members_template 908 * 909 * @return string 910 */ 911 function bp_get_member_permalink() { 912 global $members_template; 913 914 $permalink = bp_core_get_user_domain( 915 $members_template->member->id, 916 $members_template->member->user_nicename, 917 $members_template->member->user_login 918 ); 919 920 /** 921 * Filters the permalink for the current member in the loop. 922 * 923 * @since 1.2.0 924 * 925 * @param string $permalink Permalink for the current member in the loop. 926 */ 927 return apply_filters( 'bp_get_member_permalink', $permalink ); 928 } 929 930 /** 931 * Alias of {@link bp_member_permalink()}. 932 * 933 * @since 1.2.0 934 */ 935 function bp_member_link() { 936 echo esc_url( bp_get_member_permalink() ); 937 } 938 939 /** 940 * Alias of {@link bp_get_member_permalink()}. 941 * 942 * @since 1.2.0 943 */ 944 function bp_get_member_link() { 945 return bp_get_member_permalink(); 946 } 947 948 /** 949 * Output display name of current member in the loop. 950 * 951 * @since 1.2.0 952 */ 953 function bp_member_name() { 954 955 /** 956 * Filters the display name of current member in the loop. 957 * 958 * @since 1.2.0 959 * 960 * @param string $value Display name for current member. 961 */ 962 echo apply_filters( 'bp_member_name', bp_get_member_name() ); 963 } 964 /** 965 * Get the display name of the current member in the loop. 966 * 967 * Full name is, by default, pulled from xprofile's Full Name field. 968 * When this field is empty, we try to get an alternative name from the 969 * WP users table, in the following order of preference: display_name, 970 * user_nicename, user_login. 971 * 972 * @since 1.2.0 973 * 974 * @global BP_Core_Members_Template $members_template 975 * 976 * @return string The user's fullname for display. 977 */ 978 function bp_get_member_name() { 979 global $members_template; 980 981 // Generally, this only fires when xprofile is disabled. 982 if ( empty( $members_template->member->fullname ) ) { 983 // Our order of preference for alternative fullnames. 984 $name_stack = array( 985 'display_name', 986 'user_nicename', 987 'user_login' 988 ); 989 990 foreach ( $name_stack as $source ) { 991 if ( ! empty( $members_template->member->{$source} ) ) { 992 // When a value is found, set it as fullname and be done with it. 993 $members_template->member->fullname = $members_template->member->{$source}; 994 break; 995 } 996 } 997 } 998 999 /** 1000 * Filters the display name of current member in the loop. 1001 * 1002 * @since 1.2.0 1003 * 1004 * @param string $fullname Display name for current member. 1005 */ 1006 return apply_filters( 'bp_get_member_name', $members_template->member->fullname ); 1007 } 1008 add_filter( 'bp_get_member_name', 'wp_filter_kses' ); 1009 add_filter( 'bp_get_member_name', 'stripslashes' ); 1010 add_filter( 'bp_get_member_name', 'strip_tags' ); 1011 add_filter( 'bp_get_member_name', 'esc_html' ); 1012 1013 /** 1014 * Output the current member's last active time. 1015 * 1016 * @since 1.2.0 1017 * 1018 * @param array $args {@see bp_get_member_last_active()}. 1019 */ 1020 function bp_member_last_active( $args = array() ) { 1021 echo bp_get_member_last_active( $args ); 1022 } 1023 /** 1024 * Return the current member's last active time. 1025 * 1026 * @since 1.2.0 1027 * @since 2.7.0 Added 'relative' as a parameter to $args. 1028 * 1029 * @global BP_Core_Members_Template $members_template 1030 * 1031 * @param array $args { 1032 * Array of optional arguments. 1033 * @type mixed $active_format If true, formatted "active 5 minutes ago". If false, formatted "5 minutes 1034 * ago". If string, should be sprintf'able like 'last seen %s ago'. 1035 * @type bool $relative If true, will return relative time "5 minutes ago". If false, will return 1036 * date from database. Default: true. 1037 * } 1038 * @return string 1039 */ 1040 function bp_get_member_last_active( $args = array() ) { 1041 global $members_template; 1042 1043 // Parse the activity format. 1044 $r = bp_parse_args( 1045 $args, 1046 array( 1047 'active_format' => true, 1048 'relative' => true, 1049 ) 1050 ); 1051 1052 // Backwards compatibility for anyone forcing a 'true' active_format. 1053 if ( true === $r['active_format'] ) { 1054 /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */ 1055 $r['active_format'] = __( 'Active %s', 'buddypress' ); 1056 } 1057 1058 // Member has logged in at least one time. 1059 if ( isset( $members_template->member->last_activity ) ) { 1060 // We do not want relative time, so return now. 1061 // @todo Should the 'bp_member_last_active' filter be applied here? 1062 if ( ! $r['relative'] ) { 1063 return esc_attr( $members_template->member->last_activity ); 1064 } 1065 1066 // Backwards compatibility for pre 1.5 'ago' strings. 1067 $last_activity = ! empty( $r['active_format'] ) 1068 ? bp_core_get_last_activity( $members_template->member->last_activity, $r['active_format'] ) 1069 : bp_core_time_since( $members_template->member->last_activity ); 1070 1071 // Member has never logged in or been active. 1072 } else { 1073 $last_activity = __( 'Never active', 'buddypress' ); 1074 } 1075 1076 /** 1077 * Filters the current members last active time. 1078 * 1079 * @since 1.2.0 1080 * 1081 * @param string $last_activity Formatted time since last activity. 1082 * @param array $r Array of parsed arguments for query. 1083 */ 1084 return apply_filters( 'bp_member_last_active', $last_activity, $r ); 1085 } 1086 1087 /** 1088 * Output the latest update of the current member in the loop. 1089 * 1090 * @since 1.2.0 1091 * 1092 * @param array|string $args {@see bp_get_member_latest_update()}. 1093 */ 1094 function bp_member_latest_update( $args = '' ) { 1095 echo bp_get_member_latest_update( $args ); 1096 } 1097 /** 1098 * Get the latest update from the current member in the loop. 1099 * 1100 * @since 1.2.0 1101 * 1102 * @global BP_Core_Members_Template $members_template 1103 * 1104 * @param array|string $args { 1105 * Array of optional arguments. 1106 * @type int $length Truncation length. Default: 225. 1107 * @type bool $view_link Whether to provide a 'View' link for 1108 * truncated entries. Default: false. 1109 * } 1110 * @return string 1111 */ 1112 function bp_get_member_latest_update( $args = '' ) { 1113 global $members_template; 1114 1115 $defaults = array( 1116 'length' => 225, 1117 'view_link' => true, 1118 ); 1119 1120 $r = bp_parse_args( 1121 $args, 1122 $defaults 1123 ); 1124 1125 extract( $r ); 1126 1127 if ( !bp_is_active( 'activity' ) || empty( $members_template->member->latest_update ) || !$update = maybe_unserialize( $members_template->member->latest_update ) ) 1128 return false; 1129 1130 /** 1131 * Filters the excerpt of the latest update for current member in the loop. 1132 * 1133 * @since 1.2.5 1134 * @since 2.6.0 Added the `$r` parameter. 1135 * 1136 * @param string $value Excerpt of the latest update for current member in the loop. 1137 * @param array $r Array of parsed arguments. 1138 */ 1139 $update_content = apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], $length ) ) ), $r ); 1140 1141 /* translators: %s: the member latest activity update */ 1142 $update_content = sprintf( _x( '- "%s"', 'member latest update in member directory', 'buddypress' ), $update_content ); 1143 1144 // If $view_link is true and the text returned by bp_create_excerpt() is different from the original text (ie it's 1145 // been truncated), add the "View" link. 1146 if ( $view_link && ( $update_content != $update['content'] ) ) { 1147 $view = __( 'View', 'buddypress' ); 1148 1149 $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_permalink( $update['id'] ) . '" rel="nofollow">' . $view . '</a></span>'; 1150 } 1151 1152 /** 1153 * Filters the latest update from the current member in the loop. 1154 * 1155 * @since 1.2.0 1156 * @since 2.6.0 Added the `$r` parameter. 1157 * 1158 * @param string $update_content Formatted latest update for current member. 1159 * @param array $r Array of parsed arguments. 1160 */ 1161 return apply_filters( 'bp_get_member_latest_update', $update_content, $r ); 1162 } 1163 1164 /** 1165 * Output a piece of user profile data. 1166 * 1167 * @since 1.2.0 1168 * 1169 * @see bp_get_member_profile_data() for a description of params. 1170 * 1171 * @param array|string $args See {@link bp_get_member_profile_data()}. 1172 */ 1173 function bp_member_profile_data( $args = '' ) { 1174 echo bp_get_member_profile_data( $args ); 1175 } 1176 /** 1177 * Get a piece of user profile data. 1178 * 1179 * When used in a bp_has_members() loop, this function will attempt 1180 * to fetch profile data cached in the template global. It is also safe 1181 * to use outside of the loop. 1182 * 1183 * @since 1.2.0 1184 * 1185 * @global BP_Core_Members_Template $members_template 1186 * 1187 * @param array|string $args { 1188 * Array of config parameters. 1189 * @type string $field Name of the profile field. 1190 * @type int $user_id ID of the user whose data is being fetched. 1191 * Defaults to the current member in the loop, or if not 1192 * present, to the currently displayed user. 1193 * } 1194 * @return string|bool Profile data if found, otherwise false. 1195 */ 1196 function bp_get_member_profile_data( $args = '' ) { 1197 global $members_template; 1198 1199 if ( ! bp_is_active( 'xprofile' ) ) { 1200 return false; 1201 } 1202 1203 // Declare local variables. 1204 $data = false; 1205 1206 // Guess at default $user_id. 1207 $default_user_id = 0; 1208 if ( ! empty( $members_template->member->id ) ) { 1209 $default_user_id = $members_template->member->id; 1210 } elseif ( bp_displayed_user_id() ) { 1211 $default_user_id = bp_displayed_user_id(); 1212 } 1213 1214 $defaults = array( 1215 'field' => false, 1216 'user_id' => $default_user_id, 1217 ); 1218 1219 $r = bp_parse_args( 1220 $args, 1221 $defaults 1222 ); 1223 1224 // If we're in a members loop, get the data from the global. 1225 if ( ! empty( $members_template->member->profile_data ) ) { 1226 $profile_data = $members_template->member->profile_data; 1227 } 1228 1229 // Otherwise query for the data. 1230 if ( empty( $profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) ) { 1231 $profile_data = BP_XProfile_ProfileData::get_all_for_user( $r['user_id'] ); 1232 } 1233 1234 // If we're in the members loop, but the profile data has not 1235 // been loaded into the global, cache it there for later use. 1236 if ( ! empty( $members_template->member ) && empty( $members_template->member->profile_data ) ) { 1237 $members_template->member->profile_data = $profile_data; 1238 } 1239 1240 // Get the data for the specific field requested. 1241 if ( ! empty( $profile_data ) && ! empty( $profile_data[ $r['field'] ]['field_type'] ) && ! empty( $profile_data[ $r['field'] ]['field_data'] ) ) { 1242 $data = xprofile_format_profile_field( $profile_data[ $r['field'] ]['field_type'], $profile_data[ $r['field'] ]['field_data'] ); 1243 } 1244 1245 /** 1246 * Filters resulting piece of member profile data. 1247 * 1248 * @since 1.2.0 1249 * @since 2.6.0 Added the `$r` parameter. 1250 * 1251 * @param string|bool $data Profile data if found, otherwise false. 1252 * @param array $r Array of parsed arguments. 1253 */ 1254 $data = apply_filters( 'bp_get_member_profile_data', $data, $r ); 1255 1256 /** 1257 * Filters the resulting piece of member profile data by field type. 1258 * 1259 * This is a dynamic filter based on field type of the current field requested. 1260 * 1261 * @since 2.7.0 1262 * 1263 * @param string|bool $data Profile data if found, otherwise false. 1264 * @param array $r Array of parsed arguments. 1265 */ 1266 if ( ! empty( $profile_data[ $r['field'] ]['field_type'] ) ) { 1267 $data = apply_filters( 'bp_get_member_profile_data_' . $profile_data[ $r['field'] ]['field_type'], $data, $r ); 1268 } 1269 1270 return $data; 1271 } 1272 1273 /** 1274 * Output the 'registered [x days ago]' string for the current member. 1275 * 1276 * @since 1.2.0 1277 * @since 2.7.0 Added $args as a parameter. 1278 * 1279 * @param array $args Optional. {@see bp_get_member_registered()}. 1280 */ 1281 function bp_member_registered( $args = array() ) { 1282 echo bp_get_member_registered( $args ); 1283 } 1284 /** 1285 * Get the 'registered [x days ago]' string for the current member. 1286 * 1287 * @since 1.2.0 1288 * @since 2.7.0 Added `$args` as a parameter. 1289 * 1290 * @global BP_Core_Members_Template $members_template 1291 * 1292 * @param array $args { 1293 * Array of optional parameters. 1294 * @type bool $relative Optional. If true, returns relative registered date. eg. registered 5 months ago. 1295 * If false, returns registered date value from database. 1296 * } 1297 * @return string 1298 */ 1299 function bp_get_member_registered( $args = array() ) { 1300 global $members_template; 1301 1302 $r = bp_parse_args( 1303 $args, 1304 array( 1305 'relative' => true, 1306 ) 1307 ); 1308 1309 // We do not want relative time, so return now. 1310 // @todo Should the 'bp_member_registered' filter be applied here? 1311 if ( ! $r['relative'] ) { 1312 return esc_attr( $members_template->member->user_registered ); 1313 } 1314 1315 /* translators: %s: last activity timestamp (e.g. "active 1 hour ago") */ 1316 $registered = esc_attr( bp_core_get_last_activity( $members_template->member->user_registered, _x( 'registered %s', 'Records the timestamp that the user registered into the activity stream', 'buddypress' ) ) ); 1317 1318 /** 1319 * Filters the 'registered [x days ago]' string for the current member. 1320 * 1321 * @since 2.1.0 1322 * 1323 * @param string $registered The 'registered [x days ago]' string. 1324 * @param array $r Array of parsed arguments. 1325 */ 1326 return apply_filters( 'bp_member_registered', $registered, $r ); 1327 } 1328 1329 /** 1330 * Output a random piece of profile data for the current member in the loop. 1331 * 1332 * @since 1.2.0 1333 * @since 10.0.0 Updated to get member ID using `bp_get_member_user_id`. 1334 */ 1335 function bp_member_random_profile_data() { 1336 if ( bp_is_active( 'xprofile' ) ) { ?> 1337 <?php $random_data = xprofile_get_random_profile_data( bp_get_member_user_id(), true ); ?> 1338 <strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong> 1339 <?php echo wp_filter_kses( $random_data[0]->value ) ?> 1340 <?php } 1341 } 1342 1343 /** 1344 * Output hidden input for preserving member search params on form submit. 1345 * 1346 * @since 1.2.0 1347 */ 1348 function bp_member_hidden_fields() { 1349 $query_arg = bp_core_get_component_search_query_arg( 'members' ); 1350 1351 if ( isset( $_REQUEST[ $query_arg ] ) ) { 1352 echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST[ $query_arg ] ) . '" name="search_terms" />'; 1353 } 1354 1355 if ( isset( $_REQUEST['letter'] ) ) { 1356 echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />'; 1357 } 1358 1359 if ( isset( $_REQUEST['members_search'] ) ) { 1360 echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['members_search'] ) . '" name="search_terms" />'; 1361 } 1362 } 1363 1364 /** 1365 * Output the Members directory search form. 1366 * 1367 * @since 1.0.0 1368 */ 1369 function bp_directory_members_search_form() { 1370 1371 $query_arg = bp_core_get_component_search_query_arg( 'members' ); 1372 1373 if ( ! empty( $_REQUEST[ $query_arg ] ) ) { 1374 $search_value = stripslashes( $_REQUEST[ $query_arg ] ); 1375 } else { 1376 $search_value = bp_get_search_default_text( 'members' ); 1377 } 1378 1379 $search_form_html = '<form action="" method="get" id="search-members-form"> 1380 <label for="members_search"><input type="text" name="' . esc_attr( $query_arg ) . '" id="members_search" placeholder="'. esc_attr( $search_value ) .'" /></label> 1381 <input type="submit" id="members_search_submit" name="members_search_submit" value="' . __( 'Search', 'buddypress' ) . '" /> 1382 </form>'; 1383 1384 /** 1385 * Filters the Members component search form. 1386 * 1387 * @since 1.9.0 1388 * 1389 * @param string $search_form_html HTML markup for the member search form. 1390 */ 1391 echo apply_filters( 'bp_directory_members_search_form', $search_form_html ); 1392 } 1393 1394 /** 1395 * Output the total member count. 1396 * 1397 * @since 1.2.0 1398 */ 1399 function bp_total_site_member_count() { 1400 echo bp_get_total_site_member_count(); 1401 } 1402 /** 1403 * Get the total site member count. 1404 * 1405 * @since 1.2.0 1406 * 1407 * @return string 1408 */ 1409 function bp_get_total_site_member_count() { 1410 1411 /** 1412 * Filters the total site member count. 1413 * 1414 * @since 1.2.0 1415 * 1416 * @param string $value Number-formatted total site member count. 1417 */ 1418 return apply_filters( 'bp_get_total_site_member_count', bp_core_number_format( bp_core_get_total_member_count() ) ); 1419 } 1420 1421 /** Navigation and other misc template tags ***********************************/ 1422 1423 /** 1424 * Render the navigation markup for the logged-in user. 1425 * 1426 * Each component adds to this navigation array within its own 1427 * [component_name]setup_nav() function. 1428 * 1429 * This navigation array is the top level navigation, so it contains items such as: 1430 * [Blog, Profile, Messages, Groups, Friends] ... 1431 * 1432 * The function will also analyze the current component the user is in, to 1433 * determine whether or not to highlight a particular nav item. 1434 * 1435 * @since 1.1.0 1436 * 1437 * @global BuddyPress $bp The one true BuddyPress instance. 1438 * 1439 * @todo Move to a back-compat file? 1440 * @deprecated Does not seem to be called anywhere in BP core. 1441 */ 1442 function bp_get_loggedin_user_nav() { 1443 $bp = buddypress(); 1444 1445 // Loop through each navigation item. 1446 foreach ( (array) $bp->members->nav->get_primary() as $nav_item ) { 1447 1448 $selected = ''; 1449 1450 // If the current component matches the nav item id, then add a highlight CSS class. 1451 if ( ! bp_is_directory() && ! empty( $bp->active_components[ bp_current_component() ] ) && $bp->active_components[ bp_current_component() ] == $nav_item->css_id ) { 1452 $selected = ' class="current selected"'; 1453 } 1454 1455 // If we are viewing another person (current_userid does not equal 1456 // loggedin_user->id then check to see if the two users are friends. 1457 // if they are, add a highlight CSS class to the friends nav item 1458 // if it exists. 1459 if ( !bp_is_my_profile() && bp_displayed_user_id() ) { 1460 $selected = ''; 1461 1462 if ( bp_is_active( 'friends' ) ) { 1463 if ( $nav_item->css_id == $bp->friends->id ) { 1464 if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) ) { 1465 $selected = ' class="current selected"'; 1466 } 1467 } 1468 } 1469 } 1470 1471 // Echo out the final list item. 1472 echo apply_filters_ref_array( 'bp_get_loggedin_user_nav_' . $nav_item->css_id, array( '<li id="li-nav-' . $nav_item->css_id . '" ' . $selected . '><a id="my-' . $nav_item->css_id . '" href="' . $nav_item->link . '">' . $nav_item->name . '</a></li>', &$nav_item ) ); 1473 } 1474 1475 // Always add a log out list item to the end of the navigation. 1476 $logout_link = '<li><a id="wp-logout" href="' . wp_logout_url( bp_get_root_domain() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>'; 1477 1478 echo apply_filters( 'bp_logout_nav_link', $logout_link ); 1479 } 1480 1481 /** 1482 * Output the contents of the current user's home page. 1483 * 1484 * @since 2.6.0 1485 */ 1486 function bp_displayed_user_front_template_part() { 1487 $located = bp_displayed_user_get_front_template(); 1488 1489 if ( false !== $located ) { 1490 $slug = str_replace( '.php', '', $located ); 1491 $name = null; 1492 1493 /** 1494 * Let plugins adding an action to bp_get_template_part get it from here 1495 * 1496 * @param string $slug Template part slug requested. 1497 * @param string $name Template part name requested. 1498 */ 1499 do_action( 'get_template_part_' . $slug, $slug, $name ); 1500 1501 load_template( $located, true ); 1502 } 1503 1504 return $located; 1505 } 1506 1507 /** 1508 * Locate a custom user front template if it exists. 1509 * 1510 * @since 2.6.0 1511 * 1512 * @param object|null $displayed_user Optional. Falls back to current user if not passed. 1513 * @return string|bool Path to front template on success; boolean false on failure. 1514 */ 1515 function bp_displayed_user_get_front_template( $displayed_user = null ) { 1516 if ( ! is_object( $displayed_user ) || empty( $displayed_user->id ) ) { 1517 $displayed_user = bp_get_displayed_user(); 1518 } 1519 1520 if ( ! isset( $displayed_user->id ) ) { 1521 return false; 1522 } 1523 1524 if ( isset( $displayed_user->front_template ) ) { 1525 return $displayed_user->front_template; 1526 } 1527 1528 // Init the hierarchy. 1529 $template_names = array( 1530 'members/single/front-id-' . (int) $displayed_user->id . '.php', 1531 'members/single/front-nicename-' . sanitize_file_name( $displayed_user->userdata->user_nicename ) . '.php', 1532 ); 1533 1534 /** 1535 * Check for member types and add it to the hierarchy 1536 * 1537 * Make sure to register your member 1538 * type using the hook 'bp_register_member_types' 1539 */ 1540 if ( bp_get_member_types() ) { 1541 $displayed_user_member_type = bp_get_member_type( $displayed_user->id ); 1542 if ( ! $displayed_user_member_type ) { 1543 $displayed_user_member_type = 'none'; 1544 } 1545 1546 $template_names[] = 'members/single/front-member-type-' . sanitize_file_name( $displayed_user_member_type ) . '.php'; 1547 } 1548 1549 // Add The generic template to the end of the hierarchy. 1550 $template_names[] = 'members/single/front.php'; 1551 1552 /** 1553 * Filters the hierarchy of user front templates corresponding to a specific user. 1554 * 1555 * @since 2.6.0 1556 * 1557 * @param array $template_names Array of template paths. 1558 */ 1559 $template_names = apply_filters( 'bp_displayed_user_get_front_template', $template_names ); 1560 1561 return bp_locate_template( $template_names, false, true ); 1562 } 1563 1564 /** 1565 * Check if the displayed user has a custom front template. 1566 * 1567 * @since 2.6.0 1568 */ 1569 function bp_displayed_user_has_front_template() { 1570 $displayed_user = bp_get_displayed_user(); 1571 1572 return ! empty( $displayed_user->front_template ); 1573 } 1574 1575 /** 1576 * Render the navigation markup for the displayed user. 1577 * 1578 * @since 1.1.0 1579 * 1580 * @global BuddyPress $bp The one true BuddyPress instance. 1581 */ 1582 function bp_get_displayed_user_nav() { 1583 $bp = buddypress(); 1584 1585 foreach ( $bp->members->nav->get_primary() as $user_nav_item ) { 1586 if ( empty( $user_nav_item->show_for_displayed_user ) && ! bp_is_my_profile() ) { 1587 continue; 1588 } 1589 1590 $selected = ''; 1591 if ( bp_is_current_component( $user_nav_item->slug ) ) { 1592 $selected = ' class="current selected"'; 1593 } 1594 1595 if ( bp_loggedin_user_domain() ) { 1596 $link = str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $user_nav_item->link ); 1597 } else { 1598 $link = trailingslashit( bp_displayed_user_domain() . $user_nav_item->link ); 1599 } 1600 1601 /** 1602 * Filters the navigation markup for the displayed user. 1603 * 1604 * This is a dynamic filter that is dependent on the navigation tab component being rendered. 1605 * 1606 * @since 1.1.0 1607 * 1608 * @param string $value Markup for the tab list item including link. 1609 * @param array $user_nav_item Array holding parts used to construct tab list item. 1610 * Passed by reference. 1611 */ 1612 echo apply_filters_ref_array( 'bp_get_displayed_user_nav_' . $user_nav_item->css_id, array( '<li id="' . $user_nav_item->css_id . '-personal-li" ' . $selected . '><a id="user-' . $user_nav_item->css_id . '" href="' . $link . '">' . $user_nav_item->name . '</a></li>', &$user_nav_item ) ); 1613 } 1614 } 1615 1616 /** Cover image ***************************************************************/ 1617 1618 /** 1619 * Should we use the cover image header 1620 * 1621 * @since 2.4.0 1622 * 1623 * @return bool True if the displayed user has a cover image, 1624 * False otherwise 1625 */ 1626 function bp_displayed_user_use_cover_image_header() { 1627 return (bool) bp_is_active( 'members', 'cover_image' ) && ! bp_disable_cover_image_uploads(); 1628 } 1629 1630 /** Avatars *******************************************************************/ 1631 1632 /** 1633 * Output the logged-in user's avatar. 1634 * 1635 * @since 1.1.0 1636 * 1637 * @see bp_get_loggedin_user_avatar() for a description of params. 1638 * 1639 * @param array|string $args {@see bp_get_loggedin_user_avatar()}. 1640 */ 1641 function bp_loggedin_user_avatar( $args = '' ) { 1642 echo bp_get_loggedin_user_avatar( $args ); 1643 } 1644 /** 1645 * Get the logged-in user's avatar. 1646 * 1647 * @since 1.1.0 1648 * 1649 * @see bp_core_fetch_avatar() For a description of arguments and 1650 * return values. 1651 * 1652 * @param array|string $args { 1653 * Arguments are listed here with an explanation of their defaults. 1654 * For more information about the arguments, see 1655 * {@link bp_core_fetch_avatar()}. 1656 * @type string $alt Default: 'Profile picture of [user name]'. 1657 * @type bool $html Default: true. 1658 * @type string $type Default: 'thumb'. 1659 * @type int|bool $width Default: false. 1660 * @type int|bool $height Default: false. 1661 * } 1662 * @return string User avatar string. 1663 */ 1664 function bp_get_loggedin_user_avatar( $args = '' ) { 1665 1666 $r = bp_parse_args( 1667 $args, 1668 array( 1669 'item_id' => bp_loggedin_user_id(), 1670 'type' => 'thumb', 1671 'width' => false, 1672 'height' => false, 1673 'html' => true, 1674 /* translators: %s: member name */ 1675 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_loggedin_user_fullname() ) 1676 ) 1677 ); 1678 1679 /** 1680 * Filters the logged in user's avatar. 1681 * 1682 * @since 1.1.0 1683 * 1684 * @param string $value User avatar string. 1685 * @param array $r Array of parsed arguments. 1686 * @param array $args Array of initial arguments. 1687 */ 1688 return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( $r ), $r, $args ); 1689 } 1690 1691 /** 1692 * Output the displayed user's avatar. 1693 * 1694 * @since 1.1.0 1695 * 1696 * @see bp_get_displayed_user_avatar() for a description of params. 1697 * 1698 * @param array|string $args {@see bp_get_displayed_user_avatar()}. 1699 */ 1700 function bp_displayed_user_avatar( $args = '' ) { 1701 echo bp_get_displayed_user_avatar( $args ); 1702 } 1703 /** 1704 * Get the displayed user's avatar. 1705 * 1706 * @since 1.1.0 1707 * 1708 * @see bp_core_fetch_avatar() For a description of arguments and 1709 * return values. 1710 * 1711 * @param array|string $args { 1712 * Arguments are listed here with an explanation of their defaults. 1713 * For more information about the arguments, see 1714 * {@link bp_core_fetch_avatar()}. 1715 * @type string $alt Default: 'Profile picture of [user name]'. 1716 * @type bool $html Default: true. 1717 * @type string $type Default: 'thumb'. 1718 * @type int|bool $width Default: false. 1719 * @type int|bool $height Default: false. 1720 * } 1721 * @return string User avatar string. 1722 */ 1723 function bp_get_displayed_user_avatar( $args = '' ) { 1724 1725 $r = bp_parse_args( 1726 $args, 1727 array( 1728 'item_id' => bp_displayed_user_id(), 1729 'type' => 'thumb', 1730 'width' => false, 1731 'height' => false, 1732 'html' => true, 1733 /* translators: %s: member name */ 1734 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) 1735 ) 1736 ); 1737 1738 /** 1739 * Filters the displayed user's avatar. 1740 * 1741 * @since 1.1.0 1742 * 1743 * @param string $value User avatar string. 1744 * @param array $r Array of parsed arguments. 1745 * @param array $args Array of initial arguments. 1746 */ 1747 return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( $r ), $r, $args ); 1748 } 1749 1750 /** 1751 * Output the email address of the displayed user. 1752 * 1753 * @since 1.5.0 1754 */ 1755 function bp_displayed_user_email() { 1756 echo bp_get_displayed_user_email(); 1757 } 1758 /** 1759 * Get the email address of the displayed user. 1760 * 1761 * @since 1.5.0 1762 * 1763 * @global BuddyPress $bp The one true BuddyPress instance. 1764 * 1765 * @return string 1766 */ 1767 function bp_get_displayed_user_email() { 1768 $bp = buddypress(); 1769 1770 // If displayed user exists, return email address. 1771 if ( isset( $bp->displayed_user->userdata->user_email ) ) { 1772 $retval = $bp->displayed_user->userdata->user_email; 1773 } else { 1774 $retval = ''; 1775 } 1776 1777 /** 1778 * Filters the email address of the displayed user. 1779 * 1780 * @since 1.5.0 1781 * 1782 * @param string $retval Email address for displayed user. 1783 */ 1784 return apply_filters( 'bp_get_displayed_user_email', esc_attr( $retval ) ); 1785 } 1786 1787 /** 1788 * Output the "active [x days ago]" string for a user. 1789 * 1790 * @since 1.0.0 1791 * 1792 * @see bp_get_last_activity() for a description of parameters. 1793 * 1794 * @param int $user_id See {@link bp_get_last_activity()}. 1795 */ 1796 function bp_last_activity( $user_id = 0 ) { 1797 echo bp_get_last_activity( $user_id ); 1798 } 1799 /** 1800 * Get the "active [x days ago]" string for a user. 1801 * 1802 * @since 1.5.0 1803 * 1804 * @param int $user_id ID of the user. Default: displayed user ID. 1805 * @return string 1806 */ 1807 function bp_get_last_activity( $user_id = 0 ) { 1808 1809 if ( empty( $user_id ) ) { 1810 $user_id = bp_displayed_user_id(); 1811 } 1812 1813 /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */ 1814 $last_activity = bp_core_get_last_activity( bp_get_user_last_activity( $user_id ), __( 'Active %s', 'buddypress') ); 1815 1816 /** 1817 * Filters the 'active [x days ago]' string for a user. 1818 * 1819 * @since 1.5.0 1820 * @since 2.6.0 Added the `$user_id` parameter. 1821 * 1822 * @param string $value Formatted 'active [x days ago]' string. 1823 * @param int $user_id ID of the user. 1824 */ 1825 return apply_filters( 'bp_get_last_activity', $last_activity, $user_id ); 1826 } 1827 1828 /** 1829 * Output the calculated first name of the displayed or logged-in user. 1830 * 1831 * @since 1.2.0 1832 */ 1833 function bp_user_firstname() { 1834 echo bp_get_user_firstname(); 1835 } 1836 /** 1837 * Output the first name of a user. 1838 * 1839 * Simply takes all the characters before the first space in a name. 1840 * 1841 * @since 1.2.0 1842 * 1843 * @param string|bool $name Full name to use when generating first name. 1844 * Defaults to displayed user's first name, or to 1845 * logged-in user's first name if it's unavailable. 1846 * @return string 1847 */ 1848 function bp_get_user_firstname( $name = false ) { 1849 1850 // Try to get displayed user. 1851 if ( empty( $name ) ) { 1852 $name = bp_get_displayed_user_fullname(); 1853 } 1854 1855 // Fall back on logged in user. 1856 if ( empty( $name ) ) { 1857 $name = bp_get_loggedin_user_fullname(); 1858 } 1859 1860 $fullname = (array) explode( ' ', $name ); 1861 1862 /** 1863 * Filters the first name of a user. 1864 * 1865 * @since 1.2.0 1866 * 1867 * @param string $value First name of user. 1868 * @param string $fullname Full name of user. 1869 */ 1870 return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname ); 1871 } 1872 1873 /** 1874 * Output the link for the logged-in user's profile. 1875 * 1876 * @since 1.2.4 1877 */ 1878 function bp_loggedin_user_link() { 1879 echo esc_url( bp_get_loggedin_user_link() ); 1880 } 1881 /** 1882 * Get the link for the logged-in user's profile. 1883 * 1884 * @since 1.0.0 1885 * 1886 * @return string 1887 */ 1888 function bp_get_loggedin_user_link() { 1889 1890 /** 1891 * Filters the link for the logged-in user's profile. 1892 * 1893 * @since 1.2.4 1894 * 1895 * @param string $value Link for the logged-in user's profile. 1896 */ 1897 return apply_filters( 'bp_get_loggedin_user_link', bp_loggedin_user_domain() ); 1898 } 1899 1900 /** 1901 * Output the link for the displayed user's profile. 1902 * 1903 * @since 1.2.4 1904 */ 1905 function bp_displayed_user_link() { 1906 echo esc_url( bp_get_displayed_user_link() ); 1907 } 1908 /** 1909 * Get the link for the displayed user's profile. 1910 * 1911 * @since 1.0.0 1912 * 1913 * @return string 1914 */ 1915 function bp_get_displayed_user_link() { 1916 1917 /** 1918 * Filters the link for the displayed user's profile. 1919 * 1920 * @since 1.2.4 1921 * 1922 * @param string $value Link for the displayed user's profile. 1923 */ 1924 return apply_filters( 'bp_get_displayed_user_link', bp_displayed_user_domain() ); 1925 } 1926 1927 /** 1928 * Alias of {@link bp_displayed_user_domain()}. 1929 * 1930 * @deprecated 1931 */ 1932 function bp_user_link() { 1933 bp_displayed_user_domain(); 1934 } 1935 1936 /** 1937 * Alias of {@link bp_displayed_user_id()}. 1938 * 1939 * @since 1.0.0 1940 */ 1941 function bp_current_user_id() { 1942 return bp_displayed_user_id(); 1943 } 1944 1945 /** 1946 * Generate the link for the displayed user's profile. 1947 * 1948 * @since 1.0.0 1949 * 1950 * @global BuddyPress $bp The one true BuddyPress instance. 1951 * 1952 * @return string 1953 */ 1954 function bp_displayed_user_domain() { 1955 $bp = buddypress(); 1956 1957 /** 1958 * Filters the generated link for the displayed user's profile. 1959 * 1960 * @since 1.0.0 1961 * 1962 * @param string $value Generated link for the displayed user's profile. 1963 */ 1964 return apply_filters( 'bp_displayed_user_domain', isset( $bp->displayed_user->domain ) ? $bp->displayed_user->domain : '' ); 1965 } 1966 1967 /** 1968 * Generate the link for the logged-in user's profile. 1969 * 1970 * @since 1.0.0 1971 * 1972 * @global BuddyPress $bp The one true BuddyPress instance. 1973 * 1974 * @return string 1975 */ 1976 function bp_loggedin_user_domain() { 1977 $bp = buddypress(); 1978 1979 /** 1980 * Filters the generated link for the logged-in user's profile. 1981 * 1982 * @since 1.0.0 1983 * 1984 * @param string $value Generated link for the logged-in user's profile. 1985 */ 1986 return apply_filters( 'bp_loggedin_user_domain', isset( $bp->loggedin_user->domain ) ? $bp->loggedin_user->domain : '' ); 1987 } 1988 1989 /** 1990 * Output the displayed user's display name. 1991 * 1992 * @since 1.0.0 1993 */ 1994 function bp_displayed_user_fullname() { 1995 echo bp_get_displayed_user_fullname(); 1996 } 1997 /** 1998 * Get the displayed user's display name. 1999 * 2000 * @since 1.2.0 2001 * 2002 * @global BuddyPress $bp The one true BuddyPress instance. 2003 * 2004 * @return string 2005 */ 2006 function bp_get_displayed_user_fullname() { 2007 $bp = buddypress(); 2008 2009 /** 2010 * Filters the displayed user's display name. 2011 * 2012 * @since 1.2.0 2013 * 2014 * @param string $value Displayed user's display name. 2015 */ 2016 return apply_filters( 'bp_displayed_user_fullname', isset( $bp->displayed_user->fullname ) ? $bp->displayed_user->fullname : '' ); 2017 } 2018 2019 /** 2020 * Alias of {@link bp_get_displayed_user_fullname()}. 2021 * 2022 * @since 1.0.0 2023 */ 2024 function bp_user_fullname() { echo bp_get_displayed_user_fullname(); } 2025 2026 2027 /** 2028 * Output the logged-in user's display name. 2029 * 2030 * @since 1.0.0 2031 */ 2032 function bp_loggedin_user_fullname() { 2033 echo bp_get_loggedin_user_fullname(); 2034 } 2035 /** 2036 * Get the logged-in user's display name. 2037 * 2038 * @since 1.0.0 2039 * 2040 * @global BuddyPress $bp The one true BuddyPress instance. 2041 * 2042 * @return string 2043 */ 2044 function bp_get_loggedin_user_fullname() { 2045 $bp = buddypress(); 2046 2047 /** 2048 * Filters the logged-in user's display name. 2049 * 2050 * @since 1.0.0 2051 * 2052 * @param string $value Logged-in user's display name. 2053 */ 2054 return apply_filters( 'bp_get_loggedin_user_fullname', isset( $bp->loggedin_user->fullname ) ? $bp->loggedin_user->fullname : '' ); 2055 } 2056 2057 /** 2058 * Output the username of the displayed user. 2059 * 2060 * @since 1.2.0 2061 */ 2062 function bp_displayed_user_username() { 2063 echo bp_get_displayed_user_username(); 2064 } 2065 /** 2066 * Get the username of the displayed user. 2067 * 2068 * @since 1.2.0 2069 * 2070 * @global BuddyPress $bp The one true BuddyPress instance. 2071 * 2072 * @return string 2073 */ 2074 function bp_get_displayed_user_username() { 2075 $bp = buddypress(); 2076 2077 if ( bp_displayed_user_id() ) { 2078 $username = bp_core_get_username( bp_displayed_user_id(), $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login ); 2079 } else { 2080 $username = ''; 2081 } 2082 2083 /** 2084 * Filters the username of the displayed user. 2085 * 2086 * @since 1.2.0 2087 * 2088 * @param string $username Username of the displayed user. 2089 */ 2090 return apply_filters( 'bp_get_displayed_user_username', $username ); 2091 } 2092 2093 /** 2094 * Output the username of the logged-in user. 2095 * 2096 * @since 1.2.0 2097 */ 2098 function bp_loggedin_user_username() { 2099 echo bp_get_loggedin_user_username(); 2100 } 2101 /** 2102 * Get the username of the logged-in user. 2103 * 2104 * @since 1.2.0 2105 * 2106 * @global BuddyPress $bp The one true BuddyPress instance. 2107 * 2108 * @return string 2109 */ 2110 function bp_get_loggedin_user_username() { 2111 $bp = buddypress(); 2112 2113 if ( bp_loggedin_user_id() ) { 2114 $username = bp_core_get_username( bp_loggedin_user_id(), $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ); 2115 } else { 2116 $username = ''; 2117 } 2118 2119 /** 2120 * Filters the username of the logged-in user. 2121 * 2122 * @since 1.2.0 2123 * 2124 * @param string $username Username of the logged-in user. 2125 */ 2126 return apply_filters( 'bp_get_loggedin_user_username', $username ); 2127 } 2128 2129 /** 2130 * Echo the current member type message. 2131 * 2132 * @since 2.3.0 2133 */ 2134 function bp_current_member_type_message() { 2135 echo bp_get_current_member_type_message(); 2136 } 2137 /** 2138 * Generate the current member type message. 2139 * 2140 * @since 2.3.0 2141 * 2142 * @return string 2143 */ 2144 function bp_get_current_member_type_message() { 2145 $type_object = bp_get_member_type_object( bp_get_current_member_type() ); 2146 2147 /* translators: %s: member type singular name */ 2148 $message = sprintf( __( 'Viewing members of the type: %s', 'buddypress' ), '<strong>' . $type_object->labels['singular_name'] . '</strong>' ); 2149 2150 /** 2151 * Filters the current member type message. 2152 * 2153 * @since 2.3.0 2154 * 2155 * @param string $message Message to filter. 2156 */ 2157 return apply_filters( 'bp_get_current_member_type_message', $message ); 2158 } 2159 2160 /** 2161 * Output member type directory link. 2162 * 2163 * @since 7.0.0 2164 * 2165 * @param string $member_type Unique member type identifier as used in bp_register_member_type(). 2166 */ 2167 function bp_member_type_directory_link( $member_type = '' ) { 2168 echo bp_get_member_type_directory_link( $member_type ); 2169 } 2170 /** 2171 * Return member type directory link. 2172 * 2173 * @since 7.0.0 2174 * 2175 * @param string $member_type Unique member type identifier as used in bp_register_member_type(). 2176 * @return string 2177 */ 2178 function bp_get_member_type_directory_link( $member_type = '' ) { 2179 if ( empty( $member_type ) ) { 2180 return ''; 2181 } 2182 2183 $member_type_object = bp_get_member_type_object( $member_type ); 2184 2185 if ( ! isset( $member_type_object->labels['name'] ) ) { 2186 return ''; 2187 } 2188 2189 $member_type_text = $member_type_object->labels['name']; 2190 if ( isset( $member_type_object->labels['singular_name'] ) && $member_type_object->labels['singular_name'] ) { 2191 $member_type_text = $member_type_object->labels['singular_name']; 2192 } 2193 2194 if ( empty( $member_type_object->has_directory ) ) { 2195 return esc_html( $member_type_text ); 2196 } 2197 2198 return sprintf( 2199 '<a href="%1$s">%2$s</a>', 2200 esc_url( bp_get_member_type_directory_permalink( $member_type ) ), 2201 esc_html( $member_type_text ) 2202 ); 2203 } 2204 2205 /** 2206 * Output a comma-delimited list of member types. 2207 * 2208 * @since 7.0.0 2209 * 2210 * @see bp_get_member_type_list() For additional information on default arguments. 2211 * 2212 * @param int $user_id User ID. 2213 * @param array $r Optional. Member type list arguments. Default empty array. 2214 */ 2215 function bp_member_type_list( $user_id = 0, $r = array() ) { 2216 echo bp_get_member_type_list( $user_id, $r ); 2217 } 2218 /** 2219 * Return a comma-delimited list of member types. 2220 * 2221 * @since 7.0.0 2222 * 2223 * @param int $user_id User ID. Defaults to displayed user ID if on a member page. 2224 * @param array|string $r { 2225 * Array of parameters. All items are optional. 2226 * @type string $parent_element Element to wrap around the list. Defaults to 'p'. 2227 * @type array $parent_attr Element attributes for parent element. Defaults to 2228 * array( 'class' => 'bp-member-type-list' ). 2229 * @type array $label Plural and singular labels to use before the list. Defaults to 2230 * array( 'plural' => 'Member Types:', 'singular' => 'Member Type:' ). 2231 * @type string $label_element Element to wrap around the label. Defaults to 'strong'. 2232 * @type array $label_attr Element attributes for label element. Defaults to array(). 2233 * @type bool $show_all Whether to show all registered group types. Defaults to 'false'. If 2234 * 'false', only shows member types with the 'show_in_list' parameter set to 2235 * true. See bp_register_member_type() for more info. 2236 * @type string $list_element Element to wrap around the comma separated list of membet types. Defaults to ''. 2237 * @type string $list_element_attr Element attributes for list element. Defaults to array(). 2238 * } 2239 * @return string 2240 */ 2241 function bp_get_member_type_list( $user_id = 0, $r = array() ) { 2242 if ( empty( $user_id ) ) { 2243 $user_id = bp_displayed_user_id(); 2244 } 2245 2246 $r = bp_parse_args( 2247 $r, 2248 array( 2249 'parent_element' => 'p', 2250 'parent_attr' => array( 2251 'class' => 'bp-member-type-list', 2252 ), 2253 'label' => array(), 2254 'label_element' => 'strong', 2255 'label_attr' => array(), 2256 'show_all' => false, 2257 'list_element' => '', 2258 'list_element_attr' => array(), 2259 ), 2260 'member_type_list' 2261 ); 2262 2263 // Should the label be output? 2264 $has_label = ! empty( $r['label'] ); 2265 2266 $labels = bp_parse_args( 2267 $r['label'], 2268 array( 2269 'plural' => __( 'Member Types:', 'buddypress' ), 2270 'singular' => __( 'Member Type:', 'buddypress' ), 2271 ) 2272 ); 2273 2274 $retval = ''; 2275 $types = bp_get_member_type( $user_id, false ); 2276 2277 if ( $types ) { 2278 // Make sure we can show the type in the list. 2279 if ( false === $r['show_all'] ) { 2280 $types = array_intersect( bp_get_member_types( array( 'show_in_list' => true ) ), $types ); 2281 if ( empty( $types ) ) { 2282 return $retval; 2283 } 2284 } 2285 2286 $before = $after = $label = ''; 2287 $count = count( $types ); 2288 2289 if ( 1 === $count ) { 2290 $label_text = $labels['singular']; 2291 } else { 2292 $label_text = $labels['plural']; 2293 } 2294 2295 // Render parent element. 2296 if ( ! empty( $r['parent_element'] ) ) { 2297 $parent_elem = new BP_Core_HTML_Element( array( 2298 'element' => $r['parent_element'], 2299 'attr' => $r['parent_attr'], 2300 ) ); 2301 2302 // Set before and after. 2303 $before = $parent_elem->get( 'open_tag' ); 2304 $after = $parent_elem->get( 'close_tag' ); 2305 } 2306 2307 // Render label element. 2308 if ( ! empty( $r['label_element'] ) ) { 2309 $label = new BP_Core_HTML_Element( array( 2310 'element' => $r['label_element'], 2311 'attr' => $r['label_attr'], 2312 'inner_html' => esc_html( $label_text ), 2313 ) ); 2314 $label = $label->contents() . ' '; 2315 2316 // No element, just the label. 2317 } elseif ( $has_label ) { 2318 $label = esc_html( $label_text ); 2319 } 2320 2321 // The list of types. 2322 $list = implode( ', ', array_map( 'bp_get_member_type_directory_link', $types ) ); 2323 2324 // Render the list of types element. 2325 if ( ! empty( $r['list_element'] ) ) { 2326 $list_element = new BP_Core_HTML_Element( array( 2327 'element' => $r['list_element'], 2328 'attr' => $r['list_element_attr'], 2329 'inner_html' => $list, 2330 ) ); 2331 2332 $list = $list_element->contents(); 2333 } 2334 2335 // Comma-delimit each type into the group type directory link. 2336 $label .= $list; 2337 2338 // Retval time! 2339 $retval = $before . $label . $after; 2340 } 2341 2342 return $retval; 2343 } 2344 2345 /** Signup Form ***************************************************************/ 2346 2347 /** 2348 * Do we have a working custom sign up page? 2349 * 2350 * @since 1.5.0 2351 * 2352 * @return bool True if page and template exist, false if not. 2353 */ 2354 function bp_has_custom_signup_page() { 2355 static $has_page = false; 2356 2357 if ( empty( $has_page ) ) { 2358 $has_page = bp_get_signup_slug() && bp_locate_template( array( 'registration/register.php', 'members/register.php', 'register.php' ), false ); 2359 } 2360 2361 return (bool) $has_page; 2362 } 2363 2364 /** 2365 * Output the URL to the signup page. 2366 * 2367 * @since 1.0.0 2368 */ 2369 function bp_signup_page() { 2370 echo esc_url( bp_get_signup_page() ); 2371 } 2372 /** 2373 * Get the URL to the signup page. 2374 * 2375 * @since 1.1.0 2376 * 2377 * @return string 2378 */ 2379 function bp_get_signup_page() { 2380 if ( bp_has_custom_signup_page() ) { 2381 $page = trailingslashit( bp_get_root_domain() . '/' . bp_get_signup_slug() ); 2382 } else { 2383 $page = bp_get_root_domain() . '/wp-signup.php'; 2384 } 2385 2386 /** 2387 * Filters the URL to the signup page. 2388 * 2389 * @since 1.1.0 2390 * 2391 * @param string $page URL to the signup page. 2392 */ 2393 return apply_filters( 'bp_get_signup_page', $page ); 2394 } 2395 2396 /** 2397 * Do we have a working custom activation page? 2398 * 2399 * @since 1.5.0 2400 * 2401 * @return bool True if page and template exist, false if not. 2402 */ 2403 function bp_has_custom_activation_page() { 2404 static $has_page = false; 2405 2406 if ( empty( $has_page ) ) { 2407 $has_page = bp_get_activate_slug() && bp_locate_template( array( 'registration/activate.php', 'members/activate.php', 'activate.php' ), false ); 2408 } 2409 2410 return (bool) $has_page; 2411 } 2412 2413 /** 2414 * Output the URL of the activation page. 2415 * 2416 * @since 1.0.0 2417 */ 2418 function bp_activation_page() { 2419 echo esc_url( bp_get_activation_page() ); 2420 } 2421 /** 2422 * Get the URL of the activation page. 2423 * 2424 * @since 1.2.0 2425 * 2426 * @return string 2427 */ 2428 function bp_get_activation_page() { 2429 if ( bp_has_custom_activation_page() ) { 2430 $page = trailingslashit( bp_get_root_domain() . '/' . bp_get_activate_slug() ); 2431 } else { 2432 $page = trailingslashit( bp_get_root_domain() ) . 'wp-activate.php'; 2433 } 2434 2435 /** 2436 * Filters the URL of the activation page. 2437 * 2438 * @since 1.2.0 2439 * 2440 * @param string $page URL to the activation page. 2441 */ 2442 return apply_filters( 'bp_get_activation_page', $page ); 2443 } 2444 2445 /** 2446 * Get the activation key from the current request URL. 2447 * 2448 * @since 3.0.0 2449 * 2450 * @return string 2451 */ 2452 function bp_get_current_activation_key() { 2453 $key = ''; 2454 2455 if ( bp_is_current_component( 'activate' ) ) { 2456 if ( isset( $_GET['key'] ) ) { 2457 $key = wp_unslash( $_GET['key'] ); 2458 } else { 2459 $key = bp_current_action(); 2460 } 2461 } 2462 2463 /** 2464 * Filters the activation key from the current request URL. 2465 * 2466 * @since 3.0.0 2467 * 2468 * @param string $key Activation key. 2469 */ 2470 return apply_filters( 'bp_get_current_activation_key', $key ); 2471 } 2472 2473 /** 2474 * Output the username submitted during signup. 2475 * 2476 * @since 1.1.0 2477 */ 2478 function bp_signup_username_value() { 2479 echo bp_get_signup_username_value(); 2480 } 2481 /** 2482 * Get the username submitted during signup. 2483 * 2484 * @since 1.1.0 2485 * 2486 * @todo This should be properly escaped. 2487 * 2488 * @return string 2489 */ 2490 function bp_get_signup_username_value() { 2491 $value = ''; 2492 if ( isset( $_POST['signup_username'] ) ) 2493 $value = $_POST['signup_username']; 2494 2495 /** 2496 * Filters the username submitted during signup. 2497 * 2498 * @since 1.1.0 2499 * 2500 * @param string $value Username submitted during signup. 2501 */ 2502 return apply_filters( 'bp_get_signup_username_value', $value ); 2503 } 2504 2505 /** 2506 * Output the user email address submitted during signup. 2507 * 2508 * @since 1.1.0 2509 */ 2510 function bp_signup_email_value() { 2511 echo bp_get_signup_email_value(); 2512 } 2513 /** 2514 * Get the email address submitted during signup. 2515 * 2516 * @since 1.1.0 2517 * 2518 * @todo This should be properly escaped. 2519 * 2520 * @return string 2521 */ 2522 function bp_get_signup_email_value() { 2523 $value = ''; 2524 if ( isset( $_POST['signup_email'] ) ) { 2525 $value = $_POST['signup_email']; 2526 } else if ( bp_get_members_invitations_allowed() ) { 2527 $invite = bp_get_members_invitation_from_request(); 2528 if ( $invite ) { 2529 $value = $invite->invitee_email; 2530 } 2531 } 2532 2533 /** 2534 * Filters the email address submitted during signup. 2535 * 2536 * @since 1.1.0 2537 * 2538 * @param string $value Email address submitted during signup. 2539 */ 2540 return apply_filters( 'bp_get_signup_email_value', $value ); 2541 } 2542 2543 /** 2544 * Output the 'signup_with_blog' value submitted during signup. 2545 * 2546 * @since 1.1.0 2547 */ 2548 function bp_signup_with_blog_value() { 2549 echo bp_get_signup_with_blog_value(); 2550 } 2551 /** 2552 * Get the 'signup_with_blog' value submitted during signup. 2553 * 2554 * @since 1.1.0 2555 * 2556 * @return string 2557 */ 2558 function bp_get_signup_with_blog_value() { 2559 $value = ''; 2560 if ( isset( $_POST['signup_with_blog'] ) ) 2561 $value = $_POST['signup_with_blog']; 2562 2563 /** 2564 * Filters the 'signup_with_blog' value submitted during signup. 2565 * 2566 * @since 1.1.0 2567 * 2568 * @param string $value 'signup_with_blog' value submitted during signup. 2569 */ 2570 return apply_filters( 'bp_get_signup_with_blog_value', $value ); 2571 } 2572 2573 /** 2574 * Output the 'signup_blog_url' value submitted at signup. 2575 * 2576 * @since 1.1.0 2577 */ 2578 function bp_signup_blog_url_value() { 2579 echo bp_get_signup_blog_url_value(); 2580 } 2581 /** 2582 * Get the 'signup_blog_url' value submitted at signup. 2583 * 2584 * @since 1.1.0 2585 * 2586 * @todo Should be properly escaped. 2587 * 2588 * @return string 2589 */ 2590 function bp_get_signup_blog_url_value() { 2591 $value = ''; 2592 if ( isset( $_POST['signup_blog_url'] ) ) 2593 $value = $_POST['signup_blog_url']; 2594 2595 /** 2596 * Filters the 'signup_blog_url' value submitted during signup. 2597 * 2598 * @since 1.1.0 2599 * 2600 * @param string $value 'signup_blog_url' value submitted during signup. 2601 */ 2602 return apply_filters( 'bp_get_signup_blog_url_value', $value ); 2603 } 2604 2605 /** 2606 * Output the base URL for subdomain installations of WordPress Multisite. 2607 * 2608 * @since 2.1.0 2609 */ 2610 function bp_signup_subdomain_base() { 2611 echo bp_signup_get_subdomain_base(); 2612 } 2613 /** 2614 * Return the base URL for subdomain installations of WordPress Multisite. 2615 * 2616 * Replaces bp_blogs_get_subdomain_base() 2617 * 2618 * @since 2.1.0 2619 * 2620 * @global WP_Network $current_site 2621 * 2622 * @return string The base URL - eg, 'example.com' for site_url() example.com or www.example.com. 2623 */ 2624 function bp_signup_get_subdomain_base() { 2625 global $current_site; 2626 2627 // In case plugins are still using this filter. 2628 $subdomain_base = apply_filters( 'bp_blogs_subdomain_base', preg_replace( '|^www\.|', '', $current_site->domain ) . $current_site->path ); 2629 2630 /** 2631 * Filters the base URL for subdomain installations of WordPress Multisite. 2632 * 2633 * @since 2.1.0 2634 * 2635 * @param string $subdomain_base The base URL - eg, 'example.com' for 2636 * site_url() example.com or www.example.com. 2637 */ 2638 return apply_filters( 'bp_signup_subdomain_base', $subdomain_base ); 2639 } 2640 2641 /** 2642 * Output the 'signup_blog_titl' value submitted at signup. 2643 * 2644 * @since 1.1.0 2645 */ 2646 function bp_signup_blog_title_value() { 2647 echo bp_get_signup_blog_title_value(); 2648 } 2649 /** 2650 * Get the 'signup_blog_title' value submitted at signup. 2651 * 2652 * @since 1.1.0 2653 * 2654 * @todo Should be properly escaped. 2655 * 2656 * @return string 2657 */ 2658 function bp_get_signup_blog_title_value() { 2659 $value = ''; 2660 if ( isset( $_POST['signup_blog_title'] ) ) 2661 $value = $_POST['signup_blog_title']; 2662 2663 /** 2664 * Filters the 'signup_blog_title' value submitted during signup. 2665 * 2666 * @since 1.1.0 2667 * 2668 * @param string $value 'signup_blog_title' value submitted during signup. 2669 */ 2670 return apply_filters( 'bp_get_signup_blog_title_value', $value ); 2671 } 2672 2673 /** 2674 * Output the 'signup_blog_privacy' value submitted at signup. 2675 * 2676 * @since 1.1.0 2677 */ 2678 function bp_signup_blog_privacy_value() { 2679 echo bp_get_signup_blog_privacy_value(); 2680 } 2681 /** 2682 * Get the 'signup_blog_privacy' value submitted at signup. 2683 * 2684 * @since 1.1.0 2685 * 2686 * @todo Should be properly escaped. 2687 * 2688 * @return string 2689 */ 2690 function bp_get_signup_blog_privacy_value() { 2691 $value = ''; 2692 if ( isset( $_POST['signup_blog_privacy'] ) ) 2693 $value = $_POST['signup_blog_privacy']; 2694 2695 /** 2696 * Filters the 'signup_blog_privacy' value submitted during signup. 2697 * 2698 * @since 1.1.0 2699 * 2700 * @param string $value 'signup_blog_privacy' value submitted during signup. 2701 */ 2702 return apply_filters( 'bp_get_signup_blog_privacy_value', $value ); 2703 } 2704 2705 /** 2706 * Output the avatar dir used during signup. 2707 * 2708 * @since 1.1.0 2709 */ 2710 function bp_signup_avatar_dir_value() { 2711 echo bp_get_signup_avatar_dir_value(); 2712 } 2713 /** 2714 * Get the avatar dir used during signup. 2715 * 2716 * @since 1.1.0 2717 * 2718 * @global BuddyPress $bp The one true BuddyPress instance. 2719 * 2720 * @return string 2721 */ 2722 function bp_get_signup_avatar_dir_value() { 2723 $bp = buddypress(); 2724 2725 // Check if signup_avatar_dir is passed. 2726 if ( !empty( $_POST['signup_avatar_dir'] ) ) 2727 $signup_avatar_dir = $_POST['signup_avatar_dir']; 2728 2729 // If not, check if global is set. 2730 elseif ( !empty( $bp->signup->avatar_dir ) ) 2731 $signup_avatar_dir = $bp->signup->avatar_dir; 2732 2733 // If not, set false. 2734 else 2735 $signup_avatar_dir = false; 2736 2737 /** 2738 * Filters the avatar dir used during signup. 2739 * 2740 * @since 1.1.0 2741 * 2742 * @param string|bool $signup_avatar_dir Avatar dir used during signup or false. 2743 */ 2744 return apply_filters( 'bp_get_signup_avatar_dir_value', $signup_avatar_dir ); 2745 } 2746 2747 /** 2748 * Determines whether privacy policy acceptance is required for registration. 2749 * 2750 * @since 4.0.0 2751 * 2752 * @return bool 2753 */ 2754 function bp_signup_requires_privacy_policy_acceptance() { 2755 2756 // Default to true when a published Privacy Policy page exists. 2757 $privacy_policy_url = get_privacy_policy_url(); 2758 $required = ! empty( $privacy_policy_url ); 2759 2760 /** 2761 * Filters whether privacy policy acceptance is required for registration. 2762 * 2763 * @since 4.0.0 2764 * 2765 * @param bool $required Whether privacy policy acceptance is required. 2766 */ 2767 return (bool) apply_filters( 'bp_signup_requires_privacy_policy_acceptance', $required ); 2768 } 2769 2770 /** 2771 * Output the current signup step. 2772 * 2773 * @since 1.1.0 2774 */ 2775 function bp_current_signup_step() { 2776 echo bp_get_current_signup_step(); 2777 } 2778 /** 2779 * Get the current signup step. 2780 * 2781 * @since 1.1.0 2782 * 2783 * @global BuddyPress $bp The one true BuddyPress instance. 2784 * 2785 * @return string 2786 */ 2787 function bp_get_current_signup_step() { 2788 return (string) buddypress()->signup->step; 2789 } 2790 2791 /** 2792 * Output the user avatar during signup. 2793 * 2794 * @since 1.1.0 2795 * 2796 * @see bp_get_signup_avatar() for description of arguments. 2797 * 2798 * @param array|string $args See {@link bp_get_signup_avatar(}. 2799 */ 2800 function bp_signup_avatar( $args = '' ) { 2801 echo bp_get_signup_avatar( $args ); 2802 } 2803 /** 2804 * Get the user avatar during signup. 2805 * 2806 * @since 1.1.0 2807 * 2808 * @global BuddyPress $bp The one true BuddyPress instance. 2809 * 2810 * @see bp_core_fetch_avatar() for description of arguments. 2811 * 2812 * @param array|string $args { 2813 * Array of optional arguments. 2814 * @type int $size Height/weight in pixels. Default: value of 2815 * bp_core_avatar_full_width(). 2816 * @type string $class CSS class. Default: 'avatar'. 2817 * @type string $alt HTML 'alt' attribute. Default: 'Your Avatar'. 2818 * } 2819 * @return string 2820 */ 2821 function bp_get_signup_avatar( $args = '' ) { 2822 $bp = buddypress(); 2823 $r = bp_parse_args( 2824 $args, 2825 array( 2826 'size' => bp_core_avatar_full_width(), 2827 'class' => 'avatar', 2828 'alt' => __( 'Your Profile Photo', 'buddypress' ), 2829 ) 2830 ); 2831 2832 extract( $r, EXTR_SKIP ); 2833 2834 $signup_avatar_dir = bp_get_signup_avatar_dir_value(); 2835 2836 // Avatar DIR is found. 2837 if ( $signup_avatar_dir ) { 2838 $gravatar_img = bp_core_fetch_avatar( array( 2839 'item_id' => $signup_avatar_dir, 2840 'object' => 'signup', 2841 'avatar_dir' => 'avatars/signups', 2842 'type' => 'full', 2843 'width' => $size, 2844 'height' => $size, 2845 'alt' => $alt, 2846 'class' => $class, 2847 ) ); 2848 2849 // No avatar DIR was found. 2850 } else { 2851 2852 // Set default gravatar type. 2853 if ( empty( $bp->grav_default->user ) ) { 2854 $default_grav = 'wavatar'; 2855 } elseif ( 'mystery' === $bp->grav_default->user ) { 2856 $default_grav = $bp->plugin_url . 'bp-core/images/mystery-man.jpg'; 2857 } else { 2858 $default_grav = $bp->grav_default->user; 2859 } 2860 2861 /** 2862 * Filters the base Gravatar url used for signup avatars when no avatar dir found. 2863 * 2864 * @since 1.0.2 2865 * 2866 * @param string $value Gravatar url to use. 2867 */ 2868 $gravatar_url = apply_filters( 'bp_gravatar_url', '//www.gravatar.com/avatar/' ); 2869 $md5_lcase_email = md5( strtolower( bp_get_signup_email_value() ) ); 2870 $gravatar_img = '<img src="' . $gravatar_url . $md5_lcase_email . '?d=' . $default_grav . '&s=' . $size . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />'; 2871 } 2872 2873 /** 2874 * Filters the user avatar during signup. 2875 * 2876 * @since 1.1.0 2877 * 2878 * @param string $gravatar_img Avatar HTML image tag. 2879 * @param array $args Array of parsed args for avatar query. 2880 */ 2881 return apply_filters( 'bp_get_signup_avatar', $gravatar_img, $args ); 2882 } 2883 2884 /** 2885 * Output whether signup is allowed. 2886 * 2887 * @since 1.1.0 2888 * 2889 * @todo Remove this function. Echoing a bool is pointless. 2890 */ 2891 function bp_signup_allowed() { 2892 echo bp_get_signup_allowed(); 2893 } 2894 /** 2895 * Is user signup allowed? 2896 * 2897 * @since 1.1.0 2898 * 2899 * @return bool 2900 */ 2901 function bp_get_signup_allowed() { 2902 2903 /** 2904 * Filters whether or not new signups are allowed. 2905 * 2906 * @since 1.5.0 2907 * 2908 * @param bool $signup_allowed Whether or not new signups are allowed. 2909 */ 2910 return apply_filters( 'bp_get_signup_allowed', (bool) bp_get_option( 'users_can_register' ) ); 2911 } 2912 2913 /** 2914 * Are users allowed to invite users to join this site? 2915 * 2916 * @since 8.0.0 2917 * 2918 * @return bool 2919 */ 2920 function bp_get_members_invitations_allowed() { 2921 /** 2922 * Filters whether or not community invitations are allowed. 2923 * 2924 * @since 8.0.0 2925 * 2926 * @param bool $allowed Whether or not community invitations are allowed. 2927 */ 2928 return apply_filters( 'bp_get_members_invitations_allowed', bp_is_active( 'members', 'invitations' ) && (bool) bp_get_option( 'bp-enable-members-invitations' ) ); 2929 } 2930 2931 /** 2932 * Are membership requests required for joining this site? 2933 * 2934 * @since 10.0.0 2935 * 2936 * @param bool $context "raw" to fetch value from database, 2937 * "site" to take "anyone can register" setting into account. 2938 * @return bool 2939 */ 2940 function bp_get_membership_requests_required( $context = 'site' ) { 2941 if ( 'raw' === $context ) { 2942 $retval = bp_is_active( 'members', 'membership_requests' ) && (bool) bp_get_option( 'bp-enable-membership-requests' ); 2943 } else { 2944 $retval = bp_is_active( 'members', 'membership_requests' ) && ! bp_get_signup_allowed() && (bool) bp_get_option( 'bp-enable-membership-requests' ); 2945 } 2946 2947 /** 2948 * Filters whether or not prospective members may submit network membership requests. 2949 * 2950 * @since 10.0.0 2951 * 2952 * @param bool $retval Whether or not membership requests are required. 2953 * @param bool $retval Whether this is the value stored in the database ('raw') 2954 * or whether the site's "anyone can register" setting is 2955 * being considered ('site' or anything else). 2956 */ 2957 return apply_filters( 'bp_get_membership_requests_required', $retval, $context ); 2958 } 2959 2960 /** 2961 * Should the system create and allow access 2962 * to the Register and Activate pages? 2963 * 2964 * @since 10.0.0 2965 * 2966 * @return bool 2967 */ 2968 function bp_allow_access_to_registration_pages() { 2969 $retval = bp_get_signup_allowed() || bp_get_members_invitations_allowed() || bp_get_membership_requests_required(); 2970 2971 /** 2972 * Filters whether or not the system should create and allow access 2973 * to the Register and Activate pages. 2974 * 2975 * @since 10.0.0 2976 * 2977 * @param bool $retval Whether or not to allow access to 2978 * the Register and Activate pages. 2979 */ 2980 return apply_filters( 'bp_allow_access_to_registration_pages', $retval ); 2981 } 2982 2983 /** 2984 * Hook member activity feed to <head>. 2985 * 2986 * @since 1.5.0 2987 */ 2988 function bp_members_activity_feed() { 2989 if ( !bp_is_active( 'activity' ) || !bp_is_user() ) 2990 return; ?> 2991 2992 <link rel="alternate" type="application/rss+xml" title="<?php bloginfo( 'name' ) ?> | <?php bp_displayed_user_fullname() ?> | <?php _e( 'Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_member_activity_feed_link() ?>" /> 2993 2994 <?php 2995 } 2996 add_action( 'bp_head', 'bp_members_activity_feed' ); 2997 2998 /** 2999 * Output a link to a members component subpage. 3000 * 3001 * @since 1.5.0 3002 * 3003 * @see bp_get_members_component_link() for description of parameters. 3004 * 3005 * @param string $component See {@bp_get_members_component_link()}. 3006 * @param string $action See {@bp_get_members_component_link()}. 3007 * @param string $query_args See {@bp_get_members_component_link()}. 3008 * @param string|bool $nonce See {@bp_get_members_component_link()}. 3009 */ 3010 function bp_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) { 3011 echo esc_url( bp_get_members_component_link( $component, $action, $query_args, $nonce ) ); 3012 } 3013 /** 3014 * Generate a link to a members component subpage. 3015 * 3016 * @since 1.5.0 3017 * 3018 * @global BuddyPress $bp The one true BuddyPress instance. 3019 * 3020 * @param string $component ID of the component (eg 'friends'). 3021 * @param string $action Optional. 'action' slug (eg 'invites'). 3022 * @param array|string $query_args Optional. Array of URL params to add to the 3023 * URL. See {@link add_query_arg()} for format. 3024 * @param array|bool $nonce Optional. If provided, the URL will be passed 3025 * through wp_nonce_url() with $nonce as the 3026 * action string. 3027 * @return string 3028 */ 3029 function bp_get_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) { 3030 // Must be displayed user. 3031 if ( ! bp_displayed_user_id() ) { 3032 return; 3033 } 3034 3035 $bp = buddypress(); 3036 3037 if ( 'xprofile' === $component ) { 3038 $component = 'profile'; 3039 } 3040 3041 // Append $action to $url if there is no $type. 3042 if ( ! empty( $action ) ) { 3043 $url = bp_displayed_user_domain() . $bp->{$component}->slug . '/' . $action; 3044 } else { 3045 $url = bp_displayed_user_domain() . $bp->{$component}->slug; 3046 } 3047 3048 // Add a slash at the end of our user url. 3049 $url = trailingslashit( $url ); 3050 3051 // Add possible query arg. 3052 if ( ! empty( $query_args ) && is_array( $query_args ) ) { 3053 $url = add_query_arg( $query_args, $url ); 3054 } 3055 3056 // To nonce, or not to nonce... 3057 if ( true === $nonce ) { 3058 $url = wp_nonce_url( $url ); 3059 } elseif ( is_string( $nonce ) ) { 3060 $url = wp_nonce_url( $url, $nonce ); 3061 } 3062 3063 // Return the url, if there is one. 3064 if ( ! empty( $url ) ) { 3065 return $url; 3066 } 3067 } 3068 3069 3070 /** 3071 * Render an avatar delete link. 3072 * 3073 * @since 1.1.0 3074 * @since 6.0.0 Moved from /bp-xprofile/bp-xprofile-template.php to this file. 3075 */ 3076 function bp_avatar_delete_link() { 3077 echo bp_get_avatar_delete_link(); 3078 } 3079 /** 3080 * Return an avatar delete link. 3081 * 3082 * @since 1.1.0 3083 * @since 6.0.0 Moved from /bp-xprofile/bp-xprofile-template.php to this file. 3084 * 3085 * @return string 3086 */ 3087 function bp_get_avatar_delete_link() { 3088 3089 /** 3090 * Filters the link used for deleting an avatar. 3091 * 3092 * @since 1.1.0 3093 * 3094 * @param string $value Nonced URL used for deleting an avatar. 3095 */ 3096 return apply_filters( 'bp_get_avatar_delete_link', wp_nonce_url( bp_displayed_user_domain() . bp_get_profile_slug() . '/change-avatar/delete-avatar/', 'bp_delete_avatar_link' ) ); 3097 } 3098 3099 3100 /** The Members Invitations Loop ******************************************************************/ 3101 3102 /** 3103 * Initialize the community invitations loop. 3104 * 3105 * Based on the $args passed, bp_has_invitations() populates 3106 * buddypress()->invitations->query_loop global, enabling the use of BP 3107 * templates and template functions to display a list of invitations. 3108 * 3109 * @since 8.0.0 3110 * 3111 * @global BuddyPress $bp The one true BuddyPress instance. 3112 * 3113 * @param array|string $args { 3114 * Arguments for limiting the contents of the invitations loop. Can be 3115 * passed as an associative array, or as a URL query string. 3116 * 3117 * See {@link BP_Invitations_Invitation::get()} for detailed 3118 * information on the arguments. In addition, also supports: 3119 * 3120 * @type int $max Optional. Max items to display. Default: false. 3121 * @type string $page_arg URL argument to use for pagination. 3122 * Default: 'ipage'. 3123 * } 3124 * @return bool 3125 */ 3126 function bp_has_members_invitations( $args = '' ) { 3127 $bp = buddypress(); 3128 3129 // Get the user ID. 3130 if ( bp_displayed_user_id() ) { 3131 $user_id = bp_displayed_user_id(); 3132 } else { 3133 $user_id = bp_loggedin_user_id(); 3134 } 3135 3136 // Set the search terms (by default an empty string to get all notifications). 3137 $search_terms = ''; 3138 3139 if ( isset( $_REQUEST['s'] ) ) { 3140 $search_terms = stripslashes( $_REQUEST['s'] ); 3141 } 3142 3143 // Parse the args. 3144 $r = bp_parse_args( 3145 $args, 3146 array( 3147 'id' => false, 3148 'inviter_id' => $user_id, 3149 'invitee_email' => false, 3150 'item_id' => false, 3151 'type' => 'invite', 3152 'invite_sent' => 'all', 3153 'accepted' => 'pending', 3154 'search_terms' => $search_terms, 3155 'order_by' => 'date_modified', 3156 'sort_order' => 'DESC', 3157 'page' => 1, 3158 'per_page' => 25, 3159 'fields' => 'all', 3160 3161 // These are additional arguments that are not available in 3162 // BP_Invitations_Invitation::get(). 3163 'page_arg' => 'ipage', 3164 ), 3165 'has_members_invitations' 3166 ); 3167 3168 // Get the notifications. 3169 $query_loop = new BP_Members_Invitations_Template( $r ); 3170 3171 // Setup the global query loop. 3172 $bp->members->invitations->query_loop = $query_loop; 3173 3174 /** 3175 * Filters whether or not the user has network invitations to display. 3176 * 3177 * @since 8.0.0 3178 * 3179 * @param bool $value Whether or not there are network invitations to display. 3180 * @param BP_Notifications_Template $query_loop BP_Members_Invitations_Template object instance. 3181 * @param array $r Array of arguments passed into the BP_Members_Invitations_Template class. 3182 */ 3183 return apply_filters( 'bp_has_members_invitations', $query_loop->has_invitations(), $query_loop, $r ); 3184 } 3185 3186 /** 3187 * Get the network invitations returned by the template loop. 3188 * 3189 * @since 8.0.0 3190 * 3191 * @global BuddyPress $bp The one true BuddyPress instance. 3192 * 3193 * @return array List of network invitations. 3194 */ 3195 function bp_the_members_invitations() { 3196 return buddypress()->members->invitations->query_loop->invitations(); 3197 } 3198 3199 /** 3200 * Get the current network invitation object in the loop. 3201 * 3202 * @since 8.0.0 3203 * 3204 * @global BuddyPress $bp The one true BuddyPress instance. 3205 * 3206 * @return object The current network invitation within the loop. 3207 */ 3208 function bp_the_members_invitation() { 3209 return buddypress()->members->invitations->query_loop->the_invitation(); 3210 } 3211 3212 /** 3213 * Output the pagination count for the current network invitations loop. 3214 * 3215 * @since 8.0.0 3216 */ 3217 function bp_members_invitations_pagination_count() { 3218 echo bp_get_members_invitations_pagination_count(); 3219 } 3220 /** 3221 * Return the pagination count for the current network invitation loop. 3222 * 3223 * @since 8.0.0 3224 * 3225 * @global BuddyPress $bp The one true BuddyPress instance. 3226 * 3227 * @return string HTML for the pagination count. 3228 */ 3229 function bp_get_members_invitations_pagination_count() { 3230 $bp = buddypress(); 3231 $query_loop = $bp->members->invitations->query_loop; 3232 $start_num = intval( ( $query_loop->pag_page - 1 ) * $query_loop->pag_num ) + 1; 3233 $from_num = bp_core_number_format( $start_num ); 3234 $to_num = bp_core_number_format( ( $start_num + ( $query_loop->pag_num - 1 ) > $query_loop->total_invitation_count ) ? $query_loop->total_invitation_count : $start_num + ( $query_loop->pag_num - 1 ) ); 3235 $total = bp_core_number_format( $query_loop->total_invitation_count ); 3236 3237 if ( 1 == $query_loop->total_invitation_count ) { 3238 $pag = __( 'Viewing 1 invitation', 'buddypress' ); 3239 } else { 3240 /* translators: 1: Invitations from number. 2: Invitations to number. 3: Total invitations. */ 3241 $pag = sprintf( _nx( 'Viewing %1$s - %2$s of %3$s invitation', 'Viewing %1$s - %2$s of %3$s invitations', $query_loop->total_invitation_count, 'Community invites pagination', 'buddypress' ), $from_num, $to_num, $total ); 3242 } 3243 3244 /** 3245 * Filters the pagination count for the current network invitation loop. 3246 * 3247 * @since 8.0.0 3248 * 3249 * @param string $pag HTML for the pagination count. 3250 */ 3251 return apply_filters( 'bp_get_members_invitations_pagination_count', $pag ); 3252 } 3253 3254 /** 3255 * Output the pagination links for the current network invitation loop. 3256 * 3257 * @since 8.0.0 3258 */ 3259 function bp_members_invitations_pagination_links() { 3260 echo bp_get_members_invitations_pagination_links(); 3261 } 3262 /** 3263 * Return the pagination links for the current network invitations loop. 3264 * 3265 * @since 8.0.0 3266 * 3267 * @global BuddyPress $bp The one true BuddyPress instance. 3268 * 3269 * @return string HTML for the pagination links. 3270 */ 3271 function bp_get_members_invitations_pagination_links() { 3272 $bp = buddypress(); 3273 3274 /** 3275 * Filters the pagination links for the current network invitations loop. 3276 * 3277 * @since 8.0.0 3278 * 3279 * @param string $pag_links HTML for the pagination links. 3280 */ 3281 return apply_filters( 'bp_get_members_invitations_pagination_links', $bp->members->invitations->query_loop->pag_links ); 3282 } 3283 3284 /** 3285 * Output the requested property of the invitation currently being iterated on. 3286 * 3287 * @since 8.0.0 3288 * 3289 * @param string $property The name of the property to display. 3290 * @param string $context The context of display. 3291 * Possible values are 'attribute' and 'html'. 3292 */ 3293 function bp_the_members_invitation_property( $property = '', $context = 'html' ) { 3294 if ( ! $property ) { 3295 return; 3296 } 3297 3298 /** 3299 * Use this filter to sanitize the output. 3300 * 3301 * @since 8.0.0 3302 * 3303 * @param int|string $value The value for the requested property. 3304 * @param string $property The name of the requested property. 3305 * @param string $context The context of display. 3306 */ 3307 echo apply_filters( 'bp_the_members_invitation_property', bp_get_the_members_invitation_property( $property ), $property, $context ); 3308 } 3309 /** 3310 * Return the value for a property of the network invitation currently being iterated on. 3311 * 3312 * @since 8.0.0 3313 * 3314 * @return int ID of the current network invitation. 3315 */ 3316 function bp_get_the_members_invitation_property( $property = 'id' ) { 3317 3318 switch ( $property ) { 3319 case 'id': 3320 case 'user_id': 3321 case 'item_id': 3322 case 'secondary_item_id': 3323 case 'invite_sent': 3324 case 'accepted': 3325 $value = 0; 3326 break; 3327 case 'invitee_email': 3328 case 'type': 3329 case 'content': 3330 case 'date_modified': 3331 $value = ''; 3332 break; 3333 default: 3334 // A known property has not been specified. 3335 $property = null; 3336 $value = ''; 3337 break; 3338 } 3339 3340 if ( isset( buddypress()->members->invitations->query_loop->invitation->{$property} ) ) { 3341 $value = buddypress()->members->invitations->query_loop->invitation->{$property}; 3342 } 3343 3344 /** 3345 * Filters the property of the network invitation currently being iterated on. 3346 * 3347 * @since 8.0.0 3348 * 3349 * @param int|string $value Property value of the network invitation being iterated on. 3350 */ 3351 return apply_filters( 'bp_get_the_members_invitation_property_' . $property, $value ); 3352 } 3353 3354 /** 3355 * Output the action links for the current invitation. 3356 * 3357 * @since 8.0.0 3358 * 3359 * @param array|string $args Array of arguments. 3360 */ 3361 function bp_the_members_invitation_action_links( $args = '' ) { 3362 echo bp_get_the_members_invitation_action_links( $args ); 3363 } 3364 /** 3365 * Return the action links for the current invitation. 3366 * 3367 * @since 8.0.0 3368 * 3369 * @param array|string $args { 3370 * @type string $before HTML before the links. 3371 * @type string $after HTML after the links. 3372 * @type string $sep HTML between the links. 3373 * @type array $links Array of links to implode by 'sep'. 3374 * @type int $user_id User ID to fetch action links for. Defaults to displayed user ID. 3375 * } 3376 * @return string HTML links for actions to take on single notifications. 3377 */ 3378 function bp_get_the_members_invitation_action_links( $args = '' ) { 3379 // Set default user ID to use. 3380 $inviter_id = isset( $args['inviter_id'] ) ? $args['inviter_id'] : bp_displayed_user_id(); 3381 3382 // Parse. 3383 $r = bp_parse_args( 3384 $args, 3385 array( 3386 'before' => '', 3387 'after' => '', 3388 'sep' => ' | ', 3389 'links' => array( 3390 bp_get_the_members_invitation_resend_link( $inviter_id ), 3391 bp_get_the_members_invitation_delete_link( $inviter_id ) 3392 ) 3393 ) 3394 ); 3395 3396 // Build the links. 3397 $retval = $r['before'] . implode( $r['sep'], $r['links'] ) . $r['after']; 3398 3399 /** 3400 * Filters the action links for the current invitation. 3401 * 3402 * @since 8.0.0 3403 * 3404 * @param string $retval HTML links for actions to take on single invitation. 3405 * @param array $r Array of parsed arguments. 3406 */ 3407 return apply_filters( 'bp_get_the_members_invitation_action_links', $retval, $r ); 3408 } 3409 3410 /** 3411 * Output the resend link for the current invitation. 3412 * 3413 * @since 8.0.0 3414 * 3415 * @param int $user_id The user ID. 3416 */ 3417 function bp_the_members_invitations_resend_link( $user_id = 0 ) { 3418 echo bp_get_the_members_invitation_delete_link( $user_id ); 3419 } 3420 /** 3421 * Return the resend link for the current notification. 3422 * 3423 * @since 8.0.0 3424 * 3425 * @param int $user_id The user ID. 3426 * @return string 3427 */ 3428 function bp_get_the_members_invitation_resend_link( $user_id = 0 ) { 3429 // Set default user ID to use. 3430 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 3431 3432 // Don't allow resending of accepted invitations. 3433 if ( bp_get_the_members_invitation_property( 'accepted' ) ) { 3434 return; 3435 } 3436 3437 $retval = sprintf( '<a href="%1$s" class="resend secondary confirm bp-tooltip">%2$s</a>', esc_url( bp_get_the_members_invitations_resend_url( $user_id ) ), __( 'Resend', 'buddypress' ) ); 3438 3439 /** 3440 * Filters the resend link for the current invitation. 3441 * 3442 * @since 8.0.0 3443 * 3444 * @param string $retval HTML for the delete link for the current notification. 3445 * @param int $user_id The user ID. 3446 */ 3447 return apply_filters( 'bp_get_the_members_invitation_resend_link', $retval, $user_id ); 3448 } 3449 3450 /** 3451 * Output the URL used for resending a single invitation. 3452 * 3453 * Since this function directly outputs a URL, it is escaped. 3454 * 3455 * @since 8.0.0 3456 * 3457 * @param int $user_id The user ID. 3458 */ 3459 function bp_the_members_invitations_resend_url( $user_id = 0 ) { 3460 echo esc_url( bp_get_the_members_invitations_resend_url( $user_id ) ); 3461 } 3462 /** 3463 * Return the URL used for resending a single invitation. 3464 * 3465 * @since 8.0.0 3466 * 3467 * @param int $user_id The user ID. 3468 * @return string 3469 */ 3470 function bp_get_the_members_invitations_resend_url( $user_id = 0 ) { 3471 // Set default user ID to use. 3472 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 3473 $link = bp_get_members_invitations_list_invites_permalink( $user_id ); 3474 3475 // Get the ID. 3476 $id = bp_get_the_members_invitation_property( 'id' ); 3477 3478 // Get the args to add to the URL. 3479 $args = array( 3480 'action' => 'resend', 3481 'invitation_id' => $id 3482 ); 3483 3484 // Add the args. 3485 $url = add_query_arg( $args, $link ); 3486 3487 // Add the nonce. 3488 $url = wp_nonce_url( $url, 'bp_members_invitation_resend_' . $id ); 3489 3490 /** 3491 * Filters the URL used for resending a single invitation. 3492 * 3493 * @since 8.0.0 3494 * 3495 * @param string $url URL used for deleting a single invitation. 3496 * @param int $user_id The user ID. 3497 */ 3498 return apply_filters( 'bp_get_the_members_invitations_resend_url', $url, $user_id ); 3499 } 3500 3501 /** 3502 * Output the delete link for the current invitation. 3503 * 3504 * @since 8.0.0 3505 * 3506 * @param int $user_id The user ID. 3507 */ 3508 function bp_the_members_invitations_delete_link( $user_id = 0 ) { 3509 echo bp_get_the_members_invitation_delete_link( $user_id ); 3510 } 3511 /** 3512 * Return the delete link for the current invitation. 3513 * 3514 * @since 8.0.0 3515 * 3516 * @param int $user_id The user ID. 3517 * @return string 3518 */ 3519 function bp_get_the_members_invitation_delete_link( $user_id = 0 ) { 3520 // Set default user ID to use. 3521 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 3522 3523 // Modify the message for accepted/not accepted invitatons. 3524 if ( bp_get_the_members_invitation_property( 'accepted' ) ) { 3525 $message = __( 'Delete', 'buddypress' ); 3526 } else { 3527 $message = __( 'Cancel', 'buddypress' ); 3528 } 3529 3530 $retval = sprintf( 3531 '<a href="%1$s" class="delete secondary confirm bp-tooltip">%2$s</a>', 3532 esc_url( bp_get_the_members_invitations_delete_url( $user_id ) ), 3533 esc_html( $message ) 3534 ); 3535 3536 /** 3537 * Filters the delete link for the current invitation. 3538 * 3539 * @since 8.0.0 3540 * 3541 * @param string $retval HTML for the delete link for the current notification. 3542 * @param int $user_id The user ID. 3543 */ 3544 return apply_filters( 'bp_get_the_members_invitation_delete_link', $retval, $user_id ); 3545 } 3546 3547 /** 3548 * Output the URL used for deleting a single invitation. 3549 * 3550 * Since this function directly outputs a URL, it is escaped. 3551 * 3552 * @since 8.0.0 3553 * 3554 * @param int $user_id The user ID. 3555 */ 3556 function bp_the_members_invitations_delete_url( $user_id = 0 ) { 3557 echo esc_url( bp_get_the_members_invitations_delete_url( $user_id ) ); 3558 } 3559 /** 3560 * Return the URL used for deleting a single invitation. 3561 * 3562 * @since 8.0.0 3563 * 3564 * @param int $user_id The user ID. 3565 * @return string 3566 */ 3567 function bp_get_the_members_invitations_delete_url( $user_id = 0 ) { 3568 // Set default user ID to use. 3569 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 3570 $link = bp_get_members_invitations_list_invites_permalink( $user_id ); 3571 3572 // Get the ID. 3573 $id = bp_get_the_members_invitation_property( 'id' ); 3574 3575 // Get the args to add to the URL. 3576 $args = array( 3577 'action' => 'cancel', 3578 'invitation_id' => $id 3579 ); 3580 3581 // Add the args. 3582 $url = add_query_arg( $args, $link ); 3583 3584 // Add the nonce. 3585 $url = wp_nonce_url( $url, 'bp_members_invitations_cancel_' . $id ); 3586 3587 /** 3588 * Filters the URL used for deleting a single invitation. 3589 * 3590 * @since 8.0.0 3591 * 3592 * @param string $url URL used for deleting a single invitation. 3593 * @param int $user_id The user ID. 3594 */ 3595 return apply_filters( 'bp_get_the_members_invitations_delete_url', $url, $user_id ); 3596 } 3597 3598 /** 3599 * Output the members invitations list permalink for a user. 3600 * 3601 * @since 8.0.0 3602 * 3603 * @param int $user_id The user ID. 3604 */ 3605 function bp_members_invitations_list_invites_permalink( $user_id = 0 ) { 3606 echo bp_get_members_invitations_list_invites_permalink( $user_id ); 3607 } 3608 /** 3609 * Return the members invitations list permalink for a user. 3610 * 3611 * @since 8.0.0 3612 * 3613 * @return string Members invitations list permalink for a user. 3614 */ 3615 function bp_get_members_invitations_list_invites_permalink( $user_id = 0 ) { 3616 if ( 0 === $user_id ) { 3617 $user_id = bp_loggedin_user_id(); 3618 $domain = bp_loggedin_user_domain(); 3619 } else { 3620 $domain = bp_core_get_user_domain( (int) $user_id ); 3621 } 3622 3623 $retval = trailingslashit( $domain . bp_get_members_invitations_slug() . '/list-invites' ); 3624 3625 /** 3626 * Filters the members invitations list permalink for a user. 3627 * 3628 * @since 8.0.0 3629 * 3630 * @param string $retval Permalink for the sent invitation list screen. 3631 * @param int $user_id The user ID. 3632 */ 3633 return apply_filters( 'bp_get_members_invitations_list_invites_permalink', $retval, $user_id ); 3634 } 3635 3636 /** 3637 * Output the send invitation permalink for a user. 3638 * 3639 * @since 8.0.0 3640 * 3641 * @param int $user_id The user ID. 3642 */ 3643 function bp_members_invitations_send_invites_permalink( $user_id = 0 ) { 3644 echo bp_get_members_invitations_send_invites_permalink( $user_id ); 3645 } 3646 /** 3647 * Return the send invitations permalink. 3648 * 3649 * @since 8.0.0 3650 * 3651 * @param int $user_id The user ID. 3652 * @return string The send invitations permalink. 3653 */ 3654 function bp_get_members_invitations_send_invites_permalink( $user_id = 0 ) { 3655 if ( 0 === $user_id ) { 3656 $user_id = bp_loggedin_user_id(); 3657 $domain = bp_loggedin_user_domain(); 3658 } else { 3659 $domain = bp_core_get_user_domain( (int) $user_id ); 3660 } 3661 3662 $retval = trailingslashit( $domain . bp_get_members_invitations_slug() . '/send-invites' ); 3663 3664 /** 3665 * Filters the send invitations permalink. 3666 * 3667 * @since 8.0.0 3668 * 3669 * @param string $retval Permalink for the sent invitation list screen. 3670 * @param int $user_id The user ID. 3671 */ 3672 return apply_filters( 'bp_get_members_invitations_send_invites_permalink', $retval, $user_id ); 3673 } 3674 3675 /** 3676 * Output the dropdown for bulk management of invitations. 3677 * 3678 * @since 8.0.0 3679 */ 3680 function bp_members_invitations_bulk_management_dropdown() { 3681 ?> 3682 <label class="bp-screen-reader-text" for="invitation-select"> 3683 <?php 3684 esc_html_e( 'Select Bulk Action', 'buddypress' ); 3685 ?> 3686 </label> 3687 3688 <select name="invitation_bulk_action" id="invitation-select"> 3689 <option value="" selected="selected"><?php esc_html_e( 'Bulk Actions', 'buddypress' ); ?></option> 3690 <option value="resend"><?php echo esc_html_x( 'Resend', 'button', 'buddypress' ); ?></option> 3691 <option value="cancel"><?php echo esc_html_x( 'Cancel', 'button', 'buddypress' ); ?></option> 3692 </select> 3693 3694 <input type="submit" id="invitation-bulk-manage" class="button action" value="<?php echo esc_attr_x( 'Apply', 'button', 'buddypress' ); ?>"> 3695 <?php 3696 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |