Skip to:
Content

BuddyPress.org

Ticket #6977: 6977.03.patch

File 6977.03.patch, 38.7 KB (added by r-a-y, 9 years ago)

Work in progress. About 90% done. WIll finish up in the next few days.

  • src/bp-activity/bp-activity-functions.php

     
    176176        }
    177177
    178178        // Get activity object.
    179         $activity  = new BP_Activity_Activity( (int) $activity_id );
     179        $activity  = new BP_Activity_Activity( $activity_id );
    180180
    181181        // Try to find mentions.
    182182        $usernames = bp_activity_find_mentions( strip_tags( $activity->content ) );
     
    26332633        }
    26342634
    26352635        // Check to see if the parent activity is hidden, and if so, hide this comment publicly.
    2636         $is_hidden = ( (int) $activity->hide_sitewide ) ? 1 : 0;
     2636        $is_hidden = $activity->hide_sitewide ? 1 : 0;
    26372637
    26382638        /**
    26392639         * Filters the content of a new comment.
  • src/bp-activity/bp-activity-screens.php

     
    335335                } else {
    336336                        $url = sprintf(
    337337                                site_url( 'wp-login.php?redirect_to=%s' ),
    338                                 urlencode( esc_url_raw( bp_activity_get_permalink( (int) bp_current_action() ) ) )
     338                                urlencode( esc_url_raw( bp_activity_get_permalink( bp_current_action() ) ) )
    339339                        );
    340340                }
    341341
  • src/bp-activity/bp-activity-template.php

     
    16521652                // Users are allowed to delete their own activity. This is actually
    16531653                // quite powerful, because doing so also deletes all comments to that
    16541654                // activity item. We should revisit this eventually.
    1655                 if ( isset( $activity->user_id ) && ( (int) $activity->user_id === bp_loggedin_user_id() ) ) {
     1655                if ( isset( $activity->user_id ) && ( $activity->user_id === bp_loggedin_user_id() ) ) {
    16561656                        $can_delete = true;
    16571657                }
    16581658
     
    17071707                }
    17081708
    17091709                // Get the ID of the parent activity content.
    1710                 $parent_id = (int) $activities_template->activity->item_id;
     1710                $parent_id = $activities_template->activity->item_id;
    17111711
    17121712                // Bail if no parent content.
    17131713                if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) {
     
    17711771                }
    17721772
    17731773                // Get the ID of the parent activity content.
    1774                 $parent_id = (int) $activities_template->activity->item_id;
     1774                $parent_id = $activities_template->activity->item_id;
    17751775
    17761776                // Bail if no parent item.
    17771777                if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) {
  • src/bp-activity/classes/class-bp-activity-activity.php

     
    107107         * @since 1.1.0
    108108         * @var int
    109109         */
    110         var $hide_sitewide = false;
     110        var $hide_sitewide = 0;
    111111
    112112        /**
    113113         * Node boundary start for activity or activity comment.
     
    142142         */
    143143        public function __construct( $id = false ) {
    144144                if ( !empty( $id ) ) {
    145                         $this->id = $id;
     145                        $this->id = (int) $id;
    146146                        $this->populate();
    147147                }
    148148        }
     
    175175                        $this->action            = $row->action;
    176176                        $this->content           = $row->content;
    177177                        $this->date_recorded     = $row->date_recorded;
    178                         $this->hide_sitewide     = $row->hide_sitewide;
     178                        $this->hide_sitewide     = (int) $row->hide_sitewide;
    179179                        $this->mptt_left         = (int) $row->mptt_left;
    180180                        $this->mptt_right        = (int) $row->mptt_right;
    181                         $this->is_spam           = $row->is_spam;
     181                        $this->is_spam           = (int) $row->is_spam;
    182182                }
    183183
    184184                // Generate dynamic 'action' when possible.
     
    708708
    709709                // Now fetch data from the cache.
    710710                foreach ( $activity_ids as $activity_id ) {
    711                         $activities[] = wp_cache_get( $activity_id, 'bp_activity' );
     711                        // Integer casting.
     712                        $activity = wp_cache_get( $activity_id, 'bp_activity' );
     713                        if ( ! empty( $activity ) ) {
     714                                $activity->id                = (int) $activity->id;
     715                                $activity->user_id           = (int) $activity->user_id;
     716                                $activity->item_id           = (int) $activity->item_id;
     717                                $activity->secondary_item_id = (int) $activity->secondary_item_id;
     718                                $activity->hide_sitewide     = (int) $activity->hide_sitewide;
     719                                $activity->mptt_left         = (int) $activity->mptt_left;
     720                                $activity->mptt_right        = (int) $activity->mptt_right;
     721                                $activity->is_spam           = (int) $activity->is_spam;
     722                        }
     723
     724                        $activities[] = $activity;
    712725                }
    713726
    714727                // Then fetch user data.
     
    10711084
    10721085                if ( ! empty( $where_args ) ) {
    10731086                        $where_sql = 'WHERE ' . join( ' AND ', $where_args );
    1074                         return $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
     1087                        $query = $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
     1088
     1089                        return is_numeric( $query ) ? (int) $query : false;
    10751090                }
    10761091
    10771092                return false;
     
    17631778
    17641779                $bp = buddypress();
    17651780
    1766                 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = %s", $content ) );
     1781                $query = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = %s", $content ) );
     1782
     1783                return is_numeric( $query ) ? (int) $query : false;
    17671784        }
    17681785
    17691786        /**
  • src/bp-blogs/bp-blogs-activity.php

     
    830830        remove_action( 'transition_comment_status',     'bp_activity_transition_post_type_comment_status', 10, 3 );
    831831        remove_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment',          10, 4 );
    832832
    833         if ( 1 === (int) $activity->is_spam && 'spam' !== $post_comment_status ) {
     833        if ( 1 === $activity->is_spam && 'spam' !== $post_comment_status ) {
    834834                wp_spam_comment( $post_comment_id );
    835835        } elseif ( ! $activity->is_spam ) {
    836836                if ( 'spam' === $post_comment_status  ) {
  • src/bp-blogs/classes/class-bp-blogs-blog.php

     
    4848         */
    4949        public function __construct( $id = null ) {
    5050                if ( !empty( $id ) ) {
    51                         $this->id = $id;
     51                        $this->id = (int) $id;
    5252                        $this->populate();
    5353                }
    5454        }
     
    6363
    6464                $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) );
    6565
    66                 $this->user_id = $blog->user_id;
    67                 $this->blog_id = $blog->blog_id;
     66                $this->user_id = (int) $blog->user_id;
     67                $this->blog_id = (int) $blog->blog_id;
    6868        }
    6969
    7070        /**
     
    243243
    244244                $paged_blogs = BP_Blogs_Blog::get_blog_extras( $paged_blogs, $blog_ids, $type );
    245245
     246                // Integer casting.
     247                foreach ( (array) $paged_blogs as $key => $data ) {
     248                        $paged_blogs[ $key ]->blog_id       = (int) $paged_blogs[ $key ]->blog_id;
     249                        $paged_blogs[ $key ]->admin_user_id = (int) $paged_blogs[ $key ]->admin_user_id;
     250                }
     251
    246252                if ( $update_meta_cache ) {
    247253                        bp_blogs_update_meta_cache( $blog_ids );
    248254                }
     
    338344                $user_blogs = array();
    339345                foreach ( (array) $blogs as $blog ) {
    340346                        $user_blogs[$blog->blog_id] = new stdClass;
    341                         $user_blogs[$blog->blog_id]->id = $blog->id;
    342                         $user_blogs[$blog->blog_id]->blog_id = $blog->blog_id;
     347                        $user_blogs[$blog->blog_id]->id = (int) $blog->id;
     348                        $user_blogs[$blog->blog_id]->blog_id = (int) $blog->blog_id;
    343349                        $user_blogs[$blog->blog_id]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path;
    344350                        $user_blogs[$blog->blog_id]->name = $blog->name;
    345351                }
     
    364370                if ( !$user_id )
    365371                        $user_id = bp_displayed_user_id();
    366372
    367                 return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
     373                return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) ) );
    368374        }
    369375
    370376        /**
     
    379385
    380386                $bp = buddypress();
    381387
    382                 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
     388                $query = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
     389
     390                return is_numeric( $query ) ? (int) $query : $query;
    383391        }
    384392
    385393        /**
     
    444452                $paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND {$search_terms_sql} ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC{$pag_sql}" );
    445453                $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND {$search_terms_sql} ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC" );
    446454
    447                 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
     455                // Integer casting.
     456                foreach ( (array) $paged_blogs as $key => $data ) {
     457                        $paged_blogs[ $key ]->blog_id = (int) $paged_blogs[ $key ]->blog_id;
     458                }
     459
     460                return array( 'blogs' => $paged_blogs, 'total' => (int) $total_blogs );
    448461        }
    449462
    450463        /**
     
    472485                $paged_blogs = $wpdb->get_results( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql} {$pag_sql}" );
    473486                $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql}" );
    474487
    475                 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
     488                // Integer casting.
     489                foreach ( (array) $paged_blogs as $key => $data ) {
     490                        $paged_blogs[ $key ]->blog_id = (int) $paged_blogs[ $key ]->blog_id;
     491                }
     492
     493                return array( 'blogs' => $paged_blogs, 'total' => (int) $total_blogs );
    476494        }
    477495
    478496        /**
     
    509527                $paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND {$letter_sql} {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC{$pag_sql}" );
    510528                $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND {$letter_sql} {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC" );
    511529
    512                 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
     530                // Integer casting.
     531                foreach ( (array) $paged_blogs as $key => $data ) {
     532                        $paged_blogs[ $key ]->blog_id = (int) $paged_blogs[ $key ]->blog_id;
     533                }
     534
     535                return array( 'blogs' => $paged_blogs, 'total' => (int) $total_blogs );
    513536        }
    514537
    515538        /**
  • src/bp-core/classes/class-bp-core-user.php

     
    823823                $retval = array();
    824824                foreach ( $user_ids as $user_id ) {
    825825                        $retval[ $user_id ] = wp_cache_get( $user_id, 'bp_last_activity' );
     826                        $retval[ $user_id ]['user_id']     = (int) $retval[ $user_id ]['user_id'];
     827                        $retval[ $user_id ]['activity_id'] = (int) $retval[ $user_id ]['activity_id'];
    826828                }
    827829
    828830                return $retval;
  • src/bp-core/classes/class-bp-user-query.php

     
    591591                // Match up to the user ids from the main query.
    592592                foreach ( $this->user_ids as $key => $uid ) {
    593593                        if ( isset( $r[ $uid ] ) ) {
     594                                $r[ $uid ]->ID = (int) $uid;
     595                                $r[ $uid ]->user_status = (int) $r[ $uid ]->user_status;
     596
    594597                                $this->results[ $uid ] = $r[ $uid ];
    595598
    596599                                // The BP template functions expect an 'id'
    597600                                // (as opposed to 'ID') property.
    598                                 $this->results[ $uid ]->id = $uid;
     601                                $this->results[ $uid ]->id = (int) $uid;
    599602
    600603                        // Remove user ID from original user_ids property.
    601604                        } else {
  • src/bp-friends/classes/class-bp-friends-friendship.php

     
    241241                        }
    242242                }
    243243
    244                 return $fids;
     244                return array_map( 'intval', $fids );
    245245        }
    246246
    247247        /**
     
    251251         *
    252252         * @param int $user_id   The ID of the first user.
    253253         * @param int $friend_id The ID of the second user.
    254          * @return int|bool The ID of the friendship object if found, otherwise false.
     254         * @return int|null The ID of the friendship object if found, otherwise null.
    255255         */
    256256        public static function get_friendship_id( $user_id, $friend_id ) {
    257257                global $wpdb;
    258258
    259259                $bp = buddypress();
    260260
    261                 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->friends->table_name} WHERE ( initiator_user_id = %d AND friend_user_id = %d ) OR ( initiator_user_id = %d AND friend_user_id = %d ) AND is_confirmed = 1", $user_id, $friend_id, $friend_id, $user_id ) );
     261                $query = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->friends->table_name} WHERE ( initiator_user_id = %d AND friend_user_id = %d ) OR ( initiator_user_id = %d AND friend_user_id = %d ) AND is_confirmed = 1", $user_id, $friend_id, $friend_id, $user_id ) );
     262
     263                return is_numeric( $query ) ? (int) $query : $query;
    262264        }
    263265
    264266        /**
     
    283285                        wp_cache_set( $user_id, $friend_requests, 'bp_friends_requests' );
    284286                }
    285287
     288                // Integer casting.
     289                if ( ! empty( $friend_requests ) ) {
     290                        $friend_requests = array_map( 'intval', $friend_requests );
     291                }
     292
    286293                return $friend_requests;
    287294        }
    288295
     
    381388                if ( empty( $filtered_friend_ids ) )
    382389                        return false;
    383390
    384                 return array( 'friends' => $filtered_friend_ids, 'total' => (int) $total_friend_ids );
     391                return array( 'friends' => array_map( 'intval', $filtered_friend_ids ), 'total' => (int) $total_friend_ids );
    385392        }
    386393
    387394        /**
  • src/bp-groups/bp-groups-functions.php

     
    114114
    115115        // Pass an existing group ID.
    116116        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 ) );
    118118                $name  = ! empty( $name ) ? $name : $group->name;
    119119                $slug  = ! empty( $slug ) ? $slug : $group->slug;
    120120                $description = ! empty( $description ) ? $description : $group->description;
     
    415415 * @since 1.6.0
    416416 *
    417417 * @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.
    419419 */
    420420function groups_get_id( $group_slug ) {
    421         return (int)BP_Groups_Group::group_exists( $group_slug );
     421        return BP_Groups_Group::group_exists( $group_slug );
    422422}
    423423
    424424/** User Actions **************************************************************/
     
    879879 *
    880880 * @param int $user_id ID of the user.
    881881 * @param int $group_id ID of the group.
    882  * @return bool
     882 * @return int 1 on success; 0 on failure.
    883883 */
    884884function groups_is_user_admin( $user_id, $group_id ) {
    885885        return BP_Groups_Member::check_is_admin( $user_id, $group_id );
     
    892892 *
    893893 * @param int $user_id ID of the user.
    894894 * @param int $group_id ID of the group.
    895  * @return bool
     895 * @return int 1 on success; 0 on failure.
    896896 */
    897897function groups_is_user_mod( $user_id, $group_id ) {
    898898        return BP_Groups_Member::check_is_mod( $user_id, $group_id );
     
    905905 *
    906906 * @param int $user_id ID of the user.
    907907 * @param int $group_id ID of the group.
    908  * @return bool
     908 * @return int 1 on success; 0 on failure.
    909909 */
    910910function groups_is_user_member( $user_id, $group_id ) {
    911911        return BP_Groups_Member::check_is_member( $user_id, $group_id );
     
    919919 * @param int $user_id  ID of the user.
    920920 * @param int $group_id ID of the group.
    921921 *
    922  * @return bool
     922 * @return int|null int 1 if user is banned; int 0 if user is not banned;
     923 *                  null if user is not part of the group or if group doesn't exist.
    923924 */
    924925function groups_is_user_banned( $user_id, $group_id ) {
    925926        return BP_Groups_Member::check_is_banned( $user_id, $group_id );
     
    932933 *
    933934 * @param int $user_id ID of the user.
    934935 * @param int $group_id ID of the group.
    935  * @return bool
     936 * @return int|null int of group ID if user is the creator; null on failure.
    936937 */
    937938function groups_is_user_creator( $user_id, $group_id ) {
    938939        return BP_Groups_Member::check_is_creator( $user_id, $group_id );
     
    13361337 * @param int    $group_id ID of potential group.
    13371338 * @param string $type     Optional. Use 'sent' to check for sent invites,
    13381339 *                         'all' to check for all. Default: 'sent'.
    1339  * @return bool True if an invitation is found, otherwise false.
     1340 * @return int|null The ID of the invitation if found; null if not found.
    13401341 */
    13411342function groups_check_user_has_invite( $user_id, $group_id, $type = 'sent' ) {
    13421343        return BP_Groups_Member::check_has_invite( $user_id, $group_id, $type );
     
    16841685 *
    16851686 * @param int $user_id  ID of the user.
    16861687 * @param int $group_id ID of the group.
    1687  * @return int|null ID of the membership if found, otherwise false.
     1688 * @return int|null ID of the membership if found, otherwise null.
    16881689 */
    16891690function groups_check_for_membership_request( $user_id, $group_id ) {
    16901691        return BP_Groups_Member::check_for_membership_request( $user_id, $group_id );
  • src/bp-groups/classes/class-bp-groups-group.php

     
    175175                ) );
    176176
    177177                if ( !empty( $id ) ) {
    178                         $this->id = $id;
     178                        $this->id = (int) $id;
    179179                        $this->populate();
    180180                }
    181181        }
     
    208208                }
    209209
    210210                // 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;
    213213                $this->name         = stripslashes( $group->name );
    214214                $this->slug         = $group->slug;
    215215                $this->description  = stripslashes( $group->description );
    216216                $this->status       = $group->status;
    217                 $this->enable_forum = $group->enable_forum;
     217                $this->enable_forum = (int) $group->enable_forum;
    218218                $this->date_created = $group->date_created;
    219219
    220220                // Are we getting extra group data?
     
    231231
    232232                        // Add admins and moderators to their respective arrays.
    233233                        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
    234238                                if ( !empty( $user->is_admin ) ) {
    235239                                        $this->admins[] = $user;
    236240                                } else {
     
    241245                        // Set up some specific group vars from meta. Excluded
    242246                        // from the bp_groups cache because it's cached independently.
    243247                        $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' );
    245249
    246250                        // Set user-specific data.
    247251                        $user_id          = bp_loggedin_user_id();
     
    435439         * @param string      $slug       Slug to check.
    436440         * @param string|bool $table_name Optional. Name of the table to check
    437441         *                                against. Default: $bp->groups->table_name.
    438          * @return string|null ID of the group, if one is found, else null.
     442         * @return int Group ID if found; null if not.
    439443         */
    440444        public static function group_exists( $slug, $table_name = false ) {
    441445                global $wpdb;
     
    446450                if ( empty( $slug ) )
    447451                        return false;
    448452
    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;
    450456        }
    451457
    452458        /**
  • src/bp-groups/classes/class-bp-groups-member.php

     
    185185                $member = $wpdb->get_row($sql);
    186186
    187187                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;
    195195                        $this->user_title    = $member->user_title;
    196196                        $this->date_modified = $member->date_modified;
    197                         $this->is_confirmed  = $member->is_confirmed;
     197                        $this->is_confirmed  = (int) $member->is_confirmed;
    198198                        $this->comments      = $member->comments;
    199                         $this->invite_sent   = $member->invite_sent;
     199                        $this->invite_sent   = (int) $member->invite_sent;
    200200
    201201                        $this->user = new BP_Core_User( $this->user_id );
    202202                }
     
    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|null The ID of the invitation if found; null if not found.
    790790         */
    791791        public static function check_has_invite( $user_id, $group_id, $type = 'sent' ) {
    792792                global $wpdb;
     
    800800                if ( 'sent' == $type )
    801801                        $sql .= " AND invite_sent = 1";
    802802
    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;
    804806        }
    805807
    806808        /**
     
    861863         *
    862864         * @param int $user_id  ID of the user.
    863865         * @param int $group_id ID of the group.
    864          * @return mixed
     866         * @return int 1 on success; 0 on failure.
    865867         */
    866868        public static function check_is_admin( $user_id, $group_id ) {
    867869                global $wpdb;
     
    881883         *
    882884         * @param int $user_id  ID of the user.
    883885         * @param int $group_id ID of the group.
    884          * @return mixed
     886         * @return int 1 on success; 0 on failure.
    885887         */
    886888        public static function check_is_mod( $user_id, $group_id ) {
    887889                global $wpdb;
     
    901903         *
    902904         * @param int $user_id  ID of the user.
    903905         * @param int $group_id ID of the group.
    904          * @return mixed
     906         * @return int 1 on success; 0 on failure.
    905907         */
    906908        public static function check_is_member( $user_id, $group_id ) {
    907909                global $wpdb;
     
    921923         *
    922924         * @param int $user_id  ID of the user.
    923925         * @param int $group_id ID of the group.
    924          * @return mixed
     926         * @return int|null int 1 if user is banned; int 0 if user is not banned;
     927         *                  null if user is not part of the group or if group doesn't exist.
    925928         */
    926929        public static function check_is_banned( $user_id, $group_id ) {
    927930                global $wpdb;
     
    931934
    932935                $bp = buddypress();
    933936
    934                 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 ) );
     937                $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 ) );
     938
     939                return is_numeric( $query ) ? (int) $query : $query;
    935940        }
    936941
    937942        /**
     
    941946         *
    942947         * @param int $user_id  ID of the user.
    943948         * @param int $group_id ID of the group.
    944          * @return int|null ID of the group if the user is the creator,
    945          *                  otherwise false.
     949         * @return int|null int of group ID if user is the creator; null on failure.
    946950         */
    947951        public static function check_is_creator( $user_id, $group_id ) {
    948952                global $wpdb;
     
    952956
    953957                $bp = buddypress();
    954958
    955                 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) );
     959                $query = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) );
     960
     961                return is_numeric( $query ) ? (int) $query : $query;
    956962        }
    957963
    958964        /**
     
    962968         *
    963969         * @param int $user_id  ID of the user.
    964970         * @param int $group_id ID of the group.
    965          * @return int|null ID of the membership if found, otherwise false.
     971         * @return int Database ID of the membership if found; int 0 on failure.
    966972         */
    967973        public static function check_for_membership_request( $user_id, $group_id ) {
    968974                global $wpdb;
     
    991997
    992998                // If the user is logged in and viewing their random groups, we can show hidden and private groups.
    993999                if ( bp_is_my_profile() ) {
    994                         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 ) );
     1000                        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 ) ) );
    9951001                } else {
    996                         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 ) );
     1002                        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 ) ) );
    9971003                }
    9981004        }
    9991005
     
    10101016
    10111017                $bp = buddypress();
    10121018
    1013                 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 ) );
     1019                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 ) ) );
    10141020        }
    10151021
    10161022        /**
     
    10331039                        wp_cache_set( $group_id, $group_admins, 'bp_group_admins' );
    10341040                }
    10351041
     1042                // Integer casting.
     1043                foreach ( (array) $group_admins as $key => $data ) {
     1044                        $group_admins[ $key ]->user_id = (int) $group_admins[ $key ]->user_id;
     1045                }
     1046
    10361047                return $group_admins;
    10371048        }
    10381049
     
    10491060
    10501061                $bp = buddypress();
    10511062
    1052                 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 ) );
     1063                $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 ) );
     1064
     1065                // Integer casting.
     1066                foreach ( (array) $group_mods as $key => $data ) {
     1067                        $group_mods[ $key ]->user_id = (int) $group_mods[ $key ]->user_id;
     1068                }
     1069
     1070                return $group_mods;
    10531071        }
    10541072
    10551073        /**
     
    10651083
    10661084                $bp = buddypress();
    10671085
    1068                 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 ) );
     1086                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 ) ) );
    10691087        }
    10701088
    10711089        /**
  • src/bp-messages/classes/class-bp-messages-message.php

     
    8888                $bp = buddypress();
    8989
    9090                if ( $message = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_messages} WHERE id = %d", $id ) ) ) {
    91                         $this->id        = $message->id;
    92                         $this->thread_id = $message->thread_id;
    93                         $this->sender_id = $message->sender_id;
     91                        $this->id        = (int) $message->id;
     92                        $this->thread_id = (int) $message->thread_id;
     93                        $this->sender_id = (int) $message->sender_id;
    9494                        $this->subject   = $message->subject;
    9595                        $this->message   = $message->message;
    9696                        $this->date_sent = $message->date_sent;
     
    220220
    221221                $bp = buddypress();
    222222
    223                 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND thread_id = %d ORDER BY date_sent DESC LIMIT 1", bp_loggedin_user_id(), $thread_id ) );
     223                $query = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND thread_id = %d ORDER BY date_sent DESC LIMIT 1", bp_loggedin_user_id(), $thread_id ) );
     224
     225                return is_numeric( $query ) ? (int) $query : $query;
    224226        }
    225227
    226228        /**
     
    236238
    237239                $bp = buddypress();
    238240
    239                 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND id = %d", $user_id, $message_id ) );
     241                $query = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE sender_id = %d AND id = %d", $user_id, $message_id ) );
     242
     243                return is_numeric( $query ) ? (int) $query : $query;
    240244        }
    241245
    242246        /**
     
    250254
    251255                $bp = buddypress();
    252256
    253                 return $wpdb->get_var( $wpdb->prepare( "SELECT sender_id FROM {$bp->messages->table_name_messages} WHERE id = %d", $message_id ) );
     257                $query = $wpdb->get_var( $wpdb->prepare( "SELECT sender_id FROM {$bp->messages->table_name_messages} WHERE id = %d", $message_id ) );
     258
     259                return is_numeric( $query ) ? (int) $query : $query;
    254260        }
    255261}
  • src/bp-messages/classes/class-bp-messages-notice.php

     
    6262         */
    6363        public function __construct( $id = null ) {
    6464                if ( $id ) {
    65                         $this->id = $id;
     65                        $this->id = (int) $id;
    6666                        $this->populate();
    6767                }
    6868        }
     
    8585                        $this->subject   = $notice->subject;
    8686                        $this->message   = $notice->message;
    8787                        $this->date_sent = $notice->date_sent;
    88                         $this->is_active = $notice->is_active;
     88                        $this->is_active = (int) $notice->is_active;
    8989                }
    9090        }
    9191
     
    232232
    233233                $notices = $wpdb->get_results( "SELECT * FROM {$bp->messages->table_name_notices} ORDER BY date_sent DESC {$limit_sql}" );
    234234
     235                // Integer casting.
     236                foreach ( (array) $notices as $key => $data ) {
     237                        $notices[ $key ]->id        = (int) $notices[ $key ]->id;
     238                        $notices[ $key ]->is_active = (int) $notices[ $key ]->is_active;
     239                }
     240
    235241                return $notices;
    236242        }
    237243
  • src/bp-messages/classes/class-bp-messages-thread.php

     
    254254                        wp_cache_set( 'thread_recipients_' . $thread_id, $recipients, 'bp_messages' );
    255255                }
    256256
     257                // Cast all items from the messages DB table as integers.
     258                foreach ( (array) $recipients as $key => $data ) {
     259                        $recipients[ $key ] = (object) array_map( 'intval', (array) $data );
     260                }
     261
    257262                /**
    258263                 * Filters the recipients of a message thread.
    259264                 *
     
    291296                        wp_cache_set( $thread_id, (array) $messages, 'bp_messages_threads' );
    292297                }
    293298
     299                // Integer casting.
     300                foreach ( $messages as $key => $data ) {
     301                        $messages[ $key ]->id        = (int) $messages[ $key ]->id;
     302                        $messages[ $key ]->thread_id = (int) $messages[ $key ]->thread_id;
     303                        $messages[ $key ]->sender_id = (int) $messages[ $key ]->sender_id;
     304                }
     305
    294306                return $messages;
    295307        }
    296308
  • src/bp-notifications/classes/class-bp-notifications-notification.php

     
    9797         */
    9898        public function __construct( $id = 0 ) {
    9999                if ( ! empty( $id ) ) {
    100                         $this->id = $id;
     100                        $this->id = (int) $id;
    101101                        $this->populate();
    102102                }
    103103        }
     
    188188
    189189                // Setup the notification data.
    190190                if ( ! empty( $notification ) && ! is_wp_error( $notification ) ) {
    191                         $this->item_id           = $notification->item_id;
    192                         $this->secondary_item_id = $notification->secondary_item_id;
    193                         $this->user_id           = $notification->user_id;
     191                        $this->item_id           = (int) $notification->item_id;
     192                        $this->secondary_item_id = (int) $notification->secondary_item_id;
     193                        $this->user_id           = (int) $notification->user_id;
    194194                        $this->component_name    = $notification->component_name;
    195195                        $this->component_action  = $notification->component_action;
    196196                        $this->date_notified     = $notification->date_notified;
    197                         $this->is_new            = $notification->is_new;
     197                        $this->is_new            = (int) $notification->is_new;
    198198                }
    199199        }
    200200
     
    681681                // Concatenate query parts.
    682682                $sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} {$order_sql} {$pag_sql}";
    683683
    684                 return $wpdb->get_results( $sql );
     684                // Query!
     685                $results = $wpdb->get_results( $sql );
     686
     687                // Integer casting.
     688                foreach( (array) $results as $key => $data ) {
     689                        $results[ $key ]->id                = (int) $results[ $key ]->id;
     690                        $results[ $key ]->user_id           = (int) $results[ $key ]->user_id;
     691                        $results[ $key ]->item_id           = (int) $results[ $key ]->item_id;
     692                        $results[ $key ]->secondary_item_id = (int) $results[ $key ]->secondary_item_id;
     693                        $results[ $key ]->is_new            = (int) $results[ $key ]->is_new;
     694                }
     695
     696                return $results;
    685697        }
    686698
    687699        /**
     
    732744                $sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql}";
    733745
    734746                // Return the queried results.
    735                 return $wpdb->get_var( $sql );
     747                return (int) $wpdb->get_var( $sql );
    736748        }
    737749
    738750        /**
  • src/bp-xprofile/classes/class-bp-xprofile-field.php

     
    260260                        $args = (array) $args;
    261261                }
    262262
     263                $int_fields = array(
     264                        'id', 'is_required', 'group_id', 'parent_id', 'is_default_option',
     265                        'field_order', 'option_order', 'can_delete'
     266                );
     267
    263268                foreach ( $args as $k => $v ) {
    264269                        if ( 'name' === $k || 'description' === $k ) {
    265270                                $v = stripslashes( $v );
    266271                        }
     272
     273                        // Cast numeric strings as integers.
     274                        if ( true === in_array( $k, $int_fields ) ) {
     275                                $v = (int) $v;
     276                        }
     277
    267278                        $this->{$k} = $v;
    268279                }
    269280
     
    892903         * @global object $wpdb
    893904         *
    894905         * @param string $field_name Name of the field to query the ID for.
    895          * @return boolean
     906         * @return int|null Field ID on success; null on failure.
    896907         */
    897908        public static function get_id_from_name( $field_name = '' ) {
    898909                global $wpdb;
     
    905916
    906917                $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s AND parent_id = 0", $field_name );
    907918
    908                 return $wpdb->get_var( $sql );
     919                $query = $wpdb->get_var( $sql );
     920
     921                return is_numeric( $query ) ? (int) $query : $query;
    909922        }
    910923
    911924        /**
  • src/bp-xprofile/classes/class-bp-xprofile-group.php

     
    466466
    467467                // Merge the field array back in with the group array.
    468468                foreach( (array) $groups as $group ) {
    469 
    470469                        // Indexes may have been shifted after previous deletions, so we get a
    471470                        // fresh one each time through the loop.
    472471                        $index = array_search( $group, $groups );
     
    555554                        }
    556555                }
    557556
     557                // Integer casting.
     558                foreach ( (array) $groups as $key => $data ) {
     559                        $groups[ $key ]->id          = (int) $groups[ $key ]->id;
     560                        $groups[ $key ]->group_order = (int) $groups[ $key ]->group_order;
     561                        $groups[ $key ]->can_delete  = (int) $groups[ $key ]->can_delete;
     562                }
     563
    558564                // Reset indexes & return.
    559565                return array_values( $groups );
    560566        }
  • src/bp-xprofile/classes/class-bp-xprofile-profiledata.php

     
    8888                }
    8989
    9090                if ( $profiledata ) {
    91                         $this->id           = $profiledata->id;
    92                         $this->user_id      = $profiledata->user_id;
    93                         $this->field_id     = $profiledata->field_id;
     91                        $this->id           = (int) $profiledata->id;
     92                        $this->user_id      = (int) $profiledata->user_id;
     93                        $this->field_id     = (int) $profiledata->field_id;
    9494                        $this->value        = stripslashes( $profiledata->value );
    9595                        $this->last_updated = $profiledata->last_updated;
    9696
    9797                } else {
    9898                        // When no row is found, we'll need to set these properties manually.
    99                         $this->field_id     = $field_id;
    100                         $this->user_id      = $user_id;
     99                        $this->field_id     = (int) $field_id;
     100                        $this->user_id      = (int) $user_id;
    101101                }
    102102        }
    103103
     
    317317                        $data[]    = wp_cache_get( $cache_key, 'bp_xprofile_data' );
    318318                }
    319319
     320                // Integer casting.
     321                foreach ( (array) $data as $key => $d ) {
     322                        if ( isset( $data[ $key ]->id ) ) {
     323                                $data[ $key ]->id = (int) $data[ $key ]->id;
     324                        }
     325                        if ( isset( $data[ $key ]->user_id ) ) {
     326                                $data[ $key ]->user_id  = (int) $data[ $key ]->user_id;
     327                        }
     328
     329                        $data[ $key ]->field_id = (int) $data[ $key ]->field_id;
     330                }
     331
    320332                return $data;
    321333        }
    322334
     
    390402                        }
    391403                }
    392404
    393                 return $fielddata_id;
     405                return (int) $fielddata_id;
    394406        }
    395407
    396408        /**
     
    465477                        $data[]    = wp_cache_get( $cache_key, 'bp_xprofile_data' );
    466478                }
    467479
     480                // Integer casting.
     481                foreach ( (array) $data as $key => $d ) {
     482                        if ( isset( $data[ $key ]->id ) ) {
     483                                $data[ $key ]->id = (int) $data[ $key ]->id;
     484                        }
     485                        if ( isset( $data[ $key ]->user_id ) ) {
     486                                $data[ $key ]->user_id  = (int) $data[ $key ]->user_id;
     487                        }
     488
     489                        $data[ $key ]->field_id = (int) $data[ $key ]->field_id;
     490                }
     491
    468492                // If a single ID was passed, just return the value.
    469493                if ( $is_single ) {
    470494                        return $data[0]->value;