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


Generated: Mon Oct 14 01:01:37 2019 Cross-referenced by PHPXref 0.7.1