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


Generated: Thu Apr 25 01:01:12 2024 Cross-referenced by PHPXref 0.7.1