Changeset 11027
- Timestamp:
- 08/22/2016 10:11:20 PM (8 years ago)
- Location:
- trunk/src/bp-groups
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-functions.php
r10978 r11027 115 115 // Pass an existing group ID. 116 116 if ( ! empty( $group_id ) ) { 117 $group = groups_get_group( array( 'group_id' => (int)$group_id ) );117 $group = groups_get_group( array( 'group_id' => $group_id ) ); 118 118 $name = ! empty( $name ) ? $name : $group->name; 119 119 $slug = ! empty( $slug ) ? $slug : $group->slug; … … 416 416 * 417 417 * @param string $group_slug The group's slug. 418 * @return int The ID.418 * @return int|null The group ID on success; null on failure. 419 419 */ 420 420 function groups_get_id( $group_slug ) { 421 return (int)BP_Groups_Group::group_exists( $group_slug );421 return BP_Groups_Group::group_exists( $group_slug ); 422 422 } 423 423 -
trunk/src/bp-groups/classes/class-bp-groups-group.php
r10937 r11027 176 176 177 177 if ( !empty( $id ) ) { 178 $this->id = $id;178 $this->id = (int) $id; 179 179 $this->populate(); 180 180 } … … 209 209 210 210 // Group found so setup the object variables. 211 $this->id = $group->id;212 $this->creator_id = $group->creator_id;211 $this->id = (int) $group->id; 212 $this->creator_id = (int) $group->creator_id; 213 213 $this->name = stripslashes( $group->name ); 214 214 $this->slug = $group->slug; 215 215 $this->description = stripslashes( $group->description ); 216 216 $this->status = $group->status; 217 $this->enable_forum = $group->enable_forum;217 $this->enable_forum = (int) $group->enable_forum; 218 218 $this->date_created = $group->date_created; 219 219 … … 232 232 // Add admins and moderators to their respective arrays. 233 233 foreach ( (array) $admin_mods as $user ) { 234 $user->user_id = (int) $user->user_id; 235 $user->is_admin = (int) $user->is_admin; 236 $user->is_mod = (int) $user->is_mod; 237 234 238 if ( !empty( $user->is_admin ) ) { 235 239 $this->admins[] = $user; … … 242 246 // from the bp_groups cache because it's cached independently. 243 247 $this->last_activity = groups_get_groupmeta( $this->id, 'last_activity' ); 244 $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' );248 $this->total_member_count = (int) groups_get_groupmeta( $this->id, 'total_member_count' ); 245 249 246 250 // Set user-specific data. … … 436 440 * @param string|bool $table_name Optional. Name of the table to check 437 441 * against. Default: $bp->groups->table_name. 438 * @return string|null ID of the group, if one is found, else null.442 * @return int|null Group ID if found; null if not. 439 443 */ 440 444 public static function group_exists( $slug, $table_name = false ) { … … 447 451 return false; 448 452 449 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$table_name} WHERE slug = %s", strtolower( $slug ) ) ); 453 $query = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$table_name} WHERE slug = %s", strtolower( $slug ) ) ); 454 455 return is_numeric( $query ) ? (int) $query : $query; 450 456 } 451 457 -
trunk/src/bp-groups/classes/class-bp-groups-member.php
r10794 r11027 186 186 187 187 if ( !empty( $member ) ) { 188 $this->id = $member->id;189 $this->group_id = $member->group_id;190 $this->user_id = $member->user_id;191 $this->inviter_id = $member->inviter_id;192 $this->is_admin = $member->is_admin;193 $this->is_mod = $member->is_mod;194 $this->is_banned = $member->is_banned;188 $this->id = (int) $member->id; 189 $this->group_id = (int) $member->group_id; 190 $this->user_id = (int) $member->user_id; 191 $this->inviter_id = (int) $member->inviter_id; 192 $this->is_admin = (int) $member->is_admin; 193 $this->is_mod = (int) $member->is_mod; 194 $this->is_banned = (int) $member->is_banned; 195 195 $this->user_title = $member->user_title; 196 196 $this->date_modified = $member->date_modified; 197 $this->is_confirmed = $member->is_confirmed;197 $this->is_confirmed = (int) $member->is_confirmed; 198 198 $this->comments = $member->comments; 199 $this->invite_sent = $member->invite_sent;199 $this->invite_sent = (int) $member->invite_sent; 200 200 201 201 $this->user = new BP_Core_User( $this->user_id ); … … 787 787 * @param string $type If 'sent', results are limited to those invitations 788 788 * 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|null The ID of the invitation if found; null if not found. 790 790 */ 791 791 public static function check_has_invite( $user_id, $group_id, $type = 'sent' ) { … … 801 801 $sql .= " AND invite_sent = 1"; 802 802 803 return $wpdb->get_var( $wpdb->prepare( $sql, $user_id, $group_id ) ); 803 $query = $wpdb->get_var( $wpdb->prepare( $sql, $user_id, $group_id ) ); 804 805 return is_numeric( $query ) ? (int) $query : $query; 804 806 } 805 807 … … 932 934 * @param int $user_id ID of the user. 933 935 * @param int $group_id ID of the group. 934 * @return mixed 936 * @return int|null int 1 if user is banned; int 0 if user is not banned; 937 * null if user is not part of the group or if group doesn't exist. 935 938 */ 936 939 public static function check_is_banned( $user_id, $group_id ) { … … 942 945 $bp = buddypress(); 943 946 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 ) ); 947 $query = $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 ) ); 948 949 return is_numeric( $query ) ? (int) $query : $query; 945 950 } 946 951 … … 952 957 * @param int $user_id ID of the user. 953 958 * @param int $group_id ID of the group. 954 * @return int|null ID of the group if the user is the creator, 955 * otherwise false. 959 * @return int|null int of group ID if user is the creator; null on failure. 956 960 */ 957 961 public static function check_is_creator( $user_id, $group_id ) { … … 963 967 $bp = buddypress(); 964 968 965 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) ); 969 $query = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) ); 970 971 return is_numeric( $query ) ? (int) $query : $query; 966 972 } 967 973 … … 973 979 * @param int $user_id ID of the user. 974 980 * @param int $group_id ID of the group. 975 * @return int |null ID of the membership if found, otherwise false.981 * @return int Database ID of the membership if found; int 0 on failure. 976 982 */ 977 983 public static function check_for_membership_request( $user_id, $group_id ) { … … 1002 1008 // If the user is logged in and viewing their random groups, we can show hidden and private groups. 1003 1009 if ( bp_is_my_profile() ) { 1004 return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups) );1010 return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) ) ); 1005 1011 } else { 1006 return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups) );1012 return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) ) ); 1007 1013 } 1008 1014 } … … 1021 1027 $bp = buddypress(); 1022 1028 1023 return $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id) );1029 return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) ) ); 1024 1030 } 1025 1031 … … 1044 1050 } 1045 1051 1052 // Integer casting. 1053 foreach ( (array) $group_admins as $key => $data ) { 1054 $group_admins[ $key ]->user_id = (int) $group_admins[ $key ]->user_id; 1055 } 1056 1046 1057 return $group_admins; 1047 1058 } … … 1060 1071 $bp = buddypress(); 1061 1072 1062 return $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_mod = 1 AND is_banned = 0", $group_id ) ); 1073 $group_mods = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_mod = 1 AND is_banned = 0", $group_id ) ); 1074 1075 // Integer casting. 1076 foreach ( (array) $group_mods as $key => $data ) { 1077 $group_mods[ $key ]->user_id = (int) $group_mods[ $key ]->user_id; 1078 } 1079 1080 return $group_mods; 1063 1081 } 1064 1082 … … 1093 1111 $bp = buddypress(); 1094 1112 1095 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 = 0", $group_id) );1113 return array_map( 'intval', $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 = 0", $group_id ) ) ); 1096 1114 } 1097 1115
Note: See TracChangeset
for help on using the changeset viewer.