Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: class-wp-customize-setting.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Customize Setting classes
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Customize
[5] Fix | Delete
* @since 3.4.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Customize Setting class.
[10] Fix | Delete
*
[11] Fix | Delete
* Handles saving and sanitizing of settings.
[12] Fix | Delete
*
[13] Fix | Delete
* @since 3.4.0
[14] Fix | Delete
*
[15] Fix | Delete
* @see WP_Customize_Manager
[16] Fix | Delete
* @link https://developer.wordpress.org/themes/customize-api
[17] Fix | Delete
*/
[18] Fix | Delete
#[AllowDynamicProperties]
[19] Fix | Delete
class WP_Customize_Setting {
[20] Fix | Delete
/**
[21] Fix | Delete
* Customizer bootstrap instance.
[22] Fix | Delete
*
[23] Fix | Delete
* @since 3.4.0
[24] Fix | Delete
* @var WP_Customize_Manager
[25] Fix | Delete
*/
[26] Fix | Delete
public $manager;
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Unique string identifier for the setting.
[30] Fix | Delete
*
[31] Fix | Delete
* @since 3.4.0
[32] Fix | Delete
* @var string
[33] Fix | Delete
*/
[34] Fix | Delete
public $id;
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Type of customize settings.
[38] Fix | Delete
*
[39] Fix | Delete
* @since 3.4.0
[40] Fix | Delete
* @var string
[41] Fix | Delete
*/
[42] Fix | Delete
public $type = 'theme_mod';
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Capability required to edit this setting.
[46] Fix | Delete
*
[47] Fix | Delete
* @since 3.4.0
[48] Fix | Delete
* @var string|array
[49] Fix | Delete
*/
[50] Fix | Delete
public $capability = 'edit_theme_options';
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Theme features required to support the setting.
[54] Fix | Delete
*
[55] Fix | Delete
* @since 3.4.0
[56] Fix | Delete
* @var string|string[]
[57] Fix | Delete
*/
[58] Fix | Delete
public $theme_supports = '';
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* The default value for the setting.
[62] Fix | Delete
*
[63] Fix | Delete
* @since 3.4.0
[64] Fix | Delete
* @var string
[65] Fix | Delete
*/
[66] Fix | Delete
public $default = '';
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Options for rendering the live preview of changes in Customizer.
[70] Fix | Delete
*
[71] Fix | Delete
* Set this value to 'postMessage' to enable a custom JavaScript handler to render changes to this setting
[72] Fix | Delete
* as opposed to reloading the whole page.
[73] Fix | Delete
*
[74] Fix | Delete
* @since 3.4.0
[75] Fix | Delete
* @var string
[76] Fix | Delete
*/
[77] Fix | Delete
public $transport = 'refresh';
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Server-side validation callback for the setting's value.
[81] Fix | Delete
*
[82] Fix | Delete
* @since 4.6.0
[83] Fix | Delete
* @var callable
[84] Fix | Delete
*/
[85] Fix | Delete
public $validate_callback = '';
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Callback to filter a Customize setting value in un-slashed form.
[89] Fix | Delete
*
[90] Fix | Delete
* @since 3.4.0
[91] Fix | Delete
* @var callable
[92] Fix | Delete
*/
[93] Fix | Delete
public $sanitize_callback = '';
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Callback to convert a Customize PHP setting value to a value that is JSON serializable.
[97] Fix | Delete
*
[98] Fix | Delete
* @since 3.4.0
[99] Fix | Delete
* @var callable
[100] Fix | Delete
*/
[101] Fix | Delete
public $sanitize_js_callback = '';
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Whether or not the setting is initially dirty when created.
[105] Fix | Delete
*
[106] Fix | Delete
* This is used to ensure that a setting will be sent from the pane to the
[107] Fix | Delete
* preview when loading the Customizer. Normally a setting only is synced to
[108] Fix | Delete
* the preview if it has been changed. This allows the setting to be sent
[109] Fix | Delete
* from the start.
[110] Fix | Delete
*
[111] Fix | Delete
* @since 4.2.0
[112] Fix | Delete
* @var bool
[113] Fix | Delete
*/
[114] Fix | Delete
public $dirty = false;
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* ID Data.
[118] Fix | Delete
*
[119] Fix | Delete
* @since 3.4.0
[120] Fix | Delete
* @var array
[121] Fix | Delete
*/
[122] Fix | Delete
protected $id_data = array();
[123] Fix | Delete
[124] Fix | Delete
/**
[125] Fix | Delete
* Whether or not preview() was called.
[126] Fix | Delete
*
[127] Fix | Delete
* @since 4.4.0
[128] Fix | Delete
* @var bool
[129] Fix | Delete
*/
[130] Fix | Delete
protected $is_previewed = false;
[131] Fix | Delete
[132] Fix | Delete
/**
[133] Fix | Delete
* Cache of multidimensional values to improve performance.
[134] Fix | Delete
*
[135] Fix | Delete
* @since 4.4.0
[136] Fix | Delete
* @var array
[137] Fix | Delete
*/
[138] Fix | Delete
protected static $aggregated_multidimensionals = array();
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* Whether the multidimensional setting is aggregated.
[142] Fix | Delete
*
[143] Fix | Delete
* @since 4.4.0
[144] Fix | Delete
* @var bool
[145] Fix | Delete
*/
[146] Fix | Delete
protected $is_multidimensional_aggregated = false;
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Constructor.
[150] Fix | Delete
*
[151] Fix | Delete
* Any supplied $args override class property defaults.
[152] Fix | Delete
*
[153] Fix | Delete
* @since 3.4.0
[154] Fix | Delete
*
[155] Fix | Delete
* @param WP_Customize_Manager $manager Customizer bootstrap instance.
[156] Fix | Delete
* @param string $id A specific ID of the setting.
[157] Fix | Delete
* Can be a theme mod or option name.
[158] Fix | Delete
* @param array $args {
[159] Fix | Delete
* Optional. Array of properties for the new Setting object. Default empty array.
[160] Fix | Delete
*
[161] Fix | Delete
* @type string $type Type of the setting. Default 'theme_mod'.
[162] Fix | Delete
* @type string $capability Capability required for the setting. Default 'edit_theme_options'
[163] Fix | Delete
* @type string|string[] $theme_supports Theme features required to support the panel. Default is none.
[164] Fix | Delete
* @type string $default Default value for the setting. Default is empty string.
[165] Fix | Delete
* @type string $transport Options for rendering the live preview of changes in Customizer.
[166] Fix | Delete
* Using 'refresh' makes the change visible by reloading the whole preview.
[167] Fix | Delete
* Using 'postMessage' allows a custom JavaScript to handle live changes.
[168] Fix | Delete
* Default is 'refresh'.
[169] Fix | Delete
* @type callable $validate_callback Server-side validation callback for the setting's value.
[170] Fix | Delete
* @type callable $sanitize_callback Callback to filter a Customize setting value in un-slashed form.
[171] Fix | Delete
* @type callable $sanitize_js_callback Callback to convert a Customize PHP setting value to a value that is
[172] Fix | Delete
* JSON serializable.
[173] Fix | Delete
* @type bool $dirty Whether or not the setting is initially dirty when created.
[174] Fix | Delete
* }
[175] Fix | Delete
*/
[176] Fix | Delete
public function __construct( $manager, $id, $args = array() ) {
[177] Fix | Delete
$keys = array_keys( get_object_vars( $this ) );
[178] Fix | Delete
foreach ( $keys as $key ) {
[179] Fix | Delete
if ( isset( $args[ $key ] ) ) {
[180] Fix | Delete
$this->$key = $args[ $key ];
[181] Fix | Delete
}
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
$this->manager = $manager;
[185] Fix | Delete
$this->id = $id;
[186] Fix | Delete
[187] Fix | Delete
// Parse the ID for array keys.
[188] Fix | Delete
$this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) );
[189] Fix | Delete
$this->id_data['base'] = array_shift( $this->id_data['keys'] );
[190] Fix | Delete
[191] Fix | Delete
// Rebuild the ID.
[192] Fix | Delete
$this->id = $this->id_data['base'];
[193] Fix | Delete
if ( ! empty( $this->id_data['keys'] ) ) {
[194] Fix | Delete
$this->id .= '[' . implode( '][', $this->id_data['keys'] ) . ']';
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
if ( $this->validate_callback ) {
[198] Fix | Delete
add_filter( "customize_validate_{$this->id}", $this->validate_callback, 10, 3 );
[199] Fix | Delete
}
[200] Fix | Delete
if ( $this->sanitize_callback ) {
[201] Fix | Delete
add_filter( "customize_sanitize_{$this->id}", $this->sanitize_callback, 10, 2 );
[202] Fix | Delete
}
[203] Fix | Delete
if ( $this->sanitize_js_callback ) {
[204] Fix | Delete
add_filter( "customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2 );
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
if ( 'option' === $this->type || 'theme_mod' === $this->type ) {
[208] Fix | Delete
// Other setting types can opt-in to aggregate multidimensional explicitly.
[209] Fix | Delete
$this->aggregate_multidimensional();
[210] Fix | Delete
[211] Fix | Delete
// Allow option settings to indicate whether they should be autoloaded.
[212] Fix | Delete
if ( 'option' === $this->type && isset( $args['autoload'] ) ) {
[213] Fix | Delete
self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload'] = $args['autoload'];
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Get parsed ID data for multidimensional setting.
[220] Fix | Delete
*
[221] Fix | Delete
* @since 4.4.0
[222] Fix | Delete
*
[223] Fix | Delete
* @return array {
[224] Fix | Delete
* ID data for multidimensional setting.
[225] Fix | Delete
*
[226] Fix | Delete
* @type string $base ID base
[227] Fix | Delete
* @type array $keys Keys for multidimensional array.
[228] Fix | Delete
* }
[229] Fix | Delete
*/
[230] Fix | Delete
final public function id_data() {
[231] Fix | Delete
return $this->id_data;
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
/**
[235] Fix | Delete
* Set up the setting for aggregated multidimensional values.
[236] Fix | Delete
*
[237] Fix | Delete
* When a multidimensional setting gets aggregated, all of its preview and update
[238] Fix | Delete
* calls get combined into one call, greatly improving performance.
[239] Fix | Delete
*
[240] Fix | Delete
* @since 4.4.0
[241] Fix | Delete
*/
[242] Fix | Delete
protected function aggregate_multidimensional() {
[243] Fix | Delete
$id_base = $this->id_data['base'];
[244] Fix | Delete
if ( ! isset( self::$aggregated_multidimensionals[ $this->type ] ) ) {
[245] Fix | Delete
self::$aggregated_multidimensionals[ $this->type ] = array();
[246] Fix | Delete
}
[247] Fix | Delete
if ( ! isset( self::$aggregated_multidimensionals[ $this->type ][ $id_base ] ) ) {
[248] Fix | Delete
self::$aggregated_multidimensionals[ $this->type ][ $id_base ] = array(
[249] Fix | Delete
'previewed_instances' => array(), // Calling preview() will add the $setting to the array.
[250] Fix | Delete
'preview_applied_instances' => array(), // Flags for which settings have had their values applied.
[251] Fix | Delete
'root_value' => $this->get_root_value( array() ), // Root value for initial state, manipulated by preview and update calls.
[252] Fix | Delete
);
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
if ( ! empty( $this->id_data['keys'] ) ) {
[256] Fix | Delete
// Note the preview-applied flag is cleared at priority 9 to ensure it is cleared before a deferred-preview runs.
[257] Fix | Delete
add_action( "customize_post_value_set_{$this->id}", array( $this, '_clear_aggregated_multidimensional_preview_applied_flag' ), 9 );
[258] Fix | Delete
$this->is_multidimensional_aggregated = true;
[259] Fix | Delete
}
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
/**
[263] Fix | Delete
* Reset `$aggregated_multidimensionals` static variable.
[264] Fix | Delete
*
[265] Fix | Delete
* This is intended only for use by unit tests.
[266] Fix | Delete
*
[267] Fix | Delete
* @since 4.5.0
[268] Fix | Delete
* @ignore
[269] Fix | Delete
*/
[270] Fix | Delete
public static function reset_aggregated_multidimensionals() {
[271] Fix | Delete
self::$aggregated_multidimensionals = array();
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
/**
[275] Fix | Delete
* The ID for the current site when the preview() method was called.
[276] Fix | Delete
*
[277] Fix | Delete
* @since 4.2.0
[278] Fix | Delete
* @var int
[279] Fix | Delete
*/
[280] Fix | Delete
protected $_previewed_blog_id;
[281] Fix | Delete
[282] Fix | Delete
/**
[283] Fix | Delete
* Return true if the current site is not the same as the previewed site.
[284] Fix | Delete
*
[285] Fix | Delete
* @since 4.2.0
[286] Fix | Delete
*
[287] Fix | Delete
* @return bool If preview() has been called.
[288] Fix | Delete
*/
[289] Fix | Delete
public function is_current_blog_previewed() {
[290] Fix | Delete
if ( ! isset( $this->_previewed_blog_id ) ) {
[291] Fix | Delete
return false;
[292] Fix | Delete
}
[293] Fix | Delete
return ( get_current_blog_id() === $this->_previewed_blog_id );
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
/**
[297] Fix | Delete
* Original non-previewed value stored by the preview method.
[298] Fix | Delete
*
[299] Fix | Delete
* @see WP_Customize_Setting::preview()
[300] Fix | Delete
* @since 4.1.1
[301] Fix | Delete
* @var mixed
[302] Fix | Delete
*/
[303] Fix | Delete
protected $_original_value;
[304] Fix | Delete
[305] Fix | Delete
/**
[306] Fix | Delete
* Add filters to supply the setting's value when accessed.
[307] Fix | Delete
*
[308] Fix | Delete
* If the setting already has a pre-existing value and there is no incoming
[309] Fix | Delete
* post value for the setting, then this method will short-circuit since
[310] Fix | Delete
* there is no change to preview.
[311] Fix | Delete
*
[312] Fix | Delete
* @since 3.4.0
[313] Fix | Delete
* @since 4.4.0 Added boolean return value.
[314] Fix | Delete
*
[315] Fix | Delete
* @return bool False when preview short-circuits due no change needing to be previewed.
[316] Fix | Delete
*/
[317] Fix | Delete
public function preview() {
[318] Fix | Delete
if ( ! isset( $this->_previewed_blog_id ) ) {
[319] Fix | Delete
$this->_previewed_blog_id = get_current_blog_id();
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
// Prevent re-previewing an already-previewed setting.
[323] Fix | Delete
if ( $this->is_previewed ) {
[324] Fix | Delete
return true;
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
$id_base = $this->id_data['base'];
[328] Fix | Delete
$is_multidimensional = ! empty( $this->id_data['keys'] );
[329] Fix | Delete
$multidimensional_filter = array( $this, '_multidimensional_preview_filter' );
[330] Fix | Delete
[331] Fix | Delete
/*
[332] Fix | Delete
* Check if the setting has a pre-existing value (an isset check),
[333] Fix | Delete
* and if doesn't have any incoming post value. If both checks are true,
[334] Fix | Delete
* then the preview short-circuits because there is nothing that needs
[335] Fix | Delete
* to be previewed.
[336] Fix | Delete
*/
[337] Fix | Delete
$undefined = new stdClass();
[338] Fix | Delete
$needs_preview = ( $undefined !== $this->post_value( $undefined ) );
[339] Fix | Delete
$value = null;
[340] Fix | Delete
[341] Fix | Delete
// Since no post value was defined, check if we have an initial value set.
[342] Fix | Delete
if ( ! $needs_preview ) {
[343] Fix | Delete
if ( $this->is_multidimensional_aggregated ) {
[344] Fix | Delete
$root = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'];
[345] Fix | Delete
$value = $this->multidimensional_get( $root, $this->id_data['keys'], $undefined );
[346] Fix | Delete
} else {
[347] Fix | Delete
$default = $this->default;
[348] Fix | Delete
$this->default = $undefined; // Temporarily set default to undefined so we can detect if existing value is set.
[349] Fix | Delete
$value = $this->value();
[350] Fix | Delete
$this->default = $default;
[351] Fix | Delete
}
[352] Fix | Delete
$needs_preview = ( $undefined === $value ); // Because the default needs to be supplied.
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
// If the setting does not need previewing now, defer to when it has a value to preview.
[356] Fix | Delete
if ( ! $needs_preview ) {
[357] Fix | Delete
if ( ! has_action( "customize_post_value_set_{$this->id}", array( $this, 'preview' ) ) ) {
[358] Fix | Delete
add_action( "customize_post_value_set_{$this->id}", array( $this, 'preview' ) );
[359] Fix | Delete
}
[360] Fix | Delete
return false;
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
switch ( $this->type ) {
[364] Fix | Delete
case 'theme_mod':
[365] Fix | Delete
if ( ! $is_multidimensional ) {
[366] Fix | Delete
add_filter( "theme_mod_{$id_base}", array( $this, '_preview_filter' ) );
[367] Fix | Delete
} else {
[368] Fix | Delete
if ( empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] ) ) {
[369] Fix | Delete
// Only add this filter once for this ID base.
[370] Fix | Delete
add_filter( "theme_mod_{$id_base}", $multidimensional_filter );
[371] Fix | Delete
}
[372] Fix | Delete
self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'][ $this->id ] = $this;
[373] Fix | Delete
}
[374] Fix | Delete
break;
[375] Fix | Delete
case 'option':
[376] Fix | Delete
if ( ! $is_multidimensional ) {
[377] Fix | Delete
add_filter( "pre_option_{$id_base}", array( $this, '_preview_filter' ) );
[378] Fix | Delete
} else {
[379] Fix | Delete
if ( empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] ) ) {
[380] Fix | Delete
// Only add these filters once for this ID base.
[381] Fix | Delete
add_filter( "option_{$id_base}", $multidimensional_filter );
[382] Fix | Delete
add_filter( "default_option_{$id_base}", $multidimensional_filter );
[383] Fix | Delete
}
[384] Fix | Delete
self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'][ $this->id ] = $this;
[385] Fix | Delete
}
[386] Fix | Delete
break;
[387] Fix | Delete
default:
[388] Fix | Delete
/**
[389] Fix | Delete
* Fires when the WP_Customize_Setting::preview() method is called for settings
[390] Fix | Delete
* not handled as theme_mods or options.
[391] Fix | Delete
*
[392] Fix | Delete
* The dynamic portion of the hook name, `$this->id`, refers to the setting ID.
[393] Fix | Delete
*
[394] Fix | Delete
* @since 3.4.0
[395] Fix | Delete
*
[396] Fix | Delete
* @param WP_Customize_Setting $setting WP_Customize_Setting instance.
[397] Fix | Delete
*/
[398] Fix | Delete
do_action( "customize_preview_{$this->id}", $this );
[399] Fix | Delete
[400] Fix | Delete
/**
[401] Fix | Delete
* Fires when the WP_Customize_Setting::preview() method is called for settings
[402] Fix | Delete
* not handled as theme_mods or options.
[403] Fix | Delete
*
[404] Fix | Delete
* The dynamic portion of the hook name, `$this->type`, refers to the setting type.
[405] Fix | Delete
*
[406] Fix | Delete
* @since 4.1.0
[407] Fix | Delete
*
[408] Fix | Delete
* @param WP_Customize_Setting $setting WP_Customize_Setting instance.
[409] Fix | Delete
*/
[410] Fix | Delete
do_action( "customize_preview_{$this->type}", $this );
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
$this->is_previewed = true;
[414] Fix | Delete
[415] Fix | Delete
return true;
[416] Fix | Delete
}
[417] Fix | Delete
[418] Fix | Delete
/**
[419] Fix | Delete
* Clear out the previewed-applied flag for a multidimensional-aggregated value whenever its post value is updated.
[420] Fix | Delete
*
[421] Fix | Delete
* This ensures that the new value will get sanitized and used the next time
[422] Fix | Delete
* that `WP_Customize_Setting::_multidimensional_preview_filter()`
[423] Fix | Delete
* is called for this setting.
[424] Fix | Delete
*
[425] Fix | Delete
* @since 4.4.0
[426] Fix | Delete
*
[427] Fix | Delete
* @see WP_Customize_Manager::set_post_value()
[428] Fix | Delete
* @see WP_Customize_Setting::_multidimensional_preview_filter()
[429] Fix | Delete
*/
[430] Fix | Delete
final public function _clear_aggregated_multidimensional_preview_applied_flag() {
[431] Fix | Delete
unset( self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['preview_applied_instances'][ $this->id ] );
[432] Fix | Delete
}
[433] Fix | Delete
[434] Fix | Delete
/**
[435] Fix | Delete
* Callback function to filter non-multidimensional theme mods and options.
[436] Fix | Delete
*
[437] Fix | Delete
* If switch_to_blog() was called after the preview() method, and the current
[438] Fix | Delete
* site is now not the same site, then this method does a no-op and returns
[439] Fix | Delete
* the original value.
[440] Fix | Delete
*
[441] Fix | Delete
* @since 3.4.0
[442] Fix | Delete
*
[443] Fix | Delete
* @param mixed $original Old value.
[444] Fix | Delete
* @return mixed New or old value.
[445] Fix | Delete
*/
[446] Fix | Delete
public function _preview_filter( $original ) {
[447] Fix | Delete
if ( ! $this->is_current_blog_previewed() ) {
[448] Fix | Delete
return $original;
[449] Fix | Delete
}
[450] Fix | Delete
[451] Fix | Delete
$undefined = new stdClass(); // Symbol hack.
[452] Fix | Delete
$post_value = $this->post_value( $undefined );
[453] Fix | Delete
if ( $undefined !== $post_value ) {
[454] Fix | Delete
$value = $post_value;
[455] Fix | Delete
} else {
[456] Fix | Delete
/*
[457] Fix | Delete
* Note that we don't use $original here because preview() will
[458] Fix | Delete
* not add the filter in the first place if it has an initial value
[459] Fix | Delete
* and there is no post value.
[460] Fix | Delete
*/
[461] Fix | Delete
$value = $this->default;
[462] Fix | Delete
}
[463] Fix | Delete
return $value;
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
/**
[467] Fix | Delete
* Callback function to filter multidimensional theme mods and options.
[468] Fix | Delete
*
[469] Fix | Delete
* For all multidimensional settings of a given type, the preview filter for
[470] Fix | Delete
* the first setting previewed will be used to apply the values for the others.
[471] Fix | Delete
*
[472] Fix | Delete
* @since 4.4.0
[473] Fix | Delete
*
[474] Fix | Delete
* @see WP_Customize_Setting::$aggregated_multidimensionals
[475] Fix | Delete
* @param mixed $original Original root value.
[476] Fix | Delete
* @return mixed New or old value.
[477] Fix | Delete
*/
[478] Fix | Delete
final public function _multidimensional_preview_filter( $original ) {
[479] Fix | Delete
if ( ! $this->is_current_blog_previewed() ) {
[480] Fix | Delete
return $original;
[481] Fix | Delete
}
[482] Fix | Delete
[483] Fix | Delete
$id_base = $this->id_data['base'];
[484] Fix | Delete
[485] Fix | Delete
// If no settings have been previewed yet (which should not be the case, since $this is), just pass through the original value.
[486] Fix | Delete
if ( empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] ) ) {
[487] Fix | Delete
return $original;
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
foreach ( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] as $previewed_setting ) {
[491] Fix | Delete
// Skip applying previewed value for any settings that have already been applied.
[492] Fix | Delete
if ( ! empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['preview_applied_instances'][ $previewed_setting->id ] ) ) {
[493] Fix | Delete
continue;
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
// Do the replacements of the posted/default sub value into the root value.
[497] Fix | Delete
$value = $previewed_setting->post_value( $previewed_setting->default );
[498] Fix | Delete
$root = self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value'];
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function