Passed
Push — main ( 137754...ffd9e1 )
by TARIQ
04:53
created
packages/kirki-framework/control-dashicons/src/Field/Dashicons.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -17,68 +17,68 @@
 block discarded – undo
17 17
  */
18 18
 class Dashicons extends Field {
19 19
 
20
-	/**
21
-	 * The field type.
22
-	 *
23
-	 * @access public
24
-	 * @since 1.0
25
-	 * @var string
26
-	 */
27
-	public $type = 'kirki-dashicons';
20
+    /**
21
+     * The field type.
22
+     *
23
+     * @access public
24
+     * @since 1.0
25
+     * @var string
26
+     */
27
+    public $type = 'kirki-dashicons';
28 28
 
29
-	/**
30
-	 * The control class-name.
31
-	 *
32
-	 * @access protected
33
-	 * @since 0.1
34
-	 * @var string
35
-	 */
36
-	protected $control_class = '\Kirki\Control\Dashicons';
29
+    /**
30
+     * The control class-name.
31
+     *
32
+     * @access protected
33
+     * @since 0.1
34
+     * @var string
35
+     */
36
+    protected $control_class = '\Kirki\Control\Dashicons';
37 37
 
38
-	/**
39
-	 * Whether we should register the control class for JS-templating or not.
40
-	 *
41
-	 * @access protected
42
-	 * @since 0.1
43
-	 * @var bool
44
-	 */
45
-	protected $control_has_js_template = true;
38
+    /**
39
+     * Whether we should register the control class for JS-templating or not.
40
+     *
41
+     * @access protected
42
+     * @since 0.1
43
+     * @var bool
44
+     */
45
+    protected $control_has_js_template = true;
46 46
 
47
-	/**
48
-	 * Filter arguments before creating the setting.
49
-	 *
50
-	 * @access public
51
-	 * @since 0.1
52
-	 * @param array                $args         The field arguments.
53
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
54
-	 * @return array
55
-	 */
56
-	public function filter_setting_args( $args, $wp_customize ) {
57
-		if ( $args['settings'] === $this->args['settings'] ) {
58
-			$args = parent::filter_setting_args( $args, $wp_customize );
47
+    /**
48
+     * Filter arguments before creating the setting.
49
+     *
50
+     * @access public
51
+     * @since 0.1
52
+     * @param array                $args         The field arguments.
53
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
54
+     * @return array
55
+     */
56
+    public function filter_setting_args( $args, $wp_customize ) {
57
+        if ( $args['settings'] === $this->args['settings'] ) {
58
+            $args = parent::filter_setting_args( $args, $wp_customize );
59 59
 
60
-			// Set the sanitize-callback if none is defined.
61
-			if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
62
-				$args['sanitize_callback'] = 'sanitize_text_field';
63
-			}
64
-		}
65
-		return $args;
66
-	}
60
+            // Set the sanitize-callback if none is defined.
61
+            if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) {
62
+                $args['sanitize_callback'] = 'sanitize_text_field';
63
+            }
64
+        }
65
+        return $args;
66
+    }
67 67
 
68
-	/**
69
-	 * Filter arguments before creating the control.
70
-	 *
71
-	 * @access public
72
-	 * @since 0.1
73
-	 * @param array                $args         The field arguments.
74
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
75
-	 * @return array
76
-	 */
77
-	public function filter_control_args( $args, $wp_customize ) {
78
-		if ( $args['settings'] === $this->args['settings'] ) {
79
-			$args         = parent::filter_control_args( $args, $wp_customize );
80
-			$args['type'] = 'kirki-dashicons';
81
-		}
82
-		return $args;
83
-	}
68
+    /**
69
+     * Filter arguments before creating the control.
70
+     *
71
+     * @access public
72
+     * @since 0.1
73
+     * @param array                $args         The field arguments.
74
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
75
+     * @return array
76
+     */
77
+    public function filter_control_args( $args, $wp_customize ) {
78
+        if ( $args['settings'] === $this->args['settings'] ) {
79
+            $args         = parent::filter_control_args( $args, $wp_customize );
80
+            $args['type'] = 'kirki-dashicons';
81
+        }
82
+        return $args;
83
+    }
84 84
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-dashicons/src/Util/Dashicons.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -17,31 +17,31 @@
 block discarded – undo
17 17
  */
18 18
 class Dashicons {
19 19
 
20
-	/**
21
-	 * Get an array of all available dashicons.
22
-	 *
23
-	 * @static
24
-	 * @access public
25
-	 * @since 1.0
26
-	 * @return array
27
-	 */
28
-	public static function get_icons() {
29
-		return [
30
-			'admin-menu'     => [ 'menu', 'menu-alt', 'menu-alt2', 'menu-alt3', 'admin-site', 'admin-site-alt', 'admin-site-alt2', 'admin-site-alt3', 'dashboard', 'admin-post', 'admin-media', 'admin-links', 'admin-page', 'admin-comments', 'admin-appearance', 'admin-plugins', 'plugins-checked', 'admin-users', 'admin-tools', 'admin-settings', 'admin-network', 'admin-home', 'admin-generic', 'admin-collapse', 'filter', 'admin-customizer', 'admin-multisite' ],
31
-			'welcome-screen' => [ 'welcome-write-blog', 'welcome-add-page', 'welcome-view-site', 'welcome-widgets-menus', 'welcome-comments', 'welcome-learn-more' ],
32
-			'post-formats'   => [ 'format-aside', 'format-image', 'format-gallery', 'format-video', 'format-status', 'format-quote', 'format-chat', 'format-audio', 'camera', 'camera-alt', 'images-alt', 'images-alt2', 'video-alt', 'video-alt2', 'video-alt3' ],
33
-			'media'          => [ 'media-archive', 'media-audio', 'media-code', 'media-default', 'media-document', 'media-interactive', 'media-spreadsheet', 'media-text', 'media-video', 'playlist-audio', 'playlist-video', 'controls-play', 'controls-pause', 'controls-forward', 'controls-skipforward', 'controls-back', 'controls-skipback', 'controls-repeat', 'controls-volumeon', 'controls-volumeoff' ],
34
-			'image-editing'  => [ 'image-crop', 'image-rotate', 'image-rotate-left', 'image-rotate-right', 'image-flip-vertical', 'image-flip-horizontal', 'image-filter', 'undo', 'redo' ],
35
-			'tinymce'        => [ 'editor-bold', 'editor-italic', 'editor-ul', 'editor-ol', 'editor-ol-rtl', 'editor-quote', 'editor-alignleft', 'editor-aligncenter', 'editor-alignright', 'editor-insertmore', 'editor-spellcheck', 'editor-expand', 'editor-contract', 'editor-kitchensink', 'editor-underline', 'editor-justify', 'editor-textcolor', 'editor-paste-word', 'editor-paste-text', 'editor-removeformatting', 'editor-video', 'editor-customchar', 'editor-outdent', 'editor-indent', 'editor-help', 'editor-strikethrough', 'editor-unlink', 'editor-rtl', 'editor-ltr', 'editor-break', 'editor-code', 'editor-paragraph', 'editor-table' ],
36
-			'posts'          => [ 'align-left', 'align-right', 'align-center', 'align-none', 'lock', 'unlock', 'calendar', 'calendar-alt', 'visibility', 'hidden', 'post-status', 'edit', 'trash', 'sticky' ],
37
-			'sorting'        => [ 'external', 'arrow-up', 'arrow-down', 'arrow-right', 'arrow-left', 'arrow-up-alt', 'arrow-down-alt', 'arrow-right-alt', 'arrow-left-alt', 'arrow-up-alt2', 'arrow-down-alt2', 'arrow-right-alt2', 'arrow-left-alt2', 'sort', 'leftright', 'randomize', 'list-view', 'exerpt-view', 'grid-view', 'move' ],
38
-			'social'         => [ 'share', 'share-alt', 'share-alt2', 'twitter', 'rss', 'email', 'email-alt', 'email-alt2', 'facebook', 'facebook-alt', 'googleplus', 'networking', 'instagram' ],
39
-			'wordpress_org'  => [ 'hammer', 'art', 'migrate', 'performance', 'universal-access', 'universal-access-alt', 'tickets', 'nametag', 'clipboard', 'heart', 'megaphone', 'schedule', 'tide', 'rest-api', 'code-standards' ],
40
-			'products'       => [ 'wordpress', 'wordpress-alt', 'pressthis', 'update', 'update-alt', 'screenoptions', 'info', 'cart', 'feedback', 'cloud', 'translation' ],
41
-			'taxonomies'     => [ 'tag', 'category' ],
42
-			'widgets'        => [ 'archive', 'tagcloud', 'text' ],
43
-			'notifications'  => [ 'yes', 'yes-alt', 'no', 'no-alt', 'plus', 'plus-alt', 'minus', 'dismiss', 'marker', 'star-filled', 'star-half', 'star-empty', 'flag', 'warning' ],
44
-			'misc'           => [ 'location', 'location-alt', 'vault', 'shield', 'shield-alt', 'sos', 'search', 'slides', 'text-page', 'analytics', 'chart-pie', 'chart-bar', 'chart-line', 'chart-area', 'groups', 'businessman', 'businesswoman', 'businessperson', 'id', 'id-alt', 'products', 'awards', 'forms', 'testimonial', 'portfolio', 'book', 'book-alt', 'download', 'upload', 'backup', 'clock', 'lightbulb', 'microphone', 'desktop', 'tablet', 'smartphone', 'phone', 'index-card', 'carrot', 'building', 'store', 'album', 'palmtree', 'tickets-alt', 'money', 'smiley', 'thumbs-up', 'thumbs-down', 'layout', 'paperclip' ],
45
-		];
46
-	}
20
+    /**
21
+     * Get an array of all available dashicons.
22
+     *
23
+     * @static
24
+     * @access public
25
+     * @since 1.0
26
+     * @return array
27
+     */
28
+    public static function get_icons() {
29
+        return [
30
+            'admin-menu'     => [ 'menu', 'menu-alt', 'menu-alt2', 'menu-alt3', 'admin-site', 'admin-site-alt', 'admin-site-alt2', 'admin-site-alt3', 'dashboard', 'admin-post', 'admin-media', 'admin-links', 'admin-page', 'admin-comments', 'admin-appearance', 'admin-plugins', 'plugins-checked', 'admin-users', 'admin-tools', 'admin-settings', 'admin-network', 'admin-home', 'admin-generic', 'admin-collapse', 'filter', 'admin-customizer', 'admin-multisite' ],
31
+            'welcome-screen' => [ 'welcome-write-blog', 'welcome-add-page', 'welcome-view-site', 'welcome-widgets-menus', 'welcome-comments', 'welcome-learn-more' ],
32
+            'post-formats'   => [ 'format-aside', 'format-image', 'format-gallery', 'format-video', 'format-status', 'format-quote', 'format-chat', 'format-audio', 'camera', 'camera-alt', 'images-alt', 'images-alt2', 'video-alt', 'video-alt2', 'video-alt3' ],
33
+            'media'          => [ 'media-archive', 'media-audio', 'media-code', 'media-default', 'media-document', 'media-interactive', 'media-spreadsheet', 'media-text', 'media-video', 'playlist-audio', 'playlist-video', 'controls-play', 'controls-pause', 'controls-forward', 'controls-skipforward', 'controls-back', 'controls-skipback', 'controls-repeat', 'controls-volumeon', 'controls-volumeoff' ],
34
+            'image-editing'  => [ 'image-crop', 'image-rotate', 'image-rotate-left', 'image-rotate-right', 'image-flip-vertical', 'image-flip-horizontal', 'image-filter', 'undo', 'redo' ],
35
+            'tinymce'        => [ 'editor-bold', 'editor-italic', 'editor-ul', 'editor-ol', 'editor-ol-rtl', 'editor-quote', 'editor-alignleft', 'editor-aligncenter', 'editor-alignright', 'editor-insertmore', 'editor-spellcheck', 'editor-expand', 'editor-contract', 'editor-kitchensink', 'editor-underline', 'editor-justify', 'editor-textcolor', 'editor-paste-word', 'editor-paste-text', 'editor-removeformatting', 'editor-video', 'editor-customchar', 'editor-outdent', 'editor-indent', 'editor-help', 'editor-strikethrough', 'editor-unlink', 'editor-rtl', 'editor-ltr', 'editor-break', 'editor-code', 'editor-paragraph', 'editor-table' ],
36
+            'posts'          => [ 'align-left', 'align-right', 'align-center', 'align-none', 'lock', 'unlock', 'calendar', 'calendar-alt', 'visibility', 'hidden', 'post-status', 'edit', 'trash', 'sticky' ],
37
+            'sorting'        => [ 'external', 'arrow-up', 'arrow-down', 'arrow-right', 'arrow-left', 'arrow-up-alt', 'arrow-down-alt', 'arrow-right-alt', 'arrow-left-alt', 'arrow-up-alt2', 'arrow-down-alt2', 'arrow-right-alt2', 'arrow-left-alt2', 'sort', 'leftright', 'randomize', 'list-view', 'exerpt-view', 'grid-view', 'move' ],
38
+            'social'         => [ 'share', 'share-alt', 'share-alt2', 'twitter', 'rss', 'email', 'email-alt', 'email-alt2', 'facebook', 'facebook-alt', 'googleplus', 'networking', 'instagram' ],
39
+            'wordpress_org'  => [ 'hammer', 'art', 'migrate', 'performance', 'universal-access', 'universal-access-alt', 'tickets', 'nametag', 'clipboard', 'heart', 'megaphone', 'schedule', 'tide', 'rest-api', 'code-standards' ],
40
+            'products'       => [ 'wordpress', 'wordpress-alt', 'pressthis', 'update', 'update-alt', 'screenoptions', 'info', 'cart', 'feedback', 'cloud', 'translation' ],
41
+            'taxonomies'     => [ 'tag', 'category' ],
42
+            'widgets'        => [ 'archive', 'tagcloud', 'text' ],
43
+            'notifications'  => [ 'yes', 'yes-alt', 'no', 'no-alt', 'plus', 'plus-alt', 'minus', 'dismiss', 'marker', 'star-filled', 'star-half', 'star-empty', 'flag', 'warning' ],
44
+            'misc'           => [ 'location', 'location-alt', 'vault', 'shield', 'shield-alt', 'sos', 'search', 'slides', 'text-page', 'analytics', 'chart-pie', 'chart-bar', 'chart-line', 'chart-area', 'groups', 'businessman', 'businesswoman', 'businessperson', 'id', 'id-alt', 'products', 'awards', 'forms', 'testimonial', 'portfolio', 'book', 'book-alt', 'download', 'upload', 'backup', 'clock', 'lightbulb', 'microphone', 'desktop', 'tablet', 'smartphone', 'phone', 'index-card', 'carrot', 'building', 'store', 'album', 'palmtree', 'tickets-alt', 'money', 'smiley', 'thumbs-up', 'thumbs-down', 'layout', 'paperclip' ],
45
+        ];
46
+    }
47 47
 }
