customize_render_partials_response

Filters the response from rendering the partials.

Description

apply_filters( 'customize_render_partials_response', (array) $response, (WP_Customize_Selective_Refresh) $instance, (array) $partials ); 

Plugins may use this filter to inject $scripts and $styles,, which are dependencies for the partials being rendered. The response data will be available to the client via the render-partials-response JS event, so the client can then inject the scripts and styles into the DOM if they have not already been enqueued there.

If plugins do this, they'll need to take care for any scripts that do document.write() and make sure that these are not injected, or else to override the function to no-op, or else the page will be destroyed.

Plugins should be aware that $scripts and $styles, may eventually be included by default in the response.

Parameters (3)

0. $response (array)
1. $instance (WP_Customize_Selective_Refresh)
Selective refresh component.
2. $partials (array)
Placements' context data for the partials rendered in the request. The array is keyed by partial ID, with each item being an array of the placements' context data.

Usage

To run the hook, copy the example below.
  1. $response = apply_filters( 'customize_render_partials_response', $response, $instance, $partials ); 
  2.  
  3. if ( !empty( $response ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the customize_render_partials_response callback 
  2. function filter_customize_render_partials_response( $response, $instance, $partials ) { 
  3. // make filter magic happen here... 
  4. return $response
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'customize_render_partials_response', 'filter_customize_render_partials_response', 10, 3 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'customize_render_partials_response', 'filter_customize_render_partials_response', 10, 3 ); 

Defined (1)

The filter is defined in the following location(s).

/wp-includes/customize/class-wp-customize-selective-refresh.php  
  1. $response = apply_filters( 'customize_render_partials_response', $response, $this, $partials );