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.../httpdocs/clone/wp-inclu.../customiz...
File: class-wp-customize-custom-css-setting.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Customize API: WP_Customize_Custom_CSS_Setting class
[2] Fix | Delete
*
[3] Fix | Delete
* This handles validation, sanitization and saving of the value.
[4] Fix | Delete
*
[5] Fix | Delete
* @package WordPress
[6] Fix | Delete
* @subpackage Customize
[7] Fix | Delete
* @since 4.7.0
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Custom Setting to handle WP Custom CSS.
[12] Fix | Delete
*
[13] Fix | Delete
* @since 4.7.0
[14] Fix | Delete
*
[15] Fix | Delete
* @see WP_Customize_Setting
[16] Fix | Delete
*/
[17] Fix | Delete
final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting {
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* The setting type.
[21] Fix | Delete
*
[22] Fix | Delete
* @since 4.7.0
[23] Fix | Delete
* @var string
[24] Fix | Delete
*/
[25] Fix | Delete
public $type = 'custom_css';
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Setting Transport
[29] Fix | Delete
*
[30] Fix | Delete
* @since 4.7.0
[31] Fix | Delete
* @var string
[32] Fix | Delete
*/
[33] Fix | Delete
public $transport = 'postMessage';
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Capability required to edit this setting.
[37] Fix | Delete
*
[38] Fix | Delete
* @since 4.7.0
[39] Fix | Delete
* @var string
[40] Fix | Delete
*/
[41] Fix | Delete
public $capability = 'edit_css';
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Stylesheet
[45] Fix | Delete
*
[46] Fix | Delete
* @since 4.7.0
[47] Fix | Delete
* @var string
[48] Fix | Delete
*/
[49] Fix | Delete
public $stylesheet = '';
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* WP_Customize_Custom_CSS_Setting constructor.
[53] Fix | Delete
*
[54] Fix | Delete
* @since 4.7.0
[55] Fix | Delete
*
[56] Fix | Delete
* @throws Exception If the setting ID does not match the pattern `custom_css[$stylesheet]`.
[57] Fix | Delete
*
[58] Fix | Delete
* @param WP_Customize_Manager $manager Customizer bootstrap instance.
[59] Fix | Delete
* @param string $id A specific ID of the setting.
[60] Fix | Delete
* Can be a theme mod or option name.
[61] Fix | Delete
* @param array $args Setting arguments.
[62] Fix | Delete
*/
[63] Fix | Delete
public function __construct( $manager, $id, $args = array() ) {
[64] Fix | Delete
parent::__construct( $manager, $id, $args );
[65] Fix | Delete
if ( 'custom_css' !== $this->id_data['base'] ) {
[66] Fix | Delete
throw new Exception( 'Expected custom_css id_base.' );
[67] Fix | Delete
}
[68] Fix | Delete
if ( 1 !== count( $this->id_data['keys'] ) || empty( $this->id_data['keys'][0] ) ) {
[69] Fix | Delete
throw new Exception( 'Expected single stylesheet key.' );
[70] Fix | Delete
}
[71] Fix | Delete
$this->stylesheet = $this->id_data['keys'][0];
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Add filter to preview post value.
[76] Fix | Delete
*
[77] Fix | Delete
* @since 4.7.9
[78] Fix | Delete
*
[79] Fix | Delete
* @return bool False when preview short-circuits due no change needing to be previewed.
[80] Fix | Delete
*/
[81] Fix | Delete
public function preview() {
[82] Fix | Delete
if ( $this->is_previewed ) {
[83] Fix | Delete
return false;
[84] Fix | Delete
}
[85] Fix | Delete
$this->is_previewed = true;
[86] Fix | Delete
add_filter( 'wp_get_custom_css', array( $this, 'filter_previewed_wp_get_custom_css' ), 9, 2 );
[87] Fix | Delete
return true;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Filters `wp_get_custom_css` for applying the customized value.
[92] Fix | Delete
*
[93] Fix | Delete
* This is used in the preview when `wp_get_custom_css()` is called for rendering the styles.
[94] Fix | Delete
*
[95] Fix | Delete
* @since 4.7.0
[96] Fix | Delete
*
[97] Fix | Delete
* @see wp_get_custom_css()
[98] Fix | Delete
*
[99] Fix | Delete
* @param string $css Original CSS.
[100] Fix | Delete
* @param string $stylesheet Current stylesheet.
[101] Fix | Delete
* @return string CSS.
[102] Fix | Delete
*/
[103] Fix | Delete
public function filter_previewed_wp_get_custom_css( $css, $stylesheet ) {
[104] Fix | Delete
if ( $stylesheet === $this->stylesheet ) {
[105] Fix | Delete
$customized_value = $this->post_value( null );
[106] Fix | Delete
if ( ! is_null( $customized_value ) ) {
[107] Fix | Delete
$css = $customized_value;
[108] Fix | Delete
}
[109] Fix | Delete
}
[110] Fix | Delete
return $css;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Fetch the value of the setting. Will return the previewed value when `preview()` is called.
[115] Fix | Delete
*
[116] Fix | Delete
* @since 4.7.0
[117] Fix | Delete
*
[118] Fix | Delete
* @see WP_Customize_Setting::value()
[119] Fix | Delete
*
[120] Fix | Delete
* @return string
[121] Fix | Delete
*/
[122] Fix | Delete
public function value() {
[123] Fix | Delete
if ( $this->is_previewed ) {
[124] Fix | Delete
$post_value = $this->post_value( null );
[125] Fix | Delete
if ( null !== $post_value ) {
[126] Fix | Delete
return $post_value;
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
$id_base = $this->id_data['base'];
[130] Fix | Delete
$value = '';
[131] Fix | Delete
$post = wp_get_custom_css_post( $this->stylesheet );
[132] Fix | Delete
if ( $post ) {
[133] Fix | Delete
$value = $post->post_content;
[134] Fix | Delete
}
[135] Fix | Delete
if ( empty( $value ) ) {
[136] Fix | Delete
$value = $this->default;
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/** This filter is documented in wp-includes/class-wp-customize-setting.php */
[140] Fix | Delete
$value = apply_filters( "customize_value_{$id_base}", $value, $this );
[141] Fix | Delete
[142] Fix | Delete
return $value;
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* Validate a received value for being valid CSS.
[147] Fix | Delete
*
[148] Fix | Delete
* Checks for imbalanced braces, brackets, and comments.
[149] Fix | Delete
* Notifications are rendered when the customizer state is saved.
[150] Fix | Delete
*
[151] Fix | Delete
* @since 4.7.0
[152] Fix | Delete
* @since 4.9.0 Checking for balanced characters has been moved client-side via linting in code editor.
[153] Fix | Delete
* @since 5.9.0 Renamed `$css` to `$value` for PHP 8 named parameter support.
[154] Fix | Delete
*
[155] Fix | Delete
* @param string $value CSS to validate.
[156] Fix | Delete
* @return true|WP_Error True if the input was validated, otherwise WP_Error.
[157] Fix | Delete
*/
[158] Fix | Delete
public function validate( $value ) {
[159] Fix | Delete
// Restores the more descriptive, specific name for use within this method.
[160] Fix | Delete
$css = $value;
[161] Fix | Delete
[162] Fix | Delete
$validity = new WP_Error();
[163] Fix | Delete
[164] Fix | Delete
if ( preg_match( '#</?\w+#', $css ) ) {
[165] Fix | Delete
$validity->add( 'illegal_markup', __( 'Markup is not allowed in CSS.' ) );
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
if ( ! $validity->has_errors() ) {
[169] Fix | Delete
$validity = parent::validate( $css );
[170] Fix | Delete
}
[171] Fix | Delete
return $validity;
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Store the CSS setting value in the custom_css custom post type for the stylesheet.
[176] Fix | Delete
*
[177] Fix | Delete
* @since 4.7.0
[178] Fix | Delete
* @since 5.9.0 Renamed `$css` to `$value` for PHP 8 named parameter support.
[179] Fix | Delete
*
[180] Fix | Delete
* @param string $value CSS to update.
[181] Fix | Delete
* @return int|false The post ID or false if the value could not be saved.
[182] Fix | Delete
*/
[183] Fix | Delete
public function update( $value ) {
[184] Fix | Delete
// Restores the more descriptive, specific name for use within this method.
[185] Fix | Delete
$css = $value;
[186] Fix | Delete
[187] Fix | Delete
if ( empty( $css ) ) {
[188] Fix | Delete
$css = '';
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
$r = wp_update_custom_css_post(
[192] Fix | Delete
$css,
[193] Fix | Delete
array(
[194] Fix | Delete
'stylesheet' => $this->stylesheet,
[195] Fix | Delete
)
[196] Fix | Delete
);
[197] Fix | Delete
[198] Fix | Delete
if ( $r instanceof WP_Error ) {
[199] Fix | Delete
return false;
[200] Fix | Delete
}
[201] Fix | Delete
$post_id = $r->ID;
[202] Fix | Delete
[203] Fix | Delete
// Cache post ID in theme mod for performance to avoid additional DB query.
[204] Fix | Delete
if ( $this->manager->get_stylesheet() === $this->stylesheet ) {
[205] Fix | Delete
set_theme_mod( 'custom_css_post_id', $post_id );
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
return $post_id;
[209] Fix | Delete
}
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function