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


Generated: Mon Aug 2 01:01:43 2021 Cross-referenced by PHPXref 0.7.1