Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/05/2014 02:37:27 PM (13 years ago)
Author:
boonebgorges
Message:

Introduce 'inviter_id' and 'invite_sent' params to BP_Group_Member_Query

These additional parameters make it possible to use BP_Group_Member_Query for
unconfirmed group memberships, as in the case of invitations and requests. This
will allow it to be swapped for the internals of bp_group_has_members(). See

Props dcavins for an initial patch

File:
1 edited

Legend:

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

    r8008 r8044  
    14481448 * Query for the members of a group.
    14491449 *
     1450 * Special notes about the group members data schema:
     1451 * - *Members* are entries with is_confirmed = 1
     1452 * - *Pending requests* are entries with is_confirmed = 0 and inviter_id = 0
     1453 * - *Pending and sent invitations* are entries with is_confirmed = 0 and
     1454 *   inviter_id != 0 and invite_sent = 1
     1455 * - *Pending and unsent invitations* are entries with is_confirmed = 0 and
     1456 *   inviter_id != 0 and invite_sent = 0
     1457 *
    14501458 * @since BuddyPress (1.8.0)
    14511459 *
    … …  
    15151523                        'group_role'   => array( 'member' ),
    15161524                        'is_confirmed' => true,
     1525                        'invite_sent'  => null,
     1526                        'inviter_id'   => null,
    15171527                        'type'         => 'last_joined',
    15181528                ) );
    … …  
    15631573                $is_confirmed = ! empty( $this->query_vars['is_confirmed'] ) ? 1 : 0;
    15641574                $sql['where'][] = $wpdb->prepare( "is_confirmed = %d", $is_confirmed );
     1575
     1576                // invite_sent
     1577                if ( ! is_null( $this->query_vars['invite_sent'] ) ) {
     1578                        $invite_sent = ! empty( $this->query_vars['invite_sent'] ) ? 1 : 0;
     1579                        $sql['where'][] = $wpdb->prepare( "invite_sent = %d", $invite_sent );
     1580                }
     1581
     1582                // inviter_id
     1583                if ( ! is_null( $this->query_vars['inviter_id'] ) ) {
     1584                        $inviter_id = $this->query_vars['inviter_id'];
     1585
     1586                        // Empty: inviter_id = 0. (pass false, 0, or empty array)
     1587                        if ( empty( $inviter_id ) ) {
     1588                                $sql['where'][] = "inviter_id = 0";
     1589
     1590                        // The string 'any' matches any non-zero value (inviter_id != 0)
     1591                        } else if ( 'any' === $inviter_id ) {
     1592                                $sql['where'][] = "inviter_id != 0";
     1593
     1594                        // Assume that a list of inviter IDs has been passed
     1595                        } else {
     1596                                // Parse and sanitize
     1597                                $inviter_ids = wp_parse_id_list( $inviter_id );
     1598                                if ( ! empty( $inviter_ids ) ) {
     1599                                        $inviter_ids_sql = implode( ',', $inviter_ids );
     1600                                        $sql['where'][] = "inviter_id IN ({$inviter_ids_sql})";
     1601                                }
     1602                        }
     1603                }
    15651604
    15661605                // Role information is stored as follows: admins have
Note: See TracChangeset for help on using the changeset viewer.