Please login to merge, or discard this patch.
packages/kirki-framework/control-dashicons/src/Control/Dashicons.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 // Exit if accessed directly.
17 17
 if ( ! defined( 'ABSPATH' ) ) {
18
-	exit;
18
+    exit;
19 19
 }
20 20
 
21 21
 /**
@@ -25,68 +25,68 @@  discard block
 block discarded – undo
25 25
  */
26 26
 class Dashicons extends Base {
27 27
 
28
-	/**
29
-	 * The control type.
30
-	 *
31
-	 * @access public
32
-	 * @since 1.0
33
-	 * @var string
34
-	 */
35
-	public $type = 'kirki-dashicons';
28
+    /**
29
+     * The control type.
30
+     *
31
+     * @access public
32
+     * @since 1.0
33
+     * @var string
34
+     */
35
+    public $type = 'kirki-dashicons';
36 36
 
37
-	/**
38
-	 * The version. Used in scripts & styles for cache-busting.
39
-	 *
40
-	 * @static
41
-	 * @access public
42
-	 * @since 1.0.2
43
-	 * @var string
44
-	 */
45
-	public static $control_ver = '1.0';
37
+    /**
38
+     * The version. Used in scripts & styles for cache-busting.
39
+     *
40
+     * @static
41
+     * @access public
42
+     * @since 1.0.2
43
+     * @var string
44
+     */
45
+    public static $control_ver = '1.0';
46 46
 
47
-	/**
48
-	 * Enqueue control related scripts/styles.
49
-	 *
50
-	 * @access public
51
-	 * @since 1.0
52
-	 * @return void
53
-	 */
54
-	public function enqueue() {
55
-		parent::enqueue();
47
+    /**
48
+     * Enqueue control related scripts/styles.
49
+     *
50
+     * @access public
51
+     * @since 1.0
52
+     * @return void
53
+     */
54
+    public function enqueue() {
55
+        parent::enqueue();
56 56
 
57
-		// Enqueue the script.
58
-		wp_enqueue_script( 'kirki-control-dashicons', URL::get_from_path( dirname(dirname( __DIR__ )) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false );
57
+        // Enqueue the script.
58
+        wp_enqueue_script( 'kirki-control-dashicons', URL::get_from_path( dirname(dirname( __DIR__ )) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base' ], self::$control_ver, false );
59 59
 
60
-		// Enqueue the style.
61
-		wp_enqueue_style( 'kirki-control-dashicons-style', URL::get_from_path( dirname(dirname( __DIR__ )) . '/dist/control.css' ), [ 'dashicons' ], self::$control_ver );
62
-	}
60
+        // Enqueue the style.
61
+        wp_enqueue_style( 'kirki-control-dashicons-style', URL::get_from_path( dirname(dirname( __DIR__ )) . '/dist/control.css' ), [ 'dashicons' ], self::$control_ver );
62
+    }
63 63
 
64
-	/**
65
-	 * Refresh the parameters passed to the JavaScript via JSON.
66
-	 *
67
-	 * @access public
68
-	 * @since 1.0
69
-	 * @return void
70
-	 */
71
-	public function to_json() {
72
-		parent::to_json();
73
-		$this->json['icons'] = \Kirki\Util\Dashicons::get_icons();
74
-	}
64
+    /**
65
+     * Refresh the parameters passed to the JavaScript via JSON.
66
+     *
67
+     * @access public
68
+     * @since 1.0
69
+     * @return void
70
+     */
71
+    public function to_json() {
72
+        parent::to_json();
73
+        $this->json['icons'] = \Kirki\Util\Dashicons::get_icons();
74
+    }
75 75
 
76
-	/**
77
-	 * An Underscore (JS) template for this control's content (but not its container).
78
-	 *
79
-	 * Class variables for this control class are available in the `data` JS object;
80
-	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
81
-	 *
82
-	 * @see WP_Customize_Control::print_template()
83
-	 *
84
-	 * @access protected
85
-	 * @since 1.0
86
-	 * @return void
87
-	 */
88
-	protected function content_template() {
89
-		?>
76
+    /**
77
+     * An Underscore (JS) template for this control's content (but not its container).
78
+     *
79
+     * Class variables for this control class are available in the `data` JS object;
80
+     * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
81
+     *
82
+     * @see WP_Customize_Control::print_template()
83
+     *
84
+     * @access protected
85
+     * @since 1.0
86
+     * @return void
87
+     */
88
+    protected function content_template() {
89
+        ?>
90 90
 		<# if ( data.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #>
91 91
 		<# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #>
92 92
 		<div class="icons-wrapper">
@@ -136,5 +136,5 @@  discard block
 block discarded – undo
136 136
 			<# } #>
137 137
 		</div>
138 138
 		<?php
139
-	}
139
+    }
140 140
 }
Please login to merge, or discard this patch.
includes/kirki-4.0.24/packages/kirki-framework/field/src/Field.php 1 patch
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -21,252 +21,252 @@
 block discarded – undo
21 21
  */
22 22
 abstract class Field {
23 23
 
24
-	/**
25
-	 * The field arguments.
26
-	 *
27
-	 * @access protected
28
-	 * @since 0.1
29
-	 * @var array
30
-	 */
31
-	protected $args;
32
-
33
-	/**
34
-	 * The control class-name.
35
-	 *
36
-	 * Use the full classname, with namespace included.
37
-	 * Example: '\Kirki\Control\Color'.
38
-	 *
39
-	 * @access protected
40
-	 * @since 0.1
41
-	 * @var string
42
-	 */
43
-	protected $control_class;
44
-
45
-	/**
46
-	 * The setting class-name.
47
-	 *
48
-	 * @access protected
49
-	 * @since 0.1
50
-	 * @var string|null
51
-	 */
52
-	protected $settings_class;
53
-
54
-	/**
55
-	 * Whether we should register the control class for JS-templating or not.
56
-	 *
57
-	 * @access protected
58
-	 * @since 0.1
59
-	 * @var bool
60
-	 */
61
-	protected $control_has_js_template = false;
62
-
63
-	/**
64
-	 * Constructor.
65
-	 * Registers any hooks we need to run.
66
-	 *
67
-	 * @access public
68
-	 * @since 0.1
69
-	 * @param array $args The field arguments.
70
-	 */
71
-	public function __construct( $args ) {
72
-
73
-		$control_class = property_exists( $this, 'control_class' ) && ! empty( $this->control_class ) ? $this->control_class : '';
74
-
75
-		// Allow 3rd parties to do their custom "init" work.
76
-		do_action( 'kirki_field_custom_init', $this, $args, $control_class );
77
-
78
-		// Allow 3rd parties to early stop the field from being registered.
79
-		if ( apply_filters( 'kirki_field_exclude_init', false, $this, $args ) ) {
80
-			return;
81
-		}
82
-
83
-		// Set the arguments in this object.
84
-		$this->args = $args;
85
-
86
-		if ( ! isset( $this->args['settings'] ) ) {
87
-			$this->args['settings'] = md5( wp_json_encode( $this->args ) );
88
-		}
89
-
90
-		add_action(
91
-			'wp_loaded',
92
-			function() {
93
-				do_action( 'kirki_field_init', $this->args, $this );
94
-			}
95
-		);
96
-
97
-		add_action(
98
-			'wp',
99
-			function() {
100
-				do_action( 'kirki_field_wp', $this->args, $this );
101
-			}
102
-		);
103
-
104
-		$this->init( $this->args );
105
-
106
-		// Register control-type for JS-templating in the customizer.
107
-		add_action( 'customize_register', [ $this, 'register_control_type' ] );
108
-
109
-		// Add customizer setting.
110
-		add_action( 'customize_register', [ $this, 'add_setting' ] );
111
-
112
-		// Add customizer control.
113
-		add_action( 'customize_register', [ $this, 'add_control' ] );
114
-
115
-		// Add default filters. Can be overriden in child classes.
116
-		add_filter( 'kirki_field_add_setting_args', [ $this, 'filter_setting_args' ], 10, 2 );
117
-		add_filter( 'kirki_field_add_control_args', [ $this, 'filter_control_args' ], 10, 2 );
118
-
119
-		// Copy $this->args to a variable to be added to Kirki::$all_fields global.
120
-		$field_args = $this->args;
121
-
122
-		/**
123
-		 * Kirki::$fields contains only fields which are not extending the new base Field.
124
-		 * So we collect all fields and add them to Kirki::$all_fields.
125
-		 *
126
-		 * ! This patch is used by Kirki::get_option which calls Values::get_value method.
127
-		 * Even though this is a patch, this is fine and still a good solution to handle backwards compatibility.
128
-		 */
129
-		\Kirki\Compatibility\Kirki::$all_fields[ $field_args['settings'] ] = $field_args;
130
-
131
-	}
132
-
133
-	/**
134
-	 * Runs in the constructor. Can be used by child-classes to define extra logic.
135
-	 *
136
-	 * @access protected
137
-	 * @since 0.1
138
-	 * @param array $args The field arguments.
139
-	 * @return void
140
-	 */
141
-	protected function init( $args ) {}
142
-
143
-	/**
144
-	 * Register the control-type.
145
-	 *
146
-	 * @access public
147
-	 * @since 0.1
148
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
149
-	 * @return void
150
-	 */
151
-	public function register_control_type( $wp_customize ) {
152
-
153
-		if ( $this->control_class ) {
154
-			$wp_customize->register_control_type( $this->control_class );
155
-		}
156
-
157
-	}
158
-
159
-	/**
160
-	 * Filter setting args.
161
-	 *
162
-	 * @access public
163
-	 * @since 0.1
164
-	 * @param array                $args         The field arguments.
165
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
166
-	 * @return array
167
-	 */
168
-	public function filter_setting_args( $args, $wp_customize ) {
169
-
170
-		return $args;
171
-
172
-	}
173
-
174
-	/**
175
-	 * Filter control args.
176
-	 *
177
-	 * @access public
178
-	 * @since 0.1
179
-	 * @param array                $args         The field arguments.
180
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
181
-	 * @return array
182
-	 */
183
-	public function filter_control_args( $args, $wp_customize ) {
184
-
185
-		return $args;
186
-
187
-	}
188
-
189
-	/**
190
-	 * Registers the setting.
191
-	 *
192
-	 * @access public
193
-	 * @since 0.1
194
-	 * @param WP_Customize_Manager $customizer The customizer instance.
195
-	 * @return void
196
-	 */
197
-	public function add_setting( $customizer ) {
198
-
199
-		$args = $this->args;
200
-
201
-		// This is for postMessage purpose.
202
-		// @see wp-content/plugins/kirki/packages/kirki-framework/module-postmessage/src/Postmessage.php inside 'field_add_setting_args' method.
203
-		$args['type'] = isset( $this->type ) ? $this->type : '';
204
-
205
-		/**
206
-		 * Allow filtering the arguments.
207
-		 *
208
-		 * @since 0.1
209
-		 * @param array                $this->args The arguments.
210
-		 * @param WP_Customize_Manager $customizer The customizer instance.
211
-		 * @return array                           Return the arguments.
212
-		 */
213
-		$args = apply_filters( 'kirki_field_add_setting_args', $args, $customizer );
214
-
215
-		if ( ! isset( $args['settings'] ) || empty( $args['settings'] ) ) {
216
-			return;
217
-		}
218
-
219
-		$setting_id = $args['settings'];
220
-
221
-		$args = [
222
-			'type'                 => isset( $args['option_type'] ) ? $args['option_type'] : 'theme_mod', // 'type' here doesn't use the $args['type'] but instead checking the $args['option_type'].
223
-			'capability'           => isset( $args['capability'] ) ? $args['capability'] : 'edit_theme_options',
224
-			'theme_supports'       => isset( $args['theme_supports'] ) ? $args['theme_supports'] : '',
225
-			'default'              => isset( $args['default'] ) ? $args['default'] : '',
226
-			'transport'            => isset( $args['transport'] ) ? $args['transport'] : 'refresh',
227
-			'sanitize_callback'    => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : '',
228
-			'sanitize_js_callback' => isset( $args['sanitize_js_callback'] ) ? $args['sanitize_js_callback'] : '',
229
-		];
230
-
231
-		$settings_class = $this->settings_class ? $this->settings_class : null;
232
-
233
-		if ( $settings_class ) {
234
-			$customizer->add_setting( new $settings_class( $customizer, $setting_id, $args ) );
235
-		} else {
236
-			$customizer->add_setting( $setting_id, $args );
237
-		}
238
-
239
-	}
240
-
241
-	/**
242
-	 * Registers the control.
243
-	 *
244
-	 * @access public
245
-	 * @since 0.1
246
-	 * @param WP_Customize_Manager $wp_customize The customizer instance.
247
-	 * @return void
248
-	 */
249
-	public function add_control( $wp_customize ) {
250
-
251
-		$control_class = $this->control_class;
252
-
253
-		// If no class-name is defined, early exit.
254
-		if ( ! $control_class ) {
255
-			return;
256
-		}
257
-
258
-		/**
259
-		 * Allow filtering the arguments.
260
-		 *
261
-		 * @since 0.1
262
-		 * @param array                $this->args   The arguments.
263
-		 * @param WP_Customize_Manager $wp_customize The customizer instance.
264
-		 * @return array                             Return the arguments.
265
-		 */
266
-		$args = apply_filters( 'kirki_field_add_control_args', $this->args, $wp_customize );
267
-
268
-		$wp_customize->add_control( new $control_class( $wp_customize, $this->args['settings'], $args ) );
269
-
270
-	}
24
+    /**
25
+     * The field arguments.
26
+     *
27
+     * @access protected
28
+     * @since 0.1
29
+     * @var array
30
+     */
31
+    protected $args;
32
+
33
+    /**
34
+     * The control class-name.
35
+     *
36
+     * Use the full classname, with namespace included.
37
+     * Example: '\Kirki\Control\Color'.
38
+     *
39
+     * @access protected
40
+     * @since 0.1
41
+     * @var string
42
+     */
43
+    protected $control_class;
44
+
45
+    /**
46
+     * The setting class-name.
47
+     *
48
+     * @access protected
49
+     * @since 0.1
50
+     * @var string|null
51
+     */
52
+    protected $settings_class;
53
+
54
+    /**
55
+     * Whether we should register the control class for JS-templating or not.
56
+     *
57
+     * @access protected
58
+     * @since 0.1
59
+     * @var bool
60
+     */
61
+    protected $control_has_js_template = false;
62
+
63
+    /**
64
+     * Constructor.
65
+     * Registers any hooks we need to run.
66
+     *
67
+     * @access public
68
+     * @since 0.1
69
+     * @param array $args The field arguments.
70
+     */
71
+    public function __construct( $args ) {
72
+
73
+        $control_class = property_exists( $this, 'control_class' ) && ! empty( $this->control_class ) ? $this->control_class : '';
74
+
75
+        // Allow 3rd parties to do their custom "init" work.
76
+        do_action( 'kirki_field_custom_init', $this, $args, $control_class );
77
+
78
+        // Allow 3rd parties to early stop the field from being registered.
79
+        if ( apply_filters( 'kirki_field_exclude_init', false, $this, $args ) ) {
80
+            return;
81
+        }
82
+
83
+        // Set the arguments in this object.
84
+        $this->args = $args;
85
+
86
+        if ( ! isset( $this->args['settings'] ) ) {
87
+            $this->args['settings'] = md5( wp_json_encode( $this->args ) );
88
+        }
89
+
90
+        add_action(
91
+            'wp_loaded',
92
+            function() {
93
+                do_action( 'kirki_field_init', $this->args, $this );
94
+            }
95
+        );
96
+
97
+        add_action(
98
+            'wp',
99
+            function() {
100
+                do_action( 'kirki_field_wp', $this->args, $this );
101
+            }
102
+        );
103
+
104
+        $this->init( $this->args );
105
+
106
+        // Register control-type for JS-templating in the customizer.
107
+        add_action( 'customize_register', [ $this, 'register_control_type' ] );
108
+
109
+        // Add customizer setting.
110
+        add_action( 'customize_register', [ $this, 'add_setting' ] );
111
+
112
+        // Add customizer control.
113
+        add_action( 'customize_register', [ $this, 'add_control' ] );
114
+
115
+        // Add default filters. Can be overriden in child classes.
116
+        add_filter( 'kirki_field_add_setting_args', [ $this, 'filter_setting_args' ], 10, 2 );
117
+        add_filter( 'kirki_field_add_control_args', [ $this, 'filter_control_args' ], 10, 2 );
118
+
119
+        // Copy $this->args to a variable to be added to Kirki::$all_fields global.
120
+        $field_args = $this->args;
121
+
122
+        /**
123
+         * Kirki::$fields contains only fields which are not extending the new base Field.
124
+         * So we collect all fields and add them to Kirki::$all_fields.
125
+         *
126
+         * ! This patch is used by Kirki::get_option which calls Values::get_value method.
127
+         * Even though this is a patch, this is fine and still a good solution to handle backwards compatibility.
128
+         */
129
+        \Kirki\Compatibility\Kirki::$all_fields[ $field_args['settings'] ] = $field_args;
130
+
131
+    }
132
+
133
+    /**
134
+     * Runs in the constructor. Can be used by child-classes to define extra logic.
135
+     *
136
+     * @access protected
137
+     * @since 0.1
138
+     * @param array $args The field arguments.
139
+     * @return void
140
+     */
141
+    protected function init( $args ) {}
142
+
143
+    /**
144
+     * Register the control-type.
145
+     *
146
+     * @access public
147
+     * @since 0.1
148
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
149
+     * @return void
150
+     */
151
+    public function register_control_type( $wp_customize ) {
152
+
153
+        if ( $this->control_class ) {
154
+            $wp_customize->register_control_type( $this->control_class );
155
+        }
156
+
157
+    }
158
+
159
+    /**
160
+     * Filter setting args.
161
+     *
162
+     * @access public
163
+     * @since 0.1
164
+     * @param array                $args         The field arguments.
165
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
166
+     * @return array
167
+     */
168
+    public function filter_setting_args( $args, $wp_customize ) {
169
+
170
+        return $args;
171
+
172
+    }
173
+
174
+    /**
175
+     * Filter control args.
176
+     *
177
+     * @access public
178
+     * @since 0.1
179
+     * @param array                $args         The field arguments.
180
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
181
+     * @return array
182
+     */
183
+    public function filter_control_args( $args, $wp_customize ) {
184
+
185
+        return $args;
186
+
187
+    }
188
+
189
+    /**
190
+     * Registers the setting.
191
+     *
192
+     * @access public
193
+     * @since 0.1
194
+     * @param WP_Customize_Manager $customizer The customizer instance.
195
+     * @return void
196
+     */
197
+    public function add_setting( $customizer ) {
198
+
199
+        $args = $this->args;
200
+
201
+        // This is for postMessage purpose.
202
+        // @see wp-content/plugins/kirki/packages/kirki-framework/module-postmessage/src/Postmessage.php inside 'field_add_setting_args' method.
203
+        $args['type'] = isset( $this->type ) ? $this->type : '';
204
+
205
+        /**
206
+         * Allow filtering the arguments.
207
+         *
208
+         * @since 0.1
209
+         * @param array                $this->args The arguments.
210
+         * @param WP_Customize_Manager $customizer The customizer instance.
211
+         * @return array                           Return the arguments.
212
+         */
213
+        $args = apply_filters( 'kirki_field_add_setting_args', $args, $customizer );
214
+
215
+        if ( ! isset( $args['settings'] ) || empty( $args['settings'] ) ) {
216
+            return;
217
+        }
218
+
219
+        $setting_id = $args['settings'];
220
+
221
+        $args = [
222
+            'type'                 => isset( $args['option_type'] ) ? $args['option_type'] : 'theme_mod', // 'type' here doesn't use the $args['type'] but instead checking the $args['option_type'].
223
+            'capability'           => isset( $args['capability'] ) ? $args['capability'] : 'edit_theme_options',
224
+            'theme_supports'       => isset( $args['theme_supports'] ) ? $args['theme_supports'] : '',
225
+            'default'              => isset( $args['default'] ) ? $args['default'] : '',
226
+            'transport'            => isset( $args['transport'] ) ? $args['transport'] : 'refresh',
227
+            'sanitize_callback'    => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : '',
228
+            'sanitize_js_callback' => isset( $args['sanitize_js_callback'] ) ? $args['sanitize_js_callback'] : '',
229
+        ];
230
+
231
+        $settings_class = $this->settings_class ? $this->settings_class : null;
232
+
233
+        if ( $settings_class ) {
234
+            $customizer->add_setting( new $settings_class( $customizer, $setting_id, $args ) );
235
+        } else {
236
+            $customizer->add_setting( $setting_id, $args );
237
+        }
238
+
239
+    }
240
+
241
+    /**
242
+     * Registers the control.
243
+     *
244
+     * @access public
245
+     * @since 0.1
246
+     * @param WP_Customize_Manager $wp_customize The customizer instance.
247
+     * @return void
248
+     */
249
+    public function add_control( $wp_customize ) {
250
+
251
+        $control_class = $this->control_class;
252
+
253
+        // If no class-name is defined, early exit.
254
+        if ( ! $control_class ) {
255
+            return;
256
+        }
257
+
258
+        /**
259
+         * Allow filtering the arguments.
260
+         *
261
+         * @since 0.1
262
+         * @param array                $this->args   The arguments.
263
+         * @param WP_Customize_Manager $wp_customize The customizer instance.
264
+         * @return array                             Return the arguments.
265
+         */
266
+        $args = apply_filters( 'kirki_field_add_control_args', $this->args, $wp_customize );
267
+
268
+        $wp_customize->add_control( new $control_class( $wp_customize, $this->args['settings'], $args ) );
269
+
270
+    }
271 271
 
272 272
 }
Please login to merge, or discard this patch.
includes/kirki-4.0.24/packages/kirki-framework/module-panels/src/Panel.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -16,120 +16,120 @@
 block discarded – undo
16 16
  */
17 17
 class Panel {
18 18
 
19
-	/**
20
-	 * The panel ID.
21
-	 *
22
-	 * @access protected
23
-	 * @since 1.0
24
-	 * @var string
25
-	 */
26
-	protected $id;
27
-
28
-	/**
29
-	 * The panel arguments.
30
-	 *
31
-	 * @access protected
32
-	 * @since 1.0
33
-	 * @var array
34
-	 */
35
-	protected $args;
36
-
37
-	/**
38
-	 * An array of our panel types.
39
-	 *
40
-	 * @access private
41
-	 * @var array
42
-	 */
43
-	private $panel_types = [
44
-		'default'      => 'WP_Customize_Panel',
45
-		'kirki-nested' => '\Kirki\Panel_Types\Nested',
46
-	];
47
-
48
-	/**
49
-	 * Constructor.
50
-	 *
51
-	 * @access public
52
-	 * @since 1.0
53
-	 * @param string $id   The panel ID.
54
-	 * @param array  $args The panel args.
55
-	 */
56
-	public function __construct( $id, $args = [] ) {
57
-		$this->id   = $id;
58
-		$this->args = $args;
59
-
60
-		$this->panel_types = apply_filters( 'kirki_panel_types', $this->panel_types );
61
-
62
-		if ( $this->args ) {
63
-			add_action( 'customize_register', [ $this, 'add_panel' ] );
64
-		}
65
-		add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_scrips' ] );
66
-	}
67
-
68
-	/**
69
-	 * Add the panel using the Customizer API.
70
-	 *
71
-	 * @access public
72
-	 * @since 1.0
73
-	 * @param object $wp_customize The customizer object.
74
-	 */
75
-	public function add_panel( $wp_customize ) {
76
-
77
-		// Figure out the type of this panel.
78
-		$this->args['type'] = isset( $this->args['type'] ) ? $this->args['type'] : 'default';
79
-		if ( isset( $this->args['panel'] ) && ! empty( $this->args['panel'] ) ) {
80
-			$this->args['type'] = 'kirki-nested';
81
-		}
82
-		$this->args['type'] = false === strpos( $this->args['type'], 'kirki-' ) ? 'kirki-' . $this->args['type'] : $this->args['type'];
83
-		$this->args['type'] = 'kirki-default' === $this->args['type'] ? 'default' : $this->args['type'];
84
-
85
-		// Get the class we'll be using to create this panel.
86
-		$panel_classname = $this->panel_types[ $this->args['type'] ];
87
-
88
-		// Fallback to the default panel type if the custom class doesn't exist.
89
-		$panel_classname = class_exists( $panel_classname ) ? $panel_classname : 'WP_Customize_Panel';
90
-
91
-		// Add the panel.
92
-		$wp_customize->add_panel(
93
-			new $panel_classname(
94
-				$wp_customize,
95
-				$this->id,
96
-				apply_filters( 'kirki_panel_args', $this->args, $this->id )
97
-			)
98
-		);
99
-
100
-		// Run an action after the panel has been added.
101
-		do_action( 'kirki_panel_added', $this->id, $this->args );
102
-	}
103
-
104
-	/**
105
-	 * Removes the panel.
106
-	 *
107
-	 * @access public
108
-	 * @since 1.0
109
-	 * @return void
110
-	 */
111
-	public function remove() {
112
-		add_action( 'customize_register', [ $this, 'remove_panel' ], 9999 );
113
-	}
114
-
115
-	/**
116
-	 * Add the panel using the Customizer API.
117
-	 *
118
-	 * @access public
119
-	 * @since 1.0
120
-	 * @param object $wp_customize The customizer object.
121
-	 */
122
-	public function remove_panel( $wp_customize ) {
123
-		$wp_customize->remove_panel( $this->id );
124
-	}
19
+    /**
20
+     * The panel ID.
21
+     *
22
+     * @access protected
23
+     * @since 1.0
24
+     * @var string
25
+     */
26
+    protected $id;
27
+
28
+    /**
29
+     * The panel arguments.
30
+     *
31
+     * @access protected
32
+     * @since 1.0
33
+     * @var array
34
+     */
35
+    protected $args;
36
+
37
+    /**
38
+     * An array of our panel types.
39
+     *
40
+     * @access private
41
+     * @var array
42
+     */
43
+    private $panel_types = [
44
+        'default'      => 'WP_Customize_Panel',
45
+        'kirki-nested' => '\Kirki\Panel_Types\Nested',
46
+    ];
47
+
48
+    /**
49
+     * Constructor.
50
+     *
51
+     * @access public
52
+     * @since 1.0
53
+     * @param string $id   The panel ID.
54
+     * @param array  $args The panel args.
55
+     */
56
+    public function __construct( $id, $args = [] ) {
57
+        $this->id   = $id;
58
+        $this->args = $args;
59
+
60
+        $this->panel_types = apply_filters( 'kirki_panel_types', $this->panel_types );
61
+
62
+        if ( $this->args ) {
63
+            add_action( 'customize_register', [ $this, 'add_panel' ] );
64
+        }
65
+        add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_scrips' ] );
66
+    }
67
+
68
+    /**
69
+     * Add the panel using the Customizer API.
70
+     *
71
+     * @access public
72
+     * @since 1.0
73
+     * @param object $wp_customize The customizer object.
74
+     */
75
+    public function add_panel( $wp_customize ) {
76
+
77
+        // Figure out the type of this panel.
78
+        $this->args['type'] = isset( $this->args['type'] ) ? $this->args['type'] : 'default';
79
+        if ( isset( $this->args['panel'] ) && ! empty( $this->args['panel'] ) ) {
80
+            $this->args['type'] = 'kirki-nested';
81
+        }
82
+        $this->args['type'] = false === strpos( $this->args['type'], 'kirki-' ) ? 'kirki-' . $this->args['type'] : $this->args['type'];
83
+        $this->args['type'] = 'kirki-default' === $this->args['type'] ? 'default' : $this->args['type'];
84
+
85
+        // Get the class we'll be using to create this panel.
86
+        $panel_classname = $this->panel_types[ $this->args['type'] ];
87
+
88
+        // Fallback to the default panel type if the custom class doesn't exist.
89
+        $panel_classname = class_exists( $panel_classname ) ? $panel_classname : 'WP_Customize_Panel';
90
+
91
+        // Add the panel.
92
+        $wp_customize->add_panel(
93
+            new $panel_classname(
94
+                $wp_customize,
95
+                $this->id,
96
+                apply_filters( 'kirki_panel_args', $this->args, $this->id )
97
+            )
98
+        );
99
+
100
+        // Run an action after the panel has been added.
101
+        do_action( 'kirki_panel_added', $this->id, $this->args );
102
+    }
103
+
104
+    /**
105
+     * Removes the panel.
106
+     *
107
+     * @access public
108
+     * @since 1.0
109
+     * @return void
110
+     */
111
+    public function remove() {
112
+        add_action( 'customize_register', [ $this, 'remove_panel' ], 9999 );
113
+    }
114
+
115
+    /**
116
+     * Add the panel using the Customizer API.
117
+     *
118
+     * @access public
119
+     * @since 1.0
120
+     * @param object $wp_customize The customizer object.
121
+     */
122
+    public function remove_panel( $wp_customize ) {
123
+        $wp_customize->remove_panel( $this->id );
124
+    }
125 125
 	
126
-	/**
127
-	 * Enqueues any necessary scripts and styles.
128
-	 *
129
-	 * @access public
130
-	 * @since 1.0
131
-	 */
132
-	public function enqueue_scrips() {
133
-		wp_enqueue_script( 'kirki-panels', URL::get_from_path( __DIR__ . '/script.js' ), [ 'jquery', 'customize-base', 'customize-controls' ], '1.0', false );
134
-	}
126
+    /**
127
+     * Enqueues any necessary scripts and styles.
128
+     *
129
+     * @access public
130
+     * @since 1.0
131
+     */
132
+    public function enqueue_scrips() {
133
+        wp_enqueue_script( 'kirki-panels', URL::get_from_path( __DIR__ . '/script.js' ), [ 'jquery', 'customize-base', 'customize-controls' ], '1.0', false );
134
+    }
135 135
 }
Please login to merge, or discard this patch.
packages/kirki-framework/module-panels/src/Panel_Types/Nested.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -16,48 +16,48 @@
 block discarded – undo
16 16
  */
17 17
 class Nested extends \WP_Customize_Panel {
18 18
 
19
-	/**
20
-	 * The parent panel.
21
-	 *
22
-	 * @access public
23
-	 * @since 3.0.0
24
-	 * @var string
25
-	 */
26
-	public $panel;
19
+    /**
20
+     * The parent panel.
21
+     *
22
+     * @access public
23
+     * @since 3.0.0
24
+     * @var string
25
+     */
26
+    public $panel;
27 27
 
28
-	/**
29
-	 * Type of this panel.
30
-	 *
31
-	 * @access public
32
-	 * @since 3.0.0
33
-	 * @var string
34
-	 */
35
-	public $type = 'kirki-nested';
28
+    /**
29
+     * Type of this panel.
30
+     *
31
+     * @access public
32
+     * @since 3.0.0
33
+     * @var string
34
+     */
35
+    public $type = 'kirki-nested';
36 36
 
37
-	/**
38
-	 * Gather the parameters passed to client JavaScript via JSON.
39
-	 *
40
-	 * @access public
41
-	 * @since 3.0.0
42
-	 * @return array The array to be exported to the client as JSON.
43
-	 */
44
-	public function json() {
45
-		$array = wp_array_slice_assoc(
46
-			(array) $this,
47
-			[
48
-				'id',
49
-				'description',
50
-				'priority',
51
-				'type',
52
-				'panel',
53
-			]
54
-		);
37
+    /**
38
+     * Gather the parameters passed to client JavaScript via JSON.
39
+     *
40
+     * @access public
41
+     * @since 3.0.0
42
+     * @return array The array to be exported to the client as JSON.
43
+     */
44
+    public function json() {
45
+        $array = wp_array_slice_assoc(
46
+            (array) $this,
47
+            [
48
+                'id',
49
+                'description',
50
+                'priority',
51
+                'type',
52
+                'panel',
53
+            ]
54
+        );
55 55
 
56
-		$array['title']          = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) );
57
-		$array['content']        = $this->get_content();
58
-		$array['active']         = $this->active();
59
-		$array['instanceNumber'] = $this->instance_number;
56
+        $array['title']          = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) );
57
+        $array['content']        = $this->get_content();
58
+        $array['active']         = $this->active();
59
+        $array['instanceNumber'] = $this->instance_number;
60 60
 
61
-		return $array;
62
-	}
61
+        return $array;
62
+    }
63 63
 }
