Make WordPress Core

Opened 11 years ago

Closed 10 years ago

#29098 closed enhancement (fixed)

Send JSON success for customize_save and allow response to be filtered

Reported by: westonruter's profile westonruter Owned by: ocean90's profile ocean90
Milestone: 4.2 Priority: normal
Severity: normal Version: 3.4
Component: Customize Keywords: early needs-patch
Focuses: javascript Cc:

Description

In my development on the Customize Posts plugin, and on the work celloexpressions is doing on Menu Customizer, there is a need to create pseudo posts in the preview experience which don't correspond to actual posts in the DB. In other words, the IDs used are placeholders which aren't finalized until the Customizer settings are saved. Upon saving, we need to obtain the IDs that were generated by the DB and then pass them back to the frontend so that the model can be updated to utilize the new IDs. This currently is difficult because the customize_save Ajax action terminates with a die without providing a mechanism for returning data which plugins can filter to attach any additional information resulting from the save. So I suggest that the save method return with something like:

$response = apply_filters( 'wp_customize_save_response', array(), $this->manager );
wp_send_json_success( $response );

Another key use for this filter would be to send back the PHP-sanitized settings and to update the JS models so that they match what was saved to the DB.

Change History (12)

#1 @westonruter
11 years ago

  • Keywords has-patch added

#2 @celloexpressions
11 years ago

+1

Menu Customizer currently sidesteps this by saving and updating clones to the DB, then hooking into the customizer saved action to trigger new clones. While I don't foresee this changing there for scaling purposes, this would be really useful for a lot of other situations.

#3 @westonruter
10 years ago

  • Keywords early added
  • Milestone changed from Future Release to 4.2
  • Owner set to ocean90
  • Status changed from new to reviewing

In 29098.2.diff:

  • Refresh patch
  • Bump @since to 4.2.0
  • Use wp.ajax.post() and the promise fail callback since we're using wp_send_json_success() and wp_send_json_error().

Having this in place is a prerequisite for things that I need to do for Menu Customizer, and it will also be useful for #30028.

This ticket was mentioned in Slack in #core-customize by westonruter. View the logs.


10 years ago

#5 @ocean90
10 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 31062:

Customizer: Send JSON success for customize_save and allow response to be filtered.

props westonruter.
fixes #29098.

#6 follow-up: @DrewAPicture
10 years ago

  • Keywords needs-patch added; has-patch removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

In [31062] the parameter description for $data was missed in the hook doc for the new customize_save_response filter.

#7 in reply to: ↑ 6 @westonruter
10 years ago

Replying to DrewAPicture:

In [31062] the parameter description for $data was missed in the hook doc for the new customize_save_response filter.

You can commit this:

@param array $data Additional information passed back to the 'saved' event on wp.customize

#8 @DrewAPicture
10 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 31063:

Add a description for the $data parameter in the DocBlock for the customize_save_response hook introduced in [31062].

Props westonruter.
Fixes #29098.

Note: See TracTickets for help on using tickets.