[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

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


Generated: Sun Apr 5 01:01:30 2020 Cross-referenced by PHPXref 0.7.1