WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#28790 closed defect (bug) (invalid)

Apply widget_update_callback filter, before update() is called on a widget instance.

Reported by: jayarjo Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9.1
Component: Widgets Keywords: close
Focuses: Cc:

Description

form_callback() in WP_Widget applies filter before it invokes form() method. Among other things this gives developer an opportunity to do some manipulations on the output:

	$instance = apply_filters( 'widget_form_callback', $instance, $this );

	$return = null;
	if ( false !== $instance ) {
		$return = $this->form($instance);

display_callback() has it right as well. But for the update_callback() the same is not true:

	$instance = $this->update( $new_instance, $old_instance );

	if ( $this->is_preview() ) {
		wp_suspend_cache_addition( $was_cache_addition_suspended );
	}

	$instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this );

So basically there's no way to manipulate the instance, before it gets itself into the update() method. Could we do it opposite instead?

	$instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this );
	
	$instance = $this->update( $new_instance, $old_instance );

	if ( $this->is_preview() ) {
		wp_suspend_cache_addition( $was_cache_addition_suspended );
	}

Change History (2)

#1 @Denis-de-Bernardy
6 years ago

  • Keywords close added

Methinks invalid. This is by design as I recollect when the filters got added. You want to use the update filter to do additional side effects in addition to the default update functionality, and that is how things are at the moment.

#2 @westonruter
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Agreed that this is invalid. The update filter is specifically to filter the value that is returned by the widget's update callback. If a filter is desired for the value going into the update callback, then a new filter should be proposed. Also, we can't move the filter from where it exists right now without breaking existing plugins.

Note: See TracTickets for help on using tickets.