Skip to:
Content

BuddyPress.org

Changeset 11028


Ignore:
Timestamp:
08/22/2016 10:32:06 PM (4 years ago)
Author:
r-a-y
Message:

Messages: Cast properties as integers where appropriate.

See #6977.

Location:
trunk/src/bp-messages/classes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/classes/class-bp-messages-message.php

    r10421 r11028  
    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;
     
    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
     
    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
     
    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}
  • trunk/src/bp-messages/classes/class-bp-messages-notice.php

    r10421 r11028  
    6363    public function __construct( $id = null ) {
    6464        if ( $id ) {
    65             $this->id = $id;
     65            $this->id = (int) $id;
    6666            $this->populate();
    6767        }
     
    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    }
     
    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    }
  • trunk/src/bp-messages/classes/class-bp-messages-thread.php

    r10417 r11028  
    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.
     
    290295
    291296            wp_cache_set( $thread_id, (array) $messages, 'bp_messages_threads' );
     297        }
     298
     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;
    292304        }
    293305
Note: See TracChangeset for help on using the changeset viewer.