Skip to:
Content

BuddyPress.org


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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.