[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-members/ -> bp-members-template.php (source)

   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 Members
   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   */
  21  function bp_profile_slug() {
  22      echo bp_get_profile_slug();
  23  }
  24      /**
  25       * Return the profile component slug.
  26       *
  27       * @since 2.4.0
  28       *
  29       * @return string
  30       */
  31  	function bp_get_profile_slug() {
  32  
  33          /**
  34           * Filters the profile component slug.
  35           *
  36           * @since 2.4.0
  37           *
  38           * @param string $slug Profile component slug.
  39           */
  40          return apply_filters( 'bp_get_profile_slug', buddypress()->profile->slug );
  41      }
  42  
  43  /**
  44   * Output the members component slug.
  45   *
  46   * @since 1.5.0
  47   *
  48   */
  49  function bp_members_slug() {
  50      echo bp_get_members_slug();
  51  }
  52      /**
  53       * Return the members component slug.
  54       *
  55       * @since 1.5.0
  56       *
  57       * @return string
  58       */
  59  	function bp_get_members_slug() {
  60  
  61          /**
  62           * Filters the Members component slug.
  63           *
  64           * @since 1.5.0
  65           *
  66           * @param string $slug Members component slug.
  67           */
  68          return apply_filters( 'bp_get_members_slug', buddypress()->members->slug );
  69      }
  70  
  71  /**
  72   * Output the members component root slug.
  73   *
  74   * @since 1.5.0
  75   *
  76   */
  77  function bp_members_root_slug() {
  78      echo bp_get_members_root_slug();
  79  }
  80      /**
  81       * Return the members component root slug.
  82       *
  83       * @since 1.5.0
  84       *
  85       * @return string
  86       */
  87  	function bp_get_members_root_slug() {
  88  
  89          /**
  90           * Filters the Members component root slug.
  91           *
  92           * @since 1.5.0
  93           *
  94           * @param string $slug Members component root slug.
  95           */
  96          return apply_filters( 'bp_get_members_root_slug', buddypress()->members->root_slug );
  97      }
  98  
  99  /**
 100   * Output the member type base slug.
 101   *
 102   * @since 2.5.0
 103   */
 104  function bp_members_member_type_base() {
 105      echo esc_url( bp_get_members_member_type_base() );
 106  }
 107      /**
 108       * Get the member type base slug.
 109       *
 110       * The base slug is the string used as the base prefix when generating member type directory URLs.
 111       * For example, in example.com/members/type/foo/, 'foo' is the member type and 'type' is the
 112       * base slug.
 113       *
 114       * @since 2.5.0
 115       *
 116       * @return string
 117       */
 118  	function bp_get_members_member_type_base() {
 119          /**
 120           * Filters the member type URL base.
 121           *
 122           * @since 2.3.0
 123           *
 124           * @param string $base
 125           */
 126          return apply_filters( 'bp_members_member_type_base', _x( 'type', 'member type URL base', 'buddypress' ) );
 127      }
 128  
 129  /**
 130   * Output member directory permalink.
 131   *
 132   * @since 1.5.0
 133   *
 134   */
 135  function bp_members_directory_permalink() {
 136      echo esc_url( bp_get_members_directory_permalink() );
 137  }
 138      /**
 139       * Return member directory permalink.
 140       *
 141       * @since 1.5.0
 142       *
 143       * @return string
 144       */
 145  	function bp_get_members_directory_permalink() {
 146  
 147          /**
 148           * Filters the member directory permalink.
 149           *
 150           * @since 1.5.0
 151           *
 152           * @param string $value Members directory permalink.
 153           */
 154          return apply_filters( 'bp_get_members_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() ) );
 155      }
 156  
 157  /**
 158   * Output member type directory permalink.
 159   *
 160   * @since 2.5.0
 161   *
 162   * @param string $member_type Optional. Member type.
 163   */
 164  function bp_member_type_directory_permalink( $member_type = '' ) {
 165      echo esc_url( bp_get_member_type_directory_permalink( $member_type ) );
 166  }
 167      /**
 168       * Return member type directory permalink.
 169       *
 170       * @since 2.5.0
 171       *
 172       * @param string $member_type Optional. Member type. Defaults to current member type.
 173       * @return string Member type directory URL on success, an empty string on failure.
 174       */
 175  	function bp_get_member_type_directory_permalink( $member_type = '' ) {
 176  
 177          if ( $member_type ) {
 178              $_member_type = $member_type;
 179          } else {
 180              // Fall back on the current member type.
 181              $_member_type = bp_get_current_member_type();
 182          }
 183  
 184          $type = bp_get_member_type_object( $_member_type );
 185  
 186          // Bail when member type is not found or has no directory.
 187          if ( ! $type || ! $type->has_directory ) {
 188              return '';
 189          }
 190  
 191          /**
 192           * Filters the member type directory permalink.
 193           *
 194           * @since 2.5.0
 195           *
 196           * @param string $value       Member type directory permalink.
 197           * @param object $type        Member type object.
 198           * @param string $member_type Member type name, as passed to the function.
 199           */
 200          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 );
 201      }
 202  
 203  /**
 204   * Output the sign-up slug.
 205   *
 206   * @since 1.5.0
 207   *
 208   */
 209  function bp_signup_slug() {
 210      echo bp_get_signup_slug();
 211  }
 212      /**
 213       * Return the sign-up slug.
 214       *
 215       * @since 1.5.0
 216       *
 217       * @return string
 218       */
 219  	function bp_get_signup_slug() {
 220          $bp = buddypress();
 221  
 222          if ( !empty( $bp->pages->register->slug ) ) {
 223              $slug = $bp->pages->register->slug;
 224          } elseif ( defined( 'BP_REGISTER_SLUG' ) ) {
 225              $slug = BP_REGISTER_SLUG;
 226          } else {
 227              $slug = 'register';
 228          }
 229  
 230          /**
 231           * Filters the sign-up slug.
 232           *
 233           * @since 1.5.0
 234           *
 235           * @param string $slug Sign-up slug.
 236           */
 237          return apply_filters( 'bp_get_signup_slug', $slug );
 238      }
 239  
 240  /**
 241   * Output the activation slug.
 242   *
 243   * @since 1.5.0
 244   *
 245   */
 246  function bp_activate_slug() {
 247      echo bp_get_activate_slug();
 248  }
 249      /**
 250       * Return the activation slug.
 251       *
 252       * @since 1.5.0
 253       *
 254       * @return string
 255       */
 256  	function bp_get_activate_slug() {
 257          $bp = buddypress();
 258  
 259          if ( !empty( $bp->pages->activate->slug ) ) {
 260              $slug = $bp->pages->activate->slug;
 261          } elseif ( defined( 'BP_ACTIVATION_SLUG' ) ) {
 262              $slug = BP_ACTIVATION_SLUG;
 263          } else {
 264              $slug = 'activate';
 265          }
 266  
 267          /**
 268           * Filters the activation slug.
 269           *
 270           * @since 1.5.0
 271           *
 272           * @param string $slug Activation slug.
 273           */
 274          return apply_filters( 'bp_get_activate_slug', $slug );
 275      }
 276  
 277  /**
 278   * Initialize the members loop.
 279   *
 280   * Based on the $args passed, bp_has_members() populates the $members_template
 281   * global, enabling the use of BuddyPress templates and template functions to
 282   * display a list of members.
 283   *
 284   * @since 1.2.0
 285   * @since 7.0.0 Added `xprofile_query` parameter. Added `user_ids` parameter.
 286   *
 287   * @global object $members_template {@link BP_Members_Template}
 288   *
 289   * @param array|string $args {
 290   *     Arguments for limiting the contents of the members loop. Most arguments
 291   *     are in the same format as {@link BP_User_Query}. However, because
 292   *     the format of the arguments accepted here differs in a number of ways,
 293   *     and because bp_has_members() determines some default arguments in a
 294   *     dynamic fashion, we list all accepted arguments here as well.
 295   *
 296   *     Arguments can be passed as an associative array, or as a URL query
 297   *     string (eg, 'user_id=4&per_page=3').
 298   *
 299   *     @type int                   $type                Sort order. Accepts 'active', 'random', 'newest', 'popular',
 300   *                                                      'online', 'alphabetical'. Default: 'active'.
 301   *     @type int|bool              $page                Page of results to display. Default: 1.
 302   *     @type int|bool              $per_page            Number of results per page. Default: 20.
 303   *     @type int|bool              $max                 Maximum number of results to return. Default: false (unlimited).
 304   *     @type string                $page_arg            The string used as a query parameter in pagination links.
 305   *                                                      Default: 'bpage'.
 306   *     @type array|int|string|bool $include             Limit results by a list of user IDs. Accepts an array, a
 307   *                                                      single integer, a comma-separated list of IDs, or false (to
 308   *                                                      disable this limiting). Accepts 'active', 'alphabetical',
 309   *                                                      'newest', or 'random'. Default: false.
 310   *     @type array|int|string|bool $exclude             Exclude users from results by ID. Accepts an array, a single
 311   *                                                      integer, a comma-separated list of IDs, or false (to disable
 312   *                                                      this limiting). Default: false.
 313   *     @type array|string|bool     $user_ids            An array or comma-separated list of IDs, or false (to
 314   *                                                      disable this limiting). Default: false.
 315   *     @type int                   $user_id             If provided, results are limited to the friends of the specified
 316   *                                                      user. When on a user's Friends page, defaults to the ID of the
 317   *                                                      displayed user. Otherwise defaults to 0.
 318   *     @type string|array          $member_type         Array or comma-separated list of member types to limit
 319   *                                                      results to.
 320   *     @type string|array          $member_type__in     Array or comma-separated list of member types to limit
 321   *                                                      results to.
 322   *     @type string|array          $member_type__not_in Array or comma-separated list of member types to exclude
 323   *                                                      from results.
 324   *     @type string                $search_terms        Limit results by a search term. Default: value of
 325   *                                                      `$_REQUEST['members_search']` or `$_REQUEST['s']`, if present.
 326   *                                                      Otherwise false.
 327   *     @type string                $meta_key            Limit results by the presence of a usermeta key.
 328   *                                                      Default: false.
 329   *     @type mixed                 $meta_value          When used with meta_key, limits results by the a matching
 330   *                                                      usermeta value. Default: false.
 331   *     @type array                 $xprofile_query      Filter results by xprofile data. Requires the xprofile
 332   *                                                      component. See {@see BP_XProfile_Query} for details.
 333   *     @type bool                  $populate_extras     Whether to fetch optional data, such as friend counts.
 334   *                                                      Default: true.
 335   * }
 336   * @return bool Returns true when blogs are found, otherwise false.
 337   */
 338  function bp_has_members( $args = '' ) {
 339      global $members_template;
 340  
 341      // Default user ID.
 342      $user_id = 0;
 343  
 344      // User filtering.
 345      if ( bp_is_user_friends() && ! bp_is_user_friend_requests() ) {
 346          $user_id = bp_displayed_user_id();
 347      }
 348  
 349      $member_type = bp_get_current_member_type();
 350      if ( ! $member_type && ! empty( $_GET['member_type'] ) ) {
 351          if ( is_array( $_GET['member_type'] ) ) {
 352              $member_type = $_GET['member_type'];
 353          } else {
 354              // Can be a comma-separated list.
 355              $member_type = explode( ',', $_GET['member_type'] );
 356          }
 357      }
 358  
 359      $search_terms_default = null;
 360      $search_query_arg = bp_core_get_component_search_query_arg( 'members' );
 361      if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
 362          $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] );
 363      }
 364  
 365      // Type: active ( default ) | random | newest | popular | online | alphabetical.
 366      $r = bp_parse_args( $args, array(
 367          'type'                => 'active',
 368          'page'                => 1,
 369          'per_page'            => 20,
 370          'max'                 => false,
 371  
 372          'page_arg'            => 'upage',  // See https://buddypress.trac.wordpress.org/ticket/3679.
 373  
 374          'include'             => false,    // Pass a user_id or a list (comma-separated or array) of user_ids to only show these users.
 375          'exclude'             => false,    // Pass a user_id or a list (comma-separated or array) of user_ids to exclude these users.
 376          'user_ids'            => false,
 377  
 378          'user_id'             => $user_id, // Pass a user_id to only show friends of this user.
 379          'member_type'         => $member_type,
 380          'member_type__in'     => '',
 381          'member_type__not_in' => '',
 382          'search_terms'        => $search_terms_default,
 383  
 384          'meta_key'            => false,    // Only return users with this usermeta.
 385          'meta_value'          => false,    // Only return users where the usermeta value matches. Requires meta_key.
 386  
 387          'xprofile_query'      => false,
 388          'populate_extras'     => true      // Fetch usermeta? Friend count, last active etc.
 389      ), 'has_members' );
 390  
 391      // Pass a filter if ?s= is set.
 392      if ( is_null( $r['search_terms'] ) ) {
 393          if ( !empty( $_REQUEST['s'] ) ) {
 394              $r['search_terms'] = $_REQUEST['s'];
 395          } else {
 396              $r['search_terms'] = false;
 397          }
 398      }
 399  
 400      // Set per_page to max if max is larger than per_page.
 401      if ( !empty( $r['max'] ) && ( $r['per_page'] > $r['max'] ) ) {
 402          $r['per_page'] = $r['max'];
 403      }
 404  
 405      // Query for members and populate $members_template global.
 406      $members_template = new BP_Core_Members_Template( $r );
 407  
 408      /**
 409       * Filters whether or not BuddyPress has members to iterate over.
 410       *
 411       * @since 1.2.4
 412       * @since 2.6.0 Added the `$r` parameter
 413       *
 414       * @param bool  $value            Whether or not there are members to iterate over.
 415       * @param array $members_template Populated $members_template global.
 416       * @param array $r                Array of arguments passed into the BP_Core_Members_Template class.
 417       */
 418      return apply_filters( 'bp_has_members', $members_template->has_members(), $members_template, $r );
 419  }
 420  
 421  /**
 422   * Set up the current member inside the loop.
 423   *
 424   * @since 1.2.0
 425   *
 426   * @return object
 427   */
 428  function bp_the_member() {
 429      global $members_template;
 430      return $members_template->the_member();
 431  }
 432  
 433  /**
 434   * Check whether there are more members to iterate over.
 435   *
 436   * @since 1.2.0
 437   *
 438   * @return bool
 439   */
 440  function bp_members() {
 441      global $members_template;
 442      return $members_template->members();
 443  }
 444  
 445  /**
 446   * Output the members pagination count.
 447   *
 448   * @since 1.2.0
 449   */
 450  function bp_members_pagination_count() {
 451      echo bp_get_members_pagination_count();
 452  }
 453      /**
 454       * Generate the members pagination count.
 455       *
 456       * @since 1.5.0
 457       *
 458       * @return string
 459       */
 460  	function bp_get_members_pagination_count() {
 461          global $members_template;
 462  
 463          if ( empty( $members_template->type ) )
 464              $members_template->type = '';
 465  
 466          $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
 467          $from_num  = bp_core_number_format( $start_num );
 468          $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 ) );
 469          $total     = bp_core_number_format( $members_template->total_member_count );
 470  
 471          if ( 'active' == $members_template->type ) {
 472              if ( 1 == $members_template->total_member_count ) {
 473                  $pag = __( 'Viewing 1 active member', 'buddypress' );
 474              } else {
 475                  /* translators: 1: active member from number. 2: active member to number. 3: total active members. */
 476                  $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 );
 477              }
 478          } elseif ( 'popular' == $members_template->type ) {
 479              if ( 1 == $members_template->total_member_count ) {
 480                  $pag = __( 'Viewing 1 member with friends', 'buddypress' );
 481              } else {
 482                  /* translators: 1: member with friends from number. 2: member with friends to number. 3: total members with friends. */
 483                  $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 );
 484              }
 485          } elseif ( 'online' == $members_template->type ) {
 486              if ( 1 == $members_template->total_member_count ) {
 487                  $pag = __( 'Viewing 1 online member', 'buddypress' );
 488              } else {
 489                  /* translators: 1: online member from number. 2: online member to number. 3: total online members. */
 490                  $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 );
 491              }
 492          } else {
 493              if ( 1 == $members_template->total_member_count ) {
 494                  $pag = __( 'Viewing 1 member', 'buddypress' );
 495              } else {
 496                  /* translators: 1: member from number. 2: member to number. 3: total members. */
 497                  $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 );
 498              }
 499          }
 500  
 501          /**
 502           * Filters the members pagination count.
 503           *
 504           * @since 1.5.0
 505           *
 506           * @param string $pag Pagination count string.
 507           */
 508          return apply_filters( 'bp_members_pagination_count', $pag );
 509      }
 510  
 511  /**
 512   * Output the members pagination links.
 513   *
 514   * @since 1.2.0
 515   */
 516  function bp_members_pagination_links() {
 517      echo bp_get_members_pagination_links();
 518  }
 519      /**
 520       * Fetch the members pagination links.
 521       *
 522       * @since 1.2.0
 523       *
 524       * @return string
 525       */
 526  	function bp_get_members_pagination_links() {
 527          global $members_template;
 528  
 529          /**
 530           * Filters the members pagination link.
 531           *
 532           * @since 1.2.0
 533           *
 534           * @param string $pag_links HTML markup for pagination links.
 535           */
 536          return apply_filters( 'bp_get_members_pagination_links', $members_template->pag_links );
 537      }
 538  
 539  /**
 540   * Output the ID of the current member in the loop.
 541   *
 542   * @since 1.2.0
 543   *
 544   */
 545  function bp_member_user_id() {
 546      echo bp_get_member_user_id();
 547  }
 548      /**
 549       * Get the ID of the current member in the loop.
 550       *
 551       * @since 1.2.0
 552       *
 553       * @return string Member ID.
 554       */
 555  	function bp_get_member_user_id() {
 556          global $members_template;
 557          $member_id = isset( $members_template->member->id ) ? (int) $members_template->member->id : false;
 558  
 559          /**
 560           * Filters the ID of the current member in the loop.
 561           *
 562           * @since 1.2.0
 563           *
 564           * @param int $member_id ID of the member being iterated over.
 565           */
 566          return apply_filters( 'bp_get_member_user_id', $member_id );
 567      }
 568  
 569  /**
 570   * Output the row class of the current member in the loop.
 571   *
 572   * @since 1.7.0
 573   *
 574   * @param array $classes Array of custom classes.
 575   */
 576  function bp_member_class( $classes = array() ) {
 577      echo bp_get_member_class( $classes );
 578  }
 579      /**
 580       * Return the row class of the current member in the loop.
 581       *
 582       * @since 1.7.0
 583       *
 584       * @param array $classes Array of custom classes.
 585       * @return string Row class of the member
 586       */
 587  	function bp_get_member_class( $classes = array() ) {
 588          global $members_template;
 589  
 590          // Add even/odd classes, but only if there's more than 1 member.
 591          if ( $members_template->member_count > 1 ) {
 592              $pos_in_loop = (int) $members_template->current_member;
 593              $classes[]   = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
 594  
 595              // If we've only one member in the loop, don't bother with odd and even.
 596          } else {
 597              $classes[] = 'bp-single-member';
 598          }
 599  
 600          // Maybe add 'is-online' class.
 601          if ( ! empty( $members_template->member->last_activity ) ) {
 602  
 603              // Calculate some times.
 604              $current_time  = bp_core_current_time( true, 'timestamp' );
 605              $last_activity = strtotime( $members_template->member->last_activity );
 606              $still_online  = strtotime( '+5 minutes', $last_activity );
 607  
 608              // Has the user been active recently?
 609              if ( $current_time <= $still_online ) {
 610                  $classes[] = 'is-online';
 611              }
 612          }
 613  
 614          // Add current user class.
 615          if ( bp_loggedin_user_id() === (int) $members_template->member->id ) {
 616              $classes[] = 'is-current-user';
 617          }
 618  
 619          // Add current user member types.
 620          if ( $member_types = bp_get_member_type( $members_template->member->id, false ) ) {
 621              foreach ( $member_types as $member_type ) {
 622                  $classes[] = sprintf( 'member-type-%s', esc_attr( $member_type ) );
 623              }
 624          }
 625  
 626          /**
 627           * Filters the determined classes to add to the HTML element.
 628           *
 629           * @since 1.7.0
 630           *
 631           * @param string $classes Classes to be added to the HTML element.
 632           */
 633          $classes = apply_filters( 'bp_get_member_class', $classes );
 634          $classes = array_merge( $classes, array() );
 635          $retval  = 'class="' . join( ' ', $classes ) . '"';
 636  
 637          return $retval;
 638      }
 639  
 640  /**
 641   * Output nicename of current member in the loop.
 642   *
 643   * @since 1.2.5
 644   */
 645  function bp_member_user_nicename() {
 646      echo bp_get_member_user_nicename();
 647  }
 648      /**
 649       * Get the nicename of the current member in the loop.
 650       *
 651       * @since 1.2.5
 652       *
 653       * @return string Members nicename.
 654       */
 655  	function bp_get_member_user_nicename() {
 656          global $members_template;
 657  
 658          /**
 659           * Filters the nicename of the current member in the loop.
 660           *
 661           * @since 1.2.5
 662           *
 663           * @param string $user_nicename Nicename for the current member.
 664           */
 665          return apply_filters( 'bp_get_member_user_nicename', $members_template->member->user_nicename );
 666      }
 667  
 668  /**
 669   * Output login for current member in the loop.
 670   *
 671   * @since 1.2.5
 672   */
 673  function bp_member_user_login() {
 674      echo bp_get_member_user_login();
 675  }
 676      /**
 677       * Get the login of the current member in the loop.
 678       *
 679       * @since 1.2.5
 680       *
 681       * @return string Member's login.
 682       */
 683  	function bp_get_member_user_login() {
 684          global $members_template;
 685  
 686          /**
 687           * Filters the login of the current member in the loop.
 688           *
 689           * @since 1.2.5
 690           *
 691           * @param string $user_login Login for the current member.
 692           */
 693          return apply_filters( 'bp_get_member_user_login', $members_template->member->user_login );
 694      }
 695  
 696  /**
 697   * Output the email address for the current member in the loop.
 698   *
 699   * @since 1.2.5
 700   */
 701  function bp_member_user_email() {
 702      echo bp_get_member_user_email();
 703  }
 704      /**
 705       * Get the email address of the current member in the loop.
 706       *
 707       * @since 1.2.5
 708       *
 709       * @return string Member's email address.
 710       */
 711  	function bp_get_member_user_email() {
 712          global $members_template;
 713  
 714          /**
 715           * Filters the email address of the current member in the loop.
 716           *
 717           * @since 1.2.5
 718           *
 719           * @param string $user_email Email address for the current member.
 720           */
 721          return apply_filters( 'bp_get_member_user_email', $members_template->member->user_email );
 722      }
 723  
 724  /**
 725   * Check whether the current member in the loop is the logged-in user.
 726   *
 727   * @since 1.2.5
 728   *
 729   * @return bool
 730   */
 731  function bp_member_is_loggedin_user() {
 732      global $members_template;
 733  
 734      /**
 735       * Filters whether the current member in the loop is the logged-in user.
 736       *
 737       * @since 1.2.5
 738       *
 739       * @param bool $value Whether current member in the loop is logged in.
 740       */
 741      return apply_filters( 'bp_member_is_loggedin_user', bp_loggedin_user_id() == $members_template->member->id ? true : false );
 742  }
 743  
 744  /**
 745   * Output a member's avatar.
 746   *
 747   * @since 1.2.0
 748   *
 749   * @see bp_get_member_avatar() for description of arguments.
 750   *
 751   * @param array|string $args See {@link bp_get_member_avatar()}.
 752   */
 753  function bp_member_avatar( $args = '' ) {
 754  
 755      /**
 756       * Filters a members avatar.
 757       *
 758       * @since 1.2.0
 759       * @since 2.6.0 Added the `$args` parameter.
 760       *
 761       * @param string       $value Formatted HTML <img> element, or raw avatar URL based on $html arg.
 762       * @param array|string $args  See {@link bp_get_member_avatar()}.
 763       */
 764      echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ), $args );
 765  }
 766      /**
 767       * Get a member's avatar.
 768       *
 769       * @since 1.2.0
 770       *
 771       * @see bp_core_fetch_avatar() For a description of arguments and
 772       *      return values.
 773       *
 774       * @param array|string $args  {
 775       *     Arguments are listed here with an explanation of their defaults.
 776       *     For more information about the arguments, see
 777       *     {@link bp_core_fetch_avatar()}.
 778       *     @type string   $alt     Default: 'Profile picture of [user name]'.
 779       *     @type string   $class   Default: 'avatar'.
 780       *     @type string   $type    Default: 'thumb'.
 781       *     @type int|bool $width   Default: false.
 782       *     @type int|bool $height  Default: false.
 783       *     @type bool     $id      Currently unused.
 784       *     @type bool     $no_grav Default: false.
 785       * }
 786       * @return string User avatar string.
 787       */
 788  	function bp_get_member_avatar( $args = '' ) {
 789          global $members_template;
 790  
 791          $fullname = !empty( $members_template->member->fullname ) ? $members_template->member->fullname : $members_template->member->display_name;
 792  
 793          $defaults = array(
 794              'type'   => 'thumb',
 795              'width'  => false,
 796              'height' => false,
 797              'class'  => 'avatar',
 798              'id'     => false,
 799              'alt'    => sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname )
 800          );
 801  
 802          $r = wp_parse_args( $args, $defaults );
 803          extract( $r, EXTR_SKIP );
 804  
 805          /**
 806           * Filters a members avatar.
 807           *
 808           * @since 1.2.0
 809           * @since 2.6.0 Added the `$r` parameter.
 810           *
 811           * @param string $value Formatted HTML <img> element, or raw avatar URL based on $html arg.
 812           * @param array  $r     Array of parsed arguments. See {@link bp_get_member_avatar()}.
 813           */
 814          return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ), $r );
 815      }
 816  
 817  /**
 818   * Output the permalink for the current member in the loop.
 819   *
 820   * @since 1.2.0
 821   */
 822  function bp_member_permalink() {
 823      echo esc_url( bp_get_member_permalink() );
 824  }
 825      /**
 826       * Get the permalink for the current member in the loop.
 827       *
 828       * @since 1.2.0
 829       *
 830       * @return string
 831       */
 832  	function bp_get_member_permalink() {
 833          global $members_template;
 834  
 835          /**
 836           * Filters the permalink for the current member in the loop.
 837           *
 838           * @since 1.2.0
 839           *
 840           * @param string $value Permalink for the current member in the loop.
 841           */
 842          return apply_filters( 'bp_get_member_permalink', bp_core_get_user_domain( $members_template->member->id, $members_template->member->user_nicename, $members_template->member->user_login ) );
 843      }
 844  
 845      /**
 846       * Alias of {@link bp_member_permalink()}.
 847       *
 848       * @since 1.2.0
 849       */
 850  	function bp_member_link() { echo esc_url( bp_get_member_permalink() ); }
 851  
 852      /**
 853       * Alias of {@link bp_get_member_permalink()}.
 854       *
 855       * @since 1.2.0
 856       */
 857  	function bp_get_member_link() { return bp_get_member_permalink(); }
 858  
 859  /**
 860   * Output display name of current member in the loop.
 861   *
 862   * @since 1.2.0
 863   */
 864  function bp_member_name() {
 865  
 866      /**
 867       * Filters the display name of current member in the loop.
 868       *
 869       * @since 1.2.0
 870       *
 871       * @param string $value Display name for current member.
 872       */
 873      echo apply_filters( 'bp_member_name', bp_get_member_name() );
 874  }
 875      /**
 876       * Get the display name of the current member in the loop.
 877       *
 878       * Full name is, by default, pulled from xprofile's Full Name field.
 879       * When this field is empty, we try to get an alternative name from the
 880       * WP users table, in the following order of preference: display_name,
 881       * user_nicename, user_login.
 882       *
 883       * @since 1.2.0
 884       *
 885       * @return string The user's fullname for display.
 886       */
 887  	function bp_get_member_name() {
 888          global $members_template;
 889  
 890          // Generally, this only fires when xprofile is disabled.
 891          if ( empty( $members_template->member->fullname ) ) {
 892              // Our order of preference for alternative fullnames.
 893              $name_stack = array(
 894                  'display_name',
 895                  'user_nicename',
 896                  'user_login'
 897              );
 898  
 899              foreach ( $name_stack as $source ) {
 900                  if ( !empty( $members_template->member->{$source} ) ) {
 901                      // When a value is found, set it as fullname and be done with it.
 902                      $members_template->member->fullname = $members_template->member->{$source};
 903                      break;
 904                  }
 905              }
 906          }
 907  
 908          /**
 909           * Filters the display name of current member in the loop.
 910           *
 911           * @since 1.2.0
 912           *
 913           * @param string $fullname Display name for current member.
 914           */
 915          return apply_filters( 'bp_get_member_name', $members_template->member->fullname );
 916      }
 917      add_filter( 'bp_get_member_name', 'wp_filter_kses' );
 918      add_filter( 'bp_get_member_name', 'stripslashes'   );
 919      add_filter( 'bp_get_member_name', 'strip_tags'     );
 920      add_filter( 'bp_get_member_name', 'esc_html'       );
 921  
 922  /**
 923   * Output the current member's last active time.
 924   *
 925   * @since 1.2.0
 926   *
 927   * @param array $args {@see bp_get_member_last_active()}.
 928   */
 929  function bp_member_last_active( $args = array() ) {
 930      echo bp_get_member_last_active( $args );
 931  }
 932      /**
 933       * Return the current member's last active time.
 934       *
 935       * @since 1.2.0
 936       * @since 2.7.0 Added 'relative' as a parameter to $args.
 937       *
 938       * @param array $args {
 939       *     Array of optional arguments.
 940       *     @type mixed $active_format If true, formatted "active 5 minutes ago". If false, formatted "5 minutes
 941       *                                ago". If string, should be sprintf'able like 'last seen %s ago'.
 942       *     @type bool  $relative      If true, will return relative time "5 minutes ago". If false, will return
 943       *                                date from database. Default: true.
 944       * }
 945       * @return string
 946       */
 947  	function bp_get_member_last_active( $args = array() ) {
 948          global $members_template;
 949  
 950          // Parse the activity format.
 951          $r = bp_parse_args( $args, array(
 952              'active_format' => true,
 953              'relative'      => true,
 954          ) );
 955  
 956          // Backwards compatibility for anyone forcing a 'true' active_format.
 957          if ( true === $r['active_format'] ) {
 958              /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */
 959              $r['active_format'] = __( 'Active %s', 'buddypress' );
 960          }
 961  
 962          // Member has logged in at least one time.
 963          if ( isset( $members_template->member->last_activity ) ) {
 964              // We do not want relative time, so return now.
 965              // @todo Should the 'bp_member_last_active' filter be applied here?
 966              if ( ! $r['relative'] ) {
 967                  return esc_attr( $members_template->member->last_activity );
 968              }
 969  
 970              // Backwards compatibility for pre 1.5 'ago' strings.
 971              $last_activity = ! empty( $r['active_format'] )
 972                  ? bp_core_get_last_activity( $members_template->member->last_activity, $r['active_format'] )
 973                  : bp_core_time_since( $members_template->member->last_activity );
 974  
 975          // Member has never logged in or been active.
 976          } else {
 977              $last_activity = __( 'Never active', 'buddypress' );
 978          }
 979  
 980          /**
 981           * Filters the current members last active time.
 982           *
 983           * @since 1.2.0
 984           *
 985           * @param string $last_activity Formatted time since last activity.
 986           * @param array  $r             Array of parsed arguments for query.
 987           */
 988          return apply_filters( 'bp_member_last_active', $last_activity, $r );
 989      }
 990  
 991  /**
 992   * Output the latest update of the current member in the loop.
 993   *
 994   * @since 1.2.0
 995   *
 996   * @param array|string $args {@see bp_get_member_latest_update()}.
 997   */
 998  function bp_member_latest_update( $args = '' ) {
 999      echo bp_get_member_latest_update( $args );
1000  }
1001      /**
1002       * Get the latest update from the current member in the loop.
1003       *
1004       * @since 1.2.0
1005       *
1006       * @param array|string $args {
1007       *     Array of optional arguments.
1008       *     @type int  $length    Truncation length. Default: 225.
1009       *     @type bool $view_link Whether to provide a 'View' link for
1010       *                           truncated entries. Default: false.
1011       * }
1012       * @return string
1013       */
1014  	function bp_get_member_latest_update( $args = '' ) {
1015          global $members_template;
1016  
1017          $defaults = array(
1018              'length'    => 225,
1019              'view_link' => true
1020          );
1021  
1022          $r = wp_parse_args( $args, $defaults );
1023          extract( $r );
1024  
1025          if ( !bp_is_active( 'activity' ) || empty( $members_template->member->latest_update ) || !$update = maybe_unserialize( $members_template->member->latest_update ) )
1026              return false;
1027  
1028          /**
1029           * Filters the excerpt of the latest update for current member in the loop.
1030           *
1031           * @since 1.2.5
1032           * @since 2.6.0 Added the `$r` parameter.
1033           *
1034           * @param string $value Excerpt of the latest update for current member in the loop.
1035           * @param array  $r     Array of parsed arguments.
1036           */
1037          $update_content = apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], $length ) ) ), $r );
1038  
1039          /* translators: %s: the member latest activity update */
1040          $update_content = sprintf( _x( '- &quot;%s&quot;', 'member latest update in member directory', 'buddypress' ), $update_content );
1041  
1042          // If $view_link is true and the text returned by bp_create_excerpt() is different from the original text (ie it's
1043          // been truncated), add the "View" link.
1044          if ( $view_link && ( $update_content != $update['content'] ) ) {
1045              $view = __( 'View', 'buddypress' );
1046  
1047              $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_permalink( $update['id'] ) . '" rel="nofollow">' . $view . '</a></span>';
1048          }
1049  
1050          /**
1051           * Filters the latest update from the current member in the loop.
1052           *
1053           * @since 1.2.0
1054           * @since 2.6.0 Added the `$r` parameter.
1055           *
1056           * @param string $update_content Formatted latest update for current member.
1057           * @param array  $r              Array of parsed arguments.
1058           */
1059          return apply_filters( 'bp_get_member_latest_update', $update_content, $r );
1060      }
1061  
1062  /**
1063   * Output a piece of user profile data.
1064   *
1065   * @since 1.2.0
1066   *
1067   * @see bp_get_member_profile_data() for a description of params.
1068   *
1069   * @param array|string $args See {@link bp_get_member_profile_data()}.
1070   */
1071  function bp_member_profile_data( $args = '' ) {
1072      echo bp_get_member_profile_data( $args );
1073  }
1074      /**
1075       * Get a piece of user profile data.
1076       *
1077       * When used in a bp_has_members() loop, this function will attempt
1078       * to fetch profile data cached in the template global. It is also safe
1079       * to use outside of the loop.
1080       *
1081       * @since 1.2.0
1082       *
1083       * @param array|string $args {
1084       *     Array of config parameters.
1085       *     @type string $field   Name of the profile field.
1086       *     @type int    $user_id ID of the user whose data is being fetched.
1087       *                           Defaults to the current member in the loop, or if not
1088       *                           present, to the currently displayed user.
1089       * }
1090       * @return string|bool Profile data if found, otherwise false.
1091       */
1092  	function bp_get_member_profile_data( $args = '' ) {
1093          global $members_template;
1094  
1095          if ( ! bp_is_active( 'xprofile' ) ) {
1096              return false;
1097          }
1098  
1099          // Declare local variables.
1100          $data = false;
1101  
1102          // Guess at default $user_id.
1103          $default_user_id = 0;
1104          if ( ! empty( $members_template->member->id ) ) {
1105              $default_user_id = $members_template->member->id;
1106          } elseif ( bp_displayed_user_id() ) {
1107              $default_user_id = bp_displayed_user_id();
1108          }
1109  
1110          $defaults = array(
1111              'field'   => false,
1112              'user_id' => $default_user_id,
1113          );
1114  
1115          $r = wp_parse_args( $args, $defaults );
1116  
1117          // If we're in a members loop, get the data from the global.
1118          if ( ! empty( $members_template->member->profile_data ) ) {
1119              $profile_data = $members_template->member->profile_data;
1120          }
1121  
1122          // Otherwise query for the data.
1123          if ( empty( $profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) ) {
1124              $profile_data = BP_XProfile_ProfileData::get_all_for_user( $r['user_id'] );
1125          }
1126  
1127          // If we're in the members loop, but the profile data has not
1128          // been loaded into the global, cache it there for later use.
1129          if ( ! empty( $members_template->member ) && empty( $members_template->member->profile_data ) ) {
1130              $members_template->member->profile_data = $profile_data;
1131          }
1132  
1133          // Get the data for the specific field requested.
1134          if ( ! empty( $profile_data ) && ! empty( $profile_data[ $r['field'] ]['field_type'] ) && ! empty( $profile_data[ $r['field'] ]['field_data'] ) ) {
1135              $data = xprofile_format_profile_field( $profile_data[ $r['field'] ]['field_type'], $profile_data[ $r['field'] ]['field_data'] );
1136          }
1137  
1138          /**
1139           * Filters resulting piece of member profile data.
1140           *
1141           * @since 1.2.0
1142           * @since 2.6.0 Added the `$r` parameter.
1143           *
1144           * @param string|bool $data Profile data if found, otherwise false.
1145           * @param array       $r    Array of parsed arguments.
1146           */
1147          $data = apply_filters( 'bp_get_member_profile_data', $data, $r );
1148  
1149          /**
1150           * Filters the resulting piece of member profile data by field type.
1151           *
1152           * This is a dynamic filter based on field type of the current field requested.
1153           *
1154           * @since 2.7.0
1155           *
1156           * @param string|bool $data Profile data if found, otherwise false.
1157           * @param array       $r    Array of parsed arguments.
1158           */
1159          if ( ! empty( $profile_data[ $r['field'] ]['field_type'] ) ) {
1160              $data = apply_filters( 'bp_get_member_profile_data_' . $profile_data[ $r['field'] ]['field_type'], $data, $r );
1161          }
1162  
1163          return $data;
1164      }
1165  
1166  /**
1167   * Output the 'registered [x days ago]' string for the current member.
1168   *
1169   * @since 1.2.0
1170   * @since 2.7.0 Added $args as a parameter.
1171   *
1172   * @param array $args Optional. {@see bp_get_member_registered()}
1173   */
1174  function bp_member_registered( $args = array() ) {
1175      echo bp_get_member_registered( $args );
1176  }
1177      /**
1178       * Get the 'registered [x days ago]' string for the current member.
1179       *
1180       * @since 1.2.0
1181       * @since 2.7.0 Added $args as a parameter.
1182       *
1183       * @param array $args {
1184       *     Array of optional parameters.
1185       *
1186       *     @type bool $relative Optional. If true, returns relative registered date. eg. registered 5 months ago.
1187       *                          If false, returns registered date value from database.
1188       * }
1189       *
1190       * @return string
1191       */
1192  	function bp_get_member_registered( $args = array() ) {
1193          global $members_template;
1194  
1195          $r = wp_parse_args( $args, array(
1196              'relative' => true,
1197          ) );
1198  
1199          // We do not want relative time, so return now.
1200          // @todo Should the 'bp_member_registered' filter be applied here?
1201          if ( ! $r['relative'] ) {
1202              return esc_attr( $members_template->member->user_registered );
1203          }
1204  
1205          /* translators: %s: last activity timestamp (e.g. "active 1 hour ago") */
1206          $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' ) ) );
1207  
1208          /**
1209           * Filters the 'registered [x days ago]' string for the current member.
1210           *
1211           * @since 2.1.0
1212           *
1213           * @param string $registered The 'registered [x days ago]' string.
1214           */
1215          return apply_filters( 'bp_member_registered', $registered );
1216      }
1217  
1218  /**
1219   * Output a random piece of profile data for the current member in the loop.
1220   *
1221   * @since 1.2.0
1222   */
1223  function bp_member_random_profile_data() {
1224      global $members_template;
1225  
1226      if ( bp_is_active( 'xprofile' ) ) { ?>
1227          <?php $random_data = xprofile_get_random_profile_data( $members_template->member->id, true ); ?>
1228              <strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong>
1229              <?php echo wp_filter_kses( $random_data[0]->value ) ?>
1230      <?php }
1231  }
1232  
1233  /**
1234   * Output hidden input for preserving member search params on form submit.
1235   *
1236   * @since 1.2.0
1237   */
1238  function bp_member_hidden_fields() {
1239      $query_arg = bp_core_get_component_search_query_arg( 'members' );
1240  
1241      if ( isset( $_REQUEST[ $query_arg ] ) ) {
1242          echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST[ $query_arg ] ) . '" name="search_terms" />';
1243      }
1244  
1245      if ( isset( $_REQUEST['letter'] ) ) {
1246          echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
1247      }
1248  
1249      if ( isset( $_REQUEST['members_search'] ) ) {
1250          echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['members_search'] ) . '" name="search_terms" />';
1251      }
1252  }
1253  
1254  /**
1255   * Output the Members directory search form.
1256   *
1257   * @since 1.0.0
1258   */
1259  function bp_directory_members_search_form() {
1260  
1261      $query_arg = bp_core_get_component_search_query_arg( 'members' );
1262  
1263      if ( ! empty( $_REQUEST[ $query_arg ] ) ) {
1264          $search_value = stripslashes( $_REQUEST[ $query_arg ] );
1265      } else {
1266          $search_value = bp_get_search_default_text( 'members' );
1267      }
1268  
1269      $search_form_html = '<form action="" method="get" id="search-members-form">
1270          <label for="members_search"><input type="text" name="' . esc_attr( $query_arg ) . '" id="members_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
1271          <input type="submit" id="members_search_submit" name="members_search_submit" value="' . __( 'Search', 'buddypress' ) . '" />
1272      </form>';
1273  
1274      /**
1275       * Filters the Members component search form.
1276       *
1277       * @since 1.9.0
1278       *
1279       * @param string $search_form_html HTML markup for the member search form.
1280       */
1281      echo apply_filters( 'bp_directory_members_search_form', $search_form_html );
1282  }
1283  
1284  /**
1285   * Output the total member count.
1286   *
1287   * @since 1.2.0
1288   */
1289  function bp_total_site_member_count() {
1290      echo bp_get_total_site_member_count();
1291  }
1292      /**
1293       * Get the total site member count.
1294       *
1295       * @since 1.2.0
1296       *
1297       * @return int
1298       */
1299  	function bp_get_total_site_member_count() {
1300  
1301          /**
1302           * Filters the total site member count.
1303           *
1304           * @since 1.2.0
1305           *
1306           * @param int $value Number-formatted total site member count.
1307           */
1308          return apply_filters( 'bp_get_total_site_member_count', bp_core_number_format( bp_core_get_total_member_count() ) );
1309      }
1310  
1311  /** Navigation and other misc template tags ***********************************/
1312  
1313  /**
1314   * Render the navigation markup for the logged-in user.
1315   *
1316   * Each component adds to this navigation array within its own
1317   * [component_name]setup_nav() function.
1318   *
1319   * This navigation array is the top level navigation, so it contains items such as:
1320   *      [Blog, Profile, Messages, Groups, Friends] ...
1321   *
1322   * The function will also analyze the current component the user is in, to
1323   * determine whether or not to highlight a particular nav item.
1324   *
1325   * @since 1.1.0
1326   *
1327   * @todo Move to a back-compat file?
1328   * @deprecated Does not seem to be called anywhere in BP core.
1329   */
1330  function bp_get_loggedin_user_nav() {
1331      $bp = buddypress();
1332  
1333      // Loop through each navigation item.
1334      foreach ( (array) $bp->members->nav->get_primary() as $nav_item ) {
1335  
1336          $selected = '';
1337  
1338          // If the current component matches the nav item id, then add a highlight CSS class.
1339          if ( ! bp_is_directory() && ! empty( $bp->active_components[ bp_current_component() ] ) && $bp->active_components[ bp_current_component() ] == $nav_item->css_id ) {
1340              $selected = ' class="current selected"';
1341          }
1342  
1343          // If we are viewing another person (current_userid does not equal
1344          // loggedin_user->id then check to see if the two users are friends.
1345          // if they are, add a highlight CSS class to the friends nav item
1346          // if it exists.
1347          if ( !bp_is_my_profile() && bp_displayed_user_id() ) {
1348              $selected = '';
1349  
1350              if ( bp_is_active( 'friends' ) ) {
1351                  if ( $nav_item->css_id == $bp->friends->id ) {
1352                      if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) ) {
1353                          $selected = ' class="current selected"';
1354                      }
1355                  }
1356              }
1357          }
1358  
1359          // Echo out the final list item.
1360          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 ) );
1361      }
1362  
1363      // Always add a log out list item to the end of the navigation.
1364      $logout_link = '<li><a id="wp-logout" href="' .  wp_logout_url( bp_get_root_domain() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
1365  
1366      echo apply_filters( 'bp_logout_nav_link', $logout_link );
1367  }
1368  
1369  /**
1370   * Output the contents of the current user's home page.
1371   *
1372   * @since 2.6.0
1373   */
1374  function bp_displayed_user_front_template_part() {
1375      $located = bp_displayed_user_get_front_template();
1376  
1377      if ( false !== $located ) {
1378          $slug = str_replace( '.php', '', $located );
1379          $name = null;
1380  
1381          /**
1382           * Let plugins adding an action to bp_get_template_part get it from here
1383           *
1384           * @param string $slug Template part slug requested.
1385           * @param string $name Template part name requested.
1386           */
1387          do_action( 'get_template_part_' . $slug, $slug, $name );
1388  
1389          load_template( $located, true );
1390      }
1391  
1392      return $located;
1393  }
1394  
1395  /**
1396   * Locate a custom user front template if it exists.
1397   *
1398   * @since 2.6.0
1399   *
1400   * @param  object|null $displayed_user Optional. Falls back to current user if not passed.
1401   * @return string|bool                 Path to front template on success; boolean false on failure.
1402   */
1403  function bp_displayed_user_get_front_template( $displayed_user = null ) {
1404      if ( ! is_object( $displayed_user ) || empty( $displayed_user->id ) ) {
1405          $displayed_user = bp_get_displayed_user();
1406      }
1407  
1408      if ( ! isset( $displayed_user->id ) ) {
1409          return false;
1410      }
1411  
1412      if ( isset( $displayed_user->front_template ) ) {
1413          return $displayed_user->front_template;
1414      }
1415  
1416      // Init the hierarchy
1417      $template_names = array(
1418          'members/single/front-id-' . (int) $displayed_user->id . '.php',
1419          'members/single/front-nicename-' . sanitize_file_name( $displayed_user->userdata->user_nicename ) . '.php',
1420      );
1421  
1422      /**
1423       * Check for member types and add it to the hierarchy
1424       *
1425       * Make sure to register your member
1426       * type using the hook 'bp_register_member_types'
1427       */
1428      if ( bp_get_member_types() ) {
1429          $displayed_user_member_type = bp_get_member_type( $displayed_user->id );
1430          if ( ! $displayed_user_member_type ) {
1431              $displayed_user_member_type = 'none';
1432          }
1433  
1434          $template_names[] = 'members/single/front-member-type-' . sanitize_file_name( $displayed_user_member_type )   . '.php';
1435      }
1436  
1437      // Add The generic template to the end of the hierarchy
1438      $template_names[] = 'members/single/front.php';
1439  
1440      /**
1441       * Filters the hierarchy of user front templates corresponding to a specific user.
1442       *
1443       * @since 2.6.0
1444       *
1445       * @param array  $template_names Array of template paths.
1446       */
1447      return bp_locate_template( apply_filters( 'bp_displayed_user_get_front_template', $template_names ), false, true );
1448  }
1449  
1450  /**
1451   * Check if the displayed user has a custom front template.
1452   *
1453   * @since 2.6.0
1454   */
1455  function bp_displayed_user_has_front_template() {
1456      $displayed_user = bp_get_displayed_user();
1457  
1458      return ! empty( $displayed_user->front_template );
1459  }
1460  
1461  /**
1462   * Render the navigation markup for the displayed user.
1463   *
1464   * @since 1.1.0
1465   */
1466  function bp_get_displayed_user_nav() {
1467      $bp = buddypress();
1468  
1469      foreach ( $bp->members->nav->get_primary() as $user_nav_item ) {
1470          if ( empty( $user_nav_item->show_for_displayed_user ) && ! bp_is_my_profile() ) {
1471              continue;
1472          }
1473  
1474          $selected = '';
1475          if ( bp_is_current_component( $user_nav_item->slug ) ) {
1476              $selected = ' class="current selected"';
1477          }
1478  
1479          if ( bp_loggedin_user_domain() ) {
1480              $link = str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $user_nav_item->link );
1481          } else {
1482              $link = trailingslashit( bp_displayed_user_domain() . $user_nav_item->link );
1483          }
1484  
1485          /**
1486           * Filters the navigation markup for the displayed user.
1487           *
1488           * This is a dynamic filter that is dependent on the navigation tab component being rendered.
1489           *
1490           * @since 1.1.0
1491           *
1492           * @param string $value         Markup for the tab list item including link.
1493           * @param array  $user_nav_item Array holding parts used to construct tab list item.
1494           *                              Passed by reference.
1495           */
1496          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 ) );
1497      }
1498  }
1499  
1500  /** Cover image ***************************************************************/
1501  
1502  /**
1503   * Should we use the cover image header
1504   *
1505   * @since 2.4.0
1506   *
1507   * @return bool True if the displayed user has a cover image,
1508   *              False otherwise
1509   */
1510  function bp_displayed_user_use_cover_image_header() {
1511      return (bool) bp_is_active( 'members', 'cover_image' ) && ! bp_disable_cover_image_uploads();
1512  }
1513  
1514  /** Avatars *******************************************************************/
1515  
1516  /**
1517   * Output the logged-in user's avatar.
1518   *
1519   * @since 1.1.0
1520   *
1521   * @see bp_get_loggedin_user_avatar() for a description of params.
1522   *
1523   * @param array|string $args {@see bp_get_loggedin_user_avatar()}.
1524   */
1525  function bp_loggedin_user_avatar( $args = '' ) {
1526      echo bp_get_loggedin_user_avatar( $args );
1527  }
1528      /**
1529       * Get the logged-in user's avatar.
1530       *
1531       * @since 1.1.0
1532       *
1533       * @see bp_core_fetch_avatar() For a description of arguments and
1534       *      return values.
1535       *
1536       * @param array|string $args  {
1537       *     Arguments are listed here with an explanation of their defaults.
1538       *     For more information about the arguments, see
1539       *     {@link bp_core_fetch_avatar()}.
1540       *     @type string   $alt    Default: 'Profile picture of [user name]'.
1541       *     @type bool     $html   Default: true.
1542       *     @type string   $type   Default: 'thumb'.
1543       *     @type int|bool $width  Default: false.
1544       *     @type int|bool $height Default: false.
1545       * }
1546       * @return string User avatar string.
1547       */
1548  	function bp_get_loggedin_user_avatar( $args = '' ) {
1549  
1550          $r = wp_parse_args( $args, array(
1551              'item_id' => bp_loggedin_user_id(),
1552              'type'    => 'thumb',
1553              'width'   => false,
1554              'height'  => false,
1555              'html'    => true,
1556              'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_loggedin_user_fullname() )
1557          ) );
1558  
1559          /**
1560           * Filters the logged in user's avatar.
1561           *
1562           * @since 1.1.0
1563           *
1564           * @param string $value User avatar string.
1565           * @param array  $r     Array of parsed arguments.
1566           * @param array  $args  Array of initial arguments.
1567           */
1568          return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( $r ), $r, $args );
1569      }
1570  
1571  /**
1572   * Output the displayed user's avatar.
1573   *
1574   * @since 1.1.0
1575   *
1576   * @see bp_get_displayed_user_avatar() for a description of params.
1577   *
1578   * @param array|string $args {@see bp_get_displayed_user_avatar()}.
1579   */
1580  function bp_displayed_user_avatar( $args = '' ) {
1581      echo bp_get_displayed_user_avatar( $args );
1582  }
1583      /**
1584       * Get the displayed user's avatar.
1585       *
1586       * @since 1.1.0
1587       *
1588       * @see bp_core_fetch_avatar() For a description of arguments and
1589       *      return values.
1590       *
1591       * @param array|string $args  {
1592       *     Arguments are listed here with an explanation of their defaults.
1593       *     For more information about the arguments, see
1594       *     {@link bp_core_fetch_avatar()}.
1595       *     @type string   $alt    Default: 'Profile picture of [user name]'.
1596       *     @type bool     $html   Default: true.
1597       *     @type string   $type   Default: 'thumb'.
1598       *     @type int|bool $width  Default: false.
1599       *     @type int|bool $height Default: false.
1600       * }
1601       * @return string User avatar string.
1602       */
1603  	function bp_get_displayed_user_avatar( $args = '' ) {
1604  
1605          $r = wp_parse_args( $args, array(
1606              'item_id' => bp_displayed_user_id(),
1607              'type'    => 'thumb',
1608              'width'   => false,
1609              'height'  => false,
1610              'html'    => true,
1611              'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
1612          ) );
1613  
1614          /**
1615           * Filters the displayed user's avatar.
1616           *
1617           * @since 1.1.0
1618           *
1619           * @param string $value User avatar string.
1620           * @param array  $r     Array of parsed arguments.
1621           * @param array  $args  Array of initial arguments.
1622           */
1623          return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( $r ), $r, $args );
1624      }
1625  
1626  /**
1627   * Output the email address of the displayed user.
1628   *
1629   * @since 1.5.0
1630   */
1631  function bp_displayed_user_email() {
1632      echo bp_get_displayed_user_email();
1633  }
1634      /**
1635       * Get the email address of the displayed user.
1636       *
1637       * @since 1.5.0
1638       *
1639       * @return string
1640       */
1641  	function bp_get_displayed_user_email() {
1642          $bp = buddypress();
1643  
1644          // If displayed user exists, return email address.
1645          if ( isset( $bp->displayed_user->userdata->user_email ) )
1646              $retval = $bp->displayed_user->userdata->user_email;
1647          else
1648              $retval = '';
1649  
1650          /**
1651           * Filters the email address of the displayed user.
1652           *
1653           * @since 1.5.0
1654           *
1655           * @param string $retval Email address for displayed user.
1656           */
1657          return apply_filters( 'bp_get_displayed_user_email', esc_attr( $retval ) );
1658      }
1659  
1660  /**
1661   * Output the "active [x days ago]" string for a user.
1662   *
1663   * @since 1.0.0
1664   *
1665   * @see bp_get_last_activity() for a description of parameters.
1666   *
1667   * @param int $user_id See {@link bp_get_last_activity()}.
1668   */
1669  function bp_last_activity( $user_id = 0 ) {
1670  
1671      /**
1672       * Filters the 'active [x days ago]' string for a user.
1673       *
1674       * @since 1.0.0
1675       *
1676       * @param string $value Formatted 'active [x days ago]' string.
1677       */
1678      echo apply_filters( 'bp_last_activity', bp_get_last_activity( $user_id ) );
1679  }
1680      /**
1681       * Get the "active [x days ago]" string for a user.
1682       *
1683       * @since 1.5.0
1684       *
1685       * @param int $user_id ID of the user. Default: displayed user ID.
1686       * @return string
1687       */
1688  	function bp_get_last_activity( $user_id = 0 ) {
1689  
1690          if ( empty( $user_id ) ) {
1691              $user_id = bp_displayed_user_id();
1692          }
1693  
1694          /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */
1695          $last_activity = bp_core_get_last_activity( bp_get_user_last_activity( $user_id ), __( 'Active %s', 'buddypress') );
1696  
1697          /**
1698           * Filters the 'active [x days ago]' string for a user.
1699           *
1700           * @since 1.5.0
1701           * @since 2.6.0 Added the `$user_id` parameter.
1702           *
1703           * @param string $value   Formatted 'active [x days ago]' string.
1704           * @param int    $user_id ID of the user.
1705           */
1706          return apply_filters( 'bp_get_last_activity', $last_activity, $user_id );
1707      }
1708  
1709  /**
1710   * Output the calculated first name of the displayed or logged-in user.
1711   *
1712   * @since 1.2.0
1713   */
1714  function bp_user_firstname() {
1715      echo bp_get_user_firstname();
1716  }
1717      /**
1718       * Output the first name of a user.
1719       *
1720       * Simply takes all the characters before the first space in a name.
1721       *
1722       * @since 1.2.0
1723       *
1724       * @param string|bool $name Full name to use when generating first name.
1725       *                          Defaults to displayed user's first name, or to
1726       *                          logged-in user's first name if it's unavailable.
1727       * @return string
1728       */
1729  	function bp_get_user_firstname( $name = false ) {
1730  
1731          // Try to get displayed user.
1732          if ( empty( $name ) )
1733              $name = bp_get_displayed_user_fullname();
1734  
1735          // Fall back on logged in user.
1736          if ( empty( $name ) )
1737              $name = bp_get_loggedin_user_fullname();
1738  
1739          $fullname = (array) explode( ' ', $name );
1740  
1741          /**
1742           * Filters the first name of a user.
1743           *
1744           * @since 1.2.0
1745           *
1746           * @param string $value    First name of user.
1747           * @param string $fullname Full name of user.
1748           */
1749          return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname );
1750      }
1751  
1752  /**
1753   * Output the link for the logged-in user's profile.
1754   *
1755   * @since 1.2.4
1756   */
1757  function bp_loggedin_user_link() {
1758      echo esc_url( bp_get_loggedin_user_link() );
1759  }
1760      /**
1761       * Get the link for the logged-in user's profile.
1762       *
1763       * @since 1.0.0
1764       *
1765       * @return string
1766       */
1767  	function bp_get_loggedin_user_link() {
1768  
1769          /**
1770           * Filters the link for the logged-in user's profile.
1771           *
1772           * @since 1.2.4
1773           *
1774           * @param string $value Link for the logged-in user's profile.
1775           */
1776          return apply_filters( 'bp_get_loggedin_user_link', bp_loggedin_user_domain() );
1777      }
1778  
1779  /**
1780   * Output the link for the displayed user's profile.
1781   *
1782   * @since 1.2.4
1783   */
1784  function bp_displayed_user_link() {
1785      echo esc_url( bp_get_displayed_user_link() );
1786  }
1787      /**
1788       * Get the link for the displayed user's profile.
1789       *
1790       * @since 1.0.0
1791       *
1792       * @return string
1793       */
1794  	function bp_get_displayed_user_link() {
1795  
1796          /**
1797           * Filters the link for the displayed user's profile.
1798           *
1799           * @since 1.2.4
1800           *
1801           * @param string $value Link for the displayed user's profile.
1802           */
1803          return apply_filters( 'bp_get_displayed_user_link', bp_displayed_user_domain() );
1804      }
1805  
1806      /**
1807       * Alias of {@link bp_displayed_user_domain()}.
1808       *
1809       * @deprecated
1810       */
1811  	function bp_user_link() { bp_displayed_user_domain(); }
1812  
1813  /**
1814   * Alias of {@link bp_displayed_user_id()}.
1815   *
1816   * @since 1.0.0
1817   */
1818  function bp_current_user_id() { return bp_displayed_user_id(); }
1819  
1820  /**
1821   * Generate the link for the displayed user's profile.
1822   *
1823   * @since 1.0.0
1824   *
1825   * @return string
1826   */
1827  function bp_displayed_user_domain() {
1828      $bp = buddypress();
1829  
1830      /**
1831       * Filters the generated link for the displayed user's profile.
1832       *
1833       * @since 1.0.0
1834       *
1835       * @param string $value Generated link for the displayed user's profile.
1836       */
1837      return apply_filters( 'bp_displayed_user_domain', isset( $bp->displayed_user->domain ) ? $bp->displayed_user->domain : '' );
1838  }
1839  
1840  /**
1841   * Generate the link for the logged-in user's profile.
1842   *
1843   * @since 1.0.0
1844   *
1845   * @return string
1846   */
1847  function bp_loggedin_user_domain() {
1848      $bp = buddypress();
1849  
1850      /**
1851       * Filters the generated link for the logged-in user's profile.
1852       *
1853       * @since 1.0.0
1854       *
1855       * @param string $value Generated link for the logged-in user's profile.
1856       */
1857      return apply_filters( 'bp_loggedin_user_domain', isset( $bp->loggedin_user->domain ) ? $bp->loggedin_user->domain : '' );
1858  }
1859  
1860  /**
1861   * Output the displayed user's display name.
1862   *
1863   * @since 1.0.0
1864   */
1865  function bp_displayed_user_fullname() {
1866      echo bp_get_displayed_user_fullname();
1867  }
1868      /**
1869       * Get the displayed user's display name.
1870       *
1871       * @since 1.2.0
1872       *
1873       * @return string
1874       */
1875  	function bp_get_displayed_user_fullname() {
1876          $bp = buddypress();
1877  
1878          /**
1879           * Filters the displayed user's display name.
1880           *
1881           * @since 1.2.0
1882           *
1883           * @param string $value Displayed user's display name.
1884           */
1885          return apply_filters( 'bp_displayed_user_fullname', isset( $bp->displayed_user->fullname ) ? $bp->displayed_user->fullname : '' );
1886      }
1887  
1888      /**
1889       * Alias of {@link bp_get_displayed_user_fullname()}.
1890       *
1891       * @since 1.0.0
1892       */
1893  	function bp_user_fullname() { echo bp_get_displayed_user_fullname(); }
1894  
1895  
1896  /**
1897   * Output the logged-in user's display name.
1898   *
1899   * @since 1.0.0
1900   */
1901  function bp_loggedin_user_fullname() {
1902      echo bp_get_loggedin_user_fullname();
1903  }
1904      /**
1905       * Get the logged-in user's display name.
1906       *
1907       * @since 1.0.0
1908       *
1909       * @return string
1910       */
1911  	function bp_get_loggedin_user_fullname() {
1912          $bp = buddypress();
1913  
1914          /**
1915           * Filters the logged-in user's display name.
1916           *
1917           * @since 1.0.0
1918           *
1919           * @param string $value Logged-in user's display name.
1920           */
1921          return apply_filters( 'bp_get_loggedin_user_fullname', isset( $bp->loggedin_user->fullname ) ? $bp->loggedin_user->fullname : '' );
1922      }
1923  
1924  /**
1925   * Output the username of the displayed user.
1926   *
1927   * @since 1.2.0
1928   */
1929  function bp_displayed_user_username() {
1930      echo bp_get_displayed_user_username();
1931  }
1932      /**
1933       * Get the username of the displayed user.
1934       *
1935       * @since 1.2.0
1936       *
1937       * @return string
1938       */
1939  	function bp_get_displayed_user_username() {
1940          $bp = buddypress();
1941  
1942          if ( bp_displayed_user_id() ) {
1943              $username = bp_core_get_username( bp_displayed_user_id(), $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login );
1944          } else {
1945              $username = '';
1946          }
1947  
1948          /**
1949           * Filters the username of the displayed user.
1950           *
1951           * @since 1.2.0
1952           *
1953           * @param string $username Username of the displayed user.
1954           */
1955          return apply_filters( 'bp_get_displayed_user_username', $username );
1956      }
1957  
1958  /**
1959   * Output the username of the logged-in user.
1960   *
1961   * @since 1.2.0
1962   */
1963  function bp_loggedin_user_username() {
1964      echo bp_get_loggedin_user_username();
1965  }
1966      /**
1967       * Get the username of the logged-in user.
1968       *
1969       * @since 1.2.0
1970       *
1971       * @return string
1972       */
1973  	function bp_get_loggedin_user_username() {
1974          $bp = buddypress();
1975  
1976          if ( bp_loggedin_user_id() ) {
1977              $username = bp_core_get_username( bp_loggedin_user_id(), $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login );
1978          } else {
1979              $username = '';
1980          }
1981  
1982          /**
1983           * Filters the username of the logged-in user.
1984           *
1985           * @since 1.2.0
1986           *
1987           * @param string $username Username of the logged-in user.
1988           */
1989          return apply_filters( 'bp_get_loggedin_user_username', $username );
1990      }
1991  
1992  /**
1993   * Echo the current member type message.
1994   *
1995   * @since 2.3.0
1996   */
1997  function bp_current_member_type_message() {
1998      echo bp_get_current_member_type_message();
1999  }
2000      /**
2001       * Generate the current member type message.
2002       *
2003       * @since 2.3.0
2004       *
2005       * @return string
2006       */
2007  	function bp_get_current_member_type_message() {
2008          $type_object = bp_get_member_type_object( bp_get_current_member_type() );
2009  
2010          /* translators: %s: member type singular name */
2011          $message = sprintf( __( 'Viewing members of the type: %s', 'buddypress' ), '<strong>' . $type_object->labels['singular_name'] . '</strong>' );
2012  
2013          /**
2014           * Filters the current member type message.
2015           *
2016           * @since 2.3.0
2017           *
2018           * @param string $message Message to filter.
2019           */
2020          return apply_filters( 'bp_get_current_member_type_message', $message );
2021      }
2022  
2023  /**
2024   * Output member type directory link.
2025   *
2026   * @since 7.0.0
2027   *
2028   * @param string $member_type Unique member type identifier as used in bp_register_member_type().
2029   */
2030  function bp_member_type_directory_link( $member_type = '' ) {
2031      echo bp_get_member_type_directory_link( $member_type );
2032  }
2033      /**
2034       * Return member type directory link.
2035       *
2036       * @since 7.0.0
2037       *
2038       * @param string $member_type Unique member type identifier as used in bp_register_member_type().
2039       * @return string
2040       */
2041  	function bp_get_member_type_directory_link( $member_type = '' ) {
2042          if ( empty( $member_type ) ) {
2043              return '';
2044          }
2045  
2046          $member_type_object = bp_get_member_type_object( $member_type );
2047  
2048          if ( ! isset( $member_type_object->labels['name'] ) ) {
2049              return '';
2050          }
2051  
2052          $member_type_text = $member_type_object->labels['name'];
2053          if ( isset( $member_type_object->labels['singular_name'] ) && $member_type_object->labels['singular_name'] ) {
2054              $member_type_text = $member_type_object->labels['singular_name'];
2055          }
2056  
2057          if ( empty( $member_type_object->has_directory ) ) {
2058              return esc_html( $member_type_text );
2059          }
2060  
2061          return sprintf(
2062              '<a href="%1$s">%2$s</a>',
2063              esc_url( bp_get_member_type_directory_permalink( $member_type ) ),
2064              esc_html( $member_type_text )
2065          );
2066      }
2067  
2068  /**
2069   * Output a comma-delimited list of member types.
2070   *
2071   * @since 7.0.0
2072   * @see   bp_get_member_type_list() For additional information on default arguments.
2073   *
2074   * @param int   $user_id User ID.
2075   * @param array $r       Optional. Member type list arguments. Default empty array.
2076   */
2077  function bp_member_type_list( $user_id = 0, $r = array() ) {
2078      echo bp_get_member_type_list( $user_id, $r );
2079  }
2080      /**
2081       * Return a comma-delimited list of member types.
2082       *
2083       * @since 7.0.0
2084       *
2085       * @param int $user_id User ID. Defaults to displayed user ID if on a member page.
2086       * @param array|string $r {
2087       *     Array of parameters. All items are optional.
2088       *     @type string $parent_element     Element to wrap around the list. Defaults to 'p'.
2089       *     @type array  $parent_attr        Element attributes for parent element. Defaults to
2090       *                                      array( 'class' => 'bp-member-type-list' ).
2091       *     @type array  $label              Plural and singular labels to use before the list. Defaults to
2092       *                                      array( 'plural' => 'Member Types:', 'singular' => 'Member Type:' ).
2093       *     @type string $label_element      Element to wrap around the label. Defaults to 'strong'.
2094       *     @type array  $label_attr         Element attributes for label element. Defaults to array().
2095       *     @type bool   $show_all           Whether to show all registered group types. Defaults to 'false'. If
2096       *                                      'false', only shows member types with the 'show_in_list' parameter set to
2097       *                                      true. See bp_register_member_type() for more info.
2098       *     @type string $list_element       Element to wrap around the comma separated list of membet types. Defaults to ''.
2099       *     @type string $list_element_attr  Element attributes for list element. Defaults to array().
2100       * }
2101       * @return string
2102       */
2103  	function bp_get_member_type_list( $user_id = 0, $r = array() ) {
2104          if ( empty( $user_id ) ) {
2105              $user_id = bp_displayed_user_id();
2106          }
2107  
2108          $r = bp_parse_args(
2109              $r,
2110              array(
2111                  'parent_element'    => 'p',
2112                  'parent_attr'       => array(
2113                      'class' => 'bp-member-type-list',
2114                  ),
2115                  'label'             => array(),
2116                  'label_element'     => 'strong',
2117                  'label_attr'        => array(),
2118                  'show_all'          => false,
2119                  'list_element'      => '',
2120                  'list_element_attr' => array(),
2121              ),
2122              'member_type_list'
2123          );
2124  
2125          // Should the label be output?
2126          $has_label = ! empty( $r['label'] );
2127  
2128          $labels = wp_parse_args(
2129              $r['label'],
2130              array(
2131                  'plural'   => __( 'Member Types:', 'buddypress' ),
2132                  'singular' => __( 'Member Type:', 'buddypress' ),
2133              )
2134          );
2135  
2136          $retval = '';
2137          $types  = bp_get_member_type( $user_id, false );
2138  
2139          if ( $types ) {
2140              // Make sure we can show the type in the list.
2141              if ( false === $r['show_all'] ) {
2142                  $types = array_intersect( bp_get_member_types( array( 'show_in_list' => true ) ), $types );
2143                  if ( empty( $types ) ) {
2144                      return $retval;
2145                  }
2146              }
2147  
2148              $before = $after = $label = '';
2149              $count  = count( $types );
2150  
2151              if ( 1 === $count ) {
2152                  $label_text = $labels['singular'];
2153              } else {
2154                  $label_text = $labels['plural'];
2155              }
2156  
2157              // Render parent element.
2158              if ( ! empty( $r['parent_element'] ) ) {
2159                  $parent_elem = new BP_Core_HTML_Element( array(
2160                      'element' => $r['parent_element'],
2161                      'attr'    => $r['parent_attr'],
2162                  ) );
2163  
2164                  // Set before and after.
2165                  $before = $parent_elem->get( 'open_tag' );
2166                  $after  = $parent_elem->get( 'close_tag' );
2167              }
2168  
2169              // Render label element.
2170              if ( ! empty( $r['label_element'] ) ) {
2171                  $label = new BP_Core_HTML_Element( array(
2172                      'element'    => $r['label_element'],
2173                      'attr'       => $r['label_attr'],
2174                      'inner_html' => esc_html( $label_text ),
2175                  ) );
2176                  $label = $label->contents() . ' ';
2177  
2178              // No element, just the label.
2179              } elseif ( $has_label ) {
2180                  $label = esc_html( $label_text );
2181              }
2182  
2183              // The list of types.
2184              $list = implode( ', ', array_map( 'bp_get_member_type_directory_link', $types ) );
2185  
2186              // Render the list of types element.
2187              if ( ! empty( $r['list_element'] ) ) {
2188                  $list_element = new BP_Core_HTML_Element( array(
2189                      'element'    => $r['list_element'],
2190                      'attr'       => $r['list_element_attr'],
2191                      'inner_html' => $list,
2192                  ) );
2193  
2194                  $list = $list_element->contents();
2195              }
2196  
2197              // Comma-delimit each type into the group type directory link.
2198              $label .= $list;
2199  
2200              // Retval time!
2201              $retval = $before . $label . $after;
2202          }
2203  
2204          return $retval;
2205      }
2206  
2207  /** Signup Form ***************************************************************/
2208  
2209  /**
2210   * Do we have a working custom sign up page?
2211   *
2212   * @since 1.5.0
2213   *
2214   * @return bool True if page and template exist, false if not.
2215   */
2216  function bp_has_custom_signup_page() {
2217      static $has_page = false;
2218  
2219      if ( empty( $has_page ) )
2220          $has_page = bp_get_signup_slug() && bp_locate_template( array( 'registration/register.php', 'members/register.php', 'register.php' ), false );
2221  
2222      return (bool) $has_page;
2223  }
2224  
2225  /**
2226   * Output the URL to the signup page.
2227   *
2228   * @since 1.0.0
2229   */
2230  function bp_signup_page() {
2231      echo esc_url( bp_get_signup_page() );
2232  }
2233      /**
2234       * Get the URL to the signup page.
2235       *
2236       * @since 1.1.0
2237       *
2238       * @return string
2239       */
2240  	function bp_get_signup_page() {
2241          if ( bp_has_custom_signup_page() ) {
2242              $page = trailingslashit( bp_get_root_domain() . '/' . bp_get_signup_slug() );
2243          } else {
2244              $page = bp_get_root_domain() . '/wp-signup.php';
2245          }
2246  
2247          /**
2248           * Filters the URL to the signup page.
2249           *
2250           * @since 1.1.0
2251           *
2252           * @param string $page URL to the signup page.
2253           */
2254          return apply_filters( 'bp_get_signup_page', $page );
2255      }
2256  
2257  /**
2258   * Do we have a working custom activation page?
2259   *
2260   * @since 1.5.0
2261   *
2262   * @return boolean True if page and template exist, false if not.
2263   */
2264  function bp_has_custom_activation_page() {
2265      static $has_page = false;
2266  
2267      if ( empty( $has_page ) )
2268          $has_page = bp_get_activate_slug() && bp_locate_template( array( 'registration/activate.php', 'members/activate.php', 'activate.php' ), false );
2269  
2270      return (bool) $has_page;
2271  }
2272  
2273  /**
2274   * Output the URL of the activation page.
2275   *
2276   * @since 1.0.0
2277   */
2278  function bp_activation_page() {
2279      echo esc_url( bp_get_activation_page() );
2280  }
2281      /**
2282       * Get the URL of the activation page.
2283       *
2284       * @since 1.2.0
2285       *
2286       * @return string
2287       */
2288  	function bp_get_activation_page() {
2289          if ( bp_has_custom_activation_page() ) {
2290              $page = trailingslashit( bp_get_root_domain() . '/' . bp_get_activate_slug() );
2291          } else {
2292              $page = trailingslashit( bp_get_root_domain() ) . 'wp-activate.php';
2293          }
2294  
2295          /**
2296           * Filters the URL of the activation page.
2297           *
2298           * @since 1.2.0
2299           *
2300           * @param string $page URL to the activation page.
2301           */
2302          return apply_filters( 'bp_get_activation_page', $page );
2303      }
2304  
2305  /**
2306   * Get the activation key from the current request URL.
2307   *
2308   * @since 3.0.0
2309   *
2310   * @return string
2311   */
2312  function bp_get_current_activation_key() {
2313      $key = '';
2314  
2315      if ( bp_is_current_component( 'activate' ) ) {
2316          if ( isset( $_GET['key'] ) ) {
2317              $key = wp_unslash( $_GET['key'] );
2318          } else {
2319              $key = bp_current_action();
2320          }
2321      }
2322  
2323      /**
2324       * Filters the activation key from the current request URL.
2325       *
2326       * @since 3.0.0
2327       *
2328       * @param string $key Activation key.
2329       */
2330      return apply_filters( 'bp_get_current_activation_key', $key );
2331  }
2332  
2333  /**
2334   * Output the username submitted during signup.
2335   *
2336   * @since 1.1.0
2337   */
2338  function bp_signup_username_value() {
2339      echo bp_get_signup_username_value();
2340  }
2341      /**
2342       * Get the username submitted during signup.
2343       *
2344       * @since 1.1.0
2345       *
2346       * @todo This should be properly escaped.
2347       *
2348       * @return string
2349       */
2350  	function bp_get_signup_username_value() {
2351          $value = '';
2352          if ( isset( $_POST['signup_username'] ) )
2353              $value = $_POST['signup_username'];
2354  
2355          /**
2356           * Filters the username submitted during signup.
2357           *
2358           * @since 1.1.0
2359           *
2360           * @param string $value Username submitted during signup.
2361           */
2362          return apply_filters( 'bp_get_signup_username_value', $value );
2363      }
2364  
2365  /**
2366   * Output the user email address submitted during signup.
2367   *
2368   * @since 1.1.0
2369   */
2370  function bp_signup_email_value() {
2371      echo bp_get_signup_email_value();
2372  }
2373      /**
2374       * Get the email address submitted during signup.
2375       *
2376       * @since 1.1.0
2377       *
2378       * @todo This should be properly escaped.
2379       *
2380       * @return string
2381       */
2382  	function bp_get_signup_email_value() {
2383          $value = '';
2384          if ( isset( $_POST['signup_email'] ) )
2385              $value = $_POST['signup_email'];
2386  
2387          /**
2388           * Filters the email address submitted during signup.
2389           *
2390           * @since 1.1.0
2391           *
2392           * @param string $value Email address submitted during signup.
2393           */
2394          return apply_filters( 'bp_get_signup_email_value', $value );
2395      }
2396  
2397  /**
2398   * Output the 'signup_with_blog' value submitted during signup.
2399   *
2400   * @since 1.1.0
2401   */
2402  function bp_signup_with_blog_value() {
2403      echo bp_get_signup_with_blog_value();
2404  }
2405      /**
2406       * Get the 'signup_with_blog' value submitted during signup.
2407       *
2408       * @since 1.1.0
2409       *
2410       * @return string
2411       */
2412  	function bp_get_signup_with_blog_value() {
2413          $value = '';
2414          if ( isset( $_POST['signup_with_blog'] ) )
2415              $value = $_POST['signup_with_blog'];
2416  
2417          /**
2418           * Filters the 'signup_with_blog' value submitted during signup.
2419           *
2420           * @since 1.1.0
2421           *
2422           * @param string $value 'signup_with_blog' value submitted during signup.
2423           */
2424          return apply_filters( 'bp_get_signup_with_blog_value', $value );
2425      }
2426  
2427  /**
2428   * Output the 'signup_blog_url' value submitted at signup.
2429   *
2430   * @since 1.1.0
2431   */
2432  function bp_signup_blog_url_value() {
2433      echo bp_get_signup_blog_url_value();
2434  }
2435      /**
2436       * Get the 'signup_blog_url' value submitted at signup.
2437       *
2438       * @since 1.1.0
2439       *
2440       * @todo Should be properly escaped.
2441       *
2442       * @return string
2443       */
2444  	function bp_get_signup_blog_url_value() {
2445          $value = '';
2446          if ( isset( $_POST['signup_blog_url'] ) )
2447              $value = $_POST['signup_blog_url'];
2448  
2449          /**
2450           * Filters the 'signup_blog_url' value submitted during signup.
2451           *
2452           * @since 1.1.0
2453           *
2454           * @param string $value 'signup_blog_url' value submitted during signup.
2455           */
2456          return apply_filters( 'bp_get_signup_blog_url_value', $value );
2457      }
2458  
2459  /**
2460   * Output the base URL for subdomain installations of WordPress Multisite.
2461   *
2462   * @since 2.1.0
2463   */
2464  function bp_signup_subdomain_base() {
2465      echo bp_signup_get_subdomain_base();
2466  }
2467      /**
2468       * Return the base URL for subdomain installations of WordPress Multisite.
2469       *
2470       * Replaces bp_blogs_get_subdomain_base()
2471       *
2472       * @since 2.1.0
2473       *
2474       * @return string The base URL - eg, 'example.com' for site_url() example.com or www.example.com.
2475       */
2476  	function bp_signup_get_subdomain_base() {
2477          global $current_site;
2478  
2479          // In case plugins are still using this filter.
2480          $subdomain_base = apply_filters( 'bp_blogs_subdomain_base', preg_replace( '|^www\.|', '', $current_site->domain ) . $current_site->path );
2481  
2482          /**
2483           * Filters the base URL for subdomain installations of WordPress Multisite.
2484           *
2485           * @since 2.1.0
2486           *
2487           * @param string $subdomain_base The base URL - eg, 'example.com' for
2488           *                               site_url() example.com or www.example.com.
2489           */
2490          return apply_filters( 'bp_signup_subdomain_base', $subdomain_base );
2491      }
2492  
2493  /**
2494   * Output the 'signup_blog_titl' value submitted at signup.
2495   *
2496   * @since 1.1.0
2497   */
2498  function bp_signup_blog_title_value() {
2499      echo bp_get_signup_blog_title_value();
2500  }
2501      /**
2502       * Get the 'signup_blog_title' value submitted at signup.
2503       *
2504       * @since 1.1.0
2505       *
2506       * @todo Should be properly escaped.
2507       *
2508       * @return string
2509       */
2510  	function bp_get_signup_blog_title_value() {
2511          $value = '';
2512          if ( isset( $_POST['signup_blog_title'] ) )
2513              $value = $_POST['signup_blog_title'];
2514  
2515          /**
2516           * Filters the 'signup_blog_title' value submitted during signup.
2517           *
2518           * @since 1.1.0
2519           *
2520           * @param string $value 'signup_blog_title' value submitted during signup.
2521           */
2522          return apply_filters( 'bp_get_signup_blog_title_value', $value );
2523      }
2524  
2525  /**
2526   * Output the 'signup_blog_privacy' value submitted at signup.
2527   *
2528   * @since 1.1.0
2529   */
2530  function bp_signup_blog_privacy_value() {
2531      echo bp_get_signup_blog_privacy_value();
2532  }
2533      /**
2534       * Get the 'signup_blog_privacy' value submitted at signup.
2535       *
2536       * @since 1.1.0
2537       *
2538       * @todo Should be properly escaped.
2539       *
2540       * @return string
2541       */
2542  	function bp_get_signup_blog_privacy_value() {
2543          $value = '';
2544          if ( isset( $_POST['signup_blog_privacy'] ) )
2545              $value = $_POST['signup_blog_privacy'];
2546  
2547          /**
2548           * Filters the 'signup_blog_privacy' value submitted during signup.
2549           *
2550           * @since 1.1.0
2551           *
2552           * @param string $value 'signup_blog_privacy' value submitted during signup.
2553           */
2554          return apply_filters( 'bp_get_signup_blog_privacy_value', $value );
2555      }
2556  
2557  /**
2558   * Output the avatar dir used during signup.
2559   *
2560   * @since 1.1.0
2561   */
2562  function bp_signup_avatar_dir_value() {
2563      echo bp_get_signup_avatar_dir_value();
2564  }
2565      /**
2566       * Get the avatar dir used during signup.
2567       *
2568       * @since 1.1.0
2569       *
2570       * @return string
2571       */
2572  	function bp_get_signup_avatar_dir_value() {
2573          $bp = buddypress();
2574  
2575          // Check if signup_avatar_dir is passed.
2576          if ( !empty( $_POST['signup_avatar_dir'] ) )
2577              $signup_avatar_dir = $_POST['signup_avatar_dir'];
2578  
2579          // If not, check if global is set.
2580          elseif ( !empty( $bp->signup->avatar_dir ) )
2581              $signup_avatar_dir = $bp->signup->avatar_dir;
2582  
2583          // If not, set false.
2584          else
2585              $signup_avatar_dir = false;
2586  
2587          /**
2588           * Filters the avatar dir used during signup.
2589           *
2590           * @since 1.1.0
2591           *
2592           * @param string|bool $signup_avatar_dir Avatar dir used during signup or false.
2593           */
2594          return apply_filters( 'bp_get_signup_avatar_dir_value', $signup_avatar_dir );
2595      }
2596  
2597  /**
2598   * Determines whether privacy policy acceptance is required for registration.
2599   *
2600   * @since 4.0.0
2601   *
2602   * @return bool
2603   */
2604  function bp_signup_requires_privacy_policy_acceptance() {
2605      // Bail if we're running a version of WP that doesn't have the Privacy Policy feature.
2606      if ( bp_is_running_wp( '4.9.6', '<' ) ) {
2607          return false;
2608      }
2609  
2610      // Default to true when a published Privacy Policy page exists.
2611      $privacy_policy_url = get_privacy_policy_url();
2612      $required           = ! empty( $privacy_policy_url );
2613  
2614      /**
2615       * Filters whether privacy policy acceptance is required for registration.
2616       *
2617       * @since 4.0.0
2618       *
2619       * @param bool $required Whether privacy policy acceptance is required.
2620       */
2621      return (bool) apply_filters( 'bp_signup_requires_privacy_policy_acceptance', $required );
2622  }
2623  
2624  /**
2625   * Output the current signup step.
2626   *
2627   * @since 1.1.0
2628   */
2629  function bp_current_signup_step() {
2630      echo bp_get_current_signup_step();
2631  }
2632      /**
2633       * Get the current signup step.
2634       *
2635       * @since 1.1.0
2636       *
2637       * @return string
2638       */
2639  	function bp_get_current_signup_step() {
2640          return buddypress()->signup->step;
2641      }
2642  
2643  /**
2644   * Output the user avatar during signup.
2645   *
2646   * @since 1.1.0
2647   *
2648   * @see bp_get_signup_avatar() for description of arguments.
2649   *
2650   * @param array|string $args See {@link bp_get_signup_avatar(}.
2651   */
2652  function bp_signup_avatar( $args = '' ) {
2653      echo bp_get_signup_avatar( $args );
2654  }
2655      /**
2656       * Get the user avatar during signup.
2657       *
2658       * @since 1.1.0
2659       *
2660       * @see bp_core_fetch_avatar() for description of arguments.
2661       *
2662       * @param array|string $args {
2663       *     Array of optional arguments.
2664       *     @type int    $size  Height/weight in pixels. Default: value of
2665       *                         bp_core_avatar_full_width().
2666       *     @type string $class CSS class. Default: 'avatar'.
2667       *     @type string $alt   HTML 'alt' attribute. Default: 'Your Avatar'.
2668       * }
2669       * @return string
2670       */
2671  	function bp_get_signup_avatar( $args = '' ) {
2672          $bp = buddypress();
2673  
2674          $defaults = array(
2675              'size' => bp_core_avatar_full_width(),
2676              'class' => 'avatar',
2677              'alt' => __( 'Your Profile Photo', 'buddypress' )
2678          );
2679  
2680          $r = wp_parse_args( $args, $defaults );
2681          extract( $r, EXTR_SKIP );
2682  
2683          // Avatar DIR is found.
2684          if ( $signup_avatar_dir = bp_get_signup_avatar_dir_value() ) {
2685              $gravatar_img = bp_core_fetch_avatar( array(
2686                  'item_id'    => $signup_avatar_dir,
2687                  'object'     => 'signup',
2688                  'avatar_dir' => 'avatars/signups',
2689                  'type'       => 'full',
2690                  'width'      => $size,
2691                  'height'     => $size,
2692                  'alt'        => $alt,
2693                  'class'      => $class
2694              ) );
2695  
2696              // No avatar DIR was found.
2697          } else {
2698  
2699              // Set default gravatar type.
2700              if ( empty( $bp->grav_default->user ) )
2701                  $default_grav = 'wavatar';
2702              elseif ( 'mystery' == $bp->grav_default->user )
2703                  $default_grav = $bp->plugin_url . 'bp-core/images/mystery-man.jpg';
2704              else
2705                  $default_grav = $bp->grav_default->user;
2706  
2707              /**
2708               * Filters the base Gravatar url used for signup avatars when no avatar dir found.
2709               *
2710               * @since 1.0.2
2711               *
2712               * @param string $value Gravatar url to use.
2713               */
2714              $gravatar_url    = apply_filters( 'bp_gravatar_url', '//www.gravatar.com/avatar/' );
2715              $md5_lcase_email = md5( strtolower( bp_get_signup_email_value() ) );
2716              $gravatar_img    = '<img src="' . $gravatar_url . $md5_lcase_email . '?d=' . $default_grav . '&amp;s=' . $size . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
2717          }
2718  
2719          /**
2720           * Filters the user avatar during signup.
2721           *
2722           * @since 1.1.0
2723           *
2724           * @param string $gravatar_img Avatar HTML image tag.
2725           * @param array  $args         Array of parsed args for avatar query.
2726           */
2727          return apply_filters( 'bp_get_signup_avatar', $gravatar_img, $args );
2728      }
2729  
2730  /**
2731   * Output whether signup is allowed.
2732   *
2733   * @since 1.1.0
2734   *
2735   * @todo Remove this function. Echoing a bool is pointless.
2736   */
2737  function bp_signup_allowed() {
2738      echo bp_get_signup_allowed();
2739  }
2740      /**
2741       * Is user signup allowed?
2742       *
2743       * @since 1.1.0
2744       *
2745       * @return bool
2746       */
2747  	function bp_get_signup_allowed() {
2748          /**
2749           * Filters whether or not new signups are allowed.
2750           *
2751           * @since 1.5.0
2752           *
2753           * @param bool $signup_allowed Whether or not new signups are allowed.
2754           */
2755          return apply_filters( 'bp_get_signup_allowed', (bool) bp_get_option( 'users_can_register' ) );
2756      }
2757  
2758  /**
2759   * Hook member activity feed to <head>.
2760   *
2761   * @since 1.5.0
2762   */
2763  function bp_members_activity_feed() {
2764      if ( !bp_is_active( 'activity' ) || !bp_is_user() )
2765          return; ?>
2766  
2767      <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() ?>" />
2768  
2769  <?php
2770  }
2771  add_action( 'bp_head', 'bp_members_activity_feed' );
2772  
2773  /**
2774   * Output a link to a members component subpage.
2775   *
2776   * @since 1.5.0
2777   *
2778   * @see bp_get_members_component_link() for description of parameters.
2779   *
2780   * @param string      $component See {@bp_get_members_component_link()}.
2781   * @param string      $action See {@bp_get_members_component_link()}.
2782   * @param string      $query_args See {@bp_get_members_component_link()}.
2783   * @param string|bool $nonce See {@bp_get_members_component_link()}.
2784   */
2785  function bp_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) {
2786      echo esc_url( bp_get_members_component_link( $component, $action, $query_args, $nonce ) );
2787  }
2788      /**
2789       * Generate a link to a members component subpage.
2790       *
2791       * @since 1.5.0
2792       *
2793       * @param string       $component  ID of the component (eg 'friends').
2794       * @param string       $action     Optional. 'action' slug (eg 'invites').
2795       * @param array|string $query_args Optional. Array of URL params to add to the
2796       *                                 URL. See {@link add_query_arg()} for format.
2797       * @param array|bool   $nonce      Optional. If provided, the URL will be passed
2798       *                                 through wp_nonce_url() with $nonce as the
2799       *                                 action string.
2800       * @return string
2801       */
2802  	function bp_get_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) {
2803  
2804          // Must be displayed user.
2805          if ( !bp_displayed_user_id() )
2806              return;
2807  
2808          $bp = buddypress();
2809  
2810          // Append $action to $url if there is no $type.
2811          if ( !empty( $action ) )
2812              $url = bp_displayed_user_domain() . $bp->{$component}->slug . '/' . $action;
2813          else
2814              $url = bp_displayed_user_domain() . $bp->{$component}->slug;
2815  
2816          // Add a slash at the end of our user url.
2817          $url = trailingslashit( $url );
2818  
2819          // Add possible query arg.
2820          if ( !empty( $query_args ) && is_array( $query_args ) )
2821              $url = add_query_arg( $query_args, $url );
2822  
2823          // To nonce, or not to nonce...
2824          if ( true === $nonce )
2825              $url = wp_nonce_url( $url );
2826          elseif ( is_string( $nonce ) )
2827              $url = wp_nonce_url( $url, $nonce );
2828  
2829          // Return the url, if there is one.
2830          if ( !empty( $url ) )
2831              return $url;
2832      }
2833  
2834  
2835  /**
2836   * Render an avatar delete link.
2837   *
2838   * @since 1.1.0
2839   * @since 6.0.0 Moved from /bp-xprofile/bp-xprofile-template.php to this file.
2840   */
2841  function bp_avatar_delete_link() {
2842      echo bp_get_avatar_delete_link();
2843  }
2844  
2845      /**
2846       * Return an avatar delete link.
2847       *
2848       * @since 1.1.0
2849       * @since 6.0.0 Moved from /bp-xprofile/bp-xprofile-template.php to this file.
2850       *
2851       * @return string
2852       */
2853  	function bp_get_avatar_delete_link() {
2854  
2855          /**
2856           * Filters the link used for deleting an avatar.
2857           *
2858           * @since 1.1.0
2859           *
2860           * @param string $value Nonced URL used for deleting an avatar.
2861           */
2862          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' ) );
2863      }


Generated: Sat Apr 17 01:01:43 2021 Cross-referenced by PHPXref 0.7.1