Make WordPress Core

Ticket #31094: trac-31094.diff

File trac-31094.diff, 4.3 KB (added by ashfame, 9 years ago)

First pass

  • wp-includes/option.php

    diff --git wp-includes/option.php wp-includes/option.php
    index 6134606..ee85fb0 100644
    function get_option( $option, $default = false ) { 
    5151
    5252        if ( ! defined( 'WP_INSTALLING' ) ) {
    5353                // prevent non-existent options from triggering multiple queries
    54                 $notoptions = wp_cache_get( 'notoptions', 'options' );
     54                if ( wp_using_ext_object_cache() ) {
     55                        $notoptions = wp_cache_get( 'notoptions', 'options' );
     56                } else {
     57                        // don't attempt to look for 'notoptions_cache' in notoptions itself
     58                        if ( $option == 'notoptions_cache' ) {
     59                                $notoptions = array(); // treat as if we don't know anything
     60                        } else {
     61                                $notoptions = get_option( 'notoptions_cache', array() );
     62                        }
     63                }
    5564                if ( isset( $notoptions[ $option ] ) ) {
    5665                        /**
    5766                         * Filter the default value for an option.
    function get_option( $option, $default = false ) { 
    8190                                        $value = $row->option_value;
    8291                                        wp_cache_add( $option, $value, 'options' );
    8392                                } else { // option does not exist, so we must cache its non-existence
    84                                         $notoptions[$option] = true;
    85                                         wp_cache_set( 'notoptions', $notoptions, 'options' );
     93                                        if ( $option != 'notoptions_cache' ) {
     94                                                $notoptions[$option] = true;
     95                                                if ( wp_using_ext_object_cache() ) {
     96                                                        wp_cache_set( 'notoptions', $notoptions, 'options' );
     97                                                } else {
     98                                                        update_option( 'notoptions_cache', $notoptions );
     99                                                }
     100                                        }
    86101
    87102                                        /** This filter is documented in wp-includes/option.php */
    88103                                        return apply_filters( 'default_option_' . $option, $default );
    function wp_load_alloptions() { 
    172187                foreach ( (array) $alloptions_db as $o ) {
    173188                        $alloptions[$o->option_name] = $o->option_value;
    174189                }
     190
     191                // if this is one of those pageload where notoptions_cache isn't set, we insert it into the database directly, and append its default value i.e. empty array to $alloptions
     192                if ( ! isset( $alloptions['notoptions_cache'] ) ) {
     193                        $wpdb->insert( $wpdb->options, array( 'option_name' => 'notoptions_cache', 'option_value' => serialize( array() ) ), array( '%s', '%s' ) );
     194                        $alloptions['notoptions_cache'] = array();
     195                }
     196
    175197                if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
    176198                        wp_cache_add( 'alloptions', $alloptions, 'options' );
    177199        }
    function update_option( $option, $value ) { 
    288310        if ( ! $result )
    289311                return false;
    290312
    291         $notoptions = wp_cache_get( 'notoptions', 'options' );
     313        if ( wp_using_ext_object_cache() ) {
     314                $notoptions = wp_cache_get( 'notoptions', 'options' );
     315        } else {
     316                $notoptions = get_option( 'notoptions_cache', array() );
     317        }
    292318        if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
    293319                unset( $notoptions[$option] );
    294                 wp_cache_set( 'notoptions', $notoptions, 'options' );
     320                if ( wp_using_ext_object_cache() ) {
     321                        wp_cache_set( 'notoptions', $notoptions, 'options' );
     322                } else {
     323                        update_option( 'notoptions_cache', $notoptions );
     324                }
    295325        }
    296326
    297327        if ( ! defined( 'WP_INSTALLING' ) ) {
    function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) 
    367397        $value = sanitize_option( $option, $value );
    368398
    369399        // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
    370         $notoptions = wp_cache_get( 'notoptions', 'options' );
     400        if ( wp_using_ext_object_cache() ) {
     401                $notoptions = wp_cache_get( 'notoptions', 'options' );
     402        } else {
     403                $notoptions = get_option( 'notoptions_cache', array() );
     404        }
    371405        if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) )
    372406                if ( false !== get_option( $option ) )
    373407                        return false;
    function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) 
    400434        }
    401435
    402436        // This option exists now
    403         $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
     437        if ( wp_using_ext_object_cache() ) {
     438                $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
     439        } else {
     440                $notoptions = get_option( 'notoptions_cache', array() );
     441        }
    404442        if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
    405443                unset( $notoptions[$option] );
    406                 wp_cache_set( 'notoptions', $notoptions, 'options' );
     444                if ( wp_using_ext_object_cache() ) {
     445                        wp_cache_set( 'notoptions', $notoptions, 'options' );
     446                } else {
     447                        update_option( 'notoptions_cache', $notoptions );
     448                }
    407449        }
    408450
    409451        /**