diff options
Diffstat (limited to 'srcs/wordpress/wp-includes/customize')
35 files changed, 5592 insertions, 0 deletions
diff --git a/srcs/wordpress/wp-includes/customize/class-wp-customize-background-image-control.php b/srcs/wordpress/wp-includes/customize/class-wp-customize-background-image-control.php new file mode 100644 index 0000000..b31a811 --- /dev/null +++ b/srcs/wordpress/wp-includes/customize/class-wp-customize-background-image-control.php @@ -0,0 +1,59 @@ +<?php +/** + * Customize API: WP_Customize_Background_Image_Control class + * + * @package WordPress + * @subpackage Customize + * @since 4.4.0 + */ + +/** + * Customize Background Image Control class. + * + * @since 3.4.0 + * + * @see WP_Customize_Image_Control + */ +class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control { + public $type = 'background'; + + /** + * Constructor. + * + * @since 3.4.0 + * @uses WP_Customize_Image_Control::__construct() + * + * @param WP_Customize_Manager $manager Customizer bootstrap instance. + */ + public function __construct( $manager ) { + parent::__construct( + $manager, + 'background_image', + array( + 'label' => __( 'Background Image' ), + 'section' => 'background_image', + ) + ); + } + + /** + * Enqueue control related scripts/styles. + * + * @since 4.1.0 + */ + public function enqueue() { + parent::enqueue(); + + $custom_background = get_theme_support( 'custom-background' ); + wp_localize_script( + 'customize-controls', + '_wpCustomizeBackground', + array( + 'defaults' => ! empty( $custom_background[0] ) ? $custom_background[0] : array(), + 'nonces' => array( + 'add' => wp_create_nonce( 'background-add' ), + ), + ) + ); + } +} diff --git a/srcs/wordpress/wp-includes/customize/class-wp-customize-background-image-setting.php b/srcs/wordpress/wp-includes/customize/class-wp-customize-background-image-setting.php new file mode 100644 index 0000000..e7867d1 --- /dev/null +++ b/srcs/wordpress/wp-includes/customize/class-wp-customize-background-image-setting.php @@ -0,0 +1,28 @@ +<?php +/** + * Customize API: WP_Customize_Background_Image_Setting class + * + * @package WordPress + * @subpackage Customize + * @since 4.4.0 + */ + +/** + * Customizer Background Image Setting class. + * + * @since 3.4.0 + * + * @see WP_Customize_Setting + */ +final class WP_Customize_Background_Image_Setting extends WP_Customize_Setting { + public $id = 'background_image_thumb'; + + /** + * @since 3.4.0 + * + * @param $value + */ + public function update( $value ) { + remove_theme_mod( 'background_image_thumb' ); + } +} diff --git a/srcs/wordpress/wp-includes/customize/class-wp-customize-background-position-control.php b/srcs/wordpress/wp-includes/customize/class-wp-customize-background-position-control.php new file mode 100644 index 0000000..bb35b05 --- /dev/null +++ b/srcs/wordpress/wp-includes/customize/class-wp-customize-background-position-control.php @@ -0,0 +1,111 @@ +<?php +/** + * Customize API: WP_Customize_Background_Position_Control class + * + * @package WordPress + * @subpackage Customize + * @since 4.7.0 + */ + +/** + * Customize Background Position Control class. + * + * @since 4.7.0 + * + * @see WP_Customize_Control + */ +class WP_Customize_Background_Position_Control extends WP_Customize_Control { + + /** + * Type. + * + * @since 4.7.0 + * @var string + */ + public $type = 'background_position'; + + /** + * Don't render the control content from PHP, as it's rendered via JS on load. + * + * @since 4.7.0 + */ + public function render_content() {} + + /** + * Render a JS template for the content of the position control. + * + * @since 4.7.0 + */ + public function content_template() { + $options = array( + array( + 'left top' => array( + 'label' => __( 'Top Left' ), + 'icon' => 'dashicons dashicons-arrow-left-alt', + ), + 'center top' => array( + 'label' => __( 'Top' ), + 'icon' => 'dashicons dashicons-arrow-up-alt', + ), + 'right top' => array( + 'label' => __( 'Top Right' ), + 'icon' => 'dashicons dashicons-arrow-right-alt', + ), + ), + array( + 'left center' => array( + 'label' => __( 'Left' ), + 'icon' => 'dashicons dashicons-arrow-left-alt', + ), + 'center center' => array( + 'label' => __( 'Center' ), + 'icon' => 'background-position-center-icon', + ), + 'right center' => array( + 'label' => __( 'Right' ), + 'icon' => 'dashicons dashicons-arrow-right-alt', + ), + ), + array( + 'left bottom' => array( + 'label' => __( 'Bottom Left' ), + 'icon' => 'dashicons dashicons-arrow-left-alt', + ), + 'center bottom' => array( + 'label' => __( 'Bottom' ), + 'icon' => 'dashicons dashicons-arrow-down-alt', + ), + 'right bottom' => array( + 'label' => __( 'Bottom Right' ), + 'icon' => 'dashicons dashicons-arrow-right-alt', + ), + ), + ); + ?> + <# if ( data.label ) { #> + <span class="customize-control-title">{{{ data.label }}}</span> + <# } #> + <# if ( data.description ) { #> + <span class="description customize-control-description">{{{ data.description }}}</span> + <# } #> + <div class="customize-control-content"> + <fieldset> + <legend class="screen-reader-text"><span><?php _e( 'Image Position' ); ?></span></legend> + <div class="background-position-control"> + <?php foreach ( $options as $group ) : ?> + <div class="button-group"> + <?php foreach ( $group as $value => $input ) : ?> + <label> + <input class="screen-reader-text" name="background-position" type="radio" value="<?php echo esc_attr( $value ); ?>"> + <span class="button display-options position"><span class="<?php echo esc_attr( $input['icon'] ); ?>" aria-hidden="true"></span></span> + <span class="screen-reader-text"><?php echo $input['label']; ?></span> + </label> + <?php endforeach; ?> + </div> + <?php endforeach; ?> + </div> + </fieldset> + </div> + <?php + } +} diff --git a/srcs/wordpress/wp-includes/customize/class-wp-customize-code-editor-control.php b/srcs/wordpress/wp-includes/customize/class-wp-customize-code-editor-control.php new file mode 100644 index 0000000..0e687a2 --- /dev/null +++ b/srcs/wordpress/wp-includes/customize/class-wp-customize-code-editor-control.php @@ -0,0 +1,110 @@ +<?php +/** + * Customize API: WP_Customize_Code_Editor_Control class + * + * @package WordPress + * @subpackage Customize + * @since 4.9.0 + */ + +/** + * Customize Code Editor Control class. + * + * @since 4.9.0 + * + * @see WP_Customize_Control + */ +class WP_Customize_Code_Editor_Control extends WP_Customize_Control { + + /** + * Customize control type. + * + * @since 4.9.0 + * @var string + */ + public $type = 'code_editor'; + + /** + * Type of code that is being edited. + * + * @since 4.9.0 + * @var string + */ + public $code_type = ''; + + /** + * Code editor settings. + * + * @see wp_enqueue_code_editor() + * @since 4.9.0 + * @var array|false + */ + public $editor_settings = array(); + + /** + * Enqueue control related scripts/styles. + * + * @since 4.9.0 + */ + public function enqueue() { + $this->editor_settings = wp_enqueue_code_editor( + array_merge( + array( + 'type' => $this->code_type, + 'codemirror' => array( + 'indentUnit' => 2, + 'tabSize' => 2, + ), + ), + $this->editor_settings + ) + ); + } + + /** + * Refresh the parameters passed to the JavaScript via JSON. + * + * @since 4.9.0 + * @see WP_Customize_Control::json() + * + * @return array Array of parameters passed to the JavaScript. + */ + public function json() { + $json = parent::json(); + $json['editor_settings'] = $this->editor_settings; + $json['input_attrs'] = $this->input_attrs; + return $json; + } + + /** + * Don't render the control content from PHP, as it's rendered via JS on load. + * + * @since 4.9.0 + */ + public function render_content() {} + + /** + * Render a JS template for control display. + * + * @since 4.9.0 + */ + public function content_template() { + ?> + <# var elementIdPrefix = 'el' + String( Math.random() ); #> + <# if ( data.label ) { #> + <label for="{{ elementIdPrefix }}_editor" class="customize-control-title"> + {{ data.label }} + </label> + <# } #> + <# if ( data.description ) { #> + <span class="description customize-control-description">{{{ data.description }}}</span> + <# } #> + <div class="customize-control-notifications-container"></div> + <textarea id="{{ elementIdPrefix }}_editor" + <# _.each( _.extend( { 'class': 'code' }, data.input_attrs ), function( value, key ) { #> + {{{ key }}}="{{ value }}" + <# }); #> + ></textarea> + <?php + } +} diff --git a/srcs/wordpress/wp-includes/customize/class-wp-customize-color-control.php b/srcs/wordpress/wp-includes/customize/class-wp-customize-color-control.php new file mode 100644 index 0000000..6288ee4 --- /dev/null +++ b/srcs/wordpress/wp-includes/customize/class-wp-customize-color-control.php @@ -0,0 +1,119 @@ +<?php +/** + * Customize API: WP_Customize_Color_Control class + * + * @package WordPress + * @subpackage Customize + * @since 4.4.0 + */ + +/** + * Customize Color Control class. + * + * @since 3.4.0 + * + * @see WP_Customize_Control + */ +class WP_Customize_Color_Control extends WP_Customize_Control { + /** + * Type. + * + * @var string + */ + public $type = 'color'; + + /** + * Statuses. + * + * @var array + */ + public $statuses; + + /** + * Mode. + * + * @since 4.7.0 + * @var string + */ + public $mode = 'full'; + + /** + * Constructor. + * + * @since 3.4.0 + * @uses WP_Customize_Control::__construct() + * + * @param WP_Customize_Manager $manager Customizer bootstrap instance. + * @param string $id Control ID. + * @param array $args Optional. Arguments to override class property defaults. + */ + public function __construct( $manager, $id, $args = array() ) { + $this->statuses = array( '' => __( 'Default' ) ); + parent::__construct( $manager, $id, $args ); + } + + /** + * Enqueue scripts/styles for the color picker. + * + * @since 3.4.0 + */ + public function enqueue() { + wp_enqueue_script( 'wp-color-picker' ); + wp_enqueue_style( 'wp-color-picker' ); + } + + /** + * Refresh the parameters passed to the JavaScript via JSON. + * + * @since 3.4.0 + * @uses WP_Customize_Control::to_json() + */ + public function to_json() { + parent::to_json(); + $this->json['statuses'] = $this->statuses; + $this->json['defaultValue'] = $this->setting->default; + $this->json['mode'] = $this->mode; + } + + /** + * Don't render the control content from PHP, as it's rendered via JS on load. + * + * @since 3.4.0 + */ + public function render_content() {} + + /** + * Render a JS template for the content of the color picker control. + * + * @since 4.1.0 + */ + public function content_template() { + ?> + <# var defaultValue = '#RRGGBB', defaultValueAttr = '', + isHueSlider = data.mode === 'hue'; + if ( data.defaultValue && _.isString( data.defaultValue ) && ! isHueSlider ) { + if ( '#' !== data.defaultValue.substring( 0, 1 ) ) { + defaultValue = '#' + data.defaultValue; + } else { + defaultValue = data.defaultValue; + } + defaultValueAttr = ' data-default-color=' + defaultValue; // Quotes added automatically. + } #> + <# if ( data.label ) { #> + <span class="customize-control-title">{{{ data.label }}}</span> + <# } #> + <# if ( data.description ) { #> + <span class="description customize-control-description">{{{ data.description }}}</span> + <# } #> + <div class="customize-control-content"> + <label><span class="screen-reader-text">{{{ data.label }}}</span> + <# if ( isHueSlider ) { #> + <input class="color-picker-hue" type="text" data-type="hue" /> + <# } else { #> + <input class="color-picker-hex" type="text" maxlength="7" placeholder="{{ defaultValue }}" {{ defaultValueAttr }} /> + <# } #> + </label> + </div> + <?php + } +} diff --git a/srcs/wordpress/wp-includes/customize/class-wp-customize-cropped-image-control.php b/srcs/wordpress/wp-includes/customize/class-wp-customize-cropped-image-control.php new file mode 100644 index 0000000..c8a55f4 --- /dev/null +++ b/srcs/wordpress/wp-includes/customize/class-wp-customize-cropped-image-control.php @@ -0,0 +1,86 @@ +<?php +/** + * Customize API: WP_Customize_Cropped_Image_Control class + * + * @package WordPress + * @subpackage Customize + * @since 4.4.0 + */ + +/** + * Customize Cropped Image Control class. + * + * @since 4.3.0 + * + * @see WP_Customize_Image_Control + */ +class WP_Customize_Cropped_Image_Control extends WP_Customize_Image_Control { + + /** + * Control type. + * + * @since 4.3.0 + * @var string + */ + public $type = 'cropped_image'; + + /** + * Suggested width for cropped image. + * + * @since 4.3.0 + * @var int + */ + public $width = 150; + + /** + * Suggested height for cropped image. + * + * @since 4.3.0 + * @var int + */ + public $height = 150; + + /** + * Whether the width is flexible. + * + * @since 4.3.0 + * @var bool + */ + public $flex_width = false; + + /** + * Whether the height is flexible. + * + * @since 4.3.0 + * @var bool + */ + public $flex_height = false; + + /** + * Enqueue control related scripts/styles. + * + * @since 4.3.0 + */ + public function enqueue() { + wp_enqueue_script( 'customize-views' ); + + parent::enqueue(); + } + + /** + * Refresh the parameters passed to the JavaScript via JSON. + * + * @since 4.3.0 + * + * @see WP_Customize_Control::to_json() + */ + public function to_json() { + parent::to_json(); + + $this->json['width'] = absint( $this->width ); + $this->json['height'] = absint( $this->height ); + $this->json['flex_width'] = absint( $this->flex_width ); + $this->json['flex_height'] = absint( $this->flex_height ); + } + +} diff --git a/srcs/wordpress/wp-includes/customize/class-wp-customize-custom-css-setting.php b/srcs/wordpress/wp-includes/customize/class-wp-customize-custom-css-setting.php new file mode 100644 index 0000000..085a8b5 --- /dev/null +++ b/srcs/wordpress/wp-includes/customize/class-wp-customize-custom-css-setting.php @@ -0,0 +1,202 @@ +<?php +/** + * Customize API: WP_Customize_Custom_CSS_Setting class + * + * This handles validation, sanitization and saving of the value. + * + * @package WordPress + * @subpackage Customize + * @since 4.7.0 + */ + +/** + * Custom Setting to handle WP Custom CSS. + * + * @since 4.7.0 + * + * @see WP_Customize_Setting + */ +final class WP_Customize_Custom_CSS_Setting extends WP_Customize_Setting { + + /** + * The setting type. + * + * @since 4.7.0 + * @var string + */ + public $type = 'custom_css'; + + /** + * Setting Transport + * + * @since 4.7.0 + * @var string + */ + public $transport = 'postMessage'; + + /** + * Capability required to edit this setting. + * + * @since 4.7.0 + * @var string + */ + public $capability = 'edit_css'; + + /** + * Stylesheet + * + * @since 4.7.0 + * @var string + */ + public $stylesheet = ''; + + /** + * WP_Customize_Custom_CSS_Setting constructor. + * + * @since 4.7.0 + * + * @throws Exception If the setting ID does not match the pattern `custom_css[$stylesheet]`. + * + * @param WP_Customize_Manager $manager The Customize Manager class. + * @param string $id An specific ID of the setting. Can be a + * theme mod or option name. + * @param array $args Setting arguments. + */ + public function __construct( $manager, $id, $args = array() ) { + parent::__construct( $manager, $id, $args ); + if ( 'custom_css' !== $this->id_data['base'] ) { + throw new Exception( 'Expected custom_css id_base.' ); + } + if ( 1 !== count( $this->id_data['keys'] ) || empty( $this->id_data['keys'][0] ) ) { + throw new Exception( 'Expected single stylesheet key.' ); + } + $this->stylesheet = $this->id_data['keys'][0]; + } + + /** + * Add filter to preview post value. + * + * @since 4.7.9 + * + * @return bool False when preview short-circuits due no change needing to be previewed. + */ + public function preview() { + if ( $this->is_previewed ) { + return false; + } + $this->is_previewed = true; + add_filter( 'wp_get_custom_css', array( $this, 'filter_previewed_wp_get_custom_css' ), 9, 2 ); + return true; + } + + /** + * Filter `wp_get_custom_css` for applying the customized value. + * + * This is used in the preview when `wp_get_custom_css()` is called for rendering the styles. + * + * @since 4.7.0 + * @see wp_get_custom_css() + * + * @param string $css Original CSS. + * @param string $stylesheet Current stylesheet. + * @return string CSS. + */ + public function filter_previewed_wp_get_custom_css( $css, $stylesheet ) { + if ( $stylesheet === $this->stylesheet ) { + $customized_value = $this->post_value( null ); + if ( ! is_null( $customized_value ) ) { + $css = $customized_value; + } + } + return $css; + } + + /** + * Fetch the value of the setting. Will return the previewed value when `preview()` is called. + * + * @since 4.7.0 + * @see WP_Customize_Setting::value() + * + * @return string + */ + public function value() { + if ( $this->is_previewed ) { + $post_value = $this->post_value( null ); + if ( null !== $post_value ) { + return $post_value; + } + } + $id_base = $this->id_data['base']; + $value = ''; + $post = wp_get_custom_css_post( $this->stylesheet ); + if ( $post ) { + $value = $post->post_content; + } + if ( empty( $value ) ) { + $value = $this->default; + } + + /** This filter is documented in wp-includes/class-wp-customize-setting.php */ + $value = apply_filters( "customize_value_{$id_base}", $value, $this ); + + return $value; + } + + /** + * Validate CSS. + * + * Checks for imbalanced braces, brackets, and comments. + * Notifications are rendered when the customizer state is saved. + * + * @since 4.7.0 + * @since 4.9.0 Checking for balanced characters has been moved client-side via linting in code editor. + * + * @param string $css The input string. + * @return true|WP_Error True if the input was validated, otherwise WP_Error. + */ + public function validate( $css ) { + $validity = new WP_Error(); + + if ( preg_match( '#</?\w+#', $css ) ) { + $validity->add( 'illegal_markup', __( 'Markup is not allowed in CSS.' ) ); + } + + if ( ! $validity->has_errors() ) { + $validity = parent::validate( $css ); + } + return $validity; + } + + /** + * Store the CSS setting value in the custom_css custom post type for the stylesheet. + * + * @since 4.7.0 + * + * @param string $css The input value. + * @return int|false The post ID or false if the value could not be saved. + */ + public function update( $css ) { + if ( empty( $css ) ) { + $css = ''; + } + + $r = wp_update_custom_css_post( + $css, + array( + 'stylesheet' => $this->stylesheet, + ) + ); + + if ( $r instanceof WP_Error ) { + return false; + } + $post_id = $r->ID; + + // Cache post ID in theme mod for performance to avoid additional DB query. + if ( $this->manager->get_stylesheet() === $this->stylesheet ) { + set_theme_mod( 'custom_css_post_id', $post_id ); + } + + return $post_id; + } +} diff --git a/srcs/wordpress/wp-includes/customize/class-wp-customize-date-time-control.php b/srcs/wordpress/wp-includes/customize/class-wp-customize-date-time-control.php new file mode 100644 index 0000000..36bd192 --- /dev/null +++ b/srcs/wordpress/wp-includes/customize/class-wp-customize-date-time-control.php @@ -0,0 +1,282 @@ +<?php +/** + * Customize API: WP_Customize_Date_Time_Control class + * + * @package WordPress + * @subpackage Customize + * @since 4.9.0 + */ + +/** + * Customize Date Time Control class. + * + * @since 4.9.0 + * + * @see WP_Customize_Control + */ +class WP_Customize_Date_Time_Control extends WP_Customize_Control { + + /** + * Customize control type. + * + * @since 4.9.0 + * @var string + */ + public $type = 'date_time'; + + /** + * Minimum Year. + * + * @since 4.9.0 + * @var integer + */ + public $min_year = 1000; + + /** + * Maximum Year. + * + * @since 4.9.0 + * @var integer + */ + public $max_year = 9999; + + /** + * Allow past date, if set to false user can only select future date. + * + * @since 4.9.0 + * @var boolean + */ + public $allow_past_date = true; + + /** + * Whether hours, minutes, and meridian should be shown. + * + * @since 4.9.0 + * |
