Skip to:
Content

BuddyPress.org

Changeset 11030


Ignore:
Timestamp:
08/22/2016 10:38:28 PM (8 years ago)
Author:
r-a-y
Message:

XProfile: Cast properties as integers where appropriate.

See #6977.

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

Legend:

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

    r10948 r11030  
    258258        }
    259259
     260        $int_fields = array(
     261            'id', 'is_required', 'group_id', 'parent_id', 'is_default_option',
     262            'field_order', 'option_order', 'can_delete'
     263        );
     264
    260265        foreach ( $args as $k => $v ) {
    261266            if ( 'name' === $k || 'description' === $k ) {
    262267                $v = stripslashes( $v );
    263268            }
     269
     270            // Cast numeric strings as integers.
     271            if ( true === in_array( $k, $int_fields ) ) {
     272                $v = (int) $v;
     273            }
     274
    264275            $this->{$k} = $v;
    265276        }
     
    890901     *
    891902     * @param string $field_name Name of the field to query the ID for.
    892      * @return boolean
     903     * @return int|null Field ID on success; null on failure.
    893904     */
    894905    public static function get_id_from_name( $field_name = '' ) {
     
    903914        $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s AND parent_id = 0", $field_name );
    904915
    905         return $wpdb->get_var( $sql );
     916        $query = $wpdb->get_var( $sql );
     917
     918        return is_numeric( $query ) ? (int) $query : $query;
    906919    }
    907920
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php

    r10935 r11030  
    474474        // Merge the field array back in with the group array.
    475475        foreach( (array) $groups as $group ) {
    476 
    477476            // Indexes may have been shifted after previous deletions, so we get a
    478477            // fresh one each time through the loop.
     
    561560                }
    562561            }
     562        }
     563
     564        // Integer casting.
     565        foreach ( (array) $groups as $key => $data ) {
     566            $groups[ $key ]->id          = (int) $groups[ $key ]->id;
     567            $groups[ $key ]->group_order = (int) $groups[ $key ]->group_order;
     568            $groups[ $key ]->can_delete  = (int) $groups[ $key ]->can_delete;
    563569        }
    564570
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-profiledata.php

    r10921 r11030  
    9898
    9999        if ( $profiledata ) {
    100             $this->id           = $profiledata->id;
    101             $this->user_id      = $profiledata->user_id;
    102             $this->field_id     = $profiledata->field_id;
     100            $this->id           = (int) $profiledata->id;
     101            $this->user_id      = (int) $profiledata->user_id;
     102            $this->field_id     = (int) $profiledata->field_id;
    103103            $this->value        = stripslashes( $profiledata->value );
    104104            $this->last_updated = $profiledata->last_updated;
     
    106106        } else {
    107107            // When no row is found, we'll need to set these properties manually.
    108             $this->field_id     = $field_id;
    109             $this->user_id      = $user_id;
     108            $this->field_id     = (int) $field_id;
     109            $this->user_id      = (int) $user_id;
    110110        }
    111111    }
     
    340340        }
    341341
     342        // Integer casting.
     343        foreach ( (array) $data as $key => $d ) {
     344            if ( isset( $data[ $key ]->id ) ) {
     345                $data[ $key ]->id = (int) $data[ $key ]->id;
     346            }
     347            if ( isset( $data[ $key ]->user_id ) ) {
     348                $data[ $key ]->user_id  = (int) $data[ $key ]->user_id;
     349            }
     350
     351            $data[ $key ]->field_id = (int) $data[ $key ]->field_id;
     352        }
     353
    342354        return $data;
    343355    }
     
    417429        }
    418430
    419         return $fielddata_id;
     431        return (int) $fielddata_id;
    420432    }
    421433
     
    495507        }
    496508
     509        // Integer casting.
     510        foreach ( (array) $data as $key => $d ) {
     511            if ( isset( $data[ $key ]->id ) ) {
     512                $data[ $key ]->id = (int) $data[ $key ]->id;
     513            }
     514            if ( isset( $data[ $key ]->user_id ) ) {
     515                $data[ $key ]->user_id  = (int) $data[ $key ]->user_id;
     516            }
     517
     518            $data[ $key ]->field_id = (int) $data[ $key ]->field_id;
     519        }
     520
    497521        // If a single ID was passed, just return the value.
    498522        if ( $return_single_result ) {
Note: See TracChangeset for help on using the changeset viewer.