Make WordPress Core


Ignore:
Timestamp:
11/09/2005 09:01:24 PM (21 years ago)
Author:
matt
Message:

Missing semi, also fixes #1599

File:
1 edited

Legend:

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

    r3024 r3025  
    261261
    262262function get_settings($setting) {
    263         global $wpdb;
     263        global $wpdb, $cache_settings, $cache_nonexistantoptions;
    264264        if ( strstr($_SERVER['REQUEST_URI'], 'wp-admin/install.php') || defined('WP_INSTALLING') )
    265265                return false;
    266266
    267         $value = wp_cache_get($setting, 'options');
    268 
    269         if ( false === $value ) {
    270                 $value = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting'");
    271                 if( is_object( $value ) ) {
    272                         $value = $value->option_value;
    273                         wp_cache_set($setting, $value, 'options');
    274                 }
    275         }
    276 
    277         // If home is not set use siteurl.
    278         if ( 'home' == $setting && '' == $value )
    279                 return get_settings('siteurl');
    280 
    281         if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
    282                 $value = preg_replace('|/+$|', '', $value);
    283 
    284         @ $kellogs = unserialize($value);
    285         if ( $kellogs !== FALSE )
    286                 return apply_filters('option_' . $setting, $kellogs);
    287         else
    288                 return apply_filters('option_' . $setting, $value);
     267        if ( empty($cache_settings) )
     268                $cache_settings = get_alloptions();
     269
     270        if ( empty($cache_nonexistantoptions) )
     271                $cache_nonexistantoptions = array();
     272
     273        if ( 'home' == $setting && '' == $cache_settings->home )
     274                return apply_filters('option_' . $setting, $cache_settings->siteurl);
     275
     276        if ( isset($cache_settings->$setting) ) :
     277                return apply_filters('option_' . $setting, $cache_settings->$setting);
     278        else :
     279                // for these cases when we're asking for an unknown option
     280                if ( isset($cache_nonexistantoptions[$setting]) )
     281                        return false;
     282
     283                $option = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting'");
     284
     285                if (!$option) :
     286                        $cache_nonexistantoptions[$setting] = true;
     287                        return false;
     288                endif;
     289
     290                @ $kellogs = unserialize($option);
     291                if ( $kellogs !== FALSE )
     292                        return apply_filters('option_' . $setting, $kellogs);
     293                else return apply_filters('option_' . $setting, $option);
     294        endif;
    289295}
    290296
     
    333339
    334340function update_option($option_name, $newvalue) {
    335         global $wpdb;
     341        global $wpdb, $cache_settings;
    336342
    337343        if ( is_string($newvalue) )
     
    347353        // If it's not there add it
    348354        if ( !$wpdb->get_var("SELECT option_name FROM $wpdb->options WHERE option_name = '$option_name'") )
    349                 add_option($option_name, $newvalue);
    350 
    351         wp_cache_set($option_name, $newvalue, 'options');
     355                add_option($option_name);
    352356
    353357        $newvalue = $wpdb->escape($newvalue);
    354         $option_name = $wpdb->escape($option_name);
     358        $option_name = $wpdb->escape( $option_name );
    355359        $wpdb->query("UPDATE $wpdb->options SET option_value = '$newvalue' WHERE option_name = '$option_name'");
     360        $cache_settings = get_alloptions(); // Re cache settings
    356361        return true;
    357362}
     
    366371// thx Alex Stapleton, http://alex.vort-x.net/blog/
    367372function add_option($name, $value = '', $description = '', $autoload = 'yes') {
    368         global $wpdb;
     373        global $wpdb, $cache_settings;
    369374
    370375        // Make sure the option doesn't already exist
    371         if ( false !== get_option($name) )
     376        if ( isset($cache_settings->$name) )
    372377                return;
    373378
     
    376381                $value = serialize($value);
    377382
    378         wp_cache_set($name, $value, 'options');
    379 
    380         $name = $wpdb->escape($name);
    381         $value = $wpdb->escape($value);
    382         $description = $wpdb->escape($description);
    383         $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, option_description, autoload) VALUES ('$name', '$value', '$description', '$autoload')");
    384 
     383        if ( !$wpdb->get_var("SELECT option_name FROM $wpdb->options WHERE option_name = '$name'") ) {
     384                $name = $wpdb->escape($name);
     385                $value = $wpdb->escape($value);
     386                $description = $wpdb->escape($description);
     387                $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, option_description, autoload) VALUES ('$name', '$value', '$description', '$autoload')");
     388
     389                if ( $wpdb->insert_id ) {
     390                        global $cache_settings;
     391                        $cache_settings->{$name} = $original;
     392                }
     393        }
    385394        return;
    386395}
     
    392401        if ( !$option_id ) return false;
    393402        $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'");
    394         wp_cache_delete($name, 'options');
    395403        return true;
    396404}
     
    561569                        $_post = & $post_cache[$post];
    562570                else {
    563                         $query = "SELECT * FROM $wpdb->posts WHERE ID = '$post' LIMIT 1";
     571                        $query = "SELECT * FROM $wpdb->posts WHERE ID = '$post'";
    564572                        $post_cache[$post] = & $wpdb->get_row($query);
    565573                        $_post = & $post_cache[$post];
     
    581589// Handles page caching.
    582590function &get_page(&$page, $output = OBJECT) {
    583         global $wpdb;
     591        global $page_cache, $wpdb;
    584592
    585593        if ( empty($page) ) {
    586                 if ( isset($GLOBALS['page']) ) {
     594                if ( isset($GLOBALS['page']) )
    587595                        $_page = & $GLOBALS['page'];
    588                         wp_cache_add($_page->ID, $_page, 'pages');
    589                 } else {
     596                else
    590597                        $_page = null;
    591                 }
    592598        } elseif ( is_object($page) ) {
    593                 wp_cache_add($page->ID, $page, 'pages');
    594                 $_page = $page;
    595         } else {
    596                 if ( isset($GLOBALS['page']) && ($page == $GLOBALS['page']->ID) ) {
     599                if ( !isset($page_cache[$page->ID]) )
     600                        $page_cache[$page->ID] = &$page;
     601                $_page = & $page_cache[$page->ID];
     602        } else {
     603                if ( isset($GLOBALS['page']) && ($page == $GLOBALS['page']->ID) )
    597604                        $_page = & $GLOBALS['page'];
    598                         wp_cache_add($_page->ID, $_page, 'pages');
    599                 } elseif ( $_page = wp_cache_get($page, 'pages') ) {
    600                         // Got it.
    601                 } else {
    602                         $query = "SELECT * FROM $wpdb->posts WHERE ID= '$page' LIMIT 1";
    603                         $_page = & $wpdb->get_row($query);
    604                         wp_cache_add($_page->ID, $_page, 'pages');
     605                elseif ( isset($page_cache[$page]) )
     606                        $_page = & $page_cache[$page];
     607                else {
     608                        $query = "SELECT * FROM $wpdb->posts WHERE ID= '$page'";
     609                        $page_cache[$page] = & $wpdb->get_row($query);
     610                        $_page = & $page_cache[$page];
    605611                }
    606612        }
     
    617623}
    618624
    619 function set_category_path($cat) {
    620         $cat->fullpath = '/' . $cat->category_nicename;
    621         $path = $cat->fullpath;
    622         $curcat = $cat;
    623         while ($curcat->category_parent != 0) {
    624                 $curcat = get_category($curcat->category_parent);
    625                 $path = '/' . $curcat->category_nicename . $path;
    626         }
    627        
    628         $cat->fullpath = $path;
    629 
    630         return $cat;
    631 }
    632 
    633625// Retrieves category data given a category ID or category object.
    634626// Handles category caching.
    635627function &get_category(&$category, $output = OBJECT) {
    636         global $wpdb;
     628        global $cache_categories, $wpdb;
    637629
    638630        if ( empty($category) )
    639631                return null;
    640632
     633        if ( !isset($cache_categories) )
     634                update_category_cache();
     635
    641636        if ( is_object($category) ) {
    642                 wp_cache_add($category->cat_ID, $category, 'category');
    643                 $_category = $category;
    644         } else {
    645                 if ( ! $_category = wp_cache_get($category, 'category') ) {
    646                         $_category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$category' LIMIT 1");
    647                         wp_cache_add($category, $_category, 'category');
    648                 }
    649         }
    650 
    651         if ( !isset($_category->fullpath) ) {
    652                 $_category = set_category_path($_category);
    653                 wp_cache_replace($_category->cat_ID, $_category, 'category');   
     637                if ( !isset($cache_categories[$category->cat_ID]) )
     638                        $cache_categories[$category->cat_ID] = &$category;
     639                $_category = & $cache_categories[$category->cat_ID];
     640        } else {
     641                if ( !isset($cache_categories[$category]) ) {
     642                        $_category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = '$category'");
     643                        $cache_categories[$category->cat_ID] = & $_category;
     644                } else {
     645                        $_category = & $cache_categories[$category];
     646                }
    654647        }
    655648
     
    679672        } else {
    680673                if ( !isset($comment_cache[$comment]) ) {
    681                         $_comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment' LIMIT 1");
     674                        $_comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment'");
    682675                        $comment_cache[$comment->comment_ID] = & $_comment;
    683676                } else {
     
    700693        $category = &get_category($cat_ID);
    701694        return $category->cat_name;
    702 }
    703 
    704 function get_all_category_ids() {
    705         global $wpdb;
    706        
    707         if ( ! $cat_ids = wp_cache_get('all_category_ids', 'category') ) {
    708                 $cat_ids = $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories");
    709                 wp_cache_add('all_category_ids', $cat_ids, 'category');
    710         }
    711        
    712         return $cat_ids;
    713695}
    714696
     
    12501232        for ($i = 0; $i < count($pages); $i++) {
    12511233                $page_cache[$pages[$i]->ID] = &$pages[$i];
    1252                 wp_cache_add($pages[$i]->ID, $pages[$i], 'pages');
    12531234        }
    12541235}
     
    12631244
    12641245function update_post_category_cache($post_ids) {
    1265         global $wpdb, $category_cache;
     1246        global $wpdb, $category_cache, $cache_categories;
    12661247
    12671248        if ( empty($post_ids) )
     
    12751256        WHERE category_id = cat_ID AND post_id IN ($post_ids)");
    12761257
    1277         if ( empty($dogs) )
    1278                 return;
    1279                
    1280         foreach ($dogs as $catt)
    1281                 $category_cache[$catt->post_id][$catt->cat_ID] = &get_category($catt->cat_ID);
     1258        if ( !isset($cache_categories) )
     1259                update_category_cache();
     1260
     1261        if ( !empty($dogs) ) {
     1262                foreach ($dogs as $catt) {
     1263                        $category_cache[$catt->post_id][$catt->cat_ID] = &$cache_categories[$catt->cat_ID];
     1264                }
     1265        }
    12821266}
    12831267
     
    13391323
    13401324function update_category_cache() {
    1341         return true;
     1325        global $cache_categories, $wpdb;
     1326        if ( $dogs = $wpdb->get_results("SELECT * FROM $wpdb->categories") ):
     1327                foreach ($dogs as $catt)
     1328                        $cache_categories[$catt->cat_ID] = $catt;
     1329
     1330                foreach ($cache_categories as $catt) {
     1331                        $curcat = $catt->cat_ID;
     1332                        $cache_categories[$catt->cat_ID]->fullpath = '/' . $cache_categories[$catt->cat_ID]->category_nicename;
     1333                        while ($cache_categories[$curcat]->category_parent != 0) {
     1334                                $curcat = $cache_categories[$curcat]->category_parent;
     1335                                $cache_categories[$catt->cat_ID]->fullpath = '/' . $cache_categories[$curcat]->category_nicename . $cache_categories[$catt->cat_ID]->fullpath;
     1336                        }
     1337                }
     1338                return true;
     1339        else :
     1340                return false;
     1341        endif;
     1342}
     1343
     1344function clean_user_cache($id) {
     1345        global $cache_userdata;
     1346
     1347        if ( isset( $cache_userdata[$id] ) )
     1348                unset( $cache_userdata[$id] );
    13421349}
    13431350
     
    21172124        if ( $cur->meta_value != $meta_value )
    21182125                $wpdb->query("UPDATE $wpdb->usermeta SET meta_value = '$meta_value' WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
    2119 
    2120         wp_cache_delete($user_id, 'users');
    2121         // FIXME: Need to delete username keyed cache object.
    21222126}
    21232127
     
    21352139
    21362140function plugin_basename($file) {
    2137         $file = preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', $file)
     2141        $file = preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', $file);
    21382142        $file = stripslashes($file);
    21392143        return $file;
Note: See TracChangeset for help on using the changeset viewer.