WordPress.org

Make WordPress Core

Changeset 14307


Ignore:
Timestamp:
04/29/2010 07:19:21 PM (8 years ago)
Author:
ryan
Message:

When storing and retrieving meta data to user object, replace dashes with underscores to get a valid php var name.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/user.php

    r14303 r14307  
    237237        _deprecated_argument( __FUNCTION__, '3.0' );
    238238
    239     if ( empty($user) )
     239    if ( empty($user) ) {
    240240        $user = wp_get_current_user();
    241     else
     241        // Keys used as object vars cannot have dashes.
     242        $key = str_replace('-', '_', $option);
     243    } else {
    242244        $user = get_userdata($user);
    243 
    244     if ( isset( $user->{$wpdb->prefix . $option} ) ) // Blog specific
    245         $result = $user->{$wpdb->prefix . $option};
    246     elseif ( isset( $user->{$option} ) ) // User specific and cross-blog
    247         $result = $user->{$option};
     245        $key = $option;
     246    }
     247
     248    if ( isset( $user->{$wpdb->prefix . $key} ) ) // Blog specific
     249        $result = $user->{$wpdb->prefix . $key};
     250    elseif ( isset( $user->{$key} ) ) // User specific and cross-blog
     251        $result = $user->{$key};
    248252    else
    249253        $result = false;
     
    697701    foreach ( $metavalues as $meta ) {
    698702        $value = maybe_unserialize($meta->meta_value);
    699         $user->{$meta->meta_key} = $value;
     703        // Keys used as object vars cannot have dashes.
     704        $key = str_replace('-', '_', $meta->meta_key);
     705        $user->{$key} = $value;
    700706    }
    701707
Note: See TracChangeset for help on using the changeset viewer.