Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/21/2017 10:37:23 PM (9 years ago)
Author:
r-a-y
Message:

Groups: Add fine-grained querying of invite sent status in groups_get_invites_for_group().

This commit introduces a new $sent parameter to groups_get_invites_for_group()
and BP_Groups_Group::get_invites(). With this parameter, developers can
now query group invites by sent status or not.

See #7397.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-groups-group.php

    r11558 r11604  
    753753         *
    754754         * @since 1.6.0
    755          *
    756          * @param int $user_id ID of the inviting user.
    757          * @param int $group_id ID of the group.
    758          * @return array IDs of users who have been invited to the group by the
    759          *               user but have not yet accepted.
    760          */
    761         public static function get_invites( $user_id, $group_id ) {
     755         * @since 2.9.0 Added $sent as a parameter.
     756         *
     757         * @param  int      $user_id  ID of the inviting user.
     758         * @param  int      $group_id ID of the group.
     759         * @param  int|null $sent     Query for a specific invite sent status. If 0, this will query for users
     760         *                            that haven't had an invite sent to them yet. If 1, this will query for
     761         *                            users that have had an invite sent to them. If null, no invite status will
     762         *                            queried. Default: null.
     763         * @return array    IDs of users who have been invited to the group by the user but have not
     764         *                  yet accepted.
     765         */
     766        public static function get_invites( $user_id, $group_id, $sent = null ) {
    762767                global $wpdb;
    763768
    764                 $bp = buddypress();
    765 
    766                 return $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d and is_confirmed = 0 AND inviter_id = %d", $group_id, $user_id ) );
     769                $bp  = buddypress();
     770                $sql = $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d and is_confirmed = 0 AND inviter_id = %d", $group_id, $user_id );
     771
     772                // Query for a specific invite sent status.
     773                if ( ! is_null( $sent ) ) {
     774                        $sql .= $wpdb->prepare( ' AND invite_sent = %d', $sent );
     775                }
     776
     777                return $wpdb->get_col( $sql );
    767778        }
    768779
Note: See TracChangeset for help on using the changeset viewer.