8889841cPKë,[¦«LÖî.î.src/Background.phpnu„[µü¤ 'kirki-generic', 'default' => '', 'choices' => [ 'type' => 'hidden', 'parent_type' => 'kirki-background', ], 'sanitize_callback' => [ '\Kirki\Field\Background', 'sanitize' ], ], $args ) ); $args['parent_setting'] = $args['settings']; $args['output'] = []; $args['wrapper_attrs'] = [ 'data-kirki-parent-control-type' => 'kirki-background', ]; if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) { $args['transport'] = 'postMessage'; } $default_bg_color = isset( $args['default']['background-color'] ) ? $args['default']['background-color'] : ''; /** * Background Color. */ new \Kirki\Field\Color( wp_parse_args( [ 'settings' => $args['settings'] . '[background-color]', 'label' => '', 'description' => esc_html__( 'Background Color', 'kirki' ), 'default' => $default_bg_color, 'section' => $args['section'], 'choices' => [ 'alpha' => true, ], ], $args ) ); /** * Background Image. */ new \Kirki\Field\Image( wp_parse_args( [ 'settings' => $args['settings'] . '[background-image]', 'label' => '', 'description' => esc_html__( 'Background Image', 'kirki' ), 'default' => isset( $args['default']['background-image'] ) ? $args['default']['background-image'] : '', 'section' => $args['section'], ], $args ) ); /** * Background Repeat. */ new Kirki\Field\Select( wp_parse_args( [ 'settings' => $args['settings'] . '[background-repeat]', 'label' => '', 'description' => esc_html__( 'Background Repeat', 'kirki' ), 'section' => $args['section'], 'default' => isset( $args['default']['background-repeat'] ) ? $args['default']['background-repeat'] : '', 'choices' => [ 'no-repeat' => esc_html__( 'No Repeat', 'kirki' ), 'repeat' => esc_html__( 'Repeat All', 'kirki' ), 'repeat-x' => esc_html__( 'Repeat Horizontally', 'kirki' ), 'repeat-y' => esc_html__( 'Repeat Vertically', 'kirki' ), ], 'required' => array_merge( $args['required'], [ [ 'setting' => $args['settings'], 'operator' => '!=', 'value' => '', 'choice' => 'background-image', ], ] ), ], $args ) ); /** * Background Position. */ new Kirki\Field\Select( wp_parse_args( [ 'settings' => $args['settings'] . '[background-position]', 'label' => '', 'description' => esc_html__( 'Background Position', 'kirki' ), 'default' => isset( $args['default']['background-position'] ) ? $args['default']['background-position'] : '', 'section' => $args['section'], 'choices' => [ 'left top' => esc_html__( 'Left Top', 'kirki' ), 'left center' => esc_html__( 'Left Center', 'kirki' ), 'left bottom' => esc_html__( 'Left Bottom', 'kirki' ), 'center top' => esc_html__( 'Center Top', 'kirki' ), 'center center' => esc_html__( 'Center Center', 'kirki' ), 'center bottom' => esc_html__( 'Center Bottom', 'kirki' ), 'right top' => esc_html__( 'Right Top', 'kirki' ), 'right center' => esc_html__( 'Right Center', 'kirki' ), 'right bottom' => esc_html__( 'Right Bottom', 'kirki' ), ], 'required' => array_merge( $args['required'], [ [ 'setting' => $args['settings'], 'operator' => '!=', 'value' => '', 'choice' => 'background-image', ], ] ), ], $args ) ); /** * Background size. */ new Kirki\Field\Radio_Buttonset( wp_parse_args( [ 'settings' => $args['settings'] . '[background-size]', 'label' => '', 'description' => esc_html__( 'Background Size', 'kirki' ), 'default' => isset( $args['default']['background-size'] ) ? $args['default']['background-size'] : '', 'section' => $args['section'], 'choices' => [ 'cover' => esc_html__( 'Cover', 'kirki' ), 'contain' => esc_html__( 'Contain', 'kirki' ), 'auto' => esc_html__( 'Auto', 'kirki' ), ], 'required' => array_merge( $args['required'], [ [ 'setting' => $args['settings'], 'operator' => '!=', 'value' => '', 'choice' => 'background-image', ], ] ), ], $args ) ); /** * Background attachment. */ new Kirki\Field\Radio_Buttonset( wp_parse_args( [ 'type' => 'kirki-radio-buttonset', 'settings' => $args['settings'] . '[background-attachment]', 'description' => esc_html__( 'Background Attachment', 'kirki' ), 'label' => '', 'default' => isset( $args['default']['background-attachment'] ) ? $args['default']['background-attachment'] : '', 'section' => $args['section'], 'choices' => [ 'scroll' => esc_html__( 'Scroll', 'kirki' ), 'fixed' => esc_html__( 'Fixed', 'kirki' ), ], 'required' => array_merge( $args['required'], [ [ 'setting' => $args['settings'], 'operator' => '!=', 'value' => '', 'choice' => 'background-image', ], ] ), ], $args ) ); add_action( 'customize_preview_init', [ $this, 'enqueue_scripts' ] ); add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] ); } /** * Sets the $sanitize_callback * * @access protected * @since 1.0 * @return void */ protected function set_sanitize_callback() { // If a custom sanitize_callback has been defined, // then we don't need to proceed any further. if ( ! empty( $this->sanitize_callback ) ) { return; } $this->sanitize_callback = [ '\Kirki\Field\Background', 'sanitize' ]; } /** * Sanitizes background controls * * @static * @access public * @since 1.0 * @param array $value The value. * @return array */ public static function sanitize( $value ) { if ( ! is_array( $value ) ) { return []; } $sanitized_value = [ 'background-color' => '', 'background-image' => '', 'background-repeat' => '', 'background-position' => '', 'background-size' => '', 'background-attachment' => '', ]; if ( isset( $value['background-color'] ) ) { $sanitized_value['background-color'] = \Kirki\Field\Color::sanitize( $value['background-color'] ); } if ( isset( $value['background-image'] ) ) { $sanitized_value['background-image'] = esc_url_raw( $value['background-image'] ); } if ( isset( $value['background-repeat'] ) ) { $sanitized_value['background-repeat'] = in_array( $value['background-repeat'], [ 'no-repeat', 'repeat', 'repeat-x', 'repeat-y', ], true ) ? $value['background-repeat'] : ''; } if ( isset( $value['background-position'] ) ) { $sanitized_value['background-position'] = in_array( $value['background-position'], [ 'left top', 'left center', 'left bottom', 'center top', 'center center', 'center bottom', 'right top', 'right center', 'right bottom', ], true ) ? $value['background-position'] : ''; } if ( isset( $value['background-size'] ) ) { $sanitized_value['background-size'] = in_array( $value['background-size'], [ 'cover', 'contain', 'auto', ], true ) ? $value['background-size'] : ''; } if ( isset( $value['background-attachment'] ) ) { $sanitized_value['background-attachment'] = in_array( $value['background-attachment'], [ 'scroll', 'fixed', ], true ) ? $value['background-attachment'] : ''; } return $sanitized_value; } /** * Sets the $js_vars * * @access protected * @since 1.0 * @return void */ protected function set_js_vars() { // Typecast to array. $this->js_vars = (array) $this->js_vars; // Check if transport is set to auto. // If not, then skip the auto-calculations and exit early. if ( 'auto' !== $this->transport ) { return; } // Set transport to refresh initially. // Serves as a fallback in case we failt to auto-calculate js_vars. $this->transport = 'refresh'; $js_vars = []; // Try to auto-generate js_vars. // First we need to check if js_vars are empty, and that output is not empty. if ( empty( $this->js_vars ) && ! empty( $this->output ) ) { // Start going through each item in the $output array. foreach ( $this->output as $output ) { // If 'element' is not defined, skip this. if ( ! isset( $output['element'] ) ) { continue; } if ( is_array( $output['element'] ) ) { $output['element'] = implode( ',', $output['element'] ); } // If there's a sanitize_callback defined, skip this. if ( isset( $output['sanitize_callback'] ) && ! empty( $output['sanitize_callback'] ) ) { continue; } // If we got this far, it's safe to add this. $js_vars[] = $output; } // Did we manage to get all the items from 'output'? // If not, then we're missing something so don't add this. if ( count( $js_vars ) !== count( $this->output ) ) { return; } $this->js_vars = $js_vars; $this->transport = 'postMessage'; } } /** * Override parent method. No need to register any setting. * * @access public * @since 0.1 * @param WP_Customize_Manager $wp_customize The customizer instance. * @return void */ public function add_setting( $wp_customize ) {} /** * Override the parent method. No need for a control. * * @access public * @since 0.1 * @param WP_Customize_Manager $wp_customize The customizer instance. * @return void */ public function add_control( $wp_customize ) {} /** * Enqueue scripts & styles. * * @access public * @since 1.0 * @return void */ public function enqueue_scripts() { wp_enqueue_script( 'kirki-typography', URL::get_from_path( __DIR__ ) . '/script.js', [ 'wp-hooks' ], '1.0', true ); } /** * Adds a custom output class for typography fields. * * @access public * @since 1.0 * @param array $classnames The array of classnames. * @return array */ public function output_control_classnames( $classnames ) { $classnames['kirki-background'] = '\Kirki\Field\CSS\Background'; return $classnames; } } PKë,[Á!õ¼ src/script.jsnu„[µü¤/* global kirkiPostMessage */ /** * Hook in the kirkiPostMessageStylesOutput filter. * * Handles postMessage styles for typography controls. */ jQuery( document ).ready( function() { wp.hooks.addFilter( 'kirkiPostMessageStylesOutput', 'kirki', /** * Append styles for this control. * * @param {string} styles - The styles. * @param {Object} value - The control value. * @param {Object} output - The control's "output" argument. * @param {string} controlType - The control type. * @returns {string} - Returns CSS styles as a string. */ function( styles, value, output, controlType ) { var processedValue; if ( 'kirki-background' === controlType ) { styles += output.element + '{'; _.each( value, function( val, key ) { if ( output.choice && key !== output.choice ) { return; } if ( 'background-image' === key ) { val = -1 === val.indexOf( 'url(' ) ? 'url(' + val + ')' : val; } processedValue = kirkiPostMessage.util.processValue( output, val ); if ( '' === processedValue ) { if ( 'background-color' === output.property ) { processedValue = 'unset'; } else if ( 'background-image' === output.property ) { processedValue = 'none'; } } if ( false !== processedValue ) { styles += output.property ? output.property + ':' + processedValue + ';' : key + ':' + processedValue + ';'; } } ); styles += '}'; } return styles; } ); } ); PKë,[/¯ê¢££src/CSS/Background.phpnu„[µü¤ 'global', 'element' => 'body', 'prefix' => '', 'suffix' => '', ] ); foreach ( [ 'background-image', 'background-color', 'background-repeat', 'background-position', 'background-size', 'background-attachment' ] as $property ) { // See https://github.com/aristath/kirki/issues/1808. if ( 'background-color' === $property && isset( $value['background-color'] ) && $value['background-color'] && ( ! isset( $value['background-image'] ) || empty( $value['background-image'] ) ) ) { $this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix']; } if ( isset( $value[ $property ] ) && ! empty( $value[ $property ] ) ) { $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix']; } } } } PKë,[ØÞ¶ composer.jsonnu„[µü¤{ "name": "kirki-framework/field-background", "type": "library", "description": "Background field for the Kirki Customizer framework.", "keywords": [ "wordpress", "customizer", "framework" ], "homepage": "https://kirki.org/", "license": "MIT", "authors": [ { "name": "Kirki Framework", "email": "connect@mapsteps.com" } ], "require": { "php": ">=7.0", "kirki-framework/url-getter": "*", "kirki-framework/control-react-colorful": "*", "kirki-framework/control-select": "*", "kirki-framework/control-radio": "*" }, "autoload": { "psr-4": { "Kirki\\Field\\": "src" } } } PKë,[_•¯EELICENSEnu„[µü¤MIT License Copyright (c) 2019 kirki-framework Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PKë,[¦«LÖî.î.src/Background.phpnu„[µü¤PKë,[Á!õ¼ 0/src/script.jsnu„[µü¤PKë,[/¯ê¢££ˆ5src/CSS/Background.phpnu„[µü¤PKë,[ØÞ¶ q<composer.jsonnu„[µü¤PKë,[_•¯EE¼?LICENSEnu„[µü¤PK‰8D