Edit File by line
/home/zeestwma/richards.../wp-inclu.../customiz...
File: class-wp-customize-partial.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Customize API: WP_Customize_Partial class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Customize
[5] Fix | Delete
* @since 4.5.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core Customizer class for implementing selective refresh partials.
[10] Fix | Delete
*
[11] Fix | Delete
* Representation of a rendered region in the previewed page that gets
[12] Fix | Delete
* selectively refreshed when an associated setting is changed.
[13] Fix | Delete
* This class is analogous of WP_Customize_Control.
[14] Fix | Delete
*
[15] Fix | Delete
* @since 4.5.0
[16] Fix | Delete
*/
[17] Fix | Delete
#[AllowDynamicProperties]
[18] Fix | Delete
class WP_Customize_Partial {
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Component.
[22] Fix | Delete
*
[23] Fix | Delete
* @since 4.5.0
[24] Fix | Delete
* @var WP_Customize_Selective_Refresh
[25] Fix | Delete
*/
[26] Fix | Delete
public $component;
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Unique identifier for the partial.
[30] Fix | Delete
*
[31] Fix | Delete
* If the partial is used to display a single setting, this would generally
[32] Fix | Delete
* be the same as the associated setting's ID.
[33] Fix | Delete
*
[34] Fix | Delete
* @since 4.5.0
[35] Fix | Delete
* @var string
[36] Fix | Delete
*/
[37] Fix | Delete
public $id;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Parsed ID.
[41] Fix | Delete
*
[42] Fix | Delete
* @since 4.5.0
[43] Fix | Delete
* @var array {
[44] Fix | Delete
* @type string $base ID base.
[45] Fix | Delete
* @type array $keys Keys for multidimensional.
[46] Fix | Delete
* }
[47] Fix | Delete
*/
[48] Fix | Delete
protected $id_data = array();
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Type of this partial.
[52] Fix | Delete
*
[53] Fix | Delete
* @since 4.5.0
[54] Fix | Delete
* @var string
[55] Fix | Delete
*/
[56] Fix | Delete
public $type = 'default';
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* The jQuery selector to find the container element for the partial.
[60] Fix | Delete
*
[61] Fix | Delete
* @since 4.5.0
[62] Fix | Delete
* @var string
[63] Fix | Delete
*/
[64] Fix | Delete
public $selector;
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* IDs for settings tied to the partial.
[68] Fix | Delete
*
[69] Fix | Delete
* @since 4.5.0
[70] Fix | Delete
* @var string[]
[71] Fix | Delete
*/
[72] Fix | Delete
public $settings;
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* The ID for the setting that this partial is primarily responsible for rendering.
[76] Fix | Delete
*
[77] Fix | Delete
* If not supplied, it will default to the ID of the first setting.
[78] Fix | Delete
*
[79] Fix | Delete
* @since 4.5.0
[80] Fix | Delete
* @var string
[81] Fix | Delete
*/
[82] Fix | Delete
public $primary_setting;
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Capability required to edit this partial.
[86] Fix | Delete
*
[87] Fix | Delete
* Normally this is empty and the capability is derived from the capabilities
[88] Fix | Delete
* of the associated `$settings`.
[89] Fix | Delete
*
[90] Fix | Delete
* @since 4.5.0
[91] Fix | Delete
* @var string
[92] Fix | Delete
*/
[93] Fix | Delete
public $capability;
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Render callback.
[97] Fix | Delete
*
[98] Fix | Delete
* @since 4.5.0
[99] Fix | Delete
*
[100] Fix | Delete
* @see WP_Customize_Partial::render()
[101] Fix | Delete
* @var callable Callback is called with one argument, the instance of
[102] Fix | Delete
* WP_Customize_Partial. The callback can either echo the
[103] Fix | Delete
* partial or return the partial as a string, or return false if error.
[104] Fix | Delete
*/
[105] Fix | Delete
public $render_callback;
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* Whether the container element is included in the partial, or if only the contents are rendered.
[109] Fix | Delete
*
[110] Fix | Delete
* @since 4.5.0
[111] Fix | Delete
* @var bool
[112] Fix | Delete
*/
[113] Fix | Delete
public $container_inclusive = false;
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* Whether to refresh the entire preview in case a partial cannot be refreshed.
[117] Fix | Delete
*
[118] Fix | Delete
* A partial render is considered a failure if the render_callback returns false.
[119] Fix | Delete
*
[120] Fix | Delete
* @since 4.5.0
[121] Fix | Delete
* @var bool
[122] Fix | Delete
*/
[123] Fix | Delete
public $fallback_refresh = true;
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Constructor.
[127] Fix | Delete
*
[128] Fix | Delete
* Supplied `$args` override class property defaults.
[129] Fix | Delete
*
[130] Fix | Delete
* If `$args['settings']` is not defined, use the $id as the setting ID.
[131] Fix | Delete
*
[132] Fix | Delete
* @since 4.5.0
[133] Fix | Delete
*
[134] Fix | Delete
* @param WP_Customize_Selective_Refresh $component Customize Partial Refresh plugin instance.
[135] Fix | Delete
* @param string $id Control ID.
[136] Fix | Delete
* @param array $args {
[137] Fix | Delete
* Optional. Array of properties for the new Partials object. Default empty array.
[138] Fix | Delete
*
[139] Fix | Delete
* @type string $type Type of the partial to be created.
[140] Fix | Delete
* @type string $selector The jQuery selector to find the container element for the partial, that is,
[141] Fix | Delete
* a partial's placement.
[142] Fix | Delete
* @type string[] $settings IDs for settings tied to the partial. If undefined, `$id` will be used.
[143] Fix | Delete
* @type string $primary_setting The ID for the setting that this partial is primarily responsible for
[144] Fix | Delete
* rendering. If not supplied, it will default to the ID of the first setting.
[145] Fix | Delete
* @type string $capability Capability required to edit this partial.
[146] Fix | Delete
* Normally this is empty and the capability is derived from the capabilities
[147] Fix | Delete
* of the associated `$settings`.
[148] Fix | Delete
* @type callable $render_callback Render callback.
[149] Fix | Delete
* Callback is called with one argument, the instance of WP_Customize_Partial.
[150] Fix | Delete
* The callback can either echo the partial or return the partial as a string,
[151] Fix | Delete
* or return false if error.
[152] Fix | Delete
* @type bool $container_inclusive Whether the container element is included in the partial, or if only
[153] Fix | Delete
* the contents are rendered.
[154] Fix | Delete
* @type bool $fallback_refresh Whether to refresh the entire preview in case a partial cannot be refreshed.
[155] Fix | Delete
* A partial render is considered a failure if the render_callback returns
[156] Fix | Delete
* false.
[157] Fix | Delete
* }
[158] Fix | Delete
*/
[159] Fix | Delete
public function __construct( WP_Customize_Selective_Refresh $component, $id, $args = array() ) {
[160] Fix | Delete
$keys = array_keys( get_object_vars( $this ) );
[161] Fix | Delete
foreach ( $keys as $key ) {
[162] Fix | Delete
if ( isset( $args[ $key ] ) ) {
[163] Fix | Delete
$this->$key = $args[ $key ];
[164] Fix | Delete
}
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
$this->component = $component;
[168] Fix | Delete
$this->id = $id;
[169] Fix | Delete
$this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) );
[170] Fix | Delete
$this->id_data['base'] = array_shift( $this->id_data['keys'] );
[171] Fix | Delete
[172] Fix | Delete
if ( empty( $this->render_callback ) ) {
[173] Fix | Delete
$this->render_callback = array( $this, 'render_callback' );
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
// Process settings.
[177] Fix | Delete
if ( ! isset( $this->settings ) ) {
[178] Fix | Delete
$this->settings = array( $id );
[179] Fix | Delete
} elseif ( is_string( $this->settings ) ) {
[180] Fix | Delete
$this->settings = array( $this->settings );
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
if ( empty( $this->primary_setting ) ) {
[184] Fix | Delete
$this->primary_setting = current( $this->settings );
[185] Fix | Delete
}
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* Retrieves parsed ID data for multidimensional setting.
[190] Fix | Delete
*
[191] Fix | Delete
* @since 4.5.0
[192] Fix | Delete
*
[193] Fix | Delete
* @return array {
[194] Fix | Delete
* ID data for multidimensional partial.
[195] Fix | Delete
*
[196] Fix | Delete
* @type string $base ID base.
[197] Fix | Delete
* @type array $keys Keys for multidimensional array.
[198] Fix | Delete
* }
[199] Fix | Delete
*/
[200] Fix | Delete
final public function id_data() {
[201] Fix | Delete
return $this->id_data;
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
/**
[205] Fix | Delete
* Renders the template partial involving the associated settings.
[206] Fix | Delete
*
[207] Fix | Delete
* @since 4.5.0
[208] Fix | Delete
*
[209] Fix | Delete
* @param array $container_context Optional. Array of context data associated with the target container (placement).
[210] Fix | Delete
* Default empty array.
[211] Fix | Delete
* @return string|array|false The rendered partial as a string, raw data array (for client-side JS template),
[212] Fix | Delete
* or false if no render applied.
[213] Fix | Delete
*/
[214] Fix | Delete
final public function render( $container_context = array() ) {
[215] Fix | Delete
$partial = $this;
[216] Fix | Delete
$rendered = false;
[217] Fix | Delete
[218] Fix | Delete
if ( ! empty( $this->render_callback ) ) {
[219] Fix | Delete
ob_start();
[220] Fix | Delete
$return_render = call_user_func( $this->render_callback, $this, $container_context );
[221] Fix | Delete
$ob_render = ob_get_clean();
[222] Fix | Delete
[223] Fix | Delete
if ( null !== $return_render && '' !== $ob_render ) {
[224] Fix | Delete
_doing_it_wrong( __FUNCTION__, __( 'Partial render must echo the content or return the content string (or array), but not both.' ), '4.5.0' );
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
/*
[228] Fix | Delete
* Note that the string return takes precedence because the $ob_render may just\
[229] Fix | Delete
* include PHP warnings or notices.
[230] Fix | Delete
*/
[231] Fix | Delete
$rendered = null !== $return_render ? $return_render : $ob_render;
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
/**
[235] Fix | Delete
* Filters partial rendering.
[236] Fix | Delete
*
[237] Fix | Delete
* @since 4.5.0
[238] Fix | Delete
*
[239] Fix | Delete
* @param string|array|false $rendered The partial value. Default false.
[240] Fix | Delete
* @param WP_Customize_Partial $partial WP_Customize_Setting instance.
[241] Fix | Delete
* @param array $container_context Optional array of context data associated with
[242] Fix | Delete
* the target container.
[243] Fix | Delete
*/
[244] Fix | Delete
$rendered = apply_filters( 'customize_partial_render', $rendered, $partial, $container_context );
[245] Fix | Delete
[246] Fix | Delete
/**
[247] Fix | Delete
* Filters partial rendering for a specific partial.
[248] Fix | Delete
*
[249] Fix | Delete
* The dynamic portion of the hook name, `$partial->ID` refers to the partial ID.
[250] Fix | Delete
*
[251] Fix | Delete
* @since 4.5.0
[252] Fix | Delete
*
[253] Fix | Delete
* @param string|array|false $rendered The partial value. Default false.
[254] Fix | Delete
* @param WP_Customize_Partial $partial WP_Customize_Setting instance.
[255] Fix | Delete
* @param array $container_context Optional array of context data associated with
[256] Fix | Delete
* the target container.
[257] Fix | Delete
*/
[258] Fix | Delete
$rendered = apply_filters( "customize_partial_render_{$partial->id}", $rendered, $partial, $container_context );
[259] Fix | Delete
[260] Fix | Delete
return $rendered;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Default callback used when invoking WP_Customize_Control::render().
[265] Fix | Delete
*
[266] Fix | Delete
* Note that this method may echo the partial *or* return the partial as
[267] Fix | Delete
* a string or array, but not both. Output buffering is performed when this
[268] Fix | Delete
* is called. Subclasses can override this with their specific logic, or they
[269] Fix | Delete
* may provide an 'render_callback' argument to the constructor.
[270] Fix | Delete
*
[271] Fix | Delete
* This method may return an HTML string for straight DOM injection, or it
[272] Fix | Delete
* may return an array for supporting Partial JS subclasses to render by
[273] Fix | Delete
* applying to client-side templating.
[274] Fix | Delete
*
[275] Fix | Delete
* @since 4.5.0
[276] Fix | Delete
*
[277] Fix | Delete
* @param WP_Customize_Partial $partial Partial.
[278] Fix | Delete
* @param array $context Context.
[279] Fix | Delete
* @return string|array|false
[280] Fix | Delete
*/
[281] Fix | Delete
public function render_callback( WP_Customize_Partial $partial, $context = array() ) {
[282] Fix | Delete
unset( $partial, $context );
[283] Fix | Delete
return false;
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
/**
[287] Fix | Delete
* Retrieves the data to export to the client via JSON.
[288] Fix | Delete
*
[289] Fix | Delete
* @since 4.5.0
[290] Fix | Delete
*
[291] Fix | Delete
* @return array Array of parameters passed to the JavaScript.
[292] Fix | Delete
*/
[293] Fix | Delete
public function json() {
[294] Fix | Delete
$exports = array(
[295] Fix | Delete
'settings' => $this->settings,
[296] Fix | Delete
'primarySetting' => $this->primary_setting,
[297] Fix | Delete
'selector' => $this->selector,
[298] Fix | Delete
'type' => $this->type,
[299] Fix | Delete
'fallbackRefresh' => $this->fallback_refresh,
[300] Fix | Delete
'containerInclusive' => $this->container_inclusive,
[301] Fix | Delete
);
[302] Fix | Delete
return $exports;
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
/**
[306] Fix | Delete
* Checks if the user can refresh this partial.
[307] Fix | Delete
*
[308] Fix | Delete
* Returns false if the user cannot manipulate one of the associated settings,
[309] Fix | Delete
* or if one of the associated settings does not exist.
[310] Fix | Delete
*
[311] Fix | Delete
* @since 4.5.0
[312] Fix | Delete
*
[313] Fix | Delete
* @return bool False if user can't edit one of the related settings,
[314] Fix | Delete
* or if one of the associated settings does not exist.
[315] Fix | Delete
*/
[316] Fix | Delete
final public function check_capabilities() {
[317] Fix | Delete
if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) {
[318] Fix | Delete
return false;
[319] Fix | Delete
}
[320] Fix | Delete
foreach ( $this->settings as $setting_id ) {
[321] Fix | Delete
$setting = $this->component->manager->get_setting( $setting_id );
[322] Fix | Delete
if ( ! $setting || ! $setting->check_capabilities() ) {
[323] Fix | Delete
return false;
[324] Fix | Delete
}
[325] Fix | Delete
}
[326] Fix | Delete
return true;
[327] Fix | Delete
}
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function