WordPress.org

Make WordPress Core

Ticket #21989: 21989.diff

File 21989.diff, 1.3 KB (added by Denis-de-Bernardy, 6 years ago)

Fallback immediately on non-existent options in update_option() and update_site_option()

  • src/wp-includes/option.php

     
    240240        if ( is_object( $value ) )
    241241                $value = clone $value;
    242242
    243         $value = sanitize_option( $option, $value );
    244243        $old_value = get_option( $option );
     244        if ( false === $old_value )
     245                return add_option( $option, $value );
    245246
     247        $value = sanitize_option( $option, $value );
     248
    246249        /**
    247250         * Filter a specific option before its value is (maybe) serialized and updated.
    248251         *
     
    270273        if ( $value === $old_value )
    271274                return false;
    272275
    273         if ( false === $old_value )
    274                 return add_option( $option, $value );
    275 
    276276        $serialized_value = maybe_serialize( $value );
    277277
    278278        /**
     
    11661166        wp_protect_special_option( $option );
    11671167
    11681168        $old_value = get_site_option( $option );
     1169        if ( false === $old_value )
     1170                return add_site_option( $option, $value );
    11691171
    11701172        /**
    11711173         * Filter a specific site option before its value is updated.
     
    11831185        if ( $value === $old_value )
    11841186                return false;
    11851187
    1186         if ( false === $old_value )
    1187                 return add_site_option( $option, $value );
    1188 
    11891188        $notoptions_key = "{$wpdb->siteid}:notoptions";
    11901189        $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
    11911190        if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {