[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

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


Generated: Thu Oct 1 01:01:32 2020 Cross-referenced by PHPXref 0.7.1