[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Friends Template Functions.
   4   *
   5   * @package BuddyPress
   6   * @subpackage FriendsTemplate
   7   * @since 1.5.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Output the friends component slug.
  15   *
  16   * @since 1.5.0
  17   *
  18   */
  19  function bp_friends_slug() {
  20      echo bp_get_friends_slug();
  21  }
  22      /**
  23       * Return the friends component slug.
  24       *
  25       * @since 1.5.0
  26       *
  27       * @return string
  28       */
  29  	function bp_get_friends_slug() {
  30  
  31          /**
  32           * Filters the friends component slug.
  33           *
  34           * @since 1.5.0
  35           *
  36           * @param string $value Friends component slug.
  37           */
  38          return apply_filters( 'bp_get_friends_slug', buddypress()->friends->slug );
  39      }
  40  
  41  /**
  42   * Output the friends component root slug.
  43   *
  44   * @since 1.5.0
  45   *
  46   */
  47  function bp_friends_root_slug() {
  48      echo bp_get_friends_root_slug();
  49  }
  50      /**
  51       * Return the friends component root slug.
  52       *
  53       * @since 1.5.0
  54       *
  55       * @return string
  56       */
  57  	function bp_get_friends_root_slug() {
  58  
  59          /**
  60           * Filters the friends component root slug.
  61           *
  62           * @since 1.5.0
  63           *
  64           * @param string $value Friends component root slug.
  65           */
  66          return apply_filters( 'bp_get_friends_root_slug', buddypress()->friends->root_slug );
  67      }
  68  
  69  /**
  70   * Output a block of random friends.
  71   *
  72   * No longer used in BuddyPress.
  73   *
  74   * @todo Deprecate
  75   */
  76  function bp_friends_random_friends() {
  77  
  78      if ( !$friend_ids = wp_cache_get( 'friends_friend_ids_' . bp_displayed_user_id(), 'bp' ) ) {
  79          $friend_ids = BP_Friends_Friendship::get_random_friends( bp_displayed_user_id() );
  80          wp_cache_set( 'friends_friend_ids_' . bp_displayed_user_id(), $friend_ids, 'bp' );
  81      } ?>
  82  
  83      <div class="info-group">
  84          <h4>
  85              <?php
  86              /* translators: %s: member name */
  87              bp_word_or_name( __( "My Friends", 'buddypress' ), __( "%s's Friends", 'buddypress' ) );
  88              ?>
  89              &nbsp;
  90              (<?php echo BP_Friends_Friendship::total_friend_count( bp_displayed_user_id() ); ?>)
  91              &nbsp;
  92              <span>
  93                  <a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() ) ?>">
  94                      <?php esc_html_e( 'See All', 'buddypress' ) ?>
  95                  </a>
  96              </span>
  97          </h4>
  98  
  99          <?php if ( $friend_ids ) { ?>
 100  
 101              <ul class="horiz-gallery">
 102  
 103              <?php for ( $i = 0, $count = count( $friend_ids ); $i < $count; ++$i ) { ?>
 104  
 105                  <li>
 106                      <a href="<?php echo bp_core_get_user_domain( $friend_ids[$i] ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $friend_ids[$i], 'type' => 'thumb' ) ) ?></a>
 107                      <h5><?php echo bp_core_get_userlink($friend_ids[$i]) ?></h5>
 108                  </li>
 109  
 110              <?php } ?>
 111  
 112              </ul>
 113  
 114          <?php } else { ?>
 115  
 116              <div id="message" class="info">
 117                  <p>
 118                      <?php
 119                      /* translators: %s: member name */
 120                      bp_word_or_name( __( "You haven't added any friend connections yet.", 'buddypress' ), __( "%s hasn't created any friend connections yet.", 'buddypress' ) );
 121                      ?>
 122                  </p>
 123              </div>
 124  
 125          <?php } ?>
 126  
 127          <div class="clear"></div>
 128      </div>
 129  
 130  <?php
 131  }
 132  
 133  /**
 134   * Pull up a group of random members, and display some profile data about them.
 135   *
 136   * This function is no longer used by BuddyPress core.
 137   *
 138   * @todo Deprecate
 139   *
 140   * @param int $total_members The number of members to retrieve.
 141   */
 142  function bp_friends_random_members( $total_members = 5 ) {
 143  
 144      if ( !$user_ids = wp_cache_get( 'friends_random_users', 'bp' ) ) {
 145          $user_ids = BP_Core_User::get_users( 'random', $total_members );
 146          wp_cache_set( 'friends_random_users', $user_ids, 'bp' );
 147      }
 148  
 149      ?>
 150  
 151      <?php if ( $user_ids['users'] ) { ?>
 152  
 153          <ul class="item-list" id="random-members-list">
 154  
 155          <?php for ( $i = 0, $count = count( $user_ids['users'] ); $i < $count; ++$i ) { ?>
 156  
 157              <li>
 158                  <a href="<?php echo bp_core_get_user_domain( $user_ids['users'][$i]->id ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $user_ids['users'][$i]->id, 'type' => 'thumb' ) ) ?></a>
 159                  <h5><?php echo bp_core_get_userlink( $user_ids['users'][$i]->id ) ?></h5>
 160  
 161                  <?php if ( bp_is_active( 'xprofile' ) ) { ?>
 162  
 163                      <?php $random_data = xprofile_get_random_profile_data( $user_ids['users'][$i]->id, true ); ?>
 164  
 165                      <div class="profile-data">
 166                          <p class="field-name"><?php echo $random_data[0]->name ?></p>
 167  
 168                          <?php echo $random_data[0]->value ?>
 169  
 170                      </div>
 171  
 172                  <?php } ?>
 173  
 174                  <div class="action">
 175  
 176                      <?php if ( bp_is_active( 'friends' ) ) { ?>
 177  
 178                          <?php bp_add_friend_button( $user_ids['users'][$i]->id ) ?>
 179  
 180                      <?php } ?>
 181  
 182                  </div>
 183              </li>
 184  
 185          <?php } ?>
 186  
 187          </ul>
 188  
 189      <?php } else { ?>
 190  
 191          <div id="message" class="info">
 192              <p><?php _e( "There aren't enough site members to show a random sample just yet.", 'buddypress' ) ?></p>
 193          </div>
 194  
 195      <?php } ?>
 196  <?php
 197  }
 198  
 199  /**
 200   * Display a Friends search form.
 201   *
 202   * No longer used in BuddyPress.
 203   *
 204   * @todo Deprecate
 205   */
 206  function bp_friend_search_form() {
 207  
 208      $action = bp_displayed_user_domain() . bp_get_friends_slug() . '/my-friends/search/';
 209      $label  = __( 'Filter Friends', 'buddypress' ); ?>
 210  
 211          <form action="<?php echo $action ?>" id="friend-search-form" method="post">
 212  
 213              <label for="friend-search-box" id="friend-search-label"><?php echo $label ?></label>
 214              <input type="search" name="friend-search-box" id="friend-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> />
 215  
 216              <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?>
 217  
 218              <input type="hidden" name="initiator" id="initiator" value="<?php echo esc_attr( bp_displayed_user_id() ) ?>" />
 219  
 220          </form>
 221  
 222      <?php
 223  }
 224  
 225  /**
 226   * Output the "Add Friend" button in the member loop.
 227   *
 228   * @since 1.2.6
 229   */
 230  function bp_member_add_friend_button() {
 231      bp_add_friend_button( bp_get_member_user_id() );
 232  }
 233  add_action( 'bp_directory_members_actions', 'bp_member_add_friend_button' );
 234  
 235  /**
 236   * Output the friend count for the current member in the loop.
 237   *
 238   * @since 1.2.0
 239   */
 240  function bp_member_total_friend_count() {
 241      echo bp_get_member_total_friend_count();
 242  }
 243      /**
 244       * Return the friend count for the current member in the loop.
 245       *
 246       * Return value is a string of the form "x friends".
 247       *
 248       * @since 1.2.0
 249       *
 250       * @return string A string of the form "x friends".
 251       */
 252  	function bp_get_member_total_friend_count() {
 253          global $members_template;
 254  
 255          $total_friend_count = (int) $members_template->member->total_friend_count;
 256  
 257          /**
 258           * Filters text used to denote total friend count.
 259           *
 260           * @since 1.2.0
 261           *
 262           * @param string $value String of the form "x friends".
 263           * @param int    $value Total friend count for current member in the loop.
 264           */
 265          return apply_filters(
 266              'bp_get_member_total_friend_count',
 267              /* translators: %d: total friend count */
 268              sprintf( _n( '%d friend', '%d friends', $total_friend_count, 'buddypress' ), number_format_i18n( $total_friend_count ) )
 269          );
 270      }
 271  
 272  /**
 273   * Output the ID of the current user in the friend request loop.
 274   *
 275   * @since 1.2.6
 276   *
 277   * @see bp_get_potential_friend_id() for a description of arguments.
 278   *
 279   * @param int $user_id See {@link bp_get_potential_friend_id()}.
 280   */
 281  function bp_potential_friend_id( $user_id = 0 ) {
 282      echo bp_get_potential_friend_id( $user_id );
 283  }
 284      /**
 285       * Return the ID of current user in the friend request loop.
 286       *
 287       * @since 1.2.6
 288       *
 289       * @global object $friends_template
 290       *
 291       * @param int $user_id Optional. If provided, the function will simply
 292       *                     return this value.
 293       * @return int ID of potential friend.
 294       */
 295  	function bp_get_potential_friend_id( $user_id = 0 ) {
 296          global $friends_template;
 297  
 298          if ( empty( $user_id ) && isset( $friends_template->friendship->friend ) )
 299              $user_id = $friends_template->friendship->friend->id;
 300          elseif ( empty( $user_id ) && !isset( $friends_template->friendship->friend ) )
 301              $user_id = bp_displayed_user_id();
 302  
 303          /**
 304           * Filters the ID of current user in the friend request loop.
 305           *
 306           * @since 1.2.10
 307           *
 308           * @param int $user_id ID of current user in the friend request loop.
 309           */
 310          return apply_filters( 'bp_get_potential_friend_id', (int) $user_id );
 311      }
 312  
 313  /**
 314   * Check whether a given user is a friend of the logged-in user.
 315   *
 316   * Returns - 'is_friend', 'not_friends', 'pending'.
 317   *
 318   * @since 1.2.6
 319   *
 320   * @param int $user_id ID of the potential friend. Default: the value of
 321   *                     {@link bp_get_potential_friend_id()}.
 322   * @return string 'is_friend', 'not_friends', or 'pending'.
 323   */
 324  function bp_is_friend( $user_id = 0 ) {
 325  
 326      if ( !is_user_logged_in() )
 327          return false;
 328  
 329      if ( empty( $user_id ) )
 330          $user_id = bp_get_potential_friend_id( $user_id );
 331  
 332      if ( bp_loggedin_user_id() == $user_id )
 333          return false;
 334  
 335      /**
 336       * Filters the status of friendship between logged in user and given user.
 337       *
 338       * @since 1.2.10
 339       *
 340       * @param string $value String status of friendship. Possible values are 'is_friend', 'not_friends', 'pending'.
 341       */
 342      return apply_filters( 'bp_is_friend', friends_check_friendship_status( bp_loggedin_user_id(), $user_id ), $user_id );
 343  }
 344  
 345  /**
 346   * Output the Add Friend button.
 347   *
 348   * @since 1.0.0
 349   *
 350   * @see bp_get_add_friend_button() for information on arguments.
 351   *
 352   * @param int      $potential_friend_id See {@link bp_get_add_friend_button()}.
 353   * @param int|bool $friend_status       See {@link bp_get_add_friend_button()}.
 354   */
 355  function bp_add_friend_button( $potential_friend_id = 0, $friend_status = false ) {
 356      echo bp_get_add_friend_button( $potential_friend_id, $friend_status );
 357  }
 358      /**
 359       * Create the Add Friend button.
 360       *
 361       * @since 1.1.0
 362       *
 363       * @param int  $potential_friend_id ID of the user to whom the button
 364       *                                  applies. Default: value of {@link bp_get_potential_friend_id()}.
 365       * @param bool $friend_status       Not currently used.
 366       * @return false|string HTML for the Add Friend button.
 367       */
 368  	function bp_get_add_friend_button( $potential_friend_id = 0, $friend_status = false ) {
 369  
 370          if ( empty( $potential_friend_id ) )
 371              $potential_friend_id = bp_get_potential_friend_id( $potential_friend_id );
 372  
 373          $is_friend = bp_is_friend( $potential_friend_id );
 374  
 375          if ( empty( $is_friend ) )
 376              return false;
 377  
 378          switch ( $is_friend ) {
 379              case 'pending' :
 380                  $button = array(
 381                      'id'                => 'pending',
 382                      'component'         => 'friends',
 383                      'must_be_logged_in' => true,
 384                      'block_self'        => true,
 385                      'wrapper_class'     => 'friendship-button pending_friend',
 386                      'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
 387                      'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $potential_friend_id . '/', 'friends_withdraw_friendship' ),
 388                      'link_text'         => __( 'Cancel Friendship Request', 'buddypress' ),
 389                      'link_id'           => 'friend-' . $potential_friend_id,
 390                      'link_rel'          => 'remove',
 391                      'link_class'        => 'friendship-button pending_friend requested'
 392                  );
 393                  break;
 394  
 395              case 'awaiting_response' :
 396                  $button = array(
 397                      'id'                => 'awaiting_response',
 398                      'component'         => 'friends',
 399                      'must_be_logged_in' => true,
 400                      'block_self'        => true,
 401                      'wrapper_class'     => 'friendship-button awaiting_response_friend',
 402                      'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
 403                      'link_href'         => bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/',
 404                      'link_text'         => __( 'Friendship Requested', 'buddypress' ),
 405                      'link_id'           => 'friend-' . $potential_friend_id,
 406                      'link_rel'          => 'remove',
 407                      'link_class'        => 'friendship-button awaiting_response_friend requested'
 408                  );
 409                  break;
 410  
 411              case 'is_friend' :
 412                  $button = array(
 413                      'id'                => 'is_friend',
 414                      'component'         => 'friends',
 415                      'must_be_logged_in' => true,
 416                      'block_self'        => false,
 417                      'wrapper_class'     => 'friendship-button is_friend',
 418                      'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
 419                      'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend' ),
 420                      'link_text'         => __( 'Cancel Friendship', 'buddypress' ),
 421                      'link_id'           => 'friend-' . $potential_friend_id,
 422                      'link_rel'          => 'remove',
 423                      'link_class'        => 'friendship-button is_friend remove'
 424                  );
 425                  break;
 426  
 427              default:
 428                  $button = array(
 429                      'id'                => 'not_friends',
 430                      'component'         => 'friends',
 431                      'must_be_logged_in' => true,
 432                      'block_self'        => true,
 433                      'wrapper_class'     => 'friendship-button not_friends',
 434                      'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
 435                      'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' ),
 436                      'link_text'         => __( 'Add Friend', 'buddypress' ),
 437                      'link_id'           => 'friend-' . $potential_friend_id,
 438                      'link_rel'          => 'add',
 439                      'link_class'        => 'friendship-button not_friends add'
 440                  );
 441                  break;
 442          }
 443  
 444          /**
 445           * Filters the HTML for the add friend button.
 446           *
 447           * @since 1.1.0
 448           *
 449           * @param string $button HTML markup for add friend button.
 450           */
 451          return bp_get_button( apply_filters( 'bp_get_add_friend_button', $button ) );
 452      }
 453  
 454  /**
 455   * Get a comma-separated list of IDs of a user's friends.
 456   *
 457   * @since 1.2.0
 458   *
 459   * @param int $user_id Optional. Default: the displayed user's ID, or the
 460   *                     logged-in user's ID.
 461   * @return false|string A comma-separated list of friend IDs if any are found,
 462   *                      otherwise false.
 463   */
 464  function bp_get_friend_ids( $user_id = 0 ) {
 465  
 466      if ( empty( $user_id ) )
 467          $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
 468  
 469      $friend_ids = friends_get_friend_user_ids( $user_id );
 470  
 471      if ( empty( $friend_ids ) )
 472          return false;
 473  
 474      return implode( ',', friends_get_friend_user_ids( $user_id ) );
 475  }
 476  
 477  /**
 478   * Get a user's friendship requests.
 479   *
 480   * Note that we return a 0 if no pending requests are found. This is necessary
 481   * because of the structure of the $include parameter in bp_has_members().
 482   *
 483   * @since 1.2.0
 484   *
 485   * @param int $user_id ID of the user whose requests are being retrieved.
 486   *                     Defaults to displayed user.
 487   * @return array|int An array of user IDs if found, or a 0 if none are found.
 488   */
 489  function bp_get_friendship_requests( $user_id = 0 ) {
 490      if ( !$user_id ) {
 491          $user_id = bp_displayed_user_id();
 492      }
 493  
 494      if ( !$user_id ) {
 495          return 0;
 496      }
 497  
 498      $requests = friends_get_friendship_request_user_ids( $user_id );
 499  
 500      if ( !empty( $requests ) ) {
 501          $requests = implode( ',', (array) $requests );
 502      } else {
 503          $requests = 0;
 504      }
 505  
 506      /**
 507       * Filters the total pending friendship requests for a user.
 508       *
 509       * @since 1.2.0
 510       * @since 2.6.0 Added the `$user_id` parameter.
 511       *
 512       * @param array|int $requests An array of user IDs if found, or a 0 if none are found.
 513       * @param int       $user_id  ID of the queried user.
 514       */
 515      return apply_filters( 'bp_get_friendship_requests', $requests, $user_id );
 516  }
 517  
 518  /**
 519   * Output the ID of the friendship between the logged-in user and the current user in the loop.
 520   *
 521   * @since 1.2.0
 522   */
 523  function bp_friend_friendship_id() {
 524      echo bp_get_friend_friendship_id();
 525  }
 526      /**
 527       * Return the ID of the friendship between the logged-in user and the current user in the loop.
 528       *
 529       * @since 1.2.0
 530       *
 531       * @return int ID of the friendship.
 532       */
 533  	function bp_get_friend_friendship_id() {
 534          global $members_template;
 535  
 536          if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) {
 537              $friendship_id = friends_get_friendship_id( $members_template->member->id, bp_loggedin_user_id() );
 538              wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' );
 539          }
 540  
 541          /**
 542           * Filters the ID of the friendship between the logged in user and the current user in the loop.
 543           *
 544           * @since 1.2.0
 545           *
 546           * @param int $friendship_id ID of the friendship.
 547           */
 548          return apply_filters( 'bp_get_friend_friendship_id', $friendship_id );
 549      }
 550  
 551  /**
 552   * Output the URL for accepting the current friendship request in the loop.
 553   *
 554   * @since 1.0.0
 555   */
 556  function bp_friend_accept_request_link() {
 557      echo bp_get_friend_accept_request_link();
 558  }
 559      /**
 560       * Return the URL for accepting the current friendship request in the loop.
 561       *
 562       * @since 1.0.0
 563       *
 564       * @return string accept-friendship URL.
 565       */
 566  	function bp_get_friend_accept_request_link() {
 567          global $members_template;
 568  
 569          if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) {
 570              $friendship_id = friends_get_friendship_id( $members_template->member->id, bp_loggedin_user_id() );
 571              wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' );
 572          }
 573  
 574          /**
 575           * Filters the URL for accepting the current friendship request in the loop.
 576           *
 577           * @since 1.0.0
 578           * @since 2.6.0 Added the `$friendship_id` parameter.
 579           *
 580           * @param string $value         Accept-friendship URL.
 581           * @param int    $friendship_id ID of the friendship.
 582           */
 583          return apply_filters( 'bp_get_friend_accept_request_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/accept/' . $friendship_id ), 'friends_accept_friendship' ), $friendship_id );
 584      }
 585  
 586  /**
 587   * Output the URL for rejecting the current friendship request in the loop.
 588   *
 589   * @since 1.0.0
 590   */
 591  function bp_friend_reject_request_link() {
 592      echo bp_get_friend_reject_request_link();
 593  }
 594      /**
 595       * Return the URL for rejecting the current friendship request in the loop.
 596       *
 597       * @since 1.0.0
 598       *
 599       * @return string reject-friendship URL.
 600       */
 601  	function bp_get_friend_reject_request_link() {
 602          global $members_template;
 603  
 604          if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) {
 605              $friendship_id = friends_get_friendship_id( $members_template->member->id, bp_loggedin_user_id() );
 606              wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' );
 607          }
 608  
 609          /**
 610           * Filters the URL for rejecting the current friendship request in the loop.
 611           *
 612           * @since 1.0.0
 613           * @since 2.6.0 Added the `$friendship_id` parameter.
 614           *
 615           * @param string $value         Reject-friendship URL.
 616           * @param int    $friendship_id ID of the friendship.
 617           */
 618          return apply_filters( 'bp_get_friend_reject_request_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/reject/' . $friendship_id ), 'friends_reject_friendship' ), $friendship_id );
 619      }
 620  
 621  /**
 622   * Output the total friend count for a given user.
 623   *
 624   * @since 1.2.0
 625   *
 626   * @param int $user_id See {@link friends_get_total_friend_count()}.
 627   */
 628  function bp_total_friend_count( $user_id = 0 ) {
 629      echo bp_get_total_friend_count( $user_id );
 630  }
 631      /**
 632       * Return the total friend count for a given user.
 633       *
 634       * @since 1.2.0
 635       *
 636       * @param int $user_id See {@link friends_get_total_friend_count()}.
 637       * @return int Total friend count.
 638       */
 639  	function bp_get_total_friend_count( $user_id = 0 ) {
 640  
 641          /**
 642           * Filters the total friend count for a given user.
 643           *
 644           * @since 1.2.0
 645           * @since 2.6.0 Added the `$user_id` parameter.
 646           *
 647           * @param int $value   Total friend count.
 648           * @param int $user_id ID of the queried user.
 649           */
 650          return apply_filters( 'bp_get_total_friend_count', friends_get_total_friend_count( $user_id ), $user_id );
 651      }
 652  
 653  /**
 654   * Output the total friendship request count for a given user.
 655   *
 656   * @since 1.2.0
 657   *
 658   * @see bp_friend_get_total_requests_count() for description of arguments.
 659   *
 660   * @param int $user_id See {@link bp_friend_get_total_requests_count().
 661   */
 662  function bp_friend_total_requests_count( $user_id = 0 ) {
 663      echo bp_friend_get_total_requests_count( $user_id );
 664  }
 665      /**
 666       * Return the total friendship request count for a given user.
 667       *
 668       * @since 1.2.0
 669       *
 670       * @param int $user_id ID of the user whose requests are being counted.
 671       *                     Default: ID of the logged-in user.
 672       * @return int Friend count.
 673       */
 674  	function bp_friend_get_total_requests_count( $user_id = 0 ) {
 675          if ( empty( $user_id ) )
 676              $user_id = bp_loggedin_user_id();
 677  
 678          /**
 679           * Filters the total friendship request count for a given user.
 680           *
 681           * @since 1.2.0
 682           * @since 2.6.0 Added the `$user_id` parameter.
 683           *
 684           * @param int $value   Friendship request count.
 685           * @param int $user_id ID of the queried user.
 686           */
 687          return apply_filters( 'bp_friend_get_total_requests_count', count( BP_Friends_Friendship::get_friend_user_ids( $user_id, true ) ), $user_id );
 688      }
 689  
 690  /** Stats **********************************************************************/
 691  
 692  /**
 693   * Display the number of friends in user's profile.
 694   *
 695   * @since 2.0.0
 696   *
 697   * @param array|string $args before|after|user_id.
 698   */
 699  function bp_friends_profile_stats( $args = '' ) {
 700      echo bp_friends_get_profile_stats( $args );
 701  }
 702  add_action( 'bp_members_admin_user_stats', 'bp_friends_profile_stats', 7, 1 );
 703  
 704  /**
 705   * Return the number of friends in user's profile.
 706   *
 707   * @since 2.0.0
 708   *
 709   * @param array|string $args before|after|user_id.
 710   * @return string HTML for stats output.
 711   */
 712  function bp_friends_get_profile_stats( $args = '' ) {
 713  
 714      // Parse the args.
 715      $r = bp_parse_args( $args, array(
 716          'before'  => '<li class="bp-friends-profile-stats">',
 717          'after'   => '</li>',
 718          'user_id' => bp_displayed_user_id(),
 719          'friends' => 0,
 720          'output'  => ''
 721      ), 'friends_get_profile_stats' );
 722  
 723      // Allow completely overloaded output.
 724      if ( empty( $r['output'] ) ) {
 725  
 726          // Only proceed if a user ID was passed.
 727          if ( ! empty( $r['user_id'] ) ) {
 728  
 729              // Get the user's friends.
 730              if ( empty( $r['friends'] ) ) {
 731                  $r['friends'] = absint( friends_get_total_friend_count( $r['user_id'] ) );
 732              }
 733  
 734              // If friends exist, show some formatted output.
 735              $r['output'] = $r['before'];
 736  
 737              /* translators: %d: total friend count */
 738              $r['output'] .= sprintf( _n( '%d friend', '%d friends', $r['friends'], 'buddypress' ), '<strong>' . number_format_i18n( $r['friends'] ) . '</strong>' );
 739              $r['output'] .= $r['after'];
 740          }
 741      }
 742  
 743      /**
 744       * Filters the number of friends in user's profile.
 745       *
 746       * @since 2.0.0
 747       *
 748       * @param string $value Formatted string displaying total friends count.
 749       * @param array  $r     Array of arguments for string formatting and output.
 750       */
 751      return apply_filters( 'bp_friends_get_profile_stats', $r['output'], $r );
 752  }


Generated: Mon Sep 28 01:01:32 2020 Cross-referenced by PHPXref 0.7.1