[ 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   * @global WPDB $wpdb WordPress database access object.
  26   *
  27   * @param BP_User_Query $user_query   The BP_User_Query object.
  28   * @param string        $user_ids_sql Comma-separated list of user IDs to fetch extra
  29   *                                    data for, as determined by BP_User_Query.
  30   */
  31  function bp_friends_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql ) {
  32      global $wpdb;
  33  
  34      // Stop if user isn't logged in.
  35      if ( ! $user_id = bp_loggedin_user_id() ) {
  36          return;
  37      }
  38  
  39      $maybe_friend_ids = wp_parse_id_list( $user_ids_sql );
  40  
  41      // Bulk prepare the friendship cache.
  42      BP_Friends_Friendship::update_bp_friends_cache( $user_id, $maybe_friend_ids );
  43  
  44      foreach ( $maybe_friend_ids as $friend_id ) {
  45          $status = BP_Friends_Friendship::check_is_friend( $user_id, $friend_id );
  46          $user_query->results[ $friend_id ]->friendship_status = $status;
  47          if ( 'is_friend' == $status ) {
  48              $user_query->results[ $friend_id ]->is_friend = 1;
  49          }
  50      }
  51  
  52  }
  53  add_filter( 'bp_user_query_populate_extras', 'bp_friends_filter_user_query_populate_extras', 4, 2 );
  54  
  55  /**
  56   * Registers Friends personal data exporter.
  57   *
  58   * @since 4.0.0
  59   * @since 5.0.0 adds an `exporter_bp_friendly_name` param to exporters.
  60   *
  61   * @param array $exporters  An array of personal data exporters.
  62   * @return array An array of personal data exporters.
  63   */
  64  function bp_friends_register_personal_data_exporters( $exporters ) {
  65      $exporters['buddypress-friends'] = array(
  66          'exporter_friendly_name'    => __( 'BuddyPress Friends', 'buddypress' ),
  67          'callback'                  => 'bp_friends_personal_data_exporter',
  68          'exporter_bp_friendly_name' => _x( 'Friends', 'BuddyPress Friends data exporter friendly name', 'buddypress' ),
  69      );
  70  
  71      $exporters['buddypress-friends-pending-sent-requests'] = array(
  72          'exporter_friendly_name'    => __( 'BuddyPress Friend Requests (Sent)', 'buddypress' ),
  73          'callback'                  => 'bp_friends_pending_sent_requests_personal_data_exporter',
  74          'exporter_bp_friendly_name' => _x( 'Friend Requests (Sent)', 'BuddyPress Friend Requests data exporter friendly name', 'buddypress' ),
  75      );
  76  
  77      $exporters['buddypress-friends-pending-received-requests'] = array(
  78          'exporter_friendly_name'    => __( 'BuddyPress Friend Requests (Received)', 'buddypress' ),
  79          'callback'                  => 'bp_friends_pending_received_requests_personal_data_exporter',
  80          'exporter_bp_friendly_name' => _x( 'Friend Requests (Received)', 'BuddyPress Friend Requests data exporter friendly name', 'buddypress' ),
  81      );
  82  
  83      return $exporters;
  84  }
  85  add_filter( 'wp_privacy_personal_data_exporters', 'bp_friends_register_personal_data_exporters' );


Generated: Sun Nov 29 01:01:38 2020 Cross-referenced by PHPXref 0.7.1