[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Friend Filters.
   4   *
   5   * @package BuddyPress
   6   * @subpackage FriendsFilters
   7   * @since 1.7.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  // Format numerical output.
  14  add_filter( 'friends_get_total_friend_count', 'bp_core_number_format' );
  15  add_filter( 'bp_get_total_friend_count', 'bp_core_number_format' );
  16  
  17  /**
  18   * Filter BP_User_Query::populate_extras to add confirmed friendship status.
  19   *
  20   * Each member in the user query is checked for confirmed friendship status
  21   * against the logged-in user.
  22   *
  23   * @since 1.7.0
  24   *
  25   * @param BP_User_Query $user_query   The BP_User_Query object.
  26   * @param string        $user_ids_sql Comma-separated list of user IDs to fetch extra
  27   *                                    data for, as determined by BP_User_Query.
  28   */
  29  function bp_friends_filter_user_query_populate_extras( $user_query, $user_ids_sql ) {
  30  
  31      // Stop if user isn't logged in.
  32      $user_id = bp_loggedin_user_id();
  33      if ( ! $user_id ) {
  34          return;
  35      }
  36  
  37      $maybe_friend_ids = wp_parse_id_list( $user_ids_sql );
  38  
  39      // Bulk prepare the friendship cache.
  40      BP_Friends_Friendship::update_bp_friends_cache( $user_id, $maybe_friend_ids );
  41  
  42      foreach ( $maybe_friend_ids as $friend_id ) {
  43          $status = BP_Friends_Friendship::check_is_friend( $user_id, $friend_id );
  44          $user_query->results[ $friend_id ]->friendship_status = $status;
  45          if ( 'is_friend' === $status ) {
  46              $user_query->results[ $friend_id ]->is_friend = 1;
  47          }
  48      }
  49  }
  50  add_filter( 'bp_user_query_populate_extras', 'bp_friends_filter_user_query_populate_extras', 4, 2 );
  51  
  52  /**
  53   * Registers Friends personal data exporter.
  54   *
  55   * @since 4.0.0
  56   * @since 5.0.0 adds an `exporter_bp_friendly_name` param to exporters.
  57   *
  58   * @param array $exporters  An array of personal data exporters.
  59   * @return array An array of personal data exporters.
  60   */
  61  function bp_friends_register_personal_data_exporters( $exporters ) {
  62      $exporters['buddypress-friends'] = array(
  63          'exporter_friendly_name'    => __( 'BuddyPress Friends', 'buddypress' ),
  64          'callback'                  => 'bp_friends_personal_data_exporter',
  65          'exporter_bp_friendly_name' => _x( 'Friends', 'BuddyPress Friends data exporter friendly name', 'buddypress' ),
  66      );
  67  
  68      $exporters['buddypress-friends-pending-sent-requests'] = array(
  69          'exporter_friendly_name'    => __( 'BuddyPress Friend Requests (Sent)', 'buddypress' ),
  70          'callback'                  => 'bp_friends_pending_sent_requests_personal_data_exporter',
  71          'exporter_bp_friendly_name' => _x( 'Friend Requests (Sent)', 'BuddyPress Friend Requests data exporter friendly name', 'buddypress' ),
  72      );
  73  
  74      $exporters['buddypress-friends-pending-received-requests'] = array(
  75          'exporter_friendly_name'    => __( 'BuddyPress Friend Requests (Received)', 'buddypress' ),
  76          'callback'                  => 'bp_friends_pending_received_requests_personal_data_exporter',
  77          'exporter_bp_friendly_name' => _x( 'Friend Requests (Received)', 'BuddyPress Friend Requests data exporter friendly name', 'buddypress' ),
  78      );
  79  
  80      return $exporters;
  81  }
  82  add_filter( 'wp_privacy_personal_data_exporters', 'bp_friends_register_personal_data_exporters' );


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1