customize_render_partials_response хук-фильтрWP 4.5.0

Filters the response from rendering the 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.

Использование

add_filter( 'customize_render_partials_response', 'wp_kama_customize_render_partials_response_filter', 10, 3 );

/**
 * Function for `customize_render_partials_response` filter-hook.
 * 
 * @param array                          $response Response.
 * @param WP_Customize_Selective_Refresh $refresh  Selective refresh component.
 * @param array                          $partials 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.
 *
 * @return array
 */
function wp_kama_customize_render_partials_response_filter( $response, $refresh, $partials ){

	// filter...
	return $response;
}
$response(массив)

Response.

  • contents(массив)
    Associative array mapping a partial ID its corresponding array of contents for the containers requested.

  • errors(массив)
    List of errors triggered during rendering of partials, if WP_DEBUG_DISPLAY is enabled.
$refresh(WP_Customize_Selective_Refresh)
Selective refresh component.
$partials(массив)
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.

Список изменений

С версии 4.5.0 Введена.

Где вызывается хук

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

Где используется хук в WordPress

wp-includes/class-wp-customize-manager.php 400
add_filter( 'customize_render_partials_response', array( $this, 'export_header_video_settings' ), 10, 3 );
wp-includes/class-wp-customize-nav-menus.php 1352
add_filter( 'customize_render_partials_response', array( $this, 'export_partial_rendered_nav_menu_instances' ) );