Make WordPress Core


Ignore:
Timestamp:
07/11/2005 10:39:50 PM (19 years ago)
Author:
ryan
Message:

Role/capability system. Round one. Props: Owen Winkler

File:
1 edited

Legend:

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

    r2702 r2703  
    12191219function update_category_cache() {
    12201220    global $cache_categories, $wpdb;
    1221     $dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories");
    1222     foreach ($dogs as $catt)
    1223         $cache_categories[$catt->cat_ID] = $catt;
    1224 }
    1225 
    1226 function update_user_cache() {
    1227     global $cache_userdata, $wpdb;
    1228     $level_key = $wpdb->prefix . 'user_level';
    1229     $user_ids = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key'");
    1230     $user_ids = join(',', $user_ids);
    1231     $query = apply_filters('user_cache_query', "SELECT * FROM $wpdb->users WHERE ID IN ($user_ids)");
    1232     if ( $users = $wpdb->get_results( $query ) ) :
    1233         foreach ($users as $user) :
    1234             $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'");
    1235             foreach ( $metavalues as $meta ) {
    1236                 $user->{$meta->meta_key} = $meta->meta_value;
    1237                 // We need to set user_level from meta, not row
    1238                 if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
    1239                     $user->user_level = $meta->meta_value;
    1240             }
    1241 
    1242             $cache_userdata[$user->ID] = $user;
    1243             $cache_userdata[$user->user_login] =& $cache_userdata[$user->ID];
    1244         endforeach;
     1221    if($dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories")):
     1222        foreach ($dogs as $catt)
     1223            $cache_categories[$catt->cat_ID] = $catt;
    12451224        return true;
    1246     else :
     1225    else:
    12471226        return false;
    12481227    endif;
     
    19601939}
    19611940
     1941function get_usermeta( $user_id, $meta_key = '') {
     1942    global $wpdb;
     1943    $user_id = (int) $user_id;
     1944
     1945    if ( !empty($meta_key) ) {
     1946        $meta_key = preg_replace('|a-z0-9_|i', '', $meta_key);
     1947        $metas = $wpdb->get_results("SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
     1948    } else {
     1949        $metas = $wpdb->get_results("SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id'");
     1950    }
     1951
     1952    foreach ($metas as $index => $meta) {
     1953        @ $value = unserialize($meta->meta_key);
     1954        if ($value !== FALSE)
     1955            $metas[$index]->meta_key = $value;         
     1956    }
     1957
     1958    if ( !empty($meta_key) )
     1959        return $metas[0];
     1960    else
     1961        return $metas;
     1962}
     1963
    19621964function update_usermeta( $user_id, $meta_key, $meta_value ) {
    19631965    global $wpdb;
     
    19651967        return false;
    19661968    $meta_key = preg_replace('|a-z0-9_|i', '', $meta_key);
     1969
     1970    if ( is_array($meta_value) || is_object($meta_value) )
     1971        $meta_value = serialize($meta_value);
     1972
    19671973    $cur = $wpdb->get_row("SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
    19681974    if ( !$cur ) {
Note: See TracChangeset for help on using the changeset viewer.