- if ( false === $oldvalue )
- return add_option( $option, $newvalue );
+ /** 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;