Skip to:
Content

BuddyPress.org

Ticket #7078: 7078.01.patch

File 7078.01.patch, 7.1 KB (added by r-a-y, 9 years ago)
  • src/bp-groups/bp-groups-cache.php

     
    251251}
    252252add_action( 'bp_groups_member_before_delete', 'bp_groups_clear_user_group_cache_on_other_events', 10, 2 );
    253253add_action( 'bp_groups_member_before_delete_invite', 'bp_groups_clear_user_group_cache_on_other_events', 10, 2 );
     254add_action( 'groups_accept_invite', 'bp_groups_clear_user_group_cache_on_other_events', 10, 2 );
    254255
    255256/* List actions to clear super cached pages on, if super cache is installed */
    256257add_action( 'groups_join_group',                 'bp_core_clear_cache' );
  • src/bp-groups/bp-groups-functions.php

     
    15411541 * @param int    $group_id ID of potential group.
    15421542 * @param string $type     Optional. Use 'sent' to check for sent invites,
    15431543 *                         'all' to check for all. Default: 'sent'.
    1544  * @return bool True if an invitation is found, otherwise false.
     1544 * @return int|bool ID of the membership if found, otherwise false.
    15451545 */
    15461546function groups_check_user_has_invite( $user_id, $group_id, $type = 'sent' ) {
    1547         return BP_Groups_Member::check_has_invite( $user_id, $group_id, $type );
     1547        $invite = false;
     1548
     1549        $args = array(
     1550                'is_confirmed' => false,
     1551                'is_banned'    => null,
     1552                'is_admin'     => null,
     1553                'is_mod'       => null,
     1554        );
     1555
     1556        if ( 'sent' === $type ) {
     1557                $args['invite_sent'] = true;
     1558        }
     1559
     1560        $user_groups = bp_get_user_groups( $user_id, $args );
     1561
     1562        if ( isset( $user_groups[ $group_id ] ) && 0 !== $user_groups[ $group_id ]->inviter_id ) {
     1563                $invite = $user_groups[ $group_id ]->id;
     1564        }
     1565
     1566        return $invite;
    15481567}
    15491568
    15501569/**
     
    18891908 *
    18901909 * @param int $user_id  ID of the user.
    18911910 * @param int $group_id ID of the group.
    1892  * @return int|null ID of the membership if found, otherwise false.
     1911 * @return int|bool ID of the membership if found, otherwise false.
    18931912 */
    18941913function groups_check_for_membership_request( $user_id, $group_id ) {
    1895         return BP_Groups_Member::check_for_membership_request( $user_id, $group_id );
     1914        $request = false;
     1915
     1916        $user_groups = bp_get_user_groups( $user_id, array(
     1917                'is_confirmed' => false,
     1918                'is_banned'    => false,
     1919                'is_admin'     => null,
     1920                'is_mod'       => null
     1921        ) );
     1922
     1923        if ( isset( $user_groups[ $group_id ] ) && 0 === $user_groups[ $group_id ]->inviter_id ) {
     1924                $request = $user_groups[ $group_id ]->id;
     1925        }
     1926
     1927        return $request;
    18961928}
    18971929
    18981930/**
  • src/bp-groups/classes/class-bp-groups-member.php

     
    786786         * @param int    $group_id ID of the group.
    787787         * @param string $type     If 'sent', results are limited to those invitations
    788788         *                         that have actually been sent (non-draft). Default: 'sent'.
    789          * @return int|null The ID of the invitation if found, otherwise null.
     789         * @return int
    790790         */
    791791        public static function check_has_invite( $user_id, $group_id, $type = 'sent' ) {
    792                 global $wpdb;
    793 
    794                 if ( empty( $user_id ) )
     792                if ( empty( $user_id ) ) {
    795793                        return false;
     794                }
    796795
    797                 $bp  = buddypress();
    798                 $sql = "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id != 0";
    799 
    800                 if ( 'sent' == $type )
    801                         $sql .= " AND invite_sent = 1";
    802 
    803                 return $wpdb->get_var( $wpdb->prepare( $sql, $user_id, $group_id ) );
     796                return (int) groups_check_user_has_invite( $user_id, $group_id, $type );
    804797        }
    805798
    806799        /**
     
    871864         *
    872865         * @param int $user_id  ID of the user.
    873866         * @param int $group_id ID of the group.
    874          * @return mixed
     867         * @return int
    875868         */
    876869        public static function check_is_admin( $user_id, $group_id ) {
    877                 global $wpdb;
    878 
    879                 if ( empty( $user_id ) )
     870                if ( empty( $user_id ) ) {
    880871                        return false;
     872                }
    881873
    882                 $bp = buddypress();
    883 
    884                 return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_admin = 1 AND is_banned = 0", $user_id, $group_id ) );
     874                return (int) groups_is_user_admin( $user_id, $group_id );
    885875        }
    886876
    887877        /**
     
    891881         *
    892882         * @param int $user_id  ID of the user.
    893883         * @param int $group_id ID of the group.
    894          * @return mixed
     884         * @return int
    895885         */
    896886        public static function check_is_mod( $user_id, $group_id ) {
    897                 global $wpdb;
    898 
    899                 if ( empty( $user_id ) )
     887                if ( empty( $user_id ) ) {
    900888                        return false;
     889                }
    901890
    902                 $bp = buddypress();
    903 
    904                 return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_mod = 1 AND is_banned = 0", $user_id, $group_id ) );
     891                return (int) groups_is_user_mod( $user_id, $group_id );
    905892        }
    906893
    907894        /**
     
    911898         *
    912899         * @param int $user_id  ID of the user.
    913900         * @param int $group_id ID of the group.
    914          * @return mixed
     901         * @return int
    915902         */
    916903        public static function check_is_member( $user_id, $group_id ) {
    917                 global $wpdb;
    918 
    919                 if ( empty( $user_id ) )
     904                if ( empty( $user_id ) ) {
    920905                        return false;
     906                }
    921907
    922                 $bp = buddypress();
    923 
    924                 return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 1 AND is_banned = 0", $user_id, $group_id ) );
     908                return (int) groups_is_user_member( $user_id, $group_id );
    925909        }
    926910
    927911        /**
     
    931915         *
    932916         * @param int $user_id  ID of the user.
    933917         * @param int $group_id ID of the group.
    934          * @return mixed
     918         * @return int
    935919         */
    936920        public static function check_is_banned( $user_id, $group_id ) {
    937                 global $wpdb;
    938 
    939                 if ( empty( $user_id ) )
     921                if ( empty( $user_id ) ) {
    940922                        return false;
     923                }
    941924
    942                 $bp = buddypress();
    943 
    944                 return $wpdb->get_var( $wpdb->prepare( "SELECT is_banned FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
     925                return (int) groups_is_user_banned( $user_id, $group_id );
    945926        }
    946927
    947928        /**
     
    975956         * @return int|null ID of the membership if found, otherwise false.
    976957         */
    977958        public static function check_for_membership_request( $user_id, $group_id ) {
    978                 global $wpdb;
    979 
    980                 if ( empty( $user_id ) )
     959                if ( empty( $user_id ) ) {
    981960                        return false;
     961                }
    982962
    983                 $bp = buddypress();
    984 
    985                 return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND is_banned = 0 AND inviter_id = 0", $user_id, $group_id ) );
     963                return (int) groups_check_for_membership_request( $user_id, $group_id );
    986964        }
    987965
    988966        /**
  • tests/phpunit/testcases/groups/class-bp-groups-member.php

     
    990990                $this->assertTrue( is_numeric( $member ) && $member > 0 );
    991991                // Check that the invite has been removed.
    992992                $invite = groups_check_user_has_invite( $u2, $g1, 'all' );
    993                 $this->assertTrue( is_null( $invite ) );
     993                $this->assertFalse( $invite );
    994994        }
    995995
    996996        /**