Please login to merge, or discard this patch.
kirki-4.0.24/packages/kirki-framework/module-css/src/CSS/Property.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -17,50 +17,50 @@
 block discarded – undo
17 17
  */
18 18
 class Property {
19 19
 
20
-	/**
21
-	 * The property we're modifying.
22
-	 *
23
-	 * @access protected
24
-	 * @var string
25
-	 */
26
-	protected $property;
20
+    /**
21
+     * The property we're modifying.
22
+     *
23
+     * @access protected
24
+     * @var string
25
+     */
26
+    protected $property;
27 27
 
28
-	/**
29
-	 * The value
30
-	 *
31
-	 * @access protected
32
-	 * @var string|array
33
-	 */
34
-	protected $value;
28
+    /**
29
+     * The value
30
+     *
31
+     * @access protected
32
+     * @var string|array
33
+     */
34
+    protected $value;
35 35
 
36
-	/**
37
-	 * Constructor.
38
-	 *
39
-	 * @access public
40
-	 * @param string $property The CSS property we're modifying.
41
-	 * @param mixed  $value    The value.
42
-	 */
43
-	public function __construct( $property, $value ) {
44
-		$this->property = $property;
45
-		$this->value    = $value;
46
-		$this->process_value();
47
-	}
36
+    /**
37
+     * Constructor.
38
+     *
39
+     * @access public
40
+     * @param string $property The CSS property we're modifying.
41
+     * @param mixed  $value    The value.
42
+     */
43
+    public function __construct( $property, $value ) {
44
+        $this->property = $property;
45
+        $this->value    = $value;
46
+        $this->process_value();
47
+    }
48 48
 
49
-	/**
50
-	 * Modifies the value.
51
-	 *
52
-	 * @access protected
53
-	 */
54
-	protected function process_value() {
49
+    /**
50
+     * Modifies the value.
51
+     *
52
+     * @access protected
53
+     */
54
+    protected function process_value() {
55 55
 
56
-	}
56
+    }
57 57
 
58
-	/**
59
-	 * Gets the value.
60
-	 *
61
-	 * @access protected
62
-	 */
63
-	public function get_value() {
64
-		return $this->value;
65
-	}
58
+    /**
59
+     * Gets the value.
60
+     *
61
+     * @access protected
62
+     */
63
+    public function get_value() {
64
+        return $this->value;
65
+    }
66 66
 }
