[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

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


Generated: Sat Jul 4 01:01:33 2020 Cross-referenced by PHPXref 0.7.1