Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Mbertu

    (@mbertu)

    I’ve found this, for me is a bug in the add/update option procedure.

    If the option doesn’t already exist in the db, is called anyway the update_option function in /wp-includes/option.php.

    This funciton, reported down there, at the line 256 execute the function sanitize_option this function goes to execute the callback pased to the register_setting function. But if the option doesn’t already exist in the db, is executed further the function add_option that again call the sanitize_option, and again execute the register_setting callback but this time with the result of the first callback execution as input.

    The problem, for me, is that the first execution manipulate the submited post data and generate a different output, so the second execution of the callback fails.

    There is a problem with the input image too, but I don’t now exactly why (only on the first submit for the option).

    Is that a bug, or I’ve miss something?

    function update_option( $option, $value, $autoload = null ) {
    	global $wpdb;
    
    	$option = trim($option);
    	if ( empty($option) )
    		return false;
    
    	wp_protect_special_option( $option );
    
    	if ( is_object( $value ) )
    		$value = clone $value;
    
    	$value = sanitize_option( $option, $value );
    	$old_value = get_option( $option );
    
    	/**
    	 * Filter a specific option before its value is (maybe) serialized and updated.
    	 *
    	 * The dynamic portion of the hook name, <code>$option</code>, refers to the option name.
    	 *
    	 * @since 2.6.0
    	 *
    	 * @param mixed $value     The new, unserialized option value.
    	 * @param mixed $old_value The old option value.
    	 */
    	$value = apply_filters( 'pre_update_option_' . $option, $value, $old_value );
    
    	/**
    	 * Filter an option before its value is (maybe) serialized and updated.
    	 *
    	 * @since 3.9.0
    	 *
    	 * @param mixed  $value     The new, unserialized option value.
    	 * @param string $option    Name of the option.
    	 * @param mixed  $old_value The old option value.
    	 */
    	$value = apply_filters( 'pre_update_option', $value, $option, $old_value );
    
    	// If the new and old values are the same, no need to update.
    	if ( $value === $old_value )
    		return false;
    
    	/** This filter is documented in wp-includes/option.php */
    	if ( apply_filters( 'default_option_' . $option, false ) === $old_value ) {
    		// Default setting for new options is 'yes'.
    		if ( null === $autoload ) {
    			$autoload = 'yes';
    		}
    
    		return add_option( $option, $value, '', $autoload );
    	}
    
    	$serialized_value = maybe_serialize( $value );
    
    	/**
    	 * Fires immediately before an option value is updated.
    	 *
    	 * @since 2.9.0
    	 *
    	 * @param string $option    Name of the option to update.
    	 * @param mixed  $old_value The old option value.
    	 * @param mixed  $value     The new option value.
    	 */
    	do_action( 'update_option', $option, $old_value, $value );
    
    	$update_args = array(
    		'option_value' => $serialized_value,
    	);
    
    	if ( null !== $autoload ) {
    		$update_args['autoload'] = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
    	}
    
    	$result = $wpdb->update( $wpdb->options, $update_args, array( 'option_name' => $option ) );
    	if ( ! $result )
    		return false;
    
    	$notoptions = wp_cache_get( 'notoptions', 'options' );
    	if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
    		unset( $notoptions[$option] );
    		wp_cache_set( 'notoptions', $notoptions, 'options' );
    	}
    
    	if ( ! defined( 'WP_INSTALLING' ) ) {
    		$alloptions = wp_load_alloptions();
    		if ( isset( $alloptions[$option] ) ) {
    			$alloptions[ $option ] = $serialized_value;
    			wp_cache_set( 'alloptions', $alloptions, 'options' );
    		} else {
    			wp_cache_set( $option, $serialized_value, 'options' );
    		}
    	}
    
    	/**
    	 * Fires after the value of a specific option has been successfully updated.
    	 *
    	 * The dynamic portion of the hook name, <code>$option</code>, refers to the option name.
    	 *
    	 * @since 2.0.1
    	 *
    	 * @param mixed $old_value The old option value.
    	 * @param mixed $value     The new option value.
    	 */
    	do_action( "update_option_{$option}", $old_value, $value );
    
    	/**
    	 * Fires after the value of an option has been successfully updated.
    	 *
    	 * @since 2.9.0
    	 *
    	 * @param string $option    Name of the updated option.
    	 * @param mixed  $old_value The old option value.
    	 * @param mixed  $value     The new option value.
    	 */
    	do_action( 'updated_option', $option, $old_value, $value );
    	return true;
    }
    Thread Starter Mbertu

    (@mbertu)

    no one met this problem?

Viewing 2 replies - 1 through 2 (of 2 total)