Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/01/2016 04:59:31 PM (8 years ago)
Author:
r-a-y
Message:

Activity: Cast activity properties as integers where appropriate.

Props DJPaul, r-a-y.

See #6977.

File:
1 edited

Legend:

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

    r10588 r10853  
    108108     * @var int
    109109     */
    110     var $hide_sitewide = false;
     110    var $hide_sitewide = 0;
    111111
    112112    /**
     
    143143    public function __construct( $id = false ) {
    144144        if ( !empty( $id ) ) {
    145             $this->id = $id;
     145            $this->id = (int) $id;
    146146            $this->populate();
    147147        }
     
    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
     
    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
     
    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            $result = $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
     1088
     1089            return is_numeric( $result ) ? (int) $result : false;
    10751090        }
    10761091
     
    17641779        $bp = buddypress();
    17651780
    1766         return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = %s", $content ) );
     1781        $result = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = %s", $content ) );
     1782
     1783        return is_numeric( $result ) ? (int) $result : false;
    17671784    }
    17681785
Note: See TracChangeset for help on using the changeset viewer.