WP_Customize_Selective_Refresh::add_partial( WP_Customize_Partial|string $id, array $args = array() ): WP_Customize_Partial
Adds a partial.
Contents
Description
See also
Parameters
-
$id
WP_Customize_Partial|string Required -
Customize Partial object, or Partial ID.
-
$args
array Optional -
Array of properties for the new Partials object.
See WP_Customize_Partial::__construct() for information on accepted arguments.More Arguments from WP_Customize_Partial::__construct( ... $args )
Array of properties for the new Partials object.
type
stringType of the partial to be created.selector
stringThe jQuery selector to find the container element for the partial, that is, a partial's placement.settings
string[]IDs for settings tied to the partial. If undefined,$id
will be used.primary_setting
stringThe ID for the setting that this partial is primarily responsible for rendering. If not supplied, it will default to the ID of the first setting.capability
stringCapability required to edit this partial.
Normally this is empty and the capability is derived from the capabilities of the associated$settings
.render_callback
callableRender callback.
Callback is called with one argument, the instance of WP_Customize_Partial.
The callback can either echo the partial or return the partial as a string, or return false if error.container_inclusive
boolWhether the container element is included in the partial, or if only the contents are rendered.fallback_refresh
boolWhether to refresh the entire preview in case a partial cannot be refreshed.
A partial render is considered a failure if the render_callback returns false.
Default:
array()
Return
WP_Customize_Partial The instance of the partial that was added.
Source
File: wp-includes/customize/class-wp-customize-selective-refresh.php
.
View all references
public function add_partial( $id, $args = array() ) {
if ( $id instanceof WP_Customize_Partial ) {
$partial = $id;
} else {
$class = 'WP_Customize_Partial';
/** This filter is documented in wp-includes/customize/class-wp-customize-selective-refresh.php */
$args = apply_filters( 'customize_dynamic_partial_args', $args, $id );
/** This filter is documented in wp-includes/customize/class-wp-customize-selective-refresh.php */
$class = apply_filters( 'customize_dynamic_partial_class', $class, $id, $args );
$partial = new $class( $this, $id, $args );
}
$this->partials[ $partial->id ] = $partial;
return $partial;
}
Hooks
-
apply_filters( 'customize_dynamic_partial_args',
false|array $partial_args ,string $partial_id ) -
Filters a dynamic partial’s constructor arguments.
-
apply_filters( 'customize_dynamic_partial_class',
string $partial_class ,string $partial_id ,array $partial_args ) -
Filters the class used to construct partials.
Changelog
Version | Description |
---|---|
4.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
In case you wonder why the pencil icon is not showing in your theme (and maybe the “Shift-click to edit this element.” title does), it might be because you chose an “illegal” container selector to place it in. E.g:
If you look into
customize-selective-refresh.js
you will find that the “illegal” selectors areIn other words, you need to be sure that whatever element you point to as the container for the pencil icon is not one of those (not an image, not a hr, etc).