Make WordPress Core

Ticket #40007: 40007.diff

File 40007.diff, 1.9 KB (added by peterwilsoncc, 3 years ago)
  • src/wp-includes/option.php

    diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php
    index 13f5d49c87..ee52f3d969 100644
    a b function update_option( $option, $value, $autoload = null ) {  
    755755                $value = clone $value;
    756756        }
    757757
    758         $value     = sanitize_option( $option, $value );
    759         $old_value = get_option( $option );
     758        $value      = sanitize_option( $option, $value );
     759        $old_value  = get_option( $option );
     760        $notoptions = wp_cache_get( 'notoptions', 'options' );
     761        if ( ! is_array( $notoptions ) ) {
     762                $notoptions = array();
     763        }
     764        if ( isset( $notoptions[ $option ] ) ) {
     765                $is_new_option = true;
     766        } else {
     767                $is_new_option = false;
     768        }
    760769
    761770        /**
    762771         * Filters a specific option before its value is (maybe) serialized and updated.
    function update_option( $option, $value, $autoload = null ) {  
    783792         */
    784793        $value = apply_filters( 'pre_update_option', $value, $option, $old_value );
    785794
     795        if ( $is_new_option ) {
     796                // Default setting for new options is 'yes'.
     797                if ( null === $autoload ) {
     798                        $autoload = 'yes';
     799                }
     800
     801                return add_option( $option, $value, '', $autoload );
     802        }
     803
    786804        /*
    787805         * If the new and old values are the same, no need to update.
    788806         *
    function update_option( $option, $value, $autoload = null ) {  
    796814                return false;
    797815        }
    798816
    799         /** This filter is documented in wp-includes/option.php */
    800         if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) {
    801                 // Default setting for new options is 'yes'.
    802                 if ( null === $autoload ) {
    803                         $autoload = 'yes';
    804                 }
    805 
    806                 return add_option( $option, $value, '', $autoload );
    807         }
    808 
    809817        $serialized_value = maybe_serialize( $value );
    810818
    811819        /**
    function update_option( $option, $value, $autoload = null ) {  
    832840                return false;
    833841        }
    834842
     843        // Yes, again... it needs to be fresh.
    835844        $notoptions = wp_cache_get( 'notoptions', 'options' );
    836845
    837846        if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) {