WP_Customize_Selective_Refresh::add_dynamic_partials() WordPress Method
The WP_Customize_Selective_Refresh::add_dynamic_partials() method allows you to programmatically add partial refreshable parts to a WordPress Customizer page. This is useful if you have parts of your page that are generated by PHP and you want to be able to refresh them without refreshing the entire page.
WP_Customize_Selective_Refresh::add_dynamic_partials( string[] $partial_ids ) #
Registers dynamically-created partials.
Description
See also
Parameters
- $partial_ids
(string[])(Required)Array of the partial IDs to add.
Return
(WP_Customize_Partial[]) Array of added WP_Customize_Partial instances.
Source
File: wp-includes/customize/class-wp-customize-selective-refresh.php
public function add_dynamic_partials( $partial_ids ) { $new_partials = array(); foreach ( $partial_ids as $partial_id ) { // Skip partials already created. $partial = $this->get_partial( $partial_id ); if ( $partial ) { continue; } $partial_args = false; $partial_class = 'WP_Customize_Partial'; /** * Filters a dynamic partial's constructor arguments. * * For a dynamic partial to be registered, this filter must be employed * to override the default false value with an array of args to pass to * the WP_Customize_Partial constructor. * * @since 4.5.0 * * @param false|array $partial_args The arguments to the WP_Customize_Partial constructor. * @param string $partial_id ID for dynamic partial. */ $partial_args = apply_filters( 'customize_dynamic_partial_args', $partial_args, $partial_id ); if ( false === $partial_args ) { continue; } /** * Filters the class used to construct partials. * * Allow non-statically created partials to be constructed with custom WP_Customize_Partial subclass. * * @since 4.5.0 * * @param string $partial_class WP_Customize_Partial or a subclass. * @param string $partial_id ID for dynamic partial. * @param array $partial_args The arguments to the WP_Customize_Partial constructor. */ $partial_class = apply_filters( 'customize_dynamic_partial_class', $partial_class, $partial_id, $partial_args ); $partial = new $partial_class( $this, $partial_id, $partial_args ); $this->add_partial( $partial ); $new_partials[] = $partial; } return $new_partials; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
4.5.0 | Introduced. |