WP_Customize_Selective_Refresh::handle_render_partials_request()
- Since
- 4.5.0
- Source
wp-includes/customize/class-wp-customize-selective-refresh.php:304
Compatibility
- WordPress
- since 4.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Performance profile
How much work a call to WP_Customize_Selective_Refresh::handle_render_partials_request() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 4–105
- Plugin surface
- 3 hooks
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 152.
Third-party callbacks on 'customize_render_partials_before', 'customize_render_partials_after', 'customize_render_partials_response' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()called directly - serializeserialisation
json_decode()called directly
Further down the call graph this can also reach option, cache, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Customize_Selective_Refresh::handle_render_partials_request() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!->is_render_partials_request() | 4 | ->is_render_partials_request() |
->is_render_partials_request() && is_customize_preview() && isset($value) && is_array($partials) | 92–98 | ->is_render_partials_request(), is_customize_preview(), status_header(), wp_unslash(), json_decode(), array_keys(), ->add_dynamic_partials(), do_action(), error_reporting(), restore_error_handler(), do_action(), ->unsanitized_post_values(), ->validate_setting_values(), apply_filters(), wp_send_json_success() |
->is_render_partials_request() && is_array($partials) | 94–102 | ->is_render_partials_request(), is_customize_preview(), wp_send_json_error(), status_header(), wp_unslash(), json_decode(), array_keys(), ->add_dynamic_partials(), do_action(), error_reporting(), restore_error_handler(), do_action(), ->unsanitized_post_values(), ->validate_setting_values(), apply_filters(), wp_send_json_success() |
->is_render_partials_request() && is_customize_preview() && isset($value) && !is_array($partials) | 95–101 | ->is_render_partials_request(), is_customize_preview(), status_header(), wp_unslash(), json_decode(), wp_send_json_error(), array_keys(), ->add_dynamic_partials(), do_action(), error_reporting(), restore_error_handler(), do_action(), ->unsanitized_post_values(), ->validate_setting_values(), apply_filters(), wp_send_json_success() |
->is_render_partials_request() && !is_array($partials) | 97–105 | ->is_render_partials_request(), is_customize_preview(), wp_send_json_error(), status_header(), wp_unslash(), json_decode(), wp_send_json_error(), array_keys(), ->add_dynamic_partials(), do_action(), error_reporting(), restore_error_handler(), do_action(), ->unsanitized_post_values(), ->validate_setting_values(), apply_filters(), wp_send_json_success() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 152 instructions, 4–105 executed per call, 14 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 3
3 hooks fire while WP_Customize_Selective_Refresh::handle_render_partials_request() runs, in this order:
- do_action( customize_render_partials_before )actionline 344 (+40 into the body)
Fires immediately before partials are rendered.
- do_action( customize_render_partials_after )actionline 393 (+89 into the body)
Fires immediately after partials are rendered.
- apply_filters( customize_render_partials_response )filterline 437 (+133 into the body)
Filters the response from rendering the partials.
Uses · 10
- is_customize_preview()Whether the site is being previewed in the Customizer.
- wp_send_json_error()Sends a JSON response back to an Ajax request, indicating failure.
- status_header()Sets HTTP status header.
- wp_unslash()Removes slashes from a string or recursively removes slashes from strings within an array.
- do_action()Calls the callback functions that have been added to an action hook.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_send_json_success()Sends a JSON response back to an Ajax request, indicating success.
- WP_Customize_Selective_Refresh::is_render_partials_request()Checks whether the request is for rendering partials.
- WP_Customize_Selective_Refresh::add_dynamic_partials()Registers dynamically-created partials.
- WP_Customize_Selective_Refresh::get_partial()Retrieves a partial.
Source code
public function handle_render_partials_request() { if ( ! $this->is_render_partials_request() ) { return; } /* * Note that is_customize_preview() returning true will entail that the * user passed the 'customize' capability check and the nonce check, since * WP_Customize_Manager::setup_theme() is where the previewing flag is set. */ if ( ! is_customize_preview() ) { wp_send_json_error( 'expected_customize_preview', 403 ); } elseif ( ! isset( $_POST['partials'] ) ) { wp_send_json_error( 'missing_partials', 400 ); } // Ensure that doing selective refresh on 404 template doesn't result in fallback rendering behavior (full refreshes). status_header( 200 ); $partials = json_decode( wp_unslash( $_POST['partials'] ), true ); if ( ! is_array( $partials ) ) { wp_send_json_error( 'malformed_partials' ); } $this->add_dynamic_partials( array_keys( $partials ) ); /** * Fires immediately before partials are rendered. * * Plugins may do things like call wp_enqueue_scripts() and gather a list of the scripts * and styles which may get enqueued in the response. * * @since 4.5.0 * * @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. */ do_action( 'customize_render_partials_before', $this, $partials ); set_error_handler( array( $this, 'handle_error' ), error_reporting() ); $contents = array(); foreach ( $partials as $partial_id => $container_contexts ) { $this->current_partial_id = $partial_id; if ( ! is_array( $container_contexts ) ) { wp_send_json_error( 'malformed_container_contexts' ); } $partial = $this->get_partial( $partial_id ); if ( ! $partial || ! $partial->check_capabilities() ) { $contents[ $partial_id ] = null; continue; } $contents[ $partial_id ] = array(); // @todo The array should include not only the contents, but also whether the container is included? if ( empty( $container_contexts ) ) { // Since there are no container contexts, render just once. $contents[ $partial_id ][] = $partial->render( null ); } else { foreach ( $container_contexts as $container_context ) { $contents[ $partial_id ][] = $partial->render( $container_context ); } } } $this->current_partial_id = null; restore_error_handler(); /** * Fires immediately after partials are rendered. * * Plugins may do things like call wp_footer() to scrape scripts output and return themChangelog
Introduced in 4.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/customize/class-wp-customize-selective-refresh.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.