Edit File by line
/home/zeestwma/ceyloniy.../wp-inclu...
File: class-wp-customize-manager.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Customize Manager 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 Manager class.
[10] Fix | Delete
*
[11] Fix | Delete
* Bootstraps the Customize experience on the server-side.
[12] Fix | Delete
*
[13] Fix | Delete
* Sets up the theme-switching process if a theme other than the active one is
[14] Fix | Delete
* being previewed and customized.
[15] Fix | Delete
*
[16] Fix | Delete
* Serves as a factory for Customize Controls and Settings, and
[17] Fix | Delete
* instantiates default Customize Controls and Settings.
[18] Fix | Delete
*
[19] Fix | Delete
* @since 3.4.0
[20] Fix | Delete
*/
[21] Fix | Delete
#[AllowDynamicProperties]
[22] Fix | Delete
final class WP_Customize_Manager {
[23] Fix | Delete
/**
[24] Fix | Delete
* An instance of the theme being previewed.
[25] Fix | Delete
*
[26] Fix | Delete
* @since 3.4.0
[27] Fix | Delete
* @var WP_Theme
[28] Fix | Delete
*/
[29] Fix | Delete
protected $theme;
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* The directory name of the previously active theme (within the theme_root).
[33] Fix | Delete
*
[34] Fix | Delete
* @since 3.4.0
[35] Fix | Delete
* @var string
[36] Fix | Delete
*/
[37] Fix | Delete
protected $original_stylesheet;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Whether this is a Customizer pageload.
[41] Fix | Delete
*
[42] Fix | Delete
* @since 3.4.0
[43] Fix | Delete
* @var bool
[44] Fix | Delete
*/
[45] Fix | Delete
protected $previewing = false;
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Methods and properties dealing with managing widgets in the Customizer.
[49] Fix | Delete
*
[50] Fix | Delete
* @since 3.9.0
[51] Fix | Delete
* @var WP_Customize_Widgets
[52] Fix | Delete
*/
[53] Fix | Delete
public $widgets;
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Methods and properties dealing with managing nav menus in the Customizer.
[57] Fix | Delete
*
[58] Fix | Delete
* @since 4.3.0
[59] Fix | Delete
* @var WP_Customize_Nav_Menus
[60] Fix | Delete
*/
[61] Fix | Delete
public $nav_menus;
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Methods and properties dealing with selective refresh in the Customizer preview.
[65] Fix | Delete
*
[66] Fix | Delete
* @since 4.5.0
[67] Fix | Delete
* @var WP_Customize_Selective_Refresh
[68] Fix | Delete
*/
[69] Fix | Delete
public $selective_refresh;
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* Registered instances of WP_Customize_Setting.
[73] Fix | Delete
*
[74] Fix | Delete
* @since 3.4.0
[75] Fix | Delete
* @var array
[76] Fix | Delete
*/
[77] Fix | Delete
protected $settings = array();
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Sorted top-level instances of WP_Customize_Panel and WP_Customize_Section.
[81] Fix | Delete
*
[82] Fix | Delete
* @since 4.0.0
[83] Fix | Delete
* @var array
[84] Fix | Delete
*/
[85] Fix | Delete
protected $containers = array();
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Registered instances of WP_Customize_Panel.
[89] Fix | Delete
*
[90] Fix | Delete
* @since 4.0.0
[91] Fix | Delete
* @var array
[92] Fix | Delete
*/
[93] Fix | Delete
protected $panels = array();
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* List of core components.
[97] Fix | Delete
*
[98] Fix | Delete
* @since 4.5.0
[99] Fix | Delete
* @var array
[100] Fix | Delete
*/
[101] Fix | Delete
protected $components = array( 'nav_menus' );
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Registered instances of WP_Customize_Section.
[105] Fix | Delete
*
[106] Fix | Delete
* @since 3.4.0
[107] Fix | Delete
* @var array
[108] Fix | Delete
*/
[109] Fix | Delete
protected $sections = array();
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Registered instances of WP_Customize_Control.
[113] Fix | Delete
*
[114] Fix | Delete
* @since 3.4.0
[115] Fix | Delete
* @var array
[116] Fix | Delete
*/
[117] Fix | Delete
protected $controls = array();
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Panel types that may be rendered from JS templates.
[121] Fix | Delete
*
[122] Fix | Delete
* @since 4.3.0
[123] Fix | Delete
* @var array
[124] Fix | Delete
*/
[125] Fix | Delete
protected $registered_panel_types = array();
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Section types that may be rendered from JS templates.
[129] Fix | Delete
*
[130] Fix | Delete
* @since 4.3.0
[131] Fix | Delete
* @var array
[132] Fix | Delete
*/
[133] Fix | Delete
protected $registered_section_types = array();
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* Control types that may be rendered from JS templates.
[137] Fix | Delete
*
[138] Fix | Delete
* @since 4.1.0
[139] Fix | Delete
* @var array
[140] Fix | Delete
*/
[141] Fix | Delete
protected $registered_control_types = array();
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* Initial URL being previewed.
[145] Fix | Delete
*
[146] Fix | Delete
* @since 4.4.0
[147] Fix | Delete
* @var string
[148] Fix | Delete
*/
[149] Fix | Delete
protected $preview_url;
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* URL to link the user to when closing the Customizer.
[153] Fix | Delete
*
[154] Fix | Delete
* @since 4.4.0
[155] Fix | Delete
* @var string
[156] Fix | Delete
*/
[157] Fix | Delete
protected $return_url;
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* Mapping of 'panel', 'section', 'control' to the ID which should be autofocused.
[161] Fix | Delete
*
[162] Fix | Delete
* @since 4.4.0
[163] Fix | Delete
* @var string[]
[164] Fix | Delete
*/
[165] Fix | Delete
protected $autofocus = array();
[166] Fix | Delete
[167] Fix | Delete
/**
[168] Fix | Delete
* Messenger channel.
[169] Fix | Delete
*
[170] Fix | Delete
* @since 4.7.0
[171] Fix | Delete
* @var string
[172] Fix | Delete
*/
[173] Fix | Delete
protected $messenger_channel;
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* Whether the autosave revision of the changeset should be loaded.
[177] Fix | Delete
*
[178] Fix | Delete
* @since 4.9.0
[179] Fix | Delete
* @var bool
[180] Fix | Delete
*/
[181] Fix | Delete
protected $autosaved = false;
[182] Fix | Delete
[183] Fix | Delete
/**
[184] Fix | Delete
* Whether the changeset branching is allowed.
[185] Fix | Delete
*
[186] Fix | Delete
* @since 4.9.0
[187] Fix | Delete
* @var bool
[188] Fix | Delete
*/
[189] Fix | Delete
protected $branching = true;
[190] Fix | Delete
[191] Fix | Delete
/**
[192] Fix | Delete
* Whether settings should be previewed.
[193] Fix | Delete
*
[194] Fix | Delete
* @since 4.9.0
[195] Fix | Delete
* @var bool
[196] Fix | Delete
*/
[197] Fix | Delete
protected $settings_previewed = true;
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Whether a starter content changeset was saved.
[201] Fix | Delete
*
[202] Fix | Delete
* @since 4.9.0
[203] Fix | Delete
* @var bool
[204] Fix | Delete
*/
[205] Fix | Delete
protected $saved_starter_content_changeset = false;
[206] Fix | Delete
[207] Fix | Delete
/**
[208] Fix | Delete
* Unsanitized values for Customize Settings parsed from $_POST['customized'].
[209] Fix | Delete
*
[210] Fix | Delete
* @var array
[211] Fix | Delete
*/
[212] Fix | Delete
private $_post_values;
[213] Fix | Delete
[214] Fix | Delete
/**
[215] Fix | Delete
* Changeset UUID.
[216] Fix | Delete
*
[217] Fix | Delete
* @since 4.7.0
[218] Fix | Delete
* @var string
[219] Fix | Delete
*/
[220] Fix | Delete
private $_changeset_uuid;
[221] Fix | Delete
[222] Fix | Delete
/**
[223] Fix | Delete
* Changeset post ID.
[224] Fix | Delete
*
[225] Fix | Delete
* @since 4.7.0
[226] Fix | Delete
* @var int|false
[227] Fix | Delete
*/
[228] Fix | Delete
private $_changeset_post_id;
[229] Fix | Delete
[230] Fix | Delete
/**
[231] Fix | Delete
* Changeset data loaded from a customize_changeset post.
[232] Fix | Delete
*
[233] Fix | Delete
* @since 4.7.0
[234] Fix | Delete
* @var array|null
[235] Fix | Delete
*/
[236] Fix | Delete
private $_changeset_data;
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* Constructor.
[240] Fix | Delete
*
[241] Fix | Delete
* @since 3.4.0
[242] Fix | Delete
* @since 4.7.0 Added `$args` parameter.
[243] Fix | Delete
*
[244] Fix | Delete
* @param array $args {
[245] Fix | Delete
* Args.
[246] Fix | Delete
*
[247] Fix | Delete
* @type null|string|false $changeset_uuid Changeset UUID, the `post_name` for the customize_changeset post containing the customized state.
[248] Fix | Delete
* Defaults to `null` resulting in a UUID to be immediately generated. If `false` is provided, then
[249] Fix | Delete
* then the changeset UUID will be determined during `after_setup_theme`: when the
[250] Fix | Delete
* `customize_changeset_branching` filter returns false, then the default UUID will be that
[251] Fix | Delete
* of the most recent `customize_changeset` post that has a status other than 'auto-draft',
[252] Fix | Delete
* 'publish', or 'trash'. Otherwise, if changeset branching is enabled, then a random UUID will be used.
[253] Fix | Delete
* @type string $theme Theme to be previewed (for theme switch). Defaults to customize_theme or theme query params.
[254] Fix | Delete
* @type string $messenger_channel Messenger channel. Defaults to customize_messenger_channel query param.
[255] Fix | Delete
* @type bool $settings_previewed If settings should be previewed. Defaults to true.
[256] Fix | Delete
* @type bool $branching If changeset branching is allowed; otherwise, changesets are linear. Defaults to true.
[257] Fix | Delete
* @type bool $autosaved If data from a changeset's autosaved revision should be loaded if it exists. Defaults to false.
[258] Fix | Delete
* }
[259] Fix | Delete
*/
[260] Fix | Delete
public function __construct( $args = array() ) {
[261] Fix | Delete
[262] Fix | Delete
$args = array_merge(
[263] Fix | Delete
array_fill_keys( array( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed', 'autosaved', 'branching' ), null ),
[264] Fix | Delete
$args
[265] Fix | Delete
);
[266] Fix | Delete
[267] Fix | Delete
// Note that the UUID format will be validated in the setup_theme() method.
[268] Fix | Delete
if ( ! isset( $args['changeset_uuid'] ) ) {
[269] Fix | Delete
$args['changeset_uuid'] = wp_generate_uuid4();
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
/*
[273] Fix | Delete
* The theme and messenger_channel should be supplied via $args,
[274] Fix | Delete
* but they are also looked at in the $_REQUEST global here for back-compat.
[275] Fix | Delete
*/
[276] Fix | Delete
if ( ! isset( $args['theme'] ) ) {
[277] Fix | Delete
if ( isset( $_REQUEST['customize_theme'] ) ) {
[278] Fix | Delete
$args['theme'] = wp_unslash( $_REQUEST['customize_theme'] );
[279] Fix | Delete
} elseif ( isset( $_REQUEST['theme'] ) ) { // Deprecated.
[280] Fix | Delete
$args['theme'] = wp_unslash( $_REQUEST['theme'] );
[281] Fix | Delete
}
[282] Fix | Delete
}
[283] Fix | Delete
if ( ! isset( $args['messenger_channel'] ) && isset( $_REQUEST['customize_messenger_channel'] ) ) {
[284] Fix | Delete
$args['messenger_channel'] = sanitize_key( wp_unslash( $_REQUEST['customize_messenger_channel'] ) );
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
// Do not load 'widgets' component if a block theme is activated.
[288] Fix | Delete
if ( ! wp_is_block_theme() ) {
[289] Fix | Delete
$this->components[] = 'widgets';
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
$this->original_stylesheet = get_stylesheet();
[293] Fix | Delete
$this->theme = wp_get_theme( 0 === validate_file( $args['theme'] ) ? $args['theme'] : null );
[294] Fix | Delete
$this->messenger_channel = $args['messenger_channel'];
[295] Fix | Delete
$this->_changeset_uuid = $args['changeset_uuid'];
[296] Fix | Delete
[297] Fix | Delete
foreach ( array( 'settings_previewed', 'autosaved', 'branching' ) as $key ) {
[298] Fix | Delete
if ( isset( $args[ $key ] ) ) {
[299] Fix | Delete
$this->$key = (bool) $args[ $key ];
[300] Fix | Delete
}
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
require_once ABSPATH . WPINC . '/class-wp-customize-setting.php';
[304] Fix | Delete
require_once ABSPATH . WPINC . '/class-wp-customize-panel.php';
[305] Fix | Delete
require_once ABSPATH . WPINC . '/class-wp-customize-section.php';
[306] Fix | Delete
require_once ABSPATH . WPINC . '/class-wp-customize-control.php';
[307] Fix | Delete
[308] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-color-control.php';
[309] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-media-control.php';
[310] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-upload-control.php';
[311] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-image-control.php';
[312] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-background-image-control.php';
[313] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-background-position-control.php';
[314] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-cropped-image-control.php';
[315] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-site-icon-control.php';
[316] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-header-image-control.php';
[317] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-theme-control.php';
[318] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-code-editor-control.php';
[319] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-widget-area-customize-control.php';
[320] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-widget-form-customize-control.php';
[321] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-control.php';
[322] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-control.php';
[323] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-location-control.php';
[324] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-name-control.php';
[325] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-locations-control.php';
[326] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-auto-add-control.php';
[327] Fix | Delete
[328] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menus-panel.php';
[329] Fix | Delete
[330] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-themes-panel.php';
[331] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-themes-section.php';
[332] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-sidebar-section.php';
[333] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-section.php';
[334] Fix | Delete
[335] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-custom-css-setting.php';
[336] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-filter-setting.php';
[337] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-header-image-setting.php';
[338] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-background-image-setting.php';
[339] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-setting.php';
[340] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-setting.php';
[341] Fix | Delete
[342] Fix | Delete
/**
[343] Fix | Delete
* Filters the core Customizer components to load.
[344] Fix | Delete
*
[345] Fix | Delete
* This allows Core components to be excluded from being instantiated by
[346] Fix | Delete
* filtering them out of the array. Note that this filter generally runs
[347] Fix | Delete
* during the {@see 'plugins_loaded'} action, so it cannot be added
[348] Fix | Delete
* in a theme.
[349] Fix | Delete
*
[350] Fix | Delete
* @since 4.4.0
[351] Fix | Delete
*
[352] Fix | Delete
* @see WP_Customize_Manager::__construct()
[353] Fix | Delete
*
[354] Fix | Delete
* @param string[] $components Array of core components to load.
[355] Fix | Delete
* @param WP_Customize_Manager $manager WP_Customize_Manager instance.
[356] Fix | Delete
*/
[357] Fix | Delete
$components = apply_filters( 'customize_loaded_components', $this->components, $this );
[358] Fix | Delete
[359] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-selective-refresh.php';
[360] Fix | Delete
$this->selective_refresh = new WP_Customize_Selective_Refresh( $this );
[361] Fix | Delete
[362] Fix | Delete
if ( in_array( 'widgets', $components, true ) ) {
[363] Fix | Delete
require_once ABSPATH . WPINC . '/class-wp-customize-widgets.php';
[364] Fix | Delete
$this->widgets = new WP_Customize_Widgets( $this );
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
if ( in_array( 'nav_menus', $components, true ) ) {
[368] Fix | Delete
require_once ABSPATH . WPINC . '/class-wp-customize-nav-menus.php';
[369] Fix | Delete
$this->nav_menus = new WP_Customize_Nav_Menus( $this );
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
add_action( 'setup_theme', array( $this, 'setup_theme' ) );
[373] Fix | Delete
add_action( 'wp_loaded', array( $this, 'wp_loaded' ) );
[374] Fix | Delete
[375] Fix | Delete
// Do not spawn cron (especially the alternate cron) while running the Customizer.
[376] Fix | Delete
remove_action( 'init', 'wp_cron' );
[377] Fix | Delete
[378] Fix | Delete
// Do not run update checks when rendering the controls.
[379] Fix | Delete
remove_action( 'admin_init', '_maybe_update_core' );
[380] Fix | Delete
remove_action( 'admin_init', '_maybe_update_plugins' );
[381] Fix | Delete
remove_action( 'admin_init', '_maybe_update_themes' );
[382] Fix | Delete
[383] Fix | Delete
add_action( 'wp_ajax_customize_save', array( $this, 'save' ) );
[384] Fix | Delete
add_action( 'wp_ajax_customize_trash', array( $this, 'handle_changeset_trash_request' ) );
[385] Fix | Delete
add_action( 'wp_ajax_customize_refresh_nonces', array( $this, 'refresh_nonces' ) );
[386] Fix | Delete
add_action( 'wp_ajax_customize_load_themes', array( $this, 'handle_load_themes_request' ) );
[387] Fix | Delete
add_filter( 'heartbeat_settings', array( $this, 'add_customize_screen_to_heartbeat_settings' ) );
[388] Fix | Delete
add_filter( 'heartbeat_received', array( $this, 'check_changeset_lock_with_heartbeat' ), 10, 3 );
[389] Fix | Delete
add_action( 'wp_ajax_customize_override_changeset_lock', array( $this, 'handle_override_changeset_lock_request' ) );
[390] Fix | Delete
add_action( 'wp_ajax_customize_dismiss_autosave_or_lock', array( $this, 'handle_dismiss_autosave_or_lock_request' ) );
[391] Fix | Delete
[392] Fix | Delete
add_action( 'customize_register', array( $this, 'register_controls' ) );
[393] Fix | Delete
add_action( 'customize_register', array( $this, 'register_dynamic_settings' ), 11 ); // Allow code to create settings first.
[394] Fix | Delete
add_action( 'customize_controls_init', array( $this, 'prepare_controls' ) );
[395] Fix | Delete
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ) );
[396] Fix | Delete
[397] Fix | Delete
// Render Common, Panel, Section, and Control templates.
[398] Fix | Delete
add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_panel_templates' ), 1 );
[399] Fix | Delete
add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_section_templates' ), 1 );
[400] Fix | Delete
add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_control_templates' ), 1 );
[401] Fix | Delete
[402] Fix | Delete
// Export header video settings with the partial response.
[403] Fix | Delete
add_filter( 'customize_render_partials_response', array( $this, 'export_header_video_settings' ), 10, 3 );
[404] Fix | Delete
[405] Fix | Delete
// Export the settings to JS via the _wpCustomizeSettings variable.
[406] Fix | Delete
add_action( 'customize_controls_print_footer_scripts', array( $this, 'customize_pane_settings' ), 1000 );
[407] Fix | Delete
[408] Fix | Delete
// Add theme update notices.
[409] Fix | Delete
if ( current_user_can( 'install_themes' ) || current_user_can( 'update_themes' ) ) {
[410] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/update.php';
[411] Fix | Delete
add_action( 'customize_controls_print_footer_scripts', 'wp_print_admin_notice_templates' );
[412] Fix | Delete
}
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
/**
[416] Fix | Delete
* Returns true if it's an Ajax request.
[417] Fix | Delete
*
[418] Fix | Delete
* @since 3.4.0
[419] Fix | Delete
* @since 4.2.0 Added `$action` param.
[420] Fix | Delete
*
[421] Fix | Delete
* @param string|null $action Whether the supplied Ajax action is being run.
[422] Fix | Delete
* @return bool True if it's an Ajax request, false otherwise.
[423] Fix | Delete
*/
[424] Fix | Delete
public function doing_ajax( $action = null ) {
[425] Fix | Delete
if ( ! wp_doing_ajax() ) {
[426] Fix | Delete
return false;
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
if ( ! $action ) {
[430] Fix | Delete
return true;
[431] Fix | Delete
} else {
[432] Fix | Delete
/*
[433] Fix | Delete
* Note: we can't just use doing_action( "wp_ajax_{$action}" ) because we need
[434] Fix | Delete
* to check before admin-ajax.php gets to that point.
[435] Fix | Delete
*/
[436] Fix | Delete
return isset( $_REQUEST['action'] ) && wp_unslash( $_REQUEST['action'] ) === $action;
[437] Fix | Delete
}
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
/**
[441] Fix | Delete
* Custom wp_die wrapper. Returns either the standard message for UI
[442] Fix | Delete
* or the Ajax message.
[443] Fix | Delete
*
[444] Fix | Delete
* @since 3.4.0
[445] Fix | Delete
*
[446] Fix | Delete
* @param string|WP_Error $ajax_message Ajax return.
[447] Fix | Delete
* @param string $message Optional. UI message.
[448] Fix | Delete
*/
[449] Fix | Delete
protected function wp_die( $ajax_message, $message = null ) {
[450] Fix | Delete
if ( $this->doing_ajax() ) {
[451] Fix | Delete
wp_die( $ajax_message );
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
if ( ! $message ) {
[455] Fix | Delete
$message = __( 'An error occurred while customizing. Please refresh the page and try again.' );
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
if ( $this->messenger_channel ) {
[459] Fix | Delete
ob_start();
[460] Fix | Delete
wp_enqueue_scripts();
[461] Fix | Delete
wp_print_scripts( array( 'customize-base' ) );
[462] Fix | Delete
[463] Fix | Delete
$settings = array(
[464] Fix | Delete
'messengerArgs' => array(
[465] Fix | Delete
'channel' => $this->messenger_channel,
[466] Fix | Delete
'url' => wp_customize_url(),
[467] Fix | Delete
),
[468] Fix | Delete
'error' => $ajax_message,
[469] Fix | Delete
);
[470] Fix | Delete
$message .= ob_get_clean();
[471] Fix | Delete
ob_start();
[472] Fix | Delete
?>
[473] Fix | Delete
<script>
[474] Fix | Delete
( function( api, settings ) {
[475] Fix | Delete
var preview = new api.Messenger( settings.messengerArgs );
[476] Fix | Delete
preview.send( 'iframe-loading-error', settings.error );
[477] Fix | Delete
} )( wp.customize, <?php echo wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?> );
[478] Fix | Delete
</script>
[479] Fix | Delete
<?php
[480] Fix | Delete
$message .= wp_get_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) );
[481] Fix | Delete
}
[482] Fix | Delete
[483] Fix | Delete
wp_die( $message );
[484] Fix | Delete
}
[485] Fix | Delete
[486] Fix | Delete
/**
[487] Fix | Delete
* Returns the Ajax wp_die() handler if it's a customized request.
[488] Fix | Delete
*
[489] Fix | Delete
* @since 3.4.0
[490] Fix | Delete
* @deprecated 4.7.0
[491] Fix | Delete
*
[492] Fix | Delete
* @return callable Die handler.
[493] Fix | Delete
*/
[494] Fix | Delete
public function wp_die_handler() {
[495] Fix | Delete
_deprecated_function( __METHOD__, '4.7.0' );
[496] Fix | Delete
[497] Fix | Delete
if ( $this->doing_ajax() || isset( $_POST['customized'] ) ) {
[498] Fix | Delete
return '_ajax_wp_die_handler';
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function