[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

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


Generated: Thu Sep 19 01:01:39 2019 Cross-referenced by PHPXref 0.7.1