xwp / wp-widget-customizer

[OBSOLETE] Widget Customizer plugin for WordPress (now merged into Core)
http://wordpress.org/plugins/widget-customizer/
54 stars 18 forks source link

Eliminate use of Options Transactions #59

Closed westonruter closed 10 years ago

westonruter commented 10 years ago

The facility for Options Transactions was introduced to add support for old single widgets, whose rendering functions also do updates. For new multi WP_Widgets, the render method does not do any saving to the DB, nor does the update method which just validates the input. If we can eliminate support for old single widgets, then we can simplify the logic for previewing widget changes.

westonruter commented 10 years ago

We need to support old single widgets. Nacin indicated that ~20% plugins on WordPress.org register old single widgets.

westonruter commented 10 years ago

If we know that a widget is always only going to be updating an option named "widget_{id_base}" then we can actually add the specifically-named option actions to intercept updates via the pre_update_optionwidget{id_base} filter

westonruter commented 10 years ago

Single widgets may not follow the "widget_{id_base}" convention at all, so it seems we still need Options Transactions for single widgets.

westonruter commented 10 years ago

We can eliminate Options Transactions if update_option provided a hook like:

$value = apply_filters( 'pre_update_option', $value, $option, $old_value );

As then we'd be able to intercept all updates when a widget's update callback is running.

westonruter commented 10 years ago

It was decided that pre_update_option would be added to core.

westonruter commented 10 years ago

Core patch required for this to work is:

Index: src/wp-includes/option.php
===================================================================
--- src/wp-includes/option.php  (revision 27109)
+++ src/wp-includes/option.php  (working copy)
@@ -226,6 +226,7 @@
    $value = sanitize_option( $option, $value );
    $old_value = get_option( $option );
    $value = apply_filters( 'pre_update_option_' . $option, $value, $old_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 )