Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../clone/wp-inclu.../customiz...
File: class-wp-customize-selective-refresh.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Customize API: WP_Customize_Selective_Refresh 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.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 4.5.0
[12] Fix | Delete
*/
[13] Fix | Delete
#[AllowDynamicProperties]
[14] Fix | Delete
final class WP_Customize_Selective_Refresh {
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Query var used in requests to render partials.
[18] Fix | Delete
*
[19] Fix | Delete
* @since 4.5.0
[20] Fix | Delete
*/
[21] Fix | Delete
const RENDER_QUERY_VAR = 'wp_customize_render_partials';
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Customize manager.
[25] Fix | Delete
*
[26] Fix | Delete
* @since 4.5.0
[27] Fix | Delete
* @var WP_Customize_Manager
[28] Fix | Delete
*/
[29] Fix | Delete
public $manager;
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Registered instances of WP_Customize_Partial.
[33] Fix | Delete
*
[34] Fix | Delete
* @since 4.5.0
[35] Fix | Delete
* @var WP_Customize_Partial[]
[36] Fix | Delete
*/
[37] Fix | Delete
protected $partials = array();
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Log of errors triggered when partials are rendered.
[41] Fix | Delete
*
[42] Fix | Delete
* @since 4.5.0
[43] Fix | Delete
* @var array
[44] Fix | Delete
*/
[45] Fix | Delete
protected $triggered_errors = array();
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Keep track of the current partial being rendered.
[49] Fix | Delete
*
[50] Fix | Delete
* @since 4.5.0
[51] Fix | Delete
* @var string|null
[52] Fix | Delete
*/
[53] Fix | Delete
protected $current_partial_id;
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Plugin bootstrap for Partial Refresh functionality.
[57] Fix | Delete
*
[58] Fix | Delete
* @since 4.5.0
[59] Fix | Delete
*
[60] Fix | Delete
* @param WP_Customize_Manager $manager Customizer bootstrap instance.
[61] Fix | Delete
*/
[62] Fix | Delete
public function __construct( WP_Customize_Manager $manager ) {
[63] Fix | Delete
$this->manager = $manager;
[64] Fix | Delete
require_once ABSPATH . WPINC . '/customize/class-wp-customize-partial.php';
[65] Fix | Delete
[66] Fix | Delete
add_action( 'customize_preview_init', array( $this, 'init_preview' ) );
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Retrieves the registered partials.
[71] Fix | Delete
*
[72] Fix | Delete
* @since 4.5.0
[73] Fix | Delete
*
[74] Fix | Delete
* @return array Partials.
[75] Fix | Delete
*/
[76] Fix | Delete
public function partials() {
[77] Fix | Delete
return $this->partials;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Adds a partial.
[82] Fix | Delete
*
[83] Fix | Delete
* @since 4.5.0
[84] Fix | Delete
*
[85] Fix | Delete
* @see WP_Customize_Partial::__construct()
[86] Fix | Delete
*
[87] Fix | Delete
* @param WP_Customize_Partial|string $id Customize Partial object, or Partial ID.
[88] Fix | Delete
* @param array $args Optional. Array of properties for the new Partials object.
[89] Fix | Delete
* See WP_Customize_Partial::__construct() for information
[90] Fix | Delete
* on accepted arguments. Default empty array.
[91] Fix | Delete
* @return WP_Customize_Partial The instance of the partial that was added.
[92] Fix | Delete
*/
[93] Fix | Delete
public function add_partial( $id, $args = array() ) {
[94] Fix | Delete
if ( $id instanceof WP_Customize_Partial ) {
[95] Fix | Delete
$partial = $id;
[96] Fix | Delete
} else {
[97] Fix | Delete
$class = 'WP_Customize_Partial';
[98] Fix | Delete
[99] Fix | Delete
/** This filter is documented in wp-includes/customize/class-wp-customize-selective-refresh.php */
[100] Fix | Delete
$args = apply_filters( 'customize_dynamic_partial_args', $args, $id );
[101] Fix | Delete
[102] Fix | Delete
/** This filter is documented in wp-includes/customize/class-wp-customize-selective-refresh.php */
[103] Fix | Delete
$class = apply_filters( 'customize_dynamic_partial_class', $class, $id, $args );
[104] Fix | Delete
[105] Fix | Delete
$partial = new $class( $this, $id, $args );
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
$this->partials[ $partial->id ] = $partial;
[109] Fix | Delete
return $partial;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Retrieves a partial.
[114] Fix | Delete
*
[115] Fix | Delete
* @since 4.5.0
[116] Fix | Delete
*
[117] Fix | Delete
* @param string $id Customize Partial ID.
[118] Fix | Delete
* @return WP_Customize_Partial|null The partial, if set. Otherwise null.
[119] Fix | Delete
*/
[120] Fix | Delete
public function get_partial( $id ) {
[121] Fix | Delete
if ( isset( $this->partials[ $id ] ) ) {
[122] Fix | Delete
return $this->partials[ $id ];
[123] Fix | Delete
} else {
[124] Fix | Delete
return null;
[125] Fix | Delete
}
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Removes a partial.
[130] Fix | Delete
*
[131] Fix | Delete
* @since 4.5.0
[132] Fix | Delete
*
[133] Fix | Delete
* @param string $id Customize Partial ID.
[134] Fix | Delete
*/
[135] Fix | Delete
public function remove_partial( $id ) {
[136] Fix | Delete
unset( $this->partials[ $id ] );
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Initializes the Customizer preview.
[141] Fix | Delete
*
[142] Fix | Delete
* @since 4.5.0
[143] Fix | Delete
*/
[144] Fix | Delete
public function init_preview() {
[145] Fix | Delete
add_action( 'template_redirect', array( $this, 'handle_render_partials_request' ) );
[146] Fix | Delete
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) );
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Enqueues preview scripts.
[151] Fix | Delete
*
[152] Fix | Delete
* @since 4.5.0
[153] Fix | Delete
*/
[154] Fix | Delete
public function enqueue_preview_scripts() {
[155] Fix | Delete
wp_enqueue_script( 'customize-selective-refresh' );
[156] Fix | Delete
add_action( 'wp_footer', array( $this, 'export_preview_data' ), 1000 );
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* Exports data in preview after it has finished rendering so that partials can be added at runtime.
[161] Fix | Delete
*
[162] Fix | Delete
* @since 4.5.0
[163] Fix | Delete
*/
[164] Fix | Delete
public function export_preview_data() {
[165] Fix | Delete
$partials = array();
[166] Fix | Delete
[167] Fix | Delete
foreach ( $this->partials() as $partial ) {
[168] Fix | Delete
if ( $partial->check_capabilities() ) {
[169] Fix | Delete
$partials[ $partial->id ] = $partial->json();
[170] Fix | Delete
}
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
$switched_locale = switch_to_user_locale( get_current_user_id() );
[174] Fix | Delete
$l10n = array(
[175] Fix | Delete
'shiftClickToEdit' => __( 'Shift-click to edit this element.' ),
[176] Fix | Delete
'clickEditMenu' => __( 'Click to edit this menu.' ),
[177] Fix | Delete
'clickEditWidget' => __( 'Click to edit this widget.' ),
[178] Fix | Delete
'clickEditTitle' => __( 'Click to edit the site title.' ),
[179] Fix | Delete
'clickEditMisc' => __( 'Click to edit this element.' ),
[180] Fix | Delete
/* translators: %s: document.write() */
[181] Fix | Delete
'badDocumentWrite' => sprintf( __( '%s is forbidden' ), 'document.write()' ),
[182] Fix | Delete
);
[183] Fix | Delete
if ( $switched_locale ) {
[184] Fix | Delete
restore_previous_locale();
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
$exports = array(
[188] Fix | Delete
'partials' => $partials,
[189] Fix | Delete
'renderQueryVar' => self::RENDER_QUERY_VAR,
[190] Fix | Delete
'l10n' => $l10n,
[191] Fix | Delete
);
[192] Fix | Delete
[193] Fix | Delete
// Export data to JS.
[194] Fix | Delete
wp_print_inline_script_tag( sprintf( 'var _customizePartialRefreshExports = %s;', wp_json_encode( $exports ) ) );
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* Registers dynamically-created partials.
[199] Fix | Delete
*
[200] Fix | Delete
* @since 4.5.0
[201] Fix | Delete
*
[202] Fix | Delete
* @see WP_Customize_Manager::add_dynamic_settings()
[203] Fix | Delete
*
[204] Fix | Delete
* @param string[] $partial_ids Array of the partial IDs to add.
[205] Fix | Delete
* @return WP_Customize_Partial[] Array of added WP_Customize_Partial instances.
[206] Fix | Delete
*/
[207] Fix | Delete
public function add_dynamic_partials( $partial_ids ) {
[208] Fix | Delete
$new_partials = array();
[209] Fix | Delete
[210] Fix | Delete
foreach ( $partial_ids as $partial_id ) {
[211] Fix | Delete
[212] Fix | Delete
// Skip partials already created.
[213] Fix | Delete
$partial = $this->get_partial( $partial_id );
[214] Fix | Delete
if ( $partial ) {
[215] Fix | Delete
continue;
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
$partial_args = false;
[219] Fix | Delete
$partial_class = 'WP_Customize_Partial';
[220] Fix | Delete
[221] Fix | Delete
/**
[222] Fix | Delete
* Filters a dynamic partial's constructor arguments.
[223] Fix | Delete
*
[224] Fix | Delete
* For a dynamic partial to be registered, this filter must be employed
[225] Fix | Delete
* to override the default false value with an array of args to pass to
[226] Fix | Delete
* the WP_Customize_Partial constructor.
[227] Fix | Delete
*
[228] Fix | Delete
* @since 4.5.0
[229] Fix | Delete
*
[230] Fix | Delete
* @param false|array $partial_args The arguments to the WP_Customize_Partial constructor.
[231] Fix | Delete
* @param string $partial_id ID for dynamic partial.
[232] Fix | Delete
*/
[233] Fix | Delete
$partial_args = apply_filters( 'customize_dynamic_partial_args', $partial_args, $partial_id );
[234] Fix | Delete
if ( false === $partial_args ) {
[235] Fix | Delete
continue;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* Filters the class used to construct partials.
[240] Fix | Delete
*
[241] Fix | Delete
* Allow non-statically created partials to be constructed with custom WP_Customize_Partial subclass.
[242] Fix | Delete
*
[243] Fix | Delete
* @since 4.5.0
[244] Fix | Delete
*
[245] Fix | Delete
* @param string $partial_class WP_Customize_Partial or a subclass.
[246] Fix | Delete
* @param string $partial_id ID for dynamic partial.
[247] Fix | Delete
* @param array $partial_args The arguments to the WP_Customize_Partial constructor.
[248] Fix | Delete
*/
[249] Fix | Delete
$partial_class = apply_filters( 'customize_dynamic_partial_class', $partial_class, $partial_id, $partial_args );
[250] Fix | Delete
[251] Fix | Delete
$partial = new $partial_class( $this, $partial_id, $partial_args );
[252] Fix | Delete
[253] Fix | Delete
$this->add_partial( $partial );
[254] Fix | Delete
$new_partials[] = $partial;
[255] Fix | Delete
}
[256] Fix | Delete
return $new_partials;
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
/**
[260] Fix | Delete
* Checks whether the request is for rendering partials.
[261] Fix | Delete
*
[262] Fix | Delete
* Note that this will not consider whether the request is authorized or valid,
[263] Fix | Delete
* just that essentially the route is a match.
[264] Fix | Delete
*
[265] Fix | Delete
* @since 4.5.0
[266] Fix | Delete
*
[267] Fix | Delete
* @return bool Whether the request is for rendering partials.
[268] Fix | Delete
*/
[269] Fix | Delete
public function is_render_partials_request() {
[270] Fix | Delete
return ! empty( $_POST[ self::RENDER_QUERY_VAR ] );
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
* Handles PHP errors triggered during rendering the partials.
[275] Fix | Delete
*
[276] Fix | Delete
* These errors will be relayed back to the client in the Ajax response.
[277] Fix | Delete
*
[278] Fix | Delete
* @since 4.5.0
[279] Fix | Delete
*
[280] Fix | Delete
* @param int $errno Error number.
[281] Fix | Delete
* @param string $errstr Error string.
[282] Fix | Delete
* @param string $errfile Error file.
[283] Fix | Delete
* @param int $errline Error line.
[284] Fix | Delete
* @return true Always true.
[285] Fix | Delete
*/
[286] Fix | Delete
public function handle_error( $errno, $errstr, $errfile = null, $errline = null ) {
[287] Fix | Delete
$this->triggered_errors[] = array(
[288] Fix | Delete
'partial' => $this->current_partial_id,
[289] Fix | Delete
'error_number' => $errno,
[290] Fix | Delete
'error_string' => $errstr,
[291] Fix | Delete
'error_file' => $errfile,
[292] Fix | Delete
'error_line' => $errline,
[293] Fix | Delete
);
[294] Fix | Delete
return true;
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
/**
[298] Fix | Delete
* Handles the Ajax request to return the rendered partials for the requested placements.
[299] Fix | Delete
*
[300] Fix | Delete
* @since 4.5.0
[301] Fix | Delete
*/
[302] Fix | Delete
public function handle_render_partials_request() {
[303] Fix | Delete
if ( ! $this->is_render_partials_request() ) {
[304] Fix | Delete
return;
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
/*
[308] Fix | Delete
* Note that is_customize_preview() returning true will entail that the
[309] Fix | Delete
* user passed the 'customize' capability check and the nonce check, since
[310] Fix | Delete
* WP_Customize_Manager::setup_theme() is where the previewing flag is set.
[311] Fix | Delete
*/
[312] Fix | Delete
if ( ! is_customize_preview() ) {
[313] Fix | Delete
wp_send_json_error( 'expected_customize_preview', 403 );
[314] Fix | Delete
} elseif ( ! isset( $_POST['partials'] ) ) {
[315] Fix | Delete
wp_send_json_error( 'missing_partials', 400 );
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
// Ensure that doing selective refresh on 404 template doesn't result in fallback rendering behavior (full refreshes).
[319] Fix | Delete
status_header( 200 );
[320] Fix | Delete
[321] Fix | Delete
$partials = json_decode( wp_unslash( $_POST['partials'] ), true );
[322] Fix | Delete
[323] Fix | Delete
if ( ! is_array( $partials ) ) {
[324] Fix | Delete
wp_send_json_error( 'malformed_partials' );
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
$this->add_dynamic_partials( array_keys( $partials ) );
[328] Fix | Delete
[329] Fix | Delete
/**
[330] Fix | Delete
* Fires immediately before partials are rendered.
[331] Fix | Delete
*
[332] Fix | Delete
* Plugins may do things like call wp_enqueue_scripts() and gather a list of the scripts
[333] Fix | Delete
* and styles which may get enqueued in the response.
[334] Fix | Delete
*
[335] Fix | Delete
* @since 4.5.0
[336] Fix | Delete
*
[337] Fix | Delete
* @param WP_Customize_Selective_Refresh $refresh Selective refresh component.
[338] Fix | Delete
* @param array $partials Placements' context data for the partials rendered in the request.
[339] Fix | Delete
* The array is keyed by partial ID, with each item being an array of
[340] Fix | Delete
* the placements' context data.
[341] Fix | Delete
*/
[342] Fix | Delete
do_action( 'customize_render_partials_before', $this, $partials );
[343] Fix | Delete
[344] Fix | Delete
set_error_handler( array( $this, 'handle_error' ), error_reporting() );
[345] Fix | Delete
[346] Fix | Delete
$contents = array();
[347] Fix | Delete
[348] Fix | Delete
foreach ( $partials as $partial_id => $container_contexts ) {
[349] Fix | Delete
$this->current_partial_id = $partial_id;
[350] Fix | Delete
[351] Fix | Delete
if ( ! is_array( $container_contexts ) ) {
[352] Fix | Delete
wp_send_json_error( 'malformed_container_contexts' );
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
$partial = $this->get_partial( $partial_id );
[356] Fix | Delete
[357] Fix | Delete
if ( ! $partial || ! $partial->check_capabilities() ) {
[358] Fix | Delete
$contents[ $partial_id ] = null;
[359] Fix | Delete
continue;
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
$contents[ $partial_id ] = array();
[363] Fix | Delete
[364] Fix | Delete
// @todo The array should include not only the contents, but also whether the container is included?
[365] Fix | Delete
if ( empty( $container_contexts ) ) {
[366] Fix | Delete
// Since there are no container contexts, render just once.
[367] Fix | Delete
$contents[ $partial_id ][] = $partial->render( null );
[368] Fix | Delete
} else {
[369] Fix | Delete
foreach ( $container_contexts as $container_context ) {
[370] Fix | Delete
$contents[ $partial_id ][] = $partial->render( $container_context );
[371] Fix | Delete
}
[372] Fix | Delete
}
[373] Fix | Delete
}
[374] Fix | Delete
$this->current_partial_id = null;
[375] Fix | Delete
[376] Fix | Delete
restore_error_handler();
[377] Fix | Delete
[378] Fix | Delete
/**
[379] Fix | Delete
* Fires immediately after partials are rendered.
[380] Fix | Delete
*
[381] Fix | Delete
* Plugins may do things like call wp_footer() to scrape scripts output and return them
[382] Fix | Delete
* via the {@see 'customize_render_partials_response'} filter.
[383] Fix | Delete
*
[384] Fix | Delete
* @since 4.5.0
[385] Fix | Delete
*
[386] Fix | Delete
* @param WP_Customize_Selective_Refresh $refresh Selective refresh component.
[387] Fix | Delete
* @param array $partials Placements' context data for the partials rendered in the request.
[388] Fix | Delete
* The array is keyed by partial ID, with each item being an array of
[389] Fix | Delete
* the placements' context data.
[390] Fix | Delete
*/
[391] Fix | Delete
do_action( 'customize_render_partials_after', $this, $partials );
[392] Fix | Delete
[393] Fix | Delete
$response = array(
[394] Fix | Delete
'contents' => $contents,
[395] Fix | Delete
);
[396] Fix | Delete
[397] Fix | Delete
if ( defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY ) {
[398] Fix | Delete
$response['errors'] = $this->triggered_errors;
[399] Fix | Delete
}
[400] Fix | Delete
[401] Fix | Delete
$setting_validities = $this->manager->validate_setting_values( $this->manager->unsanitized_post_values() );
[402] Fix | Delete
$exported_setting_validities = array_map( array( $this->manager, 'prepare_setting_validity_for_js' ), $setting_validities );
[403] Fix | Delete
$response['setting_validities'] = $exported_setting_validities;
[404] Fix | Delete
[405] Fix | Delete
/**
[406] Fix | Delete
* Filters the response from rendering the partials.
[407] Fix | Delete
*
[408] Fix | Delete
* Plugins may use this filter to inject `$scripts` and `$styles`, which are dependencies
[409] Fix | Delete
* for the partials being rendered. The response data will be available to the client via
[410] Fix | Delete
* the `render-partials-response` JS event, so the client can then inject the scripts and
[411] Fix | Delete
* styles into the DOM if they have not already been enqueued there.
[412] Fix | Delete
*
[413] Fix | Delete
* If plugins do this, they'll need to take care for any scripts that do `document.write()`
[414] Fix | Delete
* and make sure that these are not injected, or else to override the function to no-op,
[415] Fix | Delete
* or else the page will be destroyed.
[416] Fix | Delete
*
[417] Fix | Delete
* Plugins should be aware that `$scripts` and `$styles` may eventually be included by
[418] Fix | Delete
* default in the response.
[419] Fix | Delete
*
[420] Fix | Delete
* @since 4.5.0
[421] Fix | Delete
*
[422] Fix | Delete
* @param array $response {
[423] Fix | Delete
* Response.
[424] Fix | Delete
*
[425] Fix | Delete
* @type array $contents Associative array mapping a partial ID its corresponding array of contents
[426] Fix | Delete
* for the containers requested.
[427] Fix | Delete
* @type array $errors List of errors triggered during rendering of partials, if `WP_DEBUG_DISPLAY`
[428] Fix | Delete
* is enabled.
[429] Fix | Delete
* }
[430] Fix | Delete
* @param WP_Customize_Selective_Refresh $refresh Selective refresh component.
[431] Fix | Delete
* @param array $partials Placements' context data for the partials rendered in the request.
[432] Fix | Delete
* The array is keyed by partial ID, with each item being an array of
[433] Fix | Delete
* the placements' context data.
[434] Fix | Delete
*/
[435] Fix | Delete
$response = apply_filters( 'customize_render_partials_response', $response, $this, $partials );
[436] Fix | Delete
[437] Fix | Delete
wp_send_json_success( $response );
[438] Fix | Delete
}
[439] Fix | Delete
}
[440] Fix | Delete
[441] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function