[wp-trac] [WordPress Trac] #21989: update_option() calls sanitize_option() twice when option does not exist

WordPress Trac noreply at wordpress.org
Sun Jun 9 00:40:45 UTC 2013


#21989: update_option() calls sanitize_option() twice when option does not exist
-------------------------------------------------+-------------------------
 Reporter:  MikeSchinkel                         |       Owner:
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
Component:  Administration                       |  Review
 Severity:  normal                               |     Version:
 Keywords:  needs-patch dev-feedback 2nd-        |  Resolution:
  opinion                                        |
-------------------------------------------------+-------------------------

Comment (by totels):

 Wouldn't it be easiest to just refactor and move the check for the old
 value and the call for `add_option()` before the `sanitize_option()` call
 in `update_option()`?


 {{{
 diff --git a/wp-includes/option.php b/wp-includes/option.php
 index 722d1f3..4df07d8 100644
 --- a/wp-includes/option.php
 +++ b/wp-includes/option.php
 @@ -224,17 +224,18 @@ function update_option( $option, $newvalue ) {
         if ( is_object($newvalue) )
                 $newvalue = clone $newvalue;

 -       $newvalue = sanitize_option( $option, $newvalue );
         $oldvalue = get_option( $option );
 +
 +       if ( false === $oldvalue )
 +               return add_option( $option, $newvalue );
 +
 +       $newvalue = sanitize_option( $option, $newvalue );
         $newvalue = apply_filters( 'pre_update_option_' . $option,
 $newvalue, $oldvalue );

         // If the new and old values are the same, no need to update.
         if ( $newvalue === $oldvalue )
                 return false;

 -       if ( false === $oldvalue )
 -               return add_option( $option, $newvalue );
 -
         $notoptions = wp_cache_get( 'notoptions', 'options' );
         if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
                 unset( $notoptions[$option] );
 }}}

--
Ticket URL: <http://core.trac.wordpress.org/ticket/21989#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list