Please login to merge, or discard this patch.
kirki-4.0.24/packages/kirki-framework/module-css/src/CSS/Generator.php 1 patch
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 
18 18
 // Exit if accessed directly.
19 19
 if ( ! defined( 'ABSPATH' ) ) {
20
-	exit;
20
+    exit;
21 21
 }
22 22
 
23 23
 /**
@@ -25,262 +25,262 @@  discard block
 block discarded – undo
25 25
  */
26 26
 final class Generator {
27 27
 
28
-	/**
29
-	 * The instance of this class (singleton pattern).
30
-	 *
31
-	 * @static
32
-	 * @access public
33
-	 * @var null|object
34
-	 */
35
-	public static $instance = null;
36
-
37
-	/**
38
-	 * Settings.
39
-	 *
40
-	 * @static
41
-	 * @access public
42
-	 * @var null|string|array
43
-	 */
44
-	public static $settings = null;
45
-
46
-	/**
47
-	 * Output.
48
-	 *
49
-	 * @static
50
-	 * @access public
51
-	 * @var array
52
-	 */
53
-	public static $output = [];
54
-
55
-	/**
56
-	 * Callback.
57
-	 *
58
-	 * @static
59
-	 * @access public
60
-	 * @var null|string|array
61
-	 */
62
-	public static $callback = null;
63
-
64
-	/**
65
-	 * Option Name.
66
-	 *
67
-	 * @static
68
-	 * @access public
69
-	 * @var null|string
70
-	 */
71
-	public static $option_name = null;
72
-
73
-	/**
74
-	 * Field Type.
75
-	 *
76
-	 * @static
77
-	 * @access public
78
-	 * @var string
79
-	 */
80
-	public static $field_type = null;
81
-
82
-	/**
83
-	 * Google Fonts
84
-	 *
85
-	 * @static
86
-	 * @access public
87
-	 * @var array
88
-	 */
89
-	public static $google_fonts = null;
90
-
91
-	/**
92
-	 * CSS
93
-	 *
94
-	 * @static
95
-	 * @access public
96
-	 * @var string
97
-	 */
98
-	public static $css;
99
-
100
-	/**
101
-	 * Value
102
-	 *
103
-	 * @static
104
-	 * @access public
105
-	 * @var mixed
106
-	 */
107
-	public static $value = null;
108
-
109
-	/**
110
-	 * The class constructor.
111
-	 */
112
-	private function __construct() {
113
-		if ( is_null( self::$google_fonts ) ) {
114
-			self::$google_fonts = Fonts::get_google_fonts();
115
-		}
116
-	}
117
-
118
-	/**
119
-	 * Get a single instance of this class
120
-	 *
121
-	 * @return object
122
-	 */
123
-	public static function get_instance() {
124
-		if ( null === self::$instance ) {
125
-			self::$instance = new self();
126
-		}
127
-		return self::$instance;
128
-	}
129
-
130
-	/**
131
-	 * Get the CSS for a field.
132
-	 *
133
-	 * @static
134
-	 * @access public
135
-	 * @param array $field The field.
136
-	 * @return array
137
-	 */
138
-	public static function css( $field ) {
139
-
140
-		// Set class vars.
141
-		self::$settings   = $field['settings'];
142
-		self::$callback   = isset( $field['sanitize_callback'] ) ? $field['sanitize_callback'] : '';
143
-		self::$field_type = $field['type'];
144
-		self::$field_type = ( isset( $field['choices'] ) && isset( $field['choices']['parent_type'] ) ) ? $field['choices']['parent_type'] : self::$field_type;
145
-		self::$output     = $field['output'];
146
-
147
-		$field['kirki_config'] = isset( $field['kirki_config'] ) ? $field['kirki_config'] : 'global';
148
-
149
-		if ( ! is_array( self::$output ) ) {
150
-			self::$output = [
151
-				[
152
-					'element'           => self::$output,
153
-					'sanitize_callback' => null,
154
-				],
155
-			];
156
-		}
157
-
158
-		// Get the value of this field.
159
-		$option_type  = ( isset( $field['option_type'] ) ) ? $field['option_type'] : 'theme_mod';
160
-		$default      = ( isset( $field['default'] ) ) ? $field['default'] : '';
161
-		$setting_name = $field['settings'];
162
-
163
-		if ( 'option' === $option_type ) {
164
-			if ( ! empty( $field['option_name'] ) && 0 !== stripos( $setting_name, $field['option_name'] . '[' ) ) {
165
-				$setting_name = $field['option_name'] . '[' . $field['settings'] . ']';
166
-			}
167
-		}
168
-
169
-		self::$value = apply_filters( 'kirki_get_value', get_theme_mod( $field['settings'], $default ), $setting_name, $default, $option_type );
170
-
171
-		// Find the class that will handle the outpout for this field.
172
-		$classname            = '\Kirki\Module\CSS\Output';
173
-		$field_output_classes = apply_filters( 'kirki_output_control_classnames', [] );
174
-		$field_output_classes = apply_filters( "kirki_{$field['kirki_config']}_output_control_classnames", $field_output_classes );
175
-		if ( array_key_exists( self::$field_type, $field_output_classes ) ) {
176
-			$classname = $field_output_classes[ self::$field_type ];
177
-		}
178
-		$obj = new $classname( $field['kirki_config'], self::$output, self::$value, $field );
179
-		return $obj->get_styles();
180
-	}
181
-
182
-	/**
183
-	 * Gets the array of generated styles and creates the minimized, inline CSS.
184
-	 *
185
-	 * @static
186
-	 * @access public
187
-	 * @param array $css The CSS definitions array.
188
-	 * @return string    The generated CSS.
189
-	 */
190
-	public static function styles_parse( $css = [] ) {
191
-
192
-		// Pass our styles from the kirki_styles_array filter.
193
-		$css = apply_filters( 'kirki_styles_array', $css );
194
-
195
-		// Process the array of CSS properties and produce the final CSS.
196
-		$final_css = '';
197
-
198
-		if ( ! is_array( $css ) || empty( $css ) ) {
199
-			return '';
200
-		}
201
-
202
-		foreach ( $css as $media_query => $styles ) {
203
-			$final_css .= ( 'global' !== $media_query ) ? $media_query . '{' : '';
204
-			foreach ( $styles as $style => $style_array ) {
205
-				$css_for_style = '';
206
-
207
-				foreach ( $style_array as $property => $value ) {
208
-					if ( is_string( $value ) && '' !== $value ) {
209
-						$css_for_style .= $property . ':' . $value . ';';
210
-					} elseif ( is_array( $value ) ) {
211
-						foreach ( $value as $subvalue ) {
212
-							if ( is_string( $subvalue ) && '' !== $subvalue ) {
213
-								$css_for_style .= $property . ':' . $subvalue . ';';
214
-							}
215
-						}
216
-					}
217
-					$value = ( is_string( $value ) ) ? $value : '';
218
-				}
219
-
220
-				if ( '' !== $css_for_style ) {
221
-					$final_css .= $style . '{' . $css_for_style . '}';
222
-				}
223
-			}
224
-
225
-			$final_css .= ( 'global' !== $media_query ) ? '}' : '';
226
-		}
227
-
228
-		return $final_css;
229
-	}
230
-
231
-	/**
232
-	 * Add prefixes if necessary.
233
-	 *
234
-	 * @param  array $css The CSS definitions array.
235
-	 * @return array
236
-	 */
237
-	public static function add_prefixes( $css ) {
238
-		if ( is_array( $css ) ) {
239
-			foreach ( $css as $media_query => $elements ) {
240
-				foreach ( $elements as $element => $style_array ) {
241
-					foreach ( $style_array as $property => $value ) {
242
-
243
-						// Add -webkit-* and -moz-*.
244
-						if ( is_string( $property ) && in_array(
245
-							$property,
246
-							[
247
-								'border-radius',
248
-								'box-shadow',
249
-								'box-sizing',
250
-								'text-shadow',
251
-								'transform',
252
-								'background-size',
253
-								'transition',
254
-								'transition-property',
255
-							],
256
-							true
257
-						) ) {
258
-							unset( $css[ $media_query ][ $element ][ $property ] );
259
-							$css[ $media_query ][ $element ][ '-webkit-' . $property ] = $value;
260
-							$css[ $media_query ][ $element ][ '-moz-' . $property ]    = $value;
261
-							$css[ $media_query ][ $element ][ $property ]              = $value;
262
-						}
263
-
264
-						// Add -ms-* and -o-*.
265
-						if ( is_string( $property ) && in_array(
266
-							$property,
267
-							[
268
-								'transform',
269
-								'background-size',
270
-								'transition',
271
-								'transition-property',
272
-							],
273
-							true
274
-						) ) {
275
-							unset( $css[ $media_query ][ $element ][ $property ] );
276
-							$css[ $media_query ][ $element ][ '-ms-' . $property ] = $value;
277
-							$css[ $media_query ][ $element ][ '-o-' . $property ]  = $value;
278
-							$css[ $media_query ][ $element ][ $property ]          = $value;
279
-						}
280
-					}
281
-				}
282
-			}
283
-		}
284
-		return $css;
285
-	}
28
+    /**
29
+     * The instance of this class (singleton pattern).
30
+     *
31
+     * @static
32
+     * @access public
33
+     * @var null|object
34
+     */
35
+    public static $instance = null;
36
+
37
+    /**
38
+     * Settings.
39
+     *
40
+     * @static
41
+     * @access public
42
+     * @var null|string|array
43
+     */
44
+    public static $settings = null;
45
+
46
+    /**
47
+     * Output.
48
+     *
49
+     * @static
50
+     * @access public
51
+     * @var array
52
+     */
53
+    public static $output = [];
54
+
55
+    /**
56
+     * Callback.
57
+     *
58
+     * @static
59
+     * @access public
60
+     * @var null|string|array
61
+     */
62
+    public static $callback = null;
63
+
64
+    /**
65
+     * Option Name.
66
+     *
67
+     * @static
68
+     * @access public
69
+     * @var null|string
70
+     */
71
+    public static $option_name = null;
72
+
73
+    /**
74
+     * Field Type.
75
+     *
76
+     * @static
77
+     * @access public
78
+     * @var string
79
+     */
80
+    public static $field_type = null;
81
+
82
+    /**
83
+     * Google Fonts
84
+     *
85
+     * @static
86
+     * @access public
87
+     * @var array
88
+     */
89
+    public static $google_fonts = null;
90
+
91
+    /**
92
+     * CSS
93
+     *
94
+     * @static
95
+     * @access public
96
+     * @var string
97
+     */
98
+    public static $css;
99
+
100
+    /**
101
+     * Value
102
+     *
103
+     * @static
104
+     * @access public
105
+     * @var mixed
106
+     */
107
+    public static $value = null;
108
+
109
+    /**
110
+     * The class constructor.
111
+     */
112
+    private function __construct() {
113
+        if ( is_null( self::$google_fonts ) ) {
114
+            self::$google_fonts = Fonts::get_google_fonts();
115
+        }
116
+    }
117
+
118
+    /**
119
+     * Get a single instance of this class
120
+     *
121
+     * @return object
122
+     */
123
+    public static function get_instance() {
124
+        if ( null === self::$instance ) {
125
+            self::$instance = new self();
126
+        }
127
+        return self::$instance;
128
+    }
129
+
130
+    /**
131
+     * Get the CSS for a field.
132
+     *
133
+     * @static
134
+     * @access public
135
+     * @param array $field The field.
136
+     * @return array
137
+     */
138
+    public static function css( $field ) {
139
+
140
+        // Set class vars.
141
+        self::$settings   = $field['settings'];
142
+        self::$callback   = isset( $field['sanitize_callback'] ) ? $field['sanitize_callback'] : '';
143
+        self::$field_type = $field['type'];
144
+        self::$field_type = ( isset( $field['choices'] ) && isset( $field['choices']['parent_type'] ) ) ? $field['choices']['parent_type'] : self::$field_type;
145
+        self::$output     = $field['output'];
146
+
147
+        $field['kirki_config'] = isset( $field['kirki_config'] ) ? $field['kirki_config'] : 'global';
148
+
149
+        if ( ! is_array( self::$output ) ) {
150
+            self::$output = [
151
+                [
152
+                    'element'           => self::$output,
153
+                    'sanitize_callback' => null,
154
+                ],
155
+            ];
156
+        }
157
+
158
+        // Get the value of this field.
159
+        $option_type  = ( isset( $field['option_type'] ) ) ? $field['option_type'] : 'theme_mod';
160
+        $default      = ( isset( $field['default'] ) ) ? $field['default'] : '';
161
+        $setting_name = $field['settings'];
162
+
163
+        if ( 'option' === $option_type ) {
164
+            if ( ! empty( $field['option_name'] ) && 0 !== stripos( $setting_name, $field['option_name'] . '[' ) ) {
165
+                $setting_name = $field['option_name'] . '[' . $field['settings'] . ']';
166
+            }
167
+        }
168
+
169
+        self::$value = apply_filters( 'kirki_get_value', get_theme_mod( $field['settings'], $default ), $setting_name, $default, $option_type );
170
+
171
+        // Find the class that will handle the outpout for this field.
172
+        $classname            = '\Kirki\Module\CSS\Output';
173
+        $field_output_classes = apply_filters( 'kirki_output_control_classnames', [] );
174
+        $field_output_classes = apply_filters( "kirki_{$field['kirki_config']}_output_control_classnames", $field_output_classes );
175
+        if ( array_key_exists( self::$field_type, $field_output_classes ) ) {
176
+            $classname = $field_output_classes[ self::$field_type ];
177
+        }
178
+        $obj = new $classname( $field['kirki_config'], self::$output, self::$value, $field );
179
+        return $obj->get_styles();
180
+    }
181
+
182
+    /**
183
+     * Gets the array of generated styles and creates the minimized, inline CSS.
184
+     *
185
+     * @static
186
+     * @access public
187
+     * @param array $css The CSS definitions array.
188
+     * @return string    The generated CSS.
189
+     */
190
+    public static function styles_parse( $css = [] ) {
191
+
192
+        // Pass our styles from the kirki_styles_array filter.
193
+        $css = apply_filters( 'kirki_styles_array', $css );
194
+
195
+        // Process the array of CSS properties and produce the final CSS.
196
+        $final_css = '';
197
+
198
+        if ( ! is_array( $css ) || empty( $css ) ) {
199
+            return '';
200
+        }
201
+
202
+        foreach ( $css as $media_query => $styles ) {
203
+            $final_css .= ( 'global' !== $media_query ) ? $media_query . '{' : '';
204
+            foreach ( $styles as $style => $style_array ) {
205
+                $css_for_style = '';
206
+
207
+                foreach ( $style_array as $property => $value ) {
208
+                    if ( is_string( $value ) && '' !== $value ) {
209
+                        $css_for_style .= $property . ':' . $value . ';';
210
+                    } elseif ( is_array( $value ) ) {
211
+                        foreach ( $value as $subvalue ) {
212
+                            if ( is_string( $subvalue ) && '' !== $subvalue ) {
213
+                                $css_for_style .= $property . ':' . $subvalue . ';';
214
+                            }
215
+                        }
216
+                    }
217
+                    $value = ( is_string( $value ) ) ? $value : '';
218
+                }
219
+
220
+                if ( '' !== $css_for_style ) {
221
+                    $final_css .= $style . '{' . $css_for_style . '}';
222
+                }
223
+            }
224
+
225
+            $final_css .= ( 'global' !== $media_query ) ? '}' : '';
226
+        }
227
+
228
+        return $final_css;
229
+    }
230
+
231
+    /**
232
+     * Add prefixes if necessary.
233
+     *
234
+     * @param  array $css The CSS definitions array.
235
+     * @return array
236
+     */
237
+    public static function add_prefixes( $css ) {
238
+        if ( is_array( $css ) ) {
239
+            foreach ( $css as $media_query => $elements ) {
240
+                foreach ( $elements as $element => $style_array ) {
241
+                    foreach ( $style_array as $property => $value ) {
242
+
243
+                        // Add -webkit-* and -moz-*.
244
+                        if ( is_string( $property ) && in_array(
245
+                            $property,
246
+                            [
247
+                                'border-radius',
248
+                                'box-shadow',
249
+                                'box-sizing',
250
+                                'text-shadow',
251
+                                'transform',
252
+                                'background-size',
253
+                                'transition',
254
+                                'transition-property',
255
+                            ],
256
+                            true
257
+                        ) ) {
258
+                            unset( $css[ $media_query ][ $element ][ $property ] );
259
+                            $css[ $media_query ][ $element ][ '-webkit-' . $property ] = $value;
260
+                            $css[ $media_query ][ $element ][ '-moz-' . $property ]    = $value;
261
+                            $css[ $media_query ][ $element ][ $property ]              = $value;
262
+                        }
263
+
264
+                        // Add -ms-* and -o-*.
265
+                        if ( is_string( $property ) && in_array(
266
+                            $property,
267
+                            [
268
+                                'transform',
269
+                                'background-size',
270
+                                'transition',
271
+                                'transition-property',
272
+                            ],
273
+                            true
274
+                        ) ) {
275
+                            unset( $css[ $media_query ][ $element ][ $property ] );
276
+                            $css[ $media_query ][ $element ][ '-ms-' . $property ] = $value;
277
+                            $css[ $media_query ][ $element ][ '-o-' . $property ]  = $value;
278
+                            $css[ $media_query ][ $element ][ $property ]          = $value;
279
+                        }
280
+                    }
281
+                }
282
+            }
283
+        }
284
+        return $css;
285
+    }
286 286
 }
Please login to merge, or discard this patch.
kirki-4.0.24/packages/kirki-framework/module-css/src/CSS/Output.php 1 patch
Indentation   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -19,359 +19,359 @@
 block discarded – undo
19 19
  */
20 20
 class Output {
21 21
 
22
-	/**
23
-	 * The field's `output` argument.
24
-	 *
25
-	 * @access protected
26
-	 * @var array
27
-	 */
28
-	protected $output = [];
29
-
30
-	/**
31
-	 * An array of the generated styles.
32
-	 *
33
-	 * @access protected
34
-	 * @var array
35
-	 */
36
-	protected $styles = [];
37
-
38
-	/**
39
-	 * The field.
40
-	 *
41
-	 * @access protected
42
-	 * @var array
43
-	 */
44
-	protected $field = [];
45
-
46
-	/**
47
-	 * The value.
48
-	 *
49
-	 * @access protected
50
-	 * @var string|array
51
-	 */
52
-	protected $value;
53
-
54
-	/**
55
-	 * The class constructor.
56
-	 *
57
-	 * @access public
58
-	 * @param string       $config_id The config ID.
59
-	 * @param array        $output    The output argument.
60
-	 * @param string|array $value     The value.
61
-	 * @param array        $field     The field.
62
-	 */
63
-	public function __construct( $config_id, $output, $value, $field ) {
64
-		$this->value  = $value;
65
-		$this->output = $output;
66
-		$this->field  = $field;
67
-
68
-		$this->parse_output();
69
-	}
70
-
71
-	/**
72
-	 * If we have a sanitize_callback defined, apply it to the value.
73
-	 *
74
-	 * @param array        $output The output args.
75
-	 * @param string|array $value  The value.
76
-	 *
77
-	 * @return string|array
78
-	 */
79
-	protected function apply_sanitize_callback( $output, $value ) {
80
-		if ( isset( $output['sanitize_callback'] ) && null !== $output['sanitize_callback'] ) {
81
-
82
-			// If the sanitize_callback is invalid, return the value.
83
-			if ( ! is_callable( $output['sanitize_callback'] ) ) {
84
-				return $value;
85
-			}
86
-			return call_user_func( $output['sanitize_callback'], $this->value );
87
-		}
88
-		return $value;
89
-	}
90
-
91
-	/**
92
-	 * If we have a value_pattern defined, apply it to the value.
93
-	 *
94
-	 * @param array        $output The output args.
95
-	 * @param string|array $value  The value.
96
-	 * @return string|array
97
-	 */
98
-	protected function apply_value_pattern( $output, $value ) {
99
-		if ( isset( $output['value_pattern'] ) && is_string( $output['value_pattern'] ) ) {
100
-			if ( ! is_array( $value ) ) {
101
-				$value = str_replace( '$', $value, $output['value_pattern'] );
102
-			}
103
-			if ( is_array( $value ) ) {
104
-				foreach ( array_keys( $value ) as $value_k ) {
105
-					if ( is_array( $value[ $value_k ] ) ) {
106
-						continue;
107
-					}
108
-					if ( isset( $output['choice'] ) ) {
109
-						if ( $output['choice'] === $value_k ) {
110
-							$value[ $output['choice'] ] = str_replace( '$', $value[ $output['choice'] ], $output['value_pattern'] );
111
-						}
112
-						continue;
113
-					}
114
-					$value[ $value_k ] = str_replace( '$', $value[ $value_k ], $output['value_pattern'] );
115
-				}
116
-			}
117
-			$value = $this->apply_pattern_replace( $output, $value );
118
-		}
119
-		return $value;
120
-	}
121
-
122
-	/**
123
-	 * If we have a value_pattern defined, apply it to the value.
124
-	 *
125
-	 * @param array        $output The output args.
126
-	 * @param string|array $value  The value.
127
-	 * @return string|array
128
-	 */
129
-	protected function apply_pattern_replace( $output, $value ) {
130
-		if ( isset( $output['pattern_replace'] ) && is_array( $output['pattern_replace'] ) ) {
131
-			$option_type = ( isset( $this->field['option_type'] ) ) ? $this->field['option_type'] : 'theme_mod';
132
-			$option_name = ( isset( $this->field['option_name'] ) ) ? $this->field['option_name'] : '';
133
-			$options     = [];
134
-			if ( $option_name ) {
135
-				$options = ( 'site_option' === $option_type ) ? get_site_option( $option_name ) : get_option( $option_name );
136
-			}
137
-			foreach ( $output['pattern_replace'] as $search => $replace ) {
138
-				$replacement = '';
139
-				switch ( $option_type ) {
140
-					case 'option':
141
-						if ( is_array( $options ) ) {
142
-							if ( $option_name ) {
143
-								$subkey      = str_replace( [ $option_name, '[', ']' ], '', $replace );
144
-								$replacement = ( isset( $options[ $subkey ] ) ) ? $options[ $subkey ] : '';
145
-								break;
146
-							}
147
-							$replacement = ( isset( $options[ $replace ] ) ) ? $options[ $replace ] : '';
148
-							break;
149
-						}
150
-						$replacement = get_option( $replace );
151
-						break;
152
-					case 'site_option':
153
-						$replacement = ( is_array( $options ) && isset( $options[ $replace ] ) ) ? $options[ $replace ] : get_site_option( $replace );
154
-						break;
155
-					case 'user_meta':
156
-						$user_id = get_current_user_id();
157
-						if ( $user_id ) {
158
-							$replacement = get_user_meta( $user_id, $replace, true );
159
-						}
160
-						break;
161
-					default:
162
-						$replacement = get_theme_mod( $replace );
163
-						if ( ! $replacement ) {
164
-							$replacement = Values::get_value( $this->field['kirki_config'], $replace );
165
-						}
166
-				}
167
-				$replacement = ( false === $replacement ) ? '' : $replacement;
168
-				if ( is_array( $value ) ) {
169
-					foreach ( $value as $k => $v ) {
170
-						$_val        = ( isset( $value[ $v ] ) ) ? $value[ $v ] : $v;
171
-						$value[ $k ] = str_replace( $search, $replacement, $_val );
172
-					}
173
-					return $value;
174
-				}
175
-				$value = str_replace( $search, $replacement, $value );
176
-			}
177
-		}
178
-		return $value;
179
-	}
180
-
181
-	/**
182
-	 * Parses the output arguments.
183
-	 * Calls the process_output method for each of them.
184
-	 *
185
-	 * @access protected
186
-	 */
187
-	protected function parse_output() {
188
-		foreach ( $this->output as $output ) {
189
-			$skip = false;
190
-
191
-			// Apply any sanitization callbacks defined.
192
-			$value = $this->apply_sanitize_callback( $output, $this->value );
193
-
194
-			// Skip if value is empty.
195
-			if ( '' === $this->value ) {
196
-				$skip = true;
197
-			}
198
-
199
-			// No need to proceed this if the current value is the same as in the "exclude" value.
200
-			if ( isset( $output['exclude'] ) && is_array( $output['exclude'] ) ) {
201
-				foreach ( $output['exclude'] as $exclude ) {
202
-					if ( is_array( $value ) ) {
203
-						if ( is_array( $exclude ) ) {
204
-							$diff1 = array_diff( $value, $exclude );
205
-							$diff2 = array_diff( $exclude, $value );
206
-
207
-							if ( empty( $diff1 ) && empty( $diff2 ) ) {
208
-								$skip = true;
209
-							}
210
-						}
211
-						// If 'choice' is defined check for sub-values too.
212
-						// Fixes https://github.com/aristath/kirki/issues/1416.
213
-						if ( isset( $output['choice'] ) && isset( $value[ $output['choice'] ] ) && $exclude == $value[ $output['choice'] ] ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
214
-							$skip = true;
215
-						}
216
-					}
217
-					if ( $skip ) {
218
-						continue;
219
-					}
220
-
221
-					// Skip if value is defined as excluded.
222
-					if ( $exclude === $value || ( '' === $exclude && empty( $value ) ) ) {
223
-						$skip = true;
224
-					}
225
-				}
226
-			}
227
-			if ( $skip ) {
228
-				continue;
229
-			}
230
-
231
-			// Apply any value patterns defined.
232
-			$value = $this->apply_value_pattern( $output, $value );
233
-
234
-			if ( isset( $output['element'] ) && is_array( $output['element'] ) ) {
235
-				$output['element'] = array_unique( $output['element'] );
236
-				sort( $output['element'] );
237
-				$output['element'] = implode( ',', $output['element'] );
238
-			}
239
-
240
-			$value = $this->process_value( $value, $output );
241
-
242
-			if ( is_admin() ) {
243
-				// In admin area, only output kirki-styles/kirki-inline-styles inside editing screen.
244
-				if ( ! isset( $_GET['editor'] ) || 1 !== (int) $_GET['editor'] ) { // phpcs:ignore WordPress.Security.NonceVerification
245
-					continue;
246
-				}
247
-			} else {
248
-				// Check if this is a frontend style.
249
-				if ( isset( $output['context'] ) && ! in_array( 'front', $output['context'], true ) ) {
250
-					continue;
251
-				}
252
-			}
253
-
254
-			/**
255
-			 * Inside gutenberg editing screen, prepend `.editor-styles-wrapper` to the element
256
-			 * so that it doesn't polute elements other than inside the editing content.
257
-			 */
258
-			if ( isset( $_GET['editor'] ) && 1 === (int) $_GET['editor'] ) {
259
-				if ( isset( $output['element'] ) && ! empty( $output['element'] ) ) {
260
-
261
-					if ( -1 < strpos( $output['element'], ',' ) ) {
262
-						$elms = explode( ',', $output['element'] );
263
-
264
-						foreach ( $elms as $index => $elm ) {
265
-							if ( ! empty( $elm ) ) {
266
-								$elms[ $index ] = '.editor-styles-wrapper ' . $elm;
267
-								$elms[ $index ] = str_ireplace( '.editor-styles-wrapper :root', '.editor-styles-wrapper', $elms[ $index ] );
268
-							}
269
-						}
270
-
271
-						$output['element'] = implode( ',', $elms );
272
-					} else {
273
-						$output['element'] = '.editor-styles-wrapper ' . $output['element'];
274
-						$output['element'] = str_ireplace( '.editor-styles-wrapper :root', '.editor-styles-wrapper', $output['element'] );
275
-					}
276
-				}
277
-			}
278
-
279
-			$this->process_output( $output, $value );
280
-		}
281
-	}
282
-
283
-	/**
284
-	 * Parses an output and creates the styles array for it.
285
-	 *
286
-	 * @access protected
287
-	 * @param array        $output The field output.
288
-	 * @param string|array $value  The value.
289
-	 *
290
-	 * @return null
291
-	 */
292
-	protected function process_output( $output, $value ) {
293
-		$output = apply_filters( 'kirki_output_item_args', $output, $value, $this->output, $this->field );
294
-
295
-		if ( ! isset( $output['element'] ) || ! isset( $output['property'] ) ) {
296
-			return;
297
-		}
298
-
299
-		$output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
300
-		$output['prefix']      = ( isset( $output['prefix'] ) ) ? $output['prefix'] : '';
301
-		$output['units']       = ( isset( $output['units'] ) ) ? $output['units'] : '';
302
-		$output['suffix']      = ( isset( $output['suffix'] ) ) ? $output['suffix'] : '';
303
-
304
-		// Properties that can accept multiple values.
305
-		// Useful for example for gradients where all browsers use the "background-image" property
306
-		// and the browser prefixes go in the value_pattern arg.
307
-		$accepts_multiple = [
308
-			'background-image',
309
-			'background',
310
-		];
311
-
312
-		if ( in_array( $output['property'], $accepts_multiple, true ) ) {
313
-			if ( isset( $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] ) && ! is_array( $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] ) ) {
314
-				$this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = (array) $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ];
315
-			}
316
-
317
-			$this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ][] = $output['prefix'] . $value . $output['units'] . $output['suffix'];
318
-			return;
319
-		}
320
-
321
-		if ( is_string( $value ) || is_numeric( $value ) ) {
322
-			$this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value ) . $output['units'] . $output['suffix'];
323
-		}
324
-	}
325
-
326
-	/**
327
-	 * Some CSS properties are unique.
328
-	 * We need to tweak the value to make everything works as expected.
329
-	 *
330
-	 * @access protected
331
-	 * @param string       $property The CSS property.
332
-	 * @param string|array $value    The value.
333
-	 *
334
-	 * @return array
335
-	 */
336
-	protected function process_property_value( $property, $value ) {
337
-		$properties = apply_filters(
338
-			'kirki_output_property_classnames',
339
-			[
340
-				'font-family'         => '\Kirki\Module\CSS\Property\Font_Family',
341
-				'background-image'    => '\Kirki\Module\CSS\Property\Background_Image',
342
-				'background-position' => '\Kirki\Module\CSS\Property\Background_Position',
343
-			]
344
-		);
345
-		if ( array_key_exists( $property, $properties ) ) {
346
-			$classname = $properties[ $property ];
347
-			$obj       = new $classname( $property, $value );
348
-			return $obj->get_value();
349
-		}
350
-		return $value;
351
-	}
352
-
353
-	/**
354
-	 * Returns the value.
355
-	 *
356
-	 * @access protected
357
-	 * @param string|array $value The value.
358
-	 * @param array        $output The field "output".
359
-	 * @return string|array
360
-	 */
361
-	protected function process_value( $value, $output ) {
362
-		if ( isset( $output['property'] ) ) {
363
-			return $this->process_property_value( $output['property'], $value );
364
-		}
365
-		return $value;
366
-	}
367
-
368
-	/**
369
-	 * Exploses the private $styles property to the world
370
-	 *
371
-	 * @access protected
372
-	 * @return array
373
-	 */
374
-	public function get_styles() {
375
-		return $this->styles;
376
-	}
22
+    /**
23
+     * The field's `output` argument.
24
+     *
25
+     * @access protected
26
+     * @var array
27
+     */
28
+    protected $output = [];
29
+
30
+    /**
31
+     * An array of the generated styles.
32
+     *
33
+     * @access protected
34
+     * @var array
35
+     */
36
+    protected $styles = [];
37
+
38
+    /**
39
+     * The field.
40
+     *
41
+     * @access protected
42
+     * @var array
43
+     */
44
+    protected $field = [];
45
+
46
+    /**
47
+     * The value.
48
+     *
49
+     * @access protected
50
+     * @var string|array
51
+     */
52
+    protected $value;
53
+
54
+    /**
55
+     * The class constructor.
56
+     *
57
+     * @access public
58
+     * @param string       $config_id The config ID.
59
+     * @param array        $output    The output argument.
60
+     * @param string|array $value     The value.
61
+     * @param array        $field     The field.
62
+     */
63
+    public function __construct( $config_id, $output, $value, $field ) {
64
+        $this->value  = $value;
65
+        $this->output = $output;
66
+        $this->field  = $field;
67
+
68
+        $this->parse_output();
69
+    }
70
+
71
+    /**
72
+     * If we have a sanitize_callback defined, apply it to the value.
73
+     *
74
+     * @param array        $output The output args.
75
+     * @param string|array $value  The value.
76
+     *
77
+     * @return string|array
78
+     */
79
+    protected function apply_sanitize_callback( $output, $value ) {
80
+        if ( isset( $output['sanitize_callback'] ) && null !== $output['sanitize_callback'] ) {
81
+
82
+            // If the sanitize_callback is invalid, return the value.
83
+            if ( ! is_callable( $output['sanitize_callback'] ) ) {
84
+                return $value;
85
+            }
86
+            return call_user_func( $output['sanitize_callback'], $this->value );
87
+        }
88
+        return $value;
89
+    }
90
+
91
+    /**
92
+     * If we have a value_pattern defined, apply it to the value.
93
+     *
94
+     * @param array        $output The output args.
95
+     * @param string|array $value  The value.
96
+     * @return string|array
97
+     */
98
+    protected function apply_value_pattern( $output, $value ) {
99
+        if ( isset( $output['value_pattern'] ) && is_string( $output['value_pattern'] ) ) {
100
+            if ( ! is_array( $value ) ) {
101
+                $value = str_replace( '$', $value, $output['value_pattern'] );
102
+            }
103
+            if ( is_array( $value ) ) {
104
+                foreach ( array_keys( $value ) as $value_k ) {
105
+                    if ( is_array( $value[ $value_k ] ) ) {
106
+                        continue;
107
+                    }
108
+                    if ( isset( $output['choice'] ) ) {
109
+                        if ( $output['choice'] === $value_k ) {
110
+                            $value[ $output['choice'] ] = str_replace( '$', $value[ $output['choice'] ], $output['value_pattern'] );
111
+                        }
112
+                        continue;
113
+                    }
114
+                    $value[ $value_k ] = str_replace( '$', $value[ $value_k ], $output['value_pattern'] );
115
+                }
116
+            }
117
+            $value = $this->apply_pattern_replace( $output, $value );
118
+        }
119
+        return $value;
120
+    }
121
+
122
+    /**
123
+     * If we have a value_pattern defined, apply it to the value.
124
+     *
125
+     * @param array        $output The output args.
126
+     * @param string|array $value  The value.
127
+     * @return string|array
128
+     */
129
+    protected function apply_pattern_replace( $output, $value ) {
130
+        if ( isset( $output['pattern_replace'] ) && is_array( $output['pattern_replace'] ) ) {
131
+            $option_type = ( isset( $this->field['option_type'] ) ) ? $this->field['option_type'] : 'theme_mod';
132
+            $option_name = ( isset( $this->field['option_name'] ) ) ? $this->field['option_name'] : '';
133
+            $options     = [];
134
+            if ( $option_name ) {
135
+                $options = ( 'site_option' === $option_type ) ? get_site_option( $option_name ) : get_option( $option_name );
136
+            }
137
+            foreach ( $output['pattern_replace'] as $search => $replace ) {
138
+                $replacement = '';
139
+                switch ( $option_type ) {
140
+                    case 'option':
141
+                        if ( is_array( $options ) ) {
142
+                            if ( $option_name ) {
143
+                                $subkey      = str_replace( [ $option_name, '[', ']' ], '', $replace );
144
+                                $replacement = ( isset( $options[ $subkey ] ) ) ? $options[ $subkey ] : '';
145
+                                break;
146
+                            }
147
+                            $replacement = ( isset( $options[ $replace ] ) ) ? $options[ $replace ] : '';
148
+                            break;
149
+                        }
150
+                        $replacement = get_option( $replace );
151
+                        break;
152
+                    case 'site_option':
153
+                        $replacement = ( is_array( $options ) && isset( $options[ $replace ] ) ) ? $options[ $replace ] : get_site_option( $replace );
154
+                        break;
155
+                    case 'user_meta':
156
+                        $user_id = get_current_user_id();
157
+                        if ( $user_id ) {
158
+                            $replacement = get_user_meta( $user_id, $replace, true );
159
+                        }
160
+                        break;
161
+                    default:
162
+                        $replacement = get_theme_mod( $replace );
163
+                        if ( ! $replacement ) {
164
+                            $replacement = Values::get_value( $this->field['kirki_config'], $replace );
165
+                        }
166
+                }
167
+                $replacement = ( false === $replacement ) ? '' : $replacement;
168
+                if ( is_array( $value ) ) {
169
+                    foreach ( $value as $k => $v ) {
170
+                        $_val        = ( isset( $value[ $v ] ) ) ? $value[ $v ] : $v;
171
+                        $value[ $k ] = str_replace( $search, $replacement, $_val );
172
+                    }
173
+                    return $value;
174
+                }
175
+                $value = str_replace( $search, $replacement, $value );
176
+            }
177
+        }
178
+        return $value;
179
+    }
180
+
181
+    /**
182
+     * Parses the output arguments.
183
+     * Calls the process_output method for each of them.
184
+     *
185
+     * @access protected
186
+     */
187
+    protected function parse_output() {
188
+        foreach ( $this->output as $output ) {
189
+            $skip = false;
190
+
191
+            // Apply any sanitization callbacks defined.
192
+            $value = $this->apply_sanitize_callback( $output, $this->value );
193
+
194
+            // Skip if value is empty.
195
+            if ( '' === $this->value ) {
196
+                $skip = true;
197
+            }
198
+
199
+            // No need to proceed this if the current value is the same as in the "exclude" value.
200
+            if ( isset( $output['exclude'] ) && is_array( $output['exclude'] ) ) {
201
+                foreach ( $output['exclude'] as $exclude ) {
202
+                    if ( is_array( $value ) ) {
203
+                        if ( is_array( $exclude ) ) {
204
+                            $diff1 = array_diff( $value, $exclude );
205
+                            $diff2 = array_diff( $exclude, $value );
206
+
207
+                            if ( empty( $diff1 ) && empty( $diff2 ) ) {
208
+                                $skip = true;
209
+                            }
210
+                        }
211
+                        // If 'choice' is defined check for sub-values too.
212
+                        // Fixes https://github.com/aristath/kirki/issues/1416.
213
+                        if ( isset( $output['choice'] ) && isset( $value[ $output['choice'] ] ) && $exclude == $value[ $output['choice'] ] ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
214
+                            $skip = true;
215
+                        }
216
+                    }
217
+                    if ( $skip ) {
218
+                        continue;
219
+                    }
220
+
221
+                    // Skip if value is defined as excluded.
222
+                    if ( $exclude === $value || ( '' === $exclude && empty( $value ) ) ) {
223
+                        $skip = true;
224
+                    }
225
+                }
226
+            }
227
+            if ( $skip ) {
228
+                continue;
229
+            }
230
+
231
+            // Apply any value patterns defined.
232
+            $value = $this->apply_value_pattern( $output, $value );
233
+
234
+            if ( isset( $output['element'] ) && is_array( $output['element'] ) ) {
235
+                $output['element'] = array_unique( $output['element'] );
236
+                sort( $output['element'] );
237
+                $output['element'] = implode( ',', $output['element'] );
238
+            }
239
+
240
+            $value = $this->process_value( $value, $output );
241
+
242
+            if ( is_admin() ) {
243
+                // In admin area, only output kirki-styles/kirki-inline-styles inside editing screen.
244
+                if ( ! isset( $_GET['editor'] ) || 1 !== (int) $_GET['editor'] ) { // phpcs:ignore WordPress.Security.NonceVerification
245
+                    continue;
246
+                }
247
+            } else {
248
+                // Check if this is a frontend style.
249
+                if ( isset( $output['context'] ) && ! in_array( 'front', $output['context'], true ) ) {
250
+                    continue;
251
+                }
252
+            }
253
+
254
+            /**
255
+             * Inside gutenberg editing screen, prepend `.editor-styles-wrapper` to the element
256
+             * so that it doesn't polute elements other than inside the editing content.
257
+             */
258
+            if ( isset( $_GET['editor'] ) && 1 === (int) $_GET['editor'] ) {
259
+                if ( isset( $output['element'] ) && ! empty( $output['element'] ) ) {
260
+
261
+                    if ( -1 < strpos( $output['element'], ',' ) ) {
262
+                        $elms = explode( ',', $output['element'] );
263
+
264
+                        foreach ( $elms as $index => $elm ) {
265
+                            if ( ! empty( $elm ) ) {
266
+                                $elms[ $index ] = '.editor-styles-wrapper ' . $elm;
267
+                                $elms[ $index ] = str_ireplace( '.editor-styles-wrapper :root', '.editor-styles-wrapper', $elms[ $index ] );
268
+                            }
269
+                        }
270
+
271
+                        $output['element'] = implode( ',', $elms );
272
+                    } else {
273
+                        $output['element'] = '.editor-styles-wrapper ' . $output['element'];
274
+                        $output['element'] = str_ireplace( '.editor-styles-wrapper :root', '.editor-styles-wrapper', $output['element'] );
275
+                    }
276
+                }
277
+            }
278
+
279
+            $this->process_output( $output, $value );
280
+        }
281
+    }
282
+
283
+    /**
284
+     * Parses an output and creates the styles array for it.
285
+     *
286
+     * @access protected
287
+     * @param array        $output The field output.
288
+     * @param string|array $value  The value.
289
+     *
290
+     * @return null
291
+     */
292
+    protected function process_output( $output, $value ) {
293
+        $output = apply_filters( 'kirki_output_item_args', $output, $value, $this->output, $this->field );
294
+
295
+        if ( ! isset( $output['element'] ) || ! isset( $output['property'] ) ) {
296
+            return;
297
+        }
298
+
299
+        $output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
300
+        $output['prefix']      = ( isset( $output['prefix'] ) ) ? $output['prefix'] : '';
301
+        $output['units']       = ( isset( $output['units'] ) ) ? $output['units'] : '';
302
+        $output['suffix']      = ( isset( $output['suffix'] ) ) ? $output['suffix'] : '';
303
+
304
+        // Properties that can accept multiple values.
305
+        // Useful for example for gradients where all browsers use the "background-image" property
306
+        // and the browser prefixes go in the value_pattern arg.
307
+        $accepts_multiple = [
308
+            'background-image',
309
+            'background',
310
+        ];
311
+
312
+        if ( in_array( $output['property'], $accepts_multiple, true ) ) {
313
+            if ( isset( $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] ) && ! is_array( $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] ) ) {
314
+                $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = (array) $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ];
315
+            }
316
+
317
+            $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ][] = $output['prefix'] . $value . $output['units'] . $output['suffix'];
318
+            return;
319
+        }
320
+
321
+        if ( is_string( $value ) || is_numeric( $value ) ) {
322
+            $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value ) . $output['units'] . $output['suffix'];
323
+        }
324
+    }
325
+
326
+    /**
327
+     * Some CSS properties are unique.
328
+     * We need to tweak the value to make everything works as expected.
329
+     *
330
+     * @access protected
331
+     * @param string       $property The CSS property.
332
+     * @param string|array $value    The value.
333
+     *
334
+     * @return array
335
+     */
336
+    protected function process_property_value( $property, $value ) {
337
+        $properties = apply_filters(
338
+            'kirki_output_property_classnames',
339
+            [
340
+                'font-family'         => '\Kirki\Module\CSS\Property\Font_Family',
341
+                'background-image'    => '\Kirki\Module\CSS\Property\Background_Image',
342
+                'background-position' => '\Kirki\Module\CSS\Property\Background_Position',
343
+            ]
344
+        );
345
+        if ( array_key_exists( $property, $properties ) ) {
346
+            $classname = $properties[ $property ];
347
+            $obj       = new $classname( $property, $value );
348
+            return $obj->get_value();
349
+        }
350
+        return $value;
351
+    }
352
+
353
+    /**
354
+     * Returns the value.
355
+     *
356
+     * @access protected
357
+     * @param string|array $value The value.
358
+     * @param array        $output The field "output".
359
+     * @return string|array
360
+     */
361
+    protected function process_value( $value, $output ) {
362
+        if ( isset( $output['property'] ) ) {
363
+            return $this->process_property_value( $output['property'], $value );
364
+        }
365
+        return $value;
366
+    }
367
+
368
+    /**
369
+     * Exploses the private $styles property to the world
370
+     *
371
+     * @access protected
372
+     * @return array
373
+     */
374
+    public function get_styles() {
375
+        return $this->styles;
376
+    }
377 377
 }
Please login to merge, or discard this patch.