@@ -25,18 +25,18 @@ discard block |
||
25 | 25 | |
26 | 26 | // a helper function to lookup "env_FILE", "env", then fallback |
27 | 27 | if (!function_exists('getenv_docker')) { |
28 | - // https://github.com/docker-library/wordpress/issues/588 (WP-CLI will load this file 2x) |
|
29 | - function getenv_docker($env, $default) { |
|
30 | - if ($fileEnv = getenv($env . '_FILE')) { |
|
31 | - return rtrim(file_get_contents($fileEnv), "\r\n"); |
|
32 | - } |
|
33 | - else if (($val = getenv($env)) !== false) { |
|
34 | - return $val; |
|
35 | - } |
|
36 | - else { |
|
37 | - return $default; |
|
38 | - } |
|
39 | - } |
|
28 | + // https://github.com/docker-library/wordpress/issues/588 (WP-CLI will load this file 2x) |
|
29 | + function getenv_docker($env, $default) { |
|
30 | + if ($fileEnv = getenv($env . '_FILE')) { |
|
31 | + return rtrim(file_get_contents($fileEnv), "\r\n"); |
|
32 | + } |
|
33 | + else if (($val = getenv($env)) !== false) { |
|
34 | + return $val; |
|
35 | + } |
|
36 | + else { |
|
37 | + return $default; |
|
38 | + } |
|
39 | + } |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | // ** Database settings - You can get this info from your web host ** // |
@@ -114,19 +114,19 @@ discard block |
||
114 | 114 | // If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact |
115 | 115 | // see also https://wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxy |
116 | 116 | if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) { |
117 | - $_SERVER['HTTPS'] = 'on'; |
|
117 | + $_SERVER['HTTPS'] = 'on'; |
|
118 | 118 | } |
119 | 119 | // (we include this by default because reverse proxying is extremely common in container environments) |
120 | 120 | |
121 | 121 | if ($configExtra = getenv_docker('WORDPRESS_CONFIG_EXTRA', '')) { |
122 | - eval($configExtra); |
|
122 | + eval($configExtra); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /* That's all, stop editing! Happy publishing. */ |
126 | 126 | |
127 | 127 | /** Absolute path to the WordPress directory. */ |
128 | 128 | if ( ! defined( 'ABSPATH' ) ) { |
129 | - define( 'ABSPATH', __DIR__ . '/' ); |
|
129 | + define( 'ABSPATH', __DIR__ . '/' ); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** Sets up WordPress vars and included files. */ |
@@ -11,20 +11,20 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | if ( ! function_exists( 'kirki_show_upgrade_notification' ) ) : |
14 | - /** |
|
15 | - * Fires at the end of the update message container in each |
|
16 | - * row of the plugins list table. |
|
17 | - * Allows us to add important notices about updates should they be needed. |
|
18 | - * Notices should be added using "== Upgrade Notice ==" in readme.txt. |
|
19 | - * |
|
20 | - * @since 2.3.8 |
|
21 | - * @param array $plugin_data An array of plugin metadata. |
|
22 | - * @param array $response An array of metadata about the available plugin update. |
|
23 | - */ |
|
24 | - function kirki_show_upgrade_notification( $plugin_data, $response ) { |
|
14 | + /** |
|
15 | + * Fires at the end of the update message container in each |
|
16 | + * row of the plugins list table. |
|
17 | + * Allows us to add important notices about updates should they be needed. |
|
18 | + * Notices should be added using "== Upgrade Notice ==" in readme.txt. |
|
19 | + * |
|
20 | + * @since 2.3.8 |
|
21 | + * @param array $plugin_data An array of plugin metadata. |
|
22 | + * @param array $response An array of metadata about the available plugin update. |
|
23 | + */ |
|
24 | + function kirki_show_upgrade_notification( $plugin_data, $response ) { |
|
25 | 25 | |
26 | - // Check "upgrade_notice". |
|
27 | - if ( isset( $response->upgrade_notice ) && strlen( trim( $response->upgrade_notice ) ) > 0 ) : ?> |
|
26 | + // Check "upgrade_notice". |
|
27 | + if ( isset( $response->upgrade_notice ) && strlen( trim( $response->upgrade_notice ) ) > 0 ) : ?> |
|
28 | 28 | <style>.kirki-upgrade-notification {background-color:#d54e21;padding:10px;color:#f9f9f9;margin-top:10px;margin-bottom:10px;}.kirki-upgrade-notification + p {display:none;}</style> |
29 | 29 | <div class="kirki-upgrade-notification"> |
30 | 30 | <strong><?php esc_html_e( 'Important Upgrade Notice:', 'kirki' ); ?></strong> |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | <?php echo esc_html( $upgrade_notice ); ?> |
33 | 33 | </div> |
34 | 34 | <?php |
35 | - endif; |
|
36 | - } |
|
35 | + endif; |
|
36 | + } |
|
37 | 37 | endif; |
38 | 38 | add_action( 'in_plugin_update_message-' . plugin_basename( __FILE__ ), 'kirki_show_upgrade_notification', 10, 2 ); |
@@ -14,20 +14,20 @@ discard block |
||
14 | 14 | |
15 | 15 | // Exit if accessed directly. |
16 | 16 | if ( ! defined( 'ABSPATH' ) ) { |
17 | - exit; |
|
17 | + exit; |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | // Do not proceed if Kirki does not exist. |
21 | 21 | if ( ! class_exists( 'Kirki' ) ) { |
22 | - return; |
|
22 | + return; |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | Kirki::add_config( |
26 | - 'kirki_demo_config', |
|
27 | - [ |
|
28 | - 'option_type' => 'theme_mod', |
|
29 | - 'capability' => 'manage_options', |
|
30 | - ] |
|
26 | + 'kirki_demo_config', |
|
27 | + [ |
|
28 | + 'option_type' => 'theme_mod', |
|
29 | + 'capability' => 'manage_options', |
|
30 | + ] |
|
31 | 31 | ); |
32 | 32 | |
33 | 33 | /** |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | * @link https://kirki.org/docs/getting-started/panels.html |
37 | 37 | */ |
38 | 38 | new \Kirki\Panel( |
39 | - 'kirki_demo_panel', |
|
40 | - [ |
|
41 | - 'priority' => 10, |
|
42 | - 'title' => esc_html__( 'Kirki Demo Panel', 'kirki' ), |
|
43 | - 'description' => esc_html__( 'Contains sections for all kirki controls.', 'kirki' ), |
|
44 | - ] |
|
39 | + 'kirki_demo_panel', |
|
40 | + [ |
|
41 | + 'priority' => 10, |
|
42 | + 'title' => esc_html__( 'Kirki Demo Panel', 'kirki' ), |
|
43 | + 'description' => esc_html__( 'Contains sections for all kirki controls.', 'kirki' ), |
|
44 | + ] |
|
45 | 45 | ); |
46 | 46 | |
47 | 47 | /** |
@@ -53,60 +53,60 @@ discard block |
||
53 | 53 | * @link https://kirki.org/docs/getting-started/sections.html |
54 | 54 | */ |
55 | 55 | $sections = [ |
56 | - 'background' => [ esc_html__( 'Background', 'kirki' ), '' ], |
|
57 | - 'code' => [ esc_html__( 'Code', 'kirki' ), '' ], |
|
58 | - 'checkbox' => [ esc_html__( 'Checkbox', 'kirki' ), '' ], |
|
59 | - 'color' => [ esc_html__( 'Color', 'kirki' ), '' ], |
|
60 | - 'color_advanced' => [ esc_html__( 'Color — Advanced', 'kirki' ), '' ], |
|
61 | - 'color_palette' => [ esc_html__( 'Color Palette', 'kirki' ), '' ], |
|
62 | - 'custom' => [ esc_html__( 'Custom', 'kirki' ), '' ], |
|
63 | - 'dashicons' => [ esc_html__( 'Dashicons', 'kirki' ), '' ], |
|
64 | - 'date' => [ esc_html__( 'Date', 'kirki' ), '' ], |
|
65 | - 'dimension' => [ esc_html__( 'Dimension', 'kirki' ), '' ], |
|
66 | - 'dimensions' => [ esc_html__( 'Dimensions', 'kirki' ), '' ], |
|
67 | - 'dropdown-pages' => [ esc_html__( 'Dropdown Pages', 'kirki' ), '' ], |
|
68 | - 'editor' => [ esc_html__( 'Editor', 'kirki' ), '' ], |
|
69 | - 'fontawesome' => [ esc_html__( 'Font-Awesome', 'kirki' ), '' ], |
|
70 | - 'generic' => [ esc_html__( 'Generic', 'kirki' ), '' ], |
|
71 | - 'image' => [ esc_html__( 'Image', 'kirki' ), '' ], |
|
72 | - 'multicheck' => [ esc_html__( 'Multicheck', 'kirki' ), '' ], |
|
73 | - 'multicolor' => [ esc_html__( 'Multicolor', 'kirki' ), '' ], |
|
74 | - 'number' => [ esc_html__( 'Number', 'kirki' ), '' ], |
|
75 | - 'palette' => [ esc_html__( 'Palette', 'kirki' ), '' ], |
|
76 | - 'preset' => [ esc_html__( 'Preset', 'kirki' ), '' ], |
|
77 | - 'radio' => [ esc_html__( 'Radio', 'kirki' ), esc_html__( 'A plain Radio control.', 'kirki' ) ], |
|
78 | - 'radio-buttonset' => [ esc_html__( 'Radio Buttonset', 'kirki' ), esc_html__( 'Radio-Buttonset controls are essentially radio controls with some fancy styling to make them look cooler.', 'kirki' ) ], |
|
79 | - 'radio-image' => [ esc_html__( 'Radio Image', 'kirki' ), esc_html__( 'Radio-Image controls are essentially radio controls with some fancy styles to use images', 'kirki' ) ], |
|
80 | - 'repeater' => [ esc_html__( 'Repeater', 'kirki' ), '' ], |
|
81 | - 'select' => [ esc_html__( 'Select', 'kirki' ), '' ], |
|
82 | - 'slider' => [ esc_html__( 'Slider', 'kirki' ), '' ], |
|
83 | - 'sortable' => [ esc_html__( 'Sortable', 'kirki' ), '' ], |
|
84 | - 'switch' => [ esc_html__( 'Switch', 'kirki' ), '', 'outer' ], |
|
85 | - 'toggle' => [ esc_html__( 'Toggle', 'kirki' ), '', 'outer' ], |
|
86 | - 'typography' => [ esc_html__( 'Typography', 'kirki' ), '' ], |
|
87 | - 'upload' => [ esc_html__( 'Upload', 'kirki' ), '' ], |
|
56 | + 'background' => [ esc_html__( 'Background', 'kirki' ), '' ], |
|
57 | + 'code' => [ esc_html__( 'Code', 'kirki' ), '' ], |
|
58 | + 'checkbox' => [ esc_html__( 'Checkbox', 'kirki' ), '' ], |
|
59 | + 'color' => [ esc_html__( 'Color', 'kirki' ), '' ], |
|
60 | + 'color_advanced' => [ esc_html__( 'Color — Advanced', 'kirki' ), '' ], |
|
61 | + 'color_palette' => [ esc_html__( 'Color Palette', 'kirki' ), '' ], |
|
62 | + 'custom' => [ esc_html__( 'Custom', 'kirki' ), '' ], |
|
63 | + 'dashicons' => [ esc_html__( 'Dashicons', 'kirki' ), '' ], |
|
64 | + 'date' => [ esc_html__( 'Date', 'kirki' ), '' ], |
|
65 | + 'dimension' => [ esc_html__( 'Dimension', 'kirki' ), '' ], |
|
66 | + 'dimensions' => [ esc_html__( 'Dimensions', 'kirki' ), '' ], |
|
67 | + 'dropdown-pages' => [ esc_html__( 'Dropdown Pages', 'kirki' ), '' ], |
|
68 | + 'editor' => [ esc_html__( 'Editor', 'kirki' ), '' ], |
|
69 | + 'fontawesome' => [ esc_html__( 'Font-Awesome', 'kirki' ), '' ], |
|
70 | + 'generic' => [ esc_html__( 'Generic', 'kirki' ), '' ], |
|
71 | + 'image' => [ esc_html__( 'Image', 'kirki' ), '' ], |
|
72 | + 'multicheck' => [ esc_html__( 'Multicheck', 'kirki' ), '' ], |
|
73 | + 'multicolor' => [ esc_html__( 'Multicolor', 'kirki' ), '' ], |
|
74 | + 'number' => [ esc_html__( 'Number', 'kirki' ), '' ], |
|
75 | + 'palette' => [ esc_html__( 'Palette', 'kirki' ), '' ], |
|
76 | + 'preset' => [ esc_html__( 'Preset', 'kirki' ), '' ], |
|
77 | + 'radio' => [ esc_html__( 'Radio', 'kirki' ), esc_html__( 'A plain Radio control.', 'kirki' ) ], |
|
78 | + 'radio-buttonset' => [ esc_html__( 'Radio Buttonset', 'kirki' ), esc_html__( 'Radio-Buttonset controls are essentially radio controls with some fancy styling to make them look cooler.', 'kirki' ) ], |
|
79 | + 'radio-image' => [ esc_html__( 'Radio Image', 'kirki' ), esc_html__( 'Radio-Image controls are essentially radio controls with some fancy styles to use images', 'kirki' ) ], |
|
80 | + 'repeater' => [ esc_html__( 'Repeater', 'kirki' ), '' ], |
|
81 | + 'select' => [ esc_html__( 'Select', 'kirki' ), '' ], |
|
82 | + 'slider' => [ esc_html__( 'Slider', 'kirki' ), '' ], |
|
83 | + 'sortable' => [ esc_html__( 'Sortable', 'kirki' ), '' ], |
|
84 | + 'switch' => [ esc_html__( 'Switch', 'kirki' ), '', 'outer' ], |
|
85 | + 'toggle' => [ esc_html__( 'Toggle', 'kirki' ), '', 'outer' ], |
|
86 | + 'typography' => [ esc_html__( 'Typography', 'kirki' ), '' ], |
|
87 | + 'upload' => [ esc_html__( 'Upload', 'kirki' ), '' ], |
|
88 | 88 | ]; |
89 | 89 | |
90 | 90 | foreach ( $sections as $section_id => $section ) { |
91 | - $section_args = [ |
|
92 | - 'title' => $section[0], |
|
93 | - 'description' => $section[1], |
|
94 | - 'panel' => 'kirki_demo_panel', |
|
95 | - ]; |
|
96 | - if ( isset( $section[2] ) ) { |
|
97 | - $section_args['type'] = $section[2]; |
|
98 | - } |
|
99 | - new \Kirki\Section( str_replace( '-', '_', $section_id ) . '_section', $section_args ); |
|
91 | + $section_args = [ |
|
92 | + 'title' => $section[0], |
|
93 | + 'description' => $section[1], |
|
94 | + 'panel' => 'kirki_demo_panel', |
|
95 | + ]; |
|
96 | + if ( isset( $section[2] ) ) { |
|
97 | + $section_args['type'] = $section[2]; |
|
98 | + } |
|
99 | + new \Kirki\Section( str_replace( '-', '_', $section_id ) . '_section', $section_args ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | new \Kirki\Section( |
103 | - 'pro_test', |
|
104 | - [ |
|
105 | - 'title' => esc_html__( 'Test Link Section', 'kirki' ), |
|
106 | - 'type' => 'link', |
|
107 | - 'button_text' => esc_html__( 'Pro', 'kirki' ), |
|
108 | - 'button_url' => 'https://kirki.org', |
|
109 | - ] |
|
103 | + 'pro_test', |
|
104 | + [ |
|
105 | + 'title' => esc_html__( 'Test Link Section', 'kirki' ), |
|
106 | + 'type' => 'link', |
|
107 | + 'button_text' => esc_html__( 'Pro', 'kirki' ), |
|
108 | + 'button_url' => 'https://kirki.org', |
|
109 | + ] |
|
110 | 110 | ); |
111 | 111 | |
112 | 112 | /** |
@@ -115,20 +115,20 @@ discard block |
||
115 | 115 | * @todo Triggers change on load. |
116 | 116 | */ |
117 | 117 | new \Kirki\Field\Background( |
118 | - [ |
|
119 | - 'settings' => 'kirki_demo_background', |
|
120 | - 'label' => esc_html__( 'Background Control', 'kirki' ), |
|
121 | - 'description' => esc_html__( 'Background conrols are pretty complex! (but useful if properly used)', 'kirki' ), |
|
122 | - 'section' => 'background_section', |
|
123 | - 'default' => [ |
|
124 | - 'background-color' => 'rgba(20,20,20,.8)', |
|
125 | - 'background-image' => '', |
|
126 | - 'background-repeat' => 'repeat', |
|
127 | - 'background-position' => 'center center', |
|
128 | - 'background-size' => 'cover', |
|
129 | - 'background-attachment' => 'scroll', |
|
130 | - ], |
|
131 | - ] |
|
118 | + [ |
|
119 | + 'settings' => 'kirki_demo_background', |
|
120 | + 'label' => esc_html__( 'Background Control', 'kirki' ), |
|
121 | + 'description' => esc_html__( 'Background conrols are pretty complex! (but useful if properly used)', 'kirki' ), |
|
122 | + 'section' => 'background_section', |
|
123 | + 'default' => [ |
|
124 | + 'background-color' => 'rgba(20,20,20,.8)', |
|
125 | + 'background-image' => '', |
|
126 | + 'background-repeat' => 'repeat', |
|
127 | + 'background-position' => 'center center', |
|
128 | + 'background-size' => 'cover', |
|
129 | + 'background-attachment' => 'scroll', |
|
130 | + ], |
|
131 | + ] |
|
132 | 132 | ); |
133 | 133 | |
134 | 134 | /** |
@@ -137,16 +137,16 @@ discard block |
||
137 | 137 | * @link https://kirki.org/docs/controls/code.html |
138 | 138 | */ |
139 | 139 | new \Kirki\Field\Code( |
140 | - [ |
|
141 | - 'settings' => 'kirki_demo_code_css', |
|
142 | - 'label' => esc_html__( 'Code Control — CSS', 'kirki' ), |
|
143 | - 'description' => esc_html__( 'Sample of code control in CSS format', 'kirki' ), |
|
144 | - 'section' => 'code_section', |
|
145 | - 'default' => '', |
|
146 | - 'choices' => [ |
|
147 | - 'language' => 'css', |
|
148 | - ], |
|
149 | - ] |
|
140 | + [ |
|
141 | + 'settings' => 'kirki_demo_code_css', |
|
142 | + 'label' => esc_html__( 'Code Control — CSS', 'kirki' ), |
|
143 | + 'description' => esc_html__( 'Sample of code control in CSS format', 'kirki' ), |
|
144 | + 'section' => 'code_section', |
|
145 | + 'default' => '', |
|
146 | + 'choices' => [ |
|
147 | + 'language' => 'css', |
|
148 | + ], |
|
149 | + ] |
|
150 | 150 | ); |
151 | 151 | |
152 | 152 | /** |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | * @link https://kirki.org/docs/controls/checkbox.html |
156 | 156 | */ |
157 | 157 | new \Kirki\Field\Checkbox( |
158 | - [ |
|
159 | - 'settings' => 'kirki_demo_checkbox', |
|
160 | - 'label' => esc_html__( 'Checkbox Control', 'kirki' ), |
|
161 | - 'description' => esc_html__( 'Sample of checkbox control', 'kirki' ), |
|
162 | - 'section' => 'checkbox_section', |
|
163 | - 'default' => true, |
|
164 | - ] |
|
158 | + [ |
|
159 | + 'settings' => 'kirki_demo_checkbox', |
|
160 | + 'label' => esc_html__( 'Checkbox Control', 'kirki' ), |
|
161 | + 'description' => esc_html__( 'Sample of checkbox control', 'kirki' ), |
|
162 | + 'section' => 'checkbox_section', |
|
163 | + 'default' => true, |
|
164 | + ] |
|
165 | 165 | ); |
166 | 166 | |
167 | 167 | /** |
@@ -170,55 +170,55 @@ discard block |
||
170 | 170 | * @link https://kirki.org/docs/controls/color.html |
171 | 171 | */ |
172 | 172 | Kirki::add_field( |
173 | - 'kirki_demo_config', |
|
174 | - [ |
|
175 | - 'type' => 'color', |
|
176 | - 'settings' => 'kirki_demo_color_alpha_old', |
|
177 | - 'label' => 'Using <code>Kirki::add_field</code> — With alpha', |
|
178 | - 'description' => esc_html__( 'This is a color control registered using `Kirki::add_field` with "alpha" => true (the old Kirki API).', 'kirki' ), |
|
179 | - 'section' => 'color_section', |
|
180 | - 'transport' => 'postMessage', |
|
181 | - 'default' => '#ff0055', |
|
182 | - 'choices' => [ |
|
183 | - 'alpha' => true, |
|
184 | - ], |
|
185 | - ] |
|
173 | + 'kirki_demo_config', |
|
174 | + [ |
|
175 | + 'type' => 'color', |
|
176 | + 'settings' => 'kirki_demo_color_alpha_old', |
|
177 | + 'label' => 'Using <code>Kirki::add_field</code> — With alpha', |
|
178 | + 'description' => esc_html__( 'This is a color control registered using `Kirki::add_field` with "alpha" => true (the old Kirki API).', 'kirki' ), |
|
179 | + 'section' => 'color_section', |
|
180 | + 'transport' => 'postMessage', |
|
181 | + 'default' => '#ff0055', |
|
182 | + 'choices' => [ |
|
183 | + 'alpha' => true, |
|
184 | + ], |
|
185 | + ] |
|
186 | 186 | ); |
187 | 187 | |
188 | 188 | new \Kirki\Field\Color( |
189 | - [ |
|
190 | - 'settings' => 'kirki_demo_color_hex', |
|
191 | - 'label' => __( 'Hex only', 'kirki' ), |
|
192 | - 'description' => esc_html__( 'This is a color control without alpha channel.', 'kirki' ), |
|
193 | - 'section' => 'color_section', |
|
194 | - 'transport' => 'postMessage', |
|
195 | - 'default' => '#0008DC', |
|
196 | - ] |
|
189 | + [ |
|
190 | + 'settings' => 'kirki_demo_color_hex', |
|
191 | + 'label' => __( 'Hex only', 'kirki' ), |
|
192 | + 'description' => esc_html__( 'This is a color control without alpha channel.', 'kirki' ), |
|
193 | + 'section' => 'color_section', |
|
194 | + 'transport' => 'postMessage', |
|
195 | + 'default' => '#0008DC', |
|
196 | + ] |
|
197 | 197 | ); |
198 | 198 | |
199 | 199 | new \Kirki\Field\Color( |
200 | - [ |
|
201 | - 'settings' => 'kirki_demo_color_alpha', |
|
202 | - 'label' => __( 'With alpha channel', 'kirki' ), |
|
203 | - 'description' => esc_html__( 'This is a color control with alpha channel.', 'kirki' ), |
|
204 | - 'section' => 'color_section', |
|
205 | - 'transport' => 'postMessage', |
|
206 | - 'choices' => [ |
|
207 | - 'alpha' => true, |
|
208 | - ], |
|
209 | - ] |
|
200 | + [ |
|
201 | + 'settings' => 'kirki_demo_color_alpha', |
|
202 | + 'label' => __( 'With alpha channel', 'kirki' ), |
|
203 | + 'description' => esc_html__( 'This is a color control with alpha channel.', 'kirki' ), |
|
204 | + 'section' => 'color_section', |
|
205 | + 'transport' => 'postMessage', |
|
206 | + 'choices' => [ |
|
207 | + 'alpha' => true, |
|
208 | + ], |
|
209 | + ] |
|
210 | 210 | ); |
211 | 211 | |
212 | 212 | new \Kirki\Field\Color( |
213 | - [ |
|
214 | - 'settings' => 'kirki_demo_color_hue', |
|
215 | - 'label' => __( 'Hue only.', 'kirki' ), |
|
216 | - 'description' => esc_html__( 'This is a color control with "mode" => "hue" (hue mode).', 'kirki' ), |
|
217 | - 'section' => 'color_section', |
|
218 | - 'transport' => 'postMessage', |
|
219 | - 'default' => 160, |
|
220 | - 'mode' => 'hue', |
|
221 | - ] |
|
213 | + [ |
|
214 | + 'settings' => 'kirki_demo_color_hue', |
|
215 | + 'label' => __( 'Hue only.', 'kirki' ), |
|
216 | + 'description' => esc_html__( 'This is a color control with "mode" => "hue" (hue mode).', 'kirki' ), |
|
217 | + 'section' => 'color_section', |
|
218 | + 'transport' => 'postMessage', |
|
219 | + 'default' => 160, |
|
220 | + 'mode' => 'hue', |
|
221 | + ] |
|
222 | 222 | ); |
223 | 223 | |
224 | 224 | /** |
@@ -232,17 +232,17 @@ discard block |
||
232 | 232 | * "#ff0000" |
233 | 233 | */ |
234 | 234 | new \Kirki\Field\Color( |
235 | - [ |
|
236 | - 'settings' => 'kirki_demo_color_form_component_hex', |
|
237 | - 'label' => __( 'v4 — form_component — HexColorPicker', 'kirki' ), |
|
238 | - 'description' => esc_html__( 'This is a color control with form_component value is HexColorPicker.', 'kirki' ), |
|
239 | - 'section' => 'color_advanced_section', |
|
240 | - 'default' => '#ffff00', |
|
241 | - 'choices' => [ |
|
242 | - 'form_component' => 'HexColorPicker', |
|
243 | - ], |
|
244 | - 'transport' => 'postMessage', |
|
245 | - ] |
|
235 | + [ |
|
236 | + 'settings' => 'kirki_demo_color_form_component_hex', |
|
237 | + 'label' => __( 'v4 — form_component — HexColorPicker', 'kirki' ), |
|
238 | + 'description' => esc_html__( 'This is a color control with form_component value is HexColorPicker.', 'kirki' ), |
|
239 | + 'section' => 'color_advanced_section', |
|
240 | + 'default' => '#ffff00', |
|
241 | + 'choices' => [ |
|
242 | + 'form_component' => 'HexColorPicker', |
|
243 | + ], |
|
244 | + 'transport' => 'postMessage', |
|
245 | + ] |
|
246 | 246 | ); |
247 | 247 | |
248 | 248 | /** |
@@ -258,17 +258,17 @@ discard block |
||
258 | 258 | * ] |
259 | 259 | */ |
260 | 260 | new \Kirki\Field\Color( |
261 | - [ |
|
262 | - 'settings' => 'kirki_demo_color_form_component_rgb', |
|
263 | - 'label' => __( 'v4 — form_component — RgbColorPicker', 'kirki' ), |
|
264 | - 'description' => esc_html__( 'This is a color control with form_component value is RgbColorPicker. The saved value will be an array.', 'kirki' ), |
|
265 | - 'section' => 'color_advanced_section', |
|
266 | - 'default' => '#ffff00', |
|
267 | - 'choices' => [ |
|
268 | - 'form_component' => 'RgbColorPicker', |
|
269 | - ], |
|
270 | - 'transport' => 'postMessage', |
|
271 | - ] |
|
261 | + [ |
|
262 | + 'settings' => 'kirki_demo_color_form_component_rgb', |
|
263 | + 'label' => __( 'v4 — form_component — RgbColorPicker', 'kirki' ), |
|
264 | + 'description' => esc_html__( 'This is a color control with form_component value is RgbColorPicker. The saved value will be an array.', 'kirki' ), |
|
265 | + 'section' => 'color_advanced_section', |
|
266 | + 'default' => '#ffff00', |
|
267 | + 'choices' => [ |
|
268 | + 'form_component' => 'RgbColorPicker', |
|
269 | + ], |
|
270 | + 'transport' => 'postMessage', |
|
271 | + ] |
|
272 | 272 | ); |
273 | 273 | |
274 | 274 | /** |
@@ -279,17 +279,17 @@ discard block |
||
279 | 279 | * "rgba(255, 255, 45)" |
280 | 280 | */ |
281 | 281 | new \Kirki\Field\Color( |
282 | - [ |
|
283 | - 'settings' => 'kirki_demo_color_form_component_rgb_string', |
|
284 | - 'label' => __( 'v4 — form_component — RgbStringColorPicker', 'kirki' ), |
|
285 | - 'description' => esc_html__( 'This is a color control with form_component value is RgbStringColorPicker. The saved value will be a string.', 'kirki' ), |
|
286 | - 'section' => 'color_advanced_section', |
|
287 | - 'default' => '#ffff00', |
|
288 | - 'choices' => [ |
|
289 | - 'form_component' => 'RgbStringColorPicker', |
|
290 | - ], |
|
291 | - 'transport' => 'postMessage', |
|
292 | - ] |
|
282 | + [ |
|
283 | + 'settings' => 'kirki_demo_color_form_component_rgb_string', |
|
284 | + 'label' => __( 'v4 — form_component — RgbStringColorPicker', 'kirki' ), |
|
285 | + 'description' => esc_html__( 'This is a color control with form_component value is RgbStringColorPicker. The saved value will be a string.', 'kirki' ), |
|
286 | + 'section' => 'color_advanced_section', |
|
287 | + 'default' => '#ffff00', |
|
288 | + 'choices' => [ |
|
289 | + 'form_component' => 'RgbStringColorPicker', |
|
290 | + ], |
|
291 | + 'transport' => 'postMessage', |
|
292 | + ] |
|
293 | 293 | ); |
294 | 294 | |
295 | 295 | /** |
@@ -305,17 +305,17 @@ discard block |
||
305 | 305 | * ] |
306 | 306 | */ |
307 | 307 | new \Kirki\Field\Color( |
308 | - [ |
|
309 | - 'settings' => 'kirki_demo_color_form_component_rgba', |
|
310 | - 'label' => __( 'v4 — form_component — RgbaColorPicker', 'kirki' ), |
|
311 | - 'description' => esc_html__( 'This is a color control with form_component value is RgbaColorPicker. The saved value will be an array.', 'kirki' ), |
|
312 | - 'section' => 'color_advanced_section', |
|
313 | - 'default' => '#ffff00', |
|
314 | - 'choices' => [ |
|
315 | - 'form_component' => 'RgbaColorPicker', |
|
316 | - ], |
|
317 | - 'transport' => 'postMessage', |
|
318 | - ] |
|
308 | + [ |
|
309 | + 'settings' => 'kirki_demo_color_form_component_rgba', |
|
310 | + 'label' => __( 'v4 — form_component — RgbaColorPicker', 'kirki' ), |
|
311 | + 'description' => esc_html__( 'This is a color control with form_component value is RgbaColorPicker. The saved value will be an array.', 'kirki' ), |
|
312 | + 'section' => 'color_advanced_section', |
|
313 | + 'default' => '#ffff00', |
|
314 | + 'choices' => [ |
|
315 | + 'form_component' => 'RgbaColorPicker', |
|
316 | + ], |
|
317 | + 'transport' => 'postMessage', |
|
318 | + ] |
|
319 | 319 | ); |
320 | 320 | |
321 | 321 | /** |
@@ -326,17 +326,17 @@ discard block |
||
326 | 326 | * "rgba(255, 255, 45, 0.5)" |
327 | 327 | */ |
328 | 328 | new \Kirki\Field\Color( |
329 | - [ |
|
330 | - 'settings' => 'kirki_demo_color_form_component_rgba_string', |
|
331 | - 'label' => __( 'v4 — form_component — RgbaStringColorPicker', 'kirki' ), |
|
332 | - 'description' => esc_html__( 'This is a color control with form_component value is RgbaStringColorPicker. The saved value will be a string.', 'kirki' ), |
|
333 | - 'section' => 'color_advanced_section', |
|
334 | - 'default' => '#ffff00', |
|
335 | - 'choices' => [ |
|
336 | - 'form_component' => 'RgbaStringColorPicker', |
|
337 | - ], |
|
338 | - 'transport' => 'postMessage', |
|
339 | - ] |
|
329 | + [ |
|
330 | + 'settings' => 'kirki_demo_color_form_component_rgba_string', |
|
331 | + 'label' => __( 'v4 — form_component — RgbaStringColorPicker', 'kirki' ), |
|
332 | + 'description' => esc_html__( 'This is a color control with form_component value is RgbaStringColorPicker. The saved value will be a string.', 'kirki' ), |
|
333 | + 'section' => 'color_advanced_section', |
|
334 | + 'default' => '#ffff00', |
|
335 | + 'choices' => [ |
|
336 | + 'form_component' => 'RgbaStringColorPicker', |
|
337 | + ], |
|
338 | + 'transport' => 'postMessage', |
|
339 | + ] |
|
340 | 340 | ); |
341 | 341 | |
342 | 342 | /** |
@@ -351,17 +351,17 @@ discard block |
||
351 | 351 | * ] |
352 | 352 | */ |
353 | 353 | new \Kirki\Field\Color( |
354 | - [ |
|
355 | - 'settings' => 'kirki_demo_color_form_component_hsl', |
|
356 | - 'label' => __( 'v4 — form_component — HslColorPicker', 'kirki' ), |
|
357 | - 'description' => esc_html__( 'This is a color control with form_component value is HslColorPicker. The saved value will be an array', 'kirki' ), |
|
358 | - 'section' => 'color_advanced_section', |
|
359 | - 'default' => 'hsl(206, 23%, 25%)', |
|
360 | - 'choices' => [ |
|
361 | - 'form_component' => 'HslColorPicker', |
|
362 | - ], |
|
363 | - 'transport' => 'postMessage', |
|
364 | - ] |
|
354 | + [ |
|
355 | + 'settings' => 'kirki_demo_color_form_component_hsl', |
|
356 | + 'label' => __( 'v4 — form_component — HslColorPicker', 'kirki' ), |
|
357 | + 'description' => esc_html__( 'This is a color control with form_component value is HslColorPicker. The saved value will be an array', 'kirki' ), |
|
358 | + 'section' => 'color_advanced_section', |
|
359 | + 'default' => 'hsl(206, 23%, 25%)', |
|
360 | + 'choices' => [ |
|
361 | + 'form_component' => 'HslColorPicker', |
|
362 | + ], |
|
363 | + 'transport' => 'postMessage', |
|
364 | + ] |
|
365 | 365 | ); |
366 | 366 | |
367 | 367 | /** |
@@ -372,17 +372,17 @@ discard block |
||
372 | 372 | * "hsl(180, 40%, 50%)" |
373 | 373 | */ |
374 | 374 | new \Kirki\Field\Color( |
375 | - [ |
|
376 | - 'settings' => 'kirki_demo_color_form_component_hsl_string', |
|
377 | - 'label' => __( 'v4 — form_component — HslStringColorPicker', 'kirki' ), |
|
378 | - 'description' => esc_html__( 'This is a color control with form_component value is HslStringColorPicker. The saved value will be a string', 'kirki' ), |
|
379 | - 'section' => 'color_advanced_section', |
|
380 | - 'default' => 'hsl(206, 23%, 25%)', |
|
381 | - 'choices' => [ |
|
382 | - 'form_component' => 'HslStringColorPicker', |
|
383 | - ], |
|
384 | - 'transport' => 'postMessage', |
|
385 | - ] |
|
375 | + [ |
|
376 | + 'settings' => 'kirki_demo_color_form_component_hsl_string', |
|
377 | + 'label' => __( 'v4 — form_component — HslStringColorPicker', 'kirki' ), |
|
378 | + 'description' => esc_html__( 'This is a color control with form_component value is HslStringColorPicker. The saved value will be a string', 'kirki' ), |
|
379 | + 'section' => 'color_advanced_section', |
|
380 | + 'default' => 'hsl(206, 23%, 25%)', |
|
381 | + 'choices' => [ |
|
382 | + 'form_component' => 'HslStringColorPicker', |
|
383 | + ], |
|
384 | + 'transport' => 'postMessage', |
|
385 | + ] |
|
386 | 386 | ); |
387 | 387 | |
388 | 388 | /** |
@@ -398,17 +398,17 @@ discard block |
||
398 | 398 | * ] |
399 | 399 | */ |
400 | 400 | new \Kirki\Field\Color( |
401 | - [ |
|
402 | - 'settings' => 'kirki_demo_color_form_component_hsla', |
|
403 | - 'label' => __( 'v4 — form_component — HslaColorPicker', 'kirki' ), |
|
404 | - 'description' => esc_html__( 'This is a color control with form_component value is HslaColorPicker. The saved value will be an array', 'kirki' ), |
|
405 | - 'section' => 'color_advanced_section', |
|
406 | - 'default' => 'hsla(206, 23%, 25%, 0.7)', |
|
407 | - 'choices' => [ |
|
408 | - 'form_component' => 'HslaColorPicker', |
|
409 | - ], |
|
410 | - 'transport' => 'postMessage', |
|
411 | - ] |
|
401 | + [ |
|
402 | + 'settings' => 'kirki_demo_color_form_component_hsla', |
|
403 | + 'label' => __( 'v4 — form_component — HslaColorPicker', 'kirki' ), |
|
404 | + 'description' => esc_html__( 'This is a color control with form_component value is HslaColorPicker. The saved value will be an array', 'kirki' ), |
|
405 | + 'section' => 'color_advanced_section', |
|
406 | + 'default' => 'hsla(206, 23%, 25%, 0.7)', |
|
407 | + 'choices' => [ |
|
408 | + 'form_component' => 'HslaColorPicker', |
|
409 | + ], |
|
410 | + 'transport' => 'postMessage', |
|
411 | + ] |
|
412 | 412 | ); |
413 | 413 | |
414 | 414 | /** |
@@ -419,63 +419,63 @@ discard block |
||
419 | 419 | * "hsla(180, 40%, 50%, 0.5)" |
420 | 420 | */ |
421 | 421 | new \Kirki\Field\Color( |
422 | - [ |
|
423 | - 'settings' => 'kirki_demo_color_form_component_hsla_string', |
|
424 | - 'label' => __( 'v4 — form_component — HslaStringColorPicker', 'kirki' ), |
|
425 | - 'description' => esc_html__( 'This is a color control with form_component value is HslaStringColorPicker. The saved value will be a string', 'kirki' ), |
|
426 | - 'section' => 'color_advanced_section', |
|
427 | - 'default' => 'hsla(206, 23%, 25%, 0.7)', |
|
428 | - 'choices' => [ |
|
429 | - 'form_component' => 'HslaStringColorPicker', |
|
430 | - ], |
|
431 | - 'transport' => 'postMessage', |
|
432 | - ] |
|
422 | + [ |
|
423 | + 'settings' => 'kirki_demo_color_form_component_hsla_string', |
|
424 | + 'label' => __( 'v4 — form_component — HslaStringColorPicker', 'kirki' ), |
|
425 | + 'description' => esc_html__( 'This is a color control with form_component value is HslaStringColorPicker. The saved value will be a string', 'kirki' ), |
|
426 | + 'section' => 'color_advanced_section', |
|
427 | + 'default' => 'hsla(206, 23%, 25%, 0.7)', |
|
428 | + 'choices' => [ |
|
429 | + 'form_component' => 'HslaStringColorPicker', |
|
430 | + ], |
|
431 | + 'transport' => 'postMessage', |
|
432 | + ] |
|
433 | 433 | ); |
434 | 434 | |
435 | 435 | /** |
436 | 436 | * DateTime Control. |
437 | 437 | */ |
438 | 438 | new \Kirki\Field\Date( |
439 | - [ |
|
440 | - 'settings' => 'kirki_demo_date', |
|
441 | - 'label' => esc_html__( 'Date Control', 'kirki' ), |
|
442 | - 'description' => esc_html__( 'This is a date control.', 'kirki' ), |
|
443 | - 'section' => 'date_section', |
|
444 | - 'default' => '', |
|
445 | - ] |
|
439 | + [ |
|
440 | + 'settings' => 'kirki_demo_date', |
|
441 | + 'label' => esc_html__( 'Date Control', 'kirki' ), |
|
442 | + 'description' => esc_html__( 'This is a date control.', 'kirki' ), |
|
443 | + 'section' => 'date_section', |
|
444 | + 'default' => '', |
|
445 | + ] |
|
446 | 446 | ); |
447 | 447 | |
448 | 448 | new \Kirki\Field\Date( |
449 | - [ |
|
450 | - 'settings' => 'kirki_demo_date_2', |
|
451 | - 'label' => esc_html__( 'Date Control 2', 'kirki' ), |
|
452 | - 'description' => esc_html__( 'This is a date control.', 'kirki' ), |
|
453 | - 'section' => 'date_section', |
|
454 | - 'default' => '', |
|
455 | - ] |
|
449 | + [ |
|
450 | + 'settings' => 'kirki_demo_date_2', |
|
451 | + 'label' => esc_html__( 'Date Control 2', 'kirki' ), |
|
452 | + 'description' => esc_html__( 'This is a date control.', 'kirki' ), |
|
453 | + 'section' => 'date_section', |
|
454 | + 'default' => '', |
|
455 | + ] |
|
456 | 456 | ); |
457 | 457 | |
458 | 458 | /** |
459 | 459 | * Editor Controls |
460 | 460 | */ |
461 | 461 | new \Kirki\Field\Editor( |
462 | - [ |
|
463 | - 'settings' => 'kirki_demo_editor_1', |
|
464 | - 'label' => esc_html__( 'First Editor Control', 'kirki' ), |
|
465 | - 'description' => esc_html__( 'This is an editor control.', 'kirki' ), |
|
466 | - 'section' => 'editor_section', |
|
467 | - 'default' => '', |
|
468 | - ] |
|
462 | + [ |
|
463 | + 'settings' => 'kirki_demo_editor_1', |
|
464 | + 'label' => esc_html__( 'First Editor Control', 'kirki' ), |
|
465 | + 'description' => esc_html__( 'This is an editor control.', 'kirki' ), |
|
466 | + 'section' => 'editor_section', |
|
467 | + 'default' => '', |
|
468 | + ] |
|
469 | 469 | ); |
470 | 470 | |
471 | 471 | new \Kirki\Field\Editor( |
472 | - [ |
|
473 | - 'settings' => 'kirki_demo_editor_2', |
|
474 | - 'label' => esc_html__( 'Second Editor Control', 'kirki' ), |
|
475 | - 'description' => esc_html__( 'This is a 2nd editor control just to check that we do not have issues with multiple instances.', 'kirki' ), |
|
476 | - 'section' => 'editor_section', |
|
477 | - 'default' => esc_html__( 'Default Text', 'kirki' ), |
|
478 | - ] |
|
472 | + [ |
|
473 | + 'settings' => 'kirki_demo_editor_2', |
|
474 | + 'label' => esc_html__( 'Second Editor Control', 'kirki' ), |
|
475 | + 'description' => esc_html__( 'This is a 2nd editor control just to check that we do not have issues with multiple instances.', 'kirki' ), |
|
476 | + 'section' => 'editor_section', |
|
477 | + 'default' => esc_html__( 'Default Text', 'kirki' ), |
|
478 | + ] |
|
479 | 479 | ); |
480 | 480 | |
481 | 481 | /** |
@@ -484,106 +484,106 @@ discard block |
||
484 | 484 | * @link https://kirki.org/docs/controls/color-palette.html |
485 | 485 | */ |
486 | 486 | new \Kirki\Field\Color_Palette( |
487 | - [ |
|
488 | - 'settings' => 'kirki_demo_color_palette_simple', |
|
489 | - 'label' => esc_html__( 'Simple Colors Set', 'kirki' ), |
|
490 | - 'description' => esc_html__( 'With default size (28). The `size` here is inner size (without border)', 'kirki' ), |
|
491 | - 'section' => 'color_palette_section', |
|
492 | - 'default' => '#888888', |
|
493 | - 'transport' => 'postMessage', |
|
494 | - 'choices' => [ |
|
495 | - 'colors' => [ '#000000', '#222222', '#444444', '#666666', '#888888', '#aaaaaa', '#cccccc', '#eeeeee', '#ffffff' ], |
|
496 | - 'style' => 'round', |
|
497 | - ], |
|
498 | - ] |
|
487 | + [ |
|
488 | + 'settings' => 'kirki_demo_color_palette_simple', |
|
489 | + 'label' => esc_html__( 'Simple Colors Set', 'kirki' ), |
|
490 | + 'description' => esc_html__( 'With default size (28). The `size` here is inner size (without border)', 'kirki' ), |
|
491 | + 'section' => 'color_palette_section', |
|
492 | + 'default' => '#888888', |
|
493 | + 'transport' => 'postMessage', |
|
494 | + 'choices' => [ |
|
495 | + 'colors' => [ '#000000', '#222222', '#444444', '#666666', '#888888', '#aaaaaa', '#cccccc', '#eeeeee', '#ffffff' ], |
|
496 | + 'style' => 'round', |
|
497 | + ], |
|
498 | + ] |
|
499 | 499 | ); |
500 | 500 | |
501 | 501 | new \Kirki\Field\Color_Palette( |
502 | - [ |
|
503 | - 'settings' => 'kirki_demo_color_palette_material_all', |
|
504 | - 'label' => esc_html__( 'Material Design Colors — All', 'kirki' ), |
|
505 | - 'description' => esc_html__( 'Showing all material design colors using `round` shape and size is 17', 'kirki' ), |
|
506 | - 'section' => 'color_palette_section', |
|
507 | - 'default' => '#D1C4E9', |
|
508 | - 'transport' => 'postMessage', |
|
509 | - 'choices' => [ |
|
510 | - 'colors' => Helper::get_material_design_colors( 'all' ), |
|
511 | - 'shape' => 'round', |
|
512 | - 'size' => 17, |
|
513 | - ], |
|
514 | - ] |
|
502 | + [ |
|
503 | + 'settings' => 'kirki_demo_color_palette_material_all', |
|
504 | + 'label' => esc_html__( 'Material Design Colors — All', 'kirki' ), |
|
505 | + 'description' => esc_html__( 'Showing all material design colors using `round` shape and size is 17', 'kirki' ), |
|
506 | + 'section' => 'color_palette_section', |
|
507 | + 'default' => '#D1C4E9', |
|
508 | + 'transport' => 'postMessage', |
|
509 | + 'choices' => [ |
|
510 | + 'colors' => Helper::get_material_design_colors( 'all' ), |
|
511 | + 'shape' => 'round', |
|
512 | + 'size' => 17, |
|
513 | + ], |
|
514 | + ] |
|
515 | 515 | ); |
516 | 516 | |
517 | 517 | new \Kirki\Field\Color_Palette( |
518 | - [ |
|
519 | - 'settings' => 'kirki_demo_color_palette_material_primary', |
|
520 | - 'label' => esc_html__( 'Material Design Colors — Primary', 'kirki' ), |
|
521 | - 'description' => esc_html__( 'Showing primary material design colors', 'kirki' ), |
|
522 | - 'section' => 'color_palette_section', |
|
523 | - 'choices' => [ |
|
524 | - 'colors' => Helper::get_material_design_colors( 'primary' ), |
|
525 | - 'size' => 25, |
|
526 | - ], |
|
527 | - ] |
|
518 | + [ |
|
519 | + 'settings' => 'kirki_demo_color_palette_material_primary', |
|
520 | + 'label' => esc_html__( 'Material Design Colors — Primary', 'kirki' ), |
|
521 | + 'description' => esc_html__( 'Showing primary material design colors', 'kirki' ), |
|
522 | + 'section' => 'color_palette_section', |
|
523 | + 'choices' => [ |
|
524 | + 'colors' => Helper::get_material_design_colors( 'primary' ), |
|
525 | + 'size' => 25, |
|
526 | + ], |
|
527 | + ] |
|
528 | 528 | ); |
529 | 529 | |
530 | 530 | new \Kirki\Field\Color_Palette( |
531 | - [ |
|
532 | - 'settings' => 'kirki_demo_color_palette_material_red', |
|
533 | - 'label' => esc_html__( 'Material Design Colors — Red', 'kirki' ), |
|
534 | - 'description' => esc_html__( 'Showing red material design colors', 'kirki' ), |
|
535 | - 'section' => 'color_palette_section', |
|
536 | - 'choices' => [ |
|
537 | - 'colors' => Helper::get_material_design_colors( 'red' ), |
|
538 | - 'size' => 16, |
|
539 | - ], |
|
540 | - ] |
|
531 | + [ |
|
532 | + 'settings' => 'kirki_demo_color_palette_material_red', |
|
533 | + 'label' => esc_html__( 'Material Design Colors — Red', 'kirki' ), |
|
534 | + 'description' => esc_html__( 'Showing red material design colors', 'kirki' ), |
|
535 | + 'section' => 'color_palette_section', |
|
536 | + 'choices' => [ |
|
537 | + 'colors' => Helper::get_material_design_colors( 'red' ), |
|
538 | + 'size' => 16, |
|
539 | + ], |
|
540 | + ] |
|
541 | 541 | ); |
542 | 542 | |
543 | 543 | new \Kirki\Field\Color_Palette( |
544 | - [ |
|
545 | - 'settings' => 'kirki_demo_color_palette_a100', |
|
546 | - 'label' => esc_html__( 'Material Design Colors — A100', 'kirki' ), |
|
547 | - 'description' => esc_html__( 'Showing "A100" variant of material design colors', 'kirki' ), |
|
548 | - 'section' => 'color_palette_section', |
|
549 | - 'default' => '#FF80AB', |
|
550 | - 'choices' => [ |
|
551 | - 'colors' => Helper::get_material_design_colors( 'A100' ), |
|
552 | - 'size' => 60, |
|
553 | - 'style' => 'round', |
|
554 | - ], |
|
555 | - ] |
|
544 | + [ |
|
545 | + 'settings' => 'kirki_demo_color_palette_a100', |
|
546 | + 'label' => esc_html__( 'Material Design Colors — A100', 'kirki' ), |
|
547 | + 'description' => esc_html__( 'Showing "A100" variant of material design colors', 'kirki' ), |
|
548 | + 'section' => 'color_palette_section', |
|
549 | + 'default' => '#FF80AB', |
|
550 | + 'choices' => [ |
|
551 | + 'colors' => Helper::get_material_design_colors( 'A100' ), |
|
552 | + 'size' => 60, |
|
553 | + 'style' => 'round', |
|
554 | + ], |
|
555 | + ] |
|
556 | 556 | ); |
557 | 557 | |
558 | 558 | Kirki::add_field( |
559 | - 'kirki_demo_config', |
|
560 | - [ |
|
561 | - 'type' => 'color-palette', |
|
562 | - 'settings' => 'kirki_demo_color_palette_old', |
|
563 | - 'label' => 'The Old Way', |
|
564 | - 'description' => 'Using `Kirki::add_field` in round shape', |
|
565 | - 'section' => 'color_palette_section', |
|
566 | - 'transport' => 'postMessage', |
|
567 | - 'choices' => [ |
|
568 | - 'colors' => [ '#000000', '#222222', '#444444', '#666666', '#888888', '#aaaaaa', '#cccccc', '#eeeeee', '#ffffff' ], |
|
569 | - 'style' => 'round', |
|
570 | - ], |
|
571 | - ] |
|
559 | + 'kirki_demo_config', |
|
560 | + [ |
|
561 | + 'type' => 'color-palette', |
|
562 | + 'settings' => 'kirki_demo_color_palette_old', |
|
563 | + 'label' => 'The Old Way', |
|
564 | + 'description' => 'Using `Kirki::add_field` in round shape', |
|
565 | + 'section' => 'color_palette_section', |
|
566 | + 'transport' => 'postMessage', |
|
567 | + 'choices' => [ |
|
568 | + 'colors' => [ '#000000', '#222222', '#444444', '#666666', '#888888', '#aaaaaa', '#cccccc', '#eeeeee', '#ffffff' ], |
|
569 | + 'style' => 'round', |
|
570 | + ], |
|
571 | + ] |
|
572 | 572 | ); |
573 | 573 | |
574 | 574 | add_action( |
575 | - 'customize_register', |
|
576 | - function( $wp_customize ) { |
|
577 | - /** |
|
578 | - * The custom control class |
|
579 | - */ |
|
580 | - class Kirki_Demo_Custom_Control extends Kirki\Control\Base { |
|
581 | - public $type = 'kirki-demo-custom-control'; |
|
575 | + 'customize_register', |
|
576 | + function( $wp_customize ) { |
|
577 | + /** |
|
578 | + * The custom control class |
|
579 | + */ |
|
580 | + class Kirki_Demo_Custom_Control extends Kirki\Control\Base { |
|
581 | + public $type = 'kirki-demo-custom-control'; |
|
582 | 582 | |
583 | - public function render_content() { |
|
583 | + public function render_content() { |
|
584 | 584 | |
585 | - $saved_value = $this->value(); |
|
586 | - ?> |
|
585 | + $saved_value = $this->value(); |
|
586 | + ?> |
|
587 | 587 | |
588 | 588 | <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
589 | 589 | <span class="customize-control-description description"><?php echo esc_html( $this->description ); ?></span> |
@@ -594,31 +594,31 @@ discard block |
||
594 | 594 | </div> |
595 | 595 | |
596 | 596 | <?php |
597 | - } |
|
598 | - } |
|
597 | + } |
|
598 | + } |
|
599 | 599 | |
600 | - // Register our custom control with Kirki. |
|
601 | - add_filter( |
|
602 | - 'kirki_control_types', |
|
603 | - function( $controls ) { |
|
604 | - $controls['kirki-demo-custom-control'] = 'Kirki_Demo_Custom_Control'; |
|
605 | - return $controls; |
|
606 | - } |
|
607 | - ); |
|
600 | + // Register our custom control with Kirki. |
|
601 | + add_filter( |
|
602 | + 'kirki_control_types', |
|
603 | + function( $controls ) { |
|
604 | + $controls['kirki-demo-custom-control'] = 'Kirki_Demo_Custom_Control'; |
|
605 | + return $controls; |
|
606 | + } |
|
607 | + ); |
|
608 | 608 | |
609 | - } |
|
609 | + } |
|
610 | 610 | ); |
611 | 611 | |
612 | 612 | Kirki::add_field( |
613 | - 'kirki_demo_config', |
|
614 | - [ |
|
615 | - 'type' => 'kirki-demo-custom-control', |
|
616 | - 'settings' => 'kirki_demo_custom_control_old_way', |
|
617 | - 'label' => esc_html__( 'Custom Control', 'kirki' ), |
|
618 | - 'description' => 'A custom control demo, registered by extending `Kirki\\Control\\Base` class.', |
|
619 | - 'section' => 'custom_section', |
|
620 | - 'transport' => 'postMessage', |
|
621 | - ] |
|
613 | + 'kirki_demo_config', |
|
614 | + [ |
|
615 | + 'type' => 'kirki-demo-custom-control', |
|
616 | + 'settings' => 'kirki_demo_custom_control_old_way', |
|
617 | + 'label' => esc_html__( 'Custom Control', 'kirki' ), |
|
618 | + 'description' => 'A custom control demo, registered by extending `Kirki\\Control\\Base` class.', |
|
619 | + 'section' => 'custom_section', |
|
620 | + 'transport' => 'postMessage', |
|
621 | + ] |
|
622 | 622 | ); |
623 | 623 | |
624 | 624 | /** |
@@ -627,674 +627,674 @@ discard block |
||
627 | 627 | * @link https://kirki.org/docs/controls/dashicons.html |
628 | 628 | */ |
629 | 629 | new \Kirki\Field\Dashicons( |
630 | - [ |
|
631 | - 'settings' => 'kirki_demo_dashicons_setting_0', |
|
632 | - 'label' => esc_html__( 'Dashicons Control', 'kirki' ), |
|
633 | - 'description' => esc_html__( 'Using a custom array of dashicons', 'kirki' ), |
|
634 | - 'section' => 'dashicons_section', |
|
635 | - 'default' => 'menu', |
|
636 | - 'choices' => [ |
|
637 | - 'menu', |
|
638 | - 'admin-site', |
|
639 | - 'dashboard', |
|
640 | - 'admin-post', |
|
641 | - 'admin-media', |
|
642 | - 'admin-links', |
|
643 | - 'admin-page', |
|
644 | - ], |
|
645 | - ] |
|
630 | + [ |
|
631 | + 'settings' => 'kirki_demo_dashicons_setting_0', |
|
632 | + 'label' => esc_html__( 'Dashicons Control', 'kirki' ), |
|
633 | + 'description' => esc_html__( 'Using a custom array of dashicons', 'kirki' ), |
|
634 | + 'section' => 'dashicons_section', |
|
635 | + 'default' => 'menu', |
|
636 | + 'choices' => [ |
|
637 | + 'menu', |
|
638 | + 'admin-site', |
|
639 | + 'dashboard', |
|
640 | + 'admin-post', |
|
641 | + 'admin-media', |
|
642 | + 'admin-links', |
|
643 | + 'admin-page', |
|
644 | + ], |
|
645 | + ] |
|
646 | 646 | ); |
647 | 647 | |
648 | 648 | new \Kirki\Field\Dashicons( |
649 | - [ |
|
650 | - 'settings' => 'kirki_demo_dashicons_setting_1', |
|
651 | - 'label' => esc_html__( 'All Dashicons', 'kirki' ), |
|
652 | - 'description' => esc_html__( 'Showing all dashicons', 'kirki' ), |
|
653 | - 'section' => 'dashicons_section', |
|
654 | - 'default' => 'menu', |
|
655 | - ] |
|
649 | + [ |
|
650 | + 'settings' => 'kirki_demo_dashicons_setting_1', |
|
651 | + 'label' => esc_html__( 'All Dashicons', 'kirki' ), |
|
652 | + 'description' => esc_html__( 'Showing all dashicons', 'kirki' ), |
|
653 | + 'section' => 'dashicons_section', |
|
654 | + 'default' => 'menu', |
|
655 | + ] |
|
656 | 656 | ); |
657 | 657 | |
658 | 658 | /** |
659 | 659 | * Dimension Control. |
660 | 660 | */ |
661 | 661 | new \Kirki\Field\Dimension( |
662 | - [ |
|
663 | - 'settings' => 'kirki_demo_dimension_0', |
|
664 | - 'label' => esc_html__( 'Dimension Control', 'kirki' ), |
|
665 | - 'description' => esc_html__( 'A simple dimension control.', 'kirki' ), |
|
666 | - 'section' => 'dimension_section', |
|
667 | - 'default' => '10px', |
|
668 | - 'choices' => [ |
|
669 | - 'accept_unitless' => true, |
|
670 | - ], |
|
671 | - ] |
|
662 | + [ |
|
663 | + 'settings' => 'kirki_demo_dimension_0', |
|
664 | + 'label' => esc_html__( 'Dimension Control', 'kirki' ), |
|
665 | + 'description' => esc_html__( 'A simple dimension control.', 'kirki' ), |
|
666 | + 'section' => 'dimension_section', |
|
667 | + 'default' => '10px', |
|
668 | + 'choices' => [ |
|
669 | + 'accept_unitless' => true, |
|
670 | + ], |
|
671 | + ] |
|
672 | 672 | ); |
673 | 673 | |
674 | 674 | /** |
675 | 675 | * Dimensions Control. |
676 | 676 | */ |
677 | 677 | new \Kirki\Field\Dimensions( |
678 | - [ |
|
679 | - 'settings' => 'kirki_demo_dimensions_0', |
|
680 | - 'label' => esc_html__( 'Dimensions Control', 'kirki' ), |
|
681 | - 'description' => esc_html__( 'Sample of dimensions control with 2 fields.', 'kirki' ), |
|
682 | - 'section' => 'dimensions_section', |
|
683 | - 'default' => [ |
|
684 | - 'width' => '100px', |
|
685 | - 'height' => '100px', |
|
686 | - ], |
|
687 | - ] |
|
678 | + [ |
|
679 | + 'settings' => 'kirki_demo_dimensions_0', |
|
680 | + 'label' => esc_html__( 'Dimensions Control', 'kirki' ), |
|
681 | + 'description' => esc_html__( 'Sample of dimensions control with 2 fields.', 'kirki' ), |
|
682 | + 'section' => 'dimensions_section', |
|
683 | + 'default' => [ |
|
684 | + 'width' => '100px', |
|
685 | + 'height' => '100px', |
|
686 | + ], |
|
687 | + ] |
|
688 | 688 | ); |
689 | 689 | |
690 | 690 | new \Kirki\Field\Dimensions( |
691 | - [ |
|
692 | - 'settings' => 'kirki_demo_dimensions_1', |
|
693 | - 'label' => esc_html__( 'Dimension Control', 'kirki' ), |
|
694 | - 'description' => esc_html__( 'Sample of dimensions control with 4 fields.', 'kirki' ), |
|
695 | - 'section' => 'dimensions_section', |
|
696 | - 'default' => [ |
|
697 | - 'padding-top' => '1em', |
|
698 | - 'padding-bottom' => '10rem', |
|
699 | - 'padding-left' => '1vh', |
|
700 | - 'padding-right' => '10px', |
|
701 | - ], |
|
702 | - ] |
|
691 | + [ |
|
692 | + 'settings' => 'kirki_demo_dimensions_1', |
|
693 | + 'label' => esc_html__( 'Dimension Control', 'kirki' ), |
|
694 | + 'description' => esc_html__( 'Sample of dimensions control with 4 fields.', 'kirki' ), |
|
695 | + 'section' => 'dimensions_section', |
|
696 | + 'default' => [ |
|
697 | + 'padding-top' => '1em', |
|
698 | + 'padding-bottom' => '10rem', |
|
699 | + 'padding-left' => '1vh', |
|
700 | + 'padding-right' => '10px', |
|
701 | + ], |
|
702 | + ] |
|
703 | 703 | ); |
704 | 704 | |
705 | 705 | new \Kirki\Field\Dimensions( |
706 | - [ |
|
707 | - 'settings' => 'kirki_demo_padding', |
|
708 | - 'label' => esc_html__( 'Padding Control', 'kirki' ), |
|
709 | - 'description' => esc_html__( 'Sample of padding controls with 3 fields.', 'kirki' ), |
|
710 | - 'section' => 'dimensions_section', |
|
711 | - 'default' => [ |
|
712 | - 'top' => '1em', |
|
713 | - 'bottom' => '10rem', |
|
714 | - 'horizontal' => '1vh', |
|
715 | - ], |
|
716 | - ] |
|
706 | + [ |
|
707 | + 'settings' => 'kirki_demo_padding', |
|
708 | + 'label' => esc_html__( 'Padding Control', 'kirki' ), |
|
709 | + 'description' => esc_html__( 'Sample of padding controls with 3 fields.', 'kirki' ), |
|
710 | + 'section' => 'dimensions_section', |
|
711 | + 'default' => [ |
|
712 | + 'top' => '1em', |
|
713 | + 'bottom' => '10rem', |
|
714 | + 'horizontal' => '1vh', |
|
715 | + ], |
|
716 | + ] |
|
717 | 717 | ); |
718 | 718 | |
719 | 719 | new \Kirki\Field\Dimensions( |
720 | - [ |
|
721 | - 'settings' => 'kirki_demo_spacing', |
|
722 | - 'label' => esc_html__( 'Spacing Control', 'kirki' ), |
|
723 | - 'description' => esc_html__( 'Sample of spacing controls with 4 fields.', 'kirki' ), |
|
724 | - 'section' => 'dimensions_section', |
|
725 | - 'default' => [ |
|
726 | - 'top' => '1em', |
|
727 | - 'bottom' => '10rem', |
|
728 | - 'left' => '1vh', |
|
729 | - 'right' => '10px', |
|
730 | - ], |
|
731 | - ] |
|
720 | + [ |
|
721 | + 'settings' => 'kirki_demo_spacing', |
|
722 | + 'label' => esc_html__( 'Spacing Control', 'kirki' ), |
|
723 | + 'description' => esc_html__( 'Sample of spacing controls with 4 fields.', 'kirki' ), |
|
724 | + 'section' => 'dimensions_section', |
|
725 | + 'default' => [ |
|
726 | + 'top' => '1em', |
|
727 | + 'bottom' => '10rem', |
|
728 | + 'left' => '1vh', |
|
729 | + 'right' => '10px', |
|
730 | + ], |
|
731 | + ] |
|
732 | 732 | ); |
733 | 733 | |
734 | 734 | /** |
735 | 735 | * Dropdown-pages Control. |
736 | 736 | */ |
737 | 737 | new \Kirki\Field\Dropdown_Pages( |
738 | - [ |
|
739 | - 'settings' => 'kirki_demo_dropdown_pages', |
|
740 | - 'label' => esc_html__( 'Dropdown Pages Control', 'kirki' ), |
|
741 | - 'description' => esc_html__( 'Sample of dropdown pages control.', 'kirki' ), |
|
742 | - 'section' => 'dropdown_pages_section', |
|
743 | - 'default' => [ |
|
744 | - 'width' => '100px', |
|
745 | - 'height' => '100px', |
|
746 | - ], |
|
747 | - ] |
|
738 | + [ |
|
739 | + 'settings' => 'kirki_demo_dropdown_pages', |
|
740 | + 'label' => esc_html__( 'Dropdown Pages Control', 'kirki' ), |
|
741 | + 'description' => esc_html__( 'Sample of dropdown pages control.', 'kirki' ), |
|
742 | + 'section' => 'dropdown_pages_section', |
|
743 | + 'default' => [ |
|
744 | + 'width' => '100px', |
|
745 | + 'height' => '100px', |
|
746 | + ], |
|
747 | + ] |
|
748 | 748 | ); |
749 | 749 | |
750 | 750 | /** |
751 | 751 | * Generic Controls. |
752 | 752 | */ |
753 | 753 | new \Kirki\Field\Text( |
754 | - [ |
|
755 | - 'settings' => 'kirki_demo_generic_text', |
|
756 | - 'label' => esc_html__( 'Generic Control — Text Field', 'kirki' ), |
|
757 | - 'description' => esc_html__( 'The demo of this control has partial refresh with transport is postMessage', 'kirki' ), |
|
758 | - 'section' => 'generic_section', |
|
759 | - 'transport' => 'postMessage', |
|
760 | - 'default' => '', |
|
761 | - 'partial_refresh' => [ |
|
762 | - 'generic_text_refresh' => [ |
|
763 | - 'selector' => '.kirki-partial-refresh-demo', |
|
764 | - 'render_callback' => function() { |
|
765 | - $value = get_theme_mod( 'kirki_demo_generic_text' ); |
|
766 | - return $value ? 'value of Generic URL Field control is: ' . $value : ''; |
|
767 | - }, |
|
768 | - ], |
|
769 | - ], |
|
770 | - ] |
|
754 | + [ |
|
755 | + 'settings' => 'kirki_demo_generic_text', |
|
756 | + 'label' => esc_html__( 'Generic Control — Text Field', 'kirki' ), |
|
757 | + 'description' => esc_html__( 'The demo of this control has partial refresh with transport is postMessage', 'kirki' ), |
|
758 | + 'section' => 'generic_section', |
|
759 | + 'transport' => 'postMessage', |
|
760 | + 'default' => '', |
|
761 | + 'partial_refresh' => [ |
|
762 | + 'generic_text_refresh' => [ |
|
763 | + 'selector' => '.kirki-partial-refresh-demo', |
|
764 | + 'render_callback' => function() { |
|
765 | + $value = get_theme_mod( 'kirki_demo_generic_text' ); |
|
766 | + return $value ? 'value of Generic URL Field control is: ' . $value : ''; |
|
767 | + }, |
|
768 | + ], |
|
769 | + ], |
|
770 | + ] |
|
771 | 771 | ); |
772 | 772 | |
773 | 773 | new \Kirki\Field\URL( |
774 | - [ |
|
775 | - 'settings' => 'kirki_demo_generic_url', |
|
776 | - 'label' => esc_html__( 'Generic Control — URL Field', 'kirki' ), |
|
777 | - 'description' => esc_html__( 'The demo of this control has partial refresh without transport is defined', 'kirki' ), |
|
778 | - 'section' => 'generic_section', |
|
779 | - 'default' => '', |
|
780 | - 'partial_refresh' => [ |
|
781 | - 'generic_text_refresh2' => [ |
|
782 | - 'selector' => '.kirki-partial-refresh-demo2', |
|
783 | - 'render_callback' => function() { |
|
784 | - $value = get_theme_mod( 'kirki_demo_generic_url' ); |
|
785 | - return $value ? 'value of Generic URL Field control is: ' . $value : ''; |
|
786 | - }, |
|
787 | - ], |
|
788 | - ], |
|
789 | - ] |
|
774 | + [ |
|
775 | + 'settings' => 'kirki_demo_generic_url', |
|
776 | + 'label' => esc_html__( 'Generic Control — URL Field', 'kirki' ), |
|
777 | + 'description' => esc_html__( 'The demo of this control has partial refresh without transport is defined', 'kirki' ), |
|
778 | + 'section' => 'generic_section', |
|
779 | + 'default' => '', |
|
780 | + 'partial_refresh' => [ |
|
781 | + 'generic_text_refresh2' => [ |
|
782 | + 'selector' => '.kirki-partial-refresh-demo2', |
|
783 | + 'render_callback' => function() { |
|
784 | + $value = get_theme_mod( 'kirki_demo_generic_url' ); |
|
785 | + return $value ? 'value of Generic URL Field control is: ' . $value : ''; |
|
786 | + }, |
|
787 | + ], |
|
788 | + ], |
|
789 | + ] |
|
790 | 790 | ); |
791 | 791 | |
792 | 792 | new \Kirki\Field\Textarea( |
793 | - [ |
|
794 | - 'settings' => 'kirki_demo_generic_textarea', |
|
795 | - 'label' => esc_html__( 'Generic Control — Textarea Field', 'kirki' ), |
|
796 | - 'description' => esc_html__( 'Description', 'kirki' ), |
|
797 | - 'section' => 'generic_section', |
|
798 | - 'default' => '', |
|
799 | - ] |
|
793 | + [ |
|
794 | + 'settings' => 'kirki_demo_generic_textarea', |
|
795 | + 'label' => esc_html__( 'Generic Control — Textarea Field', 'kirki' ), |
|
796 | + 'description' => esc_html__( 'Description', 'kirki' ), |
|
797 | + 'section' => 'generic_section', |
|
798 | + 'default' => '', |
|
799 | + ] |
|
800 | 800 | ); |
801 | 801 | |
802 | 802 | new \Kirki\Field\Generic( |
803 | - [ |
|
804 | - 'settings' => 'kirki_demo_generic_custom', |
|
805 | - 'label' => esc_html__( 'Generic Control — Custom Input.', 'kirki' ), |
|
806 | - 'description' => esc_html__( 'The "generic" control allows you to add any input type you want. In this case we use type="password" and define custom styles.', 'kirki' ), |
|
807 | - 'section' => 'generic_section', |
|
808 | - 'default' => '', |
|
809 | - 'choices' => [ |
|
810 | - 'element' => 'input', |
|
811 | - 'type' => 'password', |
|
812 | - 'style' => 'background-color:black;color:red;', |
|
813 | - 'data-foo' => 'bar', |
|
814 | - ], |
|
815 | - ] |
|
803 | + [ |
|
804 | + 'settings' => 'kirki_demo_generic_custom', |
|
805 | + 'label' => esc_html__( 'Generic Control — Custom Input.', 'kirki' ), |
|
806 | + 'description' => esc_html__( 'The "generic" control allows you to add any input type you want. In this case we use type="password" and define custom styles.', 'kirki' ), |
|
807 | + 'section' => 'generic_section', |
|
808 | + 'default' => '', |
|
809 | + 'choices' => [ |
|
810 | + 'element' => 'input', |
|
811 | + 'type' => 'password', |
|
812 | + 'style' => 'background-color:black;color:red;', |
|
813 | + 'data-foo' => 'bar', |
|
814 | + ], |
|
815 | + ] |
|
816 | 816 | ); |
817 | 817 | |
818 | 818 | /** |
819 | 819 | * Image Control. |
820 | 820 | */ |
821 | 821 | new \Kirki\Field\Image( |
822 | - [ |
|
823 | - 'settings' => 'kirki_demo_image_url', |
|
824 | - 'label' => esc_html__( 'Image Control (URL)', 'kirki' ), |
|
825 | - 'description' => esc_html__( 'The saved value will be the URL.', 'kirki' ), |
|
826 | - 'section' => 'image_section', |
|
827 | - 'default' => '', |
|
828 | - ] |
|
822 | + [ |
|
823 | + 'settings' => 'kirki_demo_image_url', |
|
824 | + 'label' => esc_html__( 'Image Control (URL)', 'kirki' ), |
|
825 | + 'description' => esc_html__( 'The saved value will be the URL.', 'kirki' ), |
|
826 | + 'section' => 'image_section', |
|
827 | + 'default' => '', |
|
828 | + ] |
|
829 | 829 | ); |
830 | 830 | |
831 | 831 | new \Kirki\Field\Image( |
832 | - [ |
|
833 | - 'settings' => 'kirki_demo_image_id', |
|
834 | - 'label' => esc_html__( 'Image Control (ID)', 'kirki' ), |
|
835 | - 'description' => esc_html__( 'The saved value will an ID.', 'kirki' ), |
|
836 | - 'section' => 'image_section', |
|
837 | - 'default' => '', |
|
838 | - 'choices' => [ |
|
839 | - 'save_as' => 'id', |
|
840 | - ], |
|
841 | - ] |
|
832 | + [ |
|
833 | + 'settings' => 'kirki_demo_image_id', |
|
834 | + 'label' => esc_html__( 'Image Control (ID)', 'kirki' ), |
|
835 | + 'description' => esc_html__( 'The saved value will an ID.', 'kirki' ), |
|
836 | + 'section' => 'image_section', |
|
837 | + 'default' => '', |
|
838 | + 'choices' => [ |
|
839 | + 'save_as' => 'id', |
|
840 | + ], |
|
841 | + ] |
|
842 | 842 | ); |
843 | 843 | |
844 | 844 | new \Kirki\Field\Image( |
845 | - [ |
|
846 | - 'settings' => 'kirki_demo_image_array', |
|
847 | - 'label' => esc_html__( 'Image Control (array)', 'kirki' ), |
|
848 | - 'description' => esc_html__( 'The saved value will an array.', 'kirki' ), |
|
849 | - 'section' => 'image_section', |
|
850 | - 'default' => '', |
|
851 | - 'choices' => [ |
|
852 | - 'save_as' => 'array', |
|
853 | - ], |
|
854 | - ] |
|
845 | + [ |
|
846 | + 'settings' => 'kirki_demo_image_array', |
|
847 | + 'label' => esc_html__( 'Image Control (array)', 'kirki' ), |
|
848 | + 'description' => esc_html__( 'The saved value will an array.', 'kirki' ), |
|
849 | + 'section' => 'image_section', |
|
850 | + 'default' => '', |
|
851 | + 'choices' => [ |
|
852 | + 'save_as' => 'array', |
|
853 | + ], |
|
854 | + ] |
|
855 | 855 | ); |
856 | 856 | |
857 | 857 | /** |
858 | 858 | * Upload control. |
859 | 859 | */ |
860 | 860 | new \Kirki\Field\Upload( |
861 | - [ |
|
862 | - 'settings' => 'kirki_demo_upload_url', |
|
863 | - 'label' => esc_html__( 'Upload Control (URL)', 'kirki' ), |
|
864 | - 'description' => esc_html__( 'The saved value will the URL.', 'kirki' ), |
|
865 | - 'section' => 'upload_section', |
|
866 | - 'default' => '', |
|
867 | - 'transport' => 'postMessage', |
|
868 | - ] |
|
861 | + [ |
|
862 | + 'settings' => 'kirki_demo_upload_url', |
|
863 | + 'label' => esc_html__( 'Upload Control (URL)', 'kirki' ), |
|
864 | + 'description' => esc_html__( 'The saved value will the URL.', 'kirki' ), |
|
865 | + 'section' => 'upload_section', |
|
866 | + 'default' => '', |
|
867 | + 'transport' => 'postMessage', |
|
868 | + ] |
|
869 | 869 | ); |
870 | 870 | |
871 | 871 | /** |
872 | 872 | * Multicheck Control. |
873 | 873 | */ |
874 | 874 | new \Kirki\Field\Multicheck( |
875 | - [ |
|
876 | - 'settings' => 'kirki_demo_multicheck', |
|
877 | - 'label' => esc_html__( 'Multickeck Control', 'kirki' ), |
|
878 | - 'section' => 'multicheck_section', |
|
879 | - 'default' => [ 'option-1', 'option-3', 'option-4' ], |
|
880 | - 'priority' => 10, |
|
881 | - 'choices' => [ |
|
882 | - 'option-1' => esc_html__( 'Option 1', 'kirki' ), |
|
883 | - 'option-2' => esc_html__( 'Option 2', 'kirki' ), |
|
884 | - 'option-3' => esc_html__( 'Option 3', 'kirki' ), |
|
885 | - 'option-4' => esc_html__( 'Option 4', 'kirki' ), |
|
886 | - 'option-5' => esc_html__( 'Option 5', 'kirki' ), |
|
887 | - ], |
|
888 | - ] |
|
875 | + [ |
|
876 | + 'settings' => 'kirki_demo_multicheck', |
|
877 | + 'label' => esc_html__( 'Multickeck Control', 'kirki' ), |
|
878 | + 'section' => 'multicheck_section', |
|
879 | + 'default' => [ 'option-1', 'option-3', 'option-4' ], |
|
880 | + 'priority' => 10, |
|
881 | + 'choices' => [ |
|
882 | + 'option-1' => esc_html__( 'Option 1', 'kirki' ), |
|
883 | + 'option-2' => esc_html__( 'Option 2', 'kirki' ), |
|
884 | + 'option-3' => esc_html__( 'Option 3', 'kirki' ), |
|
885 | + 'option-4' => esc_html__( 'Option 4', 'kirki' ), |
|
886 | + 'option-5' => esc_html__( 'Option 5', 'kirki' ), |
|
887 | + ], |
|
888 | + ] |
|
889 | 889 | ); |
890 | 890 | |
891 | 891 | /** |
892 | 892 | * Multicolor Control. |
893 | 893 | */ |
894 | 894 | new \Kirki\Field\Multicolor( |
895 | - [ |
|
896 | - 'settings' => 'kirki_demo_multicolor', |
|
897 | - 'label' => esc_html__( 'Multicolor Control', 'kirki' ), |
|
898 | - 'section' => 'multicolor_section', |
|
899 | - 'priority' => 10, |
|
900 | - 'transport' => 'postMessage', |
|
901 | - 'choices' => [ |
|
902 | - 'link' => esc_html__( 'Link Color', 'kirki' ), |
|
903 | - 'hover' => esc_html__( 'And this is hover color with long label so you know how it is displayed.', 'kirki' ), |
|
904 | - 'active' => esc_html__( 'Active Color', 'kirki' ), |
|
905 | - 'another1' => esc_html__( 'Another color 1', 'kirki' ), |
|
906 | - 'another2' => esc_html__( 'Another color 2', 'kirki' ), |
|
907 | - 'another3' => esc_html__( 'Another color 3', 'kirki' ), |
|
908 | - 'another4' => esc_html__( 'Another color 4', 'kirki' ), |
|
909 | - 'another5' => esc_html__( 'Another color 5', 'kirki' ), |
|
910 | - 'another6' => esc_html__( 'Another color 6', 'kirki' ), |
|
911 | - 'another7' => esc_html__( 'Another color 7', 'kirki' ), |
|
912 | - 'another8' => esc_html__( 'Another color 8', 'kirki' ), |
|
913 | - 'another9' => esc_html__( 'Another color 9', 'kirki' ), |
|
914 | - 'another10' => esc_html__( 'Another color 10', 'kirki' ), |
|
915 | - 'another11' => esc_html__( 'Another color 11', 'kirki' ), |
|
916 | - 'another12' => esc_html__( 'Another color 12', 'kirki' ), |
|
917 | - 'another13' => esc_html__( 'Another color 13', 'kirki' ), |
|
918 | - 'another14' => esc_html__( 'Another color 14', 'kirki' ), |
|
919 | - 'another15' => esc_html__( 'Another color 15', 'kirki' ), |
|
920 | - ], |
|
921 | - 'alpha' => true, |
|
922 | - 'default' => [ |
|
923 | - 'link' => '#0088cc', |
|
924 | - 'hover' => '#00aaff', |
|
925 | - 'active' => '#00ffff', |
|
926 | - ], |
|
927 | - ] |
|
895 | + [ |
|
896 | + 'settings' => 'kirki_demo_multicolor', |
|
897 | + 'label' => esc_html__( 'Multicolor Control', 'kirki' ), |
|
898 | + 'section' => 'multicolor_section', |
|
899 | + 'priority' => 10, |
|
900 | + 'transport' => 'postMessage', |
|
901 | + 'choices' => [ |
|
902 | + 'link' => esc_html__( 'Link Color', 'kirki' ), |
|
903 | + 'hover' => esc_html__( 'And this is hover color with long label so you know how it is displayed.', 'kirki' ), |
|
904 | + 'active' => esc_html__( 'Active Color', 'kirki' ), |
|
905 | + 'another1' => esc_html__( 'Another color 1', 'kirki' ), |
|
906 | + 'another2' => esc_html__( 'Another color 2', 'kirki' ), |
|
907 | + 'another3' => esc_html__( 'Another color 3', 'kirki' ), |
|
908 | + 'another4' => esc_html__( 'Another color 4', 'kirki' ), |
|
909 | + 'another5' => esc_html__( 'Another color 5', 'kirki' ), |
|
910 | + 'another6' => esc_html__( 'Another color 6', 'kirki' ), |
|
911 | + 'another7' => esc_html__( 'Another color 7', 'kirki' ), |
|
912 | + 'another8' => esc_html__( 'Another color 8', 'kirki' ), |
|
913 | + 'another9' => esc_html__( 'Another color 9', 'kirki' ), |
|
914 | + 'another10' => esc_html__( 'Another color 10', 'kirki' ), |
|
915 | + 'another11' => esc_html__( 'Another color 11', 'kirki' ), |
|
916 | + 'another12' => esc_html__( 'Another color 12', 'kirki' ), |
|
917 | + 'another13' => esc_html__( 'Another color 13', 'kirki' ), |
|
918 | + 'another14' => esc_html__( 'Another color 14', 'kirki' ), |
|
919 | + 'another15' => esc_html__( 'Another color 15', 'kirki' ), |
|
920 | + ], |
|
921 | + 'alpha' => true, |
|
922 | + 'default' => [ |
|
923 | + 'link' => '#0088cc', |
|
924 | + 'hover' => '#00aaff', |
|
925 | + 'active' => '#00ffff', |
|
926 | + ], |
|
927 | + ] |
|
928 | 928 | ); |
929 | 929 | |
930 | 930 | /** |
931 | 931 | * Number Control. |
932 | 932 | */ |
933 | 933 | new \Kirki\Field\Number( |
934 | - [ |
|
935 | - 'settings' => 'kirki_demo_number', |
|
936 | - 'label' => esc_html__( 'Number Control', 'kirki' ), |
|
937 | - 'section' => 'number_section', |
|
938 | - 'priority' => 10, |
|
939 | - 'choices' => [ |
|
940 | - 'min' => -5, |
|
941 | - 'max' => 5, |
|
942 | - 'step' => 1, |
|
943 | - ], |
|
944 | - ] |
|
934 | + [ |
|
935 | + 'settings' => 'kirki_demo_number', |
|
936 | + 'label' => esc_html__( 'Number Control', 'kirki' ), |
|
937 | + 'section' => 'number_section', |
|
938 | + 'priority' => 10, |
|
939 | + 'choices' => [ |
|
940 | + 'min' => -5, |
|
941 | + 'max' => 5, |
|
942 | + 'step' => 1, |
|
943 | + ], |
|
944 | + ] |
|
945 | 945 | ); |
946 | 946 | |
947 | 947 | /** |
948 | 948 | * Palette Control. |
949 | 949 | */ |
950 | 950 | new \Kirki\Field\Palette( |
951 | - array( |
|
952 | - 'settings' => 'kirki_demo_palette', |
|
953 | - 'label' => esc_html__( 'Control Palette', 'kirki' ), |
|
954 | - 'section' => 'palette_section', |
|
955 | - 'default' => 'blue', |
|
956 | - 'choices' => array( |
|
957 | - 'a200' => Kirki_Helper::get_material_design_colors( 'A200' ), |
|
958 | - 'blue' => Kirki_Helper::get_material_design_colors( 'blue' ), |
|
959 | - 'green' => array( '#E8F5E9', '#C8E6C9', '#A5D6A7', '#81C784', '#66BB6A', '#4CAF50', '#43A047', '#388E3C', '#2E7D32', '#1B5E20', '#B9F6CA', '#69F0AE', '#00E676', '#00C853' ), |
|
960 | - 'bnw' => array( '#000000', '#ffffff' ), |
|
961 | - ), |
|
962 | - ) |
|
951 | + array( |
|
952 | + 'settings' => 'kirki_demo_palette', |
|
953 | + 'label' => esc_html__( 'Control Palette', 'kirki' ), |
|
954 | + 'section' => 'palette_section', |
|
955 | + 'default' => 'blue', |
|
956 | + 'choices' => array( |
|
957 | + 'a200' => Kirki_Helper::get_material_design_colors( 'A200' ), |
|
958 | + 'blue' => Kirki_Helper::get_material_design_colors( 'blue' ), |
|
959 | + 'green' => array( '#E8F5E9', '#C8E6C9', '#A5D6A7', '#81C784', '#66BB6A', '#4CAF50', '#43A047', '#388E3C', '#2E7D32', '#1B5E20', '#B9F6CA', '#69F0AE', '#00E676', '#00C853' ), |
|
960 | + 'bnw' => array( '#000000', '#ffffff' ), |
|
961 | + ), |
|
962 | + ) |
|
963 | 963 | ); |
964 | 964 | |
965 | 965 | /** |
966 | 966 | * Radio Control. |
967 | 967 | */ |
968 | 968 | new \Kirki\Field\Radio( |
969 | - [ |
|
970 | - 'settings' => 'kirki_demo_radio', |
|
971 | - 'label' => esc_html__( 'Radio Control', 'kirki' ), |
|
972 | - 'description' => esc_html__( 'The description here.', 'kirki' ), |
|
973 | - 'section' => 'radio_section', |
|
974 | - 'default' => 'option-3', |
|
975 | - 'choices' => [ |
|
976 | - 'option-1' => esc_html__( 'Option 1', 'kirki' ), |
|
977 | - 'option-2' => esc_html__( 'Option 2', 'kirki' ), |
|
978 | - 'option-3' => esc_html__( 'Option 3', 'kirki' ), |
|
979 | - 'option-4' => esc_html__( 'Option 4', 'kirki' ), |
|
980 | - 'option-5' => esc_html__( 'Option 5', 'kirki' ), |
|
981 | - ], |
|
982 | - ] |
|
969 | + [ |
|
970 | + 'settings' => 'kirki_demo_radio', |
|
971 | + 'label' => esc_html__( 'Radio Control', 'kirki' ), |
|
972 | + 'description' => esc_html__( 'The description here.', 'kirki' ), |
|
973 | + 'section' => 'radio_section', |
|
974 | + 'default' => 'option-3', |
|
975 | + 'choices' => [ |
|
976 | + 'option-1' => esc_html__( 'Option 1', 'kirki' ), |
|
977 | + 'option-2' => esc_html__( 'Option 2', 'kirki' ), |
|
978 | + 'option-3' => esc_html__( 'Option 3', 'kirki' ), |
|
979 | + 'option-4' => esc_html__( 'Option 4', 'kirki' ), |
|
980 | + 'option-5' => esc_html__( 'Option 5', 'kirki' ), |
|
981 | + ], |
|
982 | + ] |
|
983 | 983 | ); |
984 | 984 | |
985 | 985 | /** |
986 | 986 | * Radio-Buttonset Control. |
987 | 987 | */ |
988 | 988 | new \Kirki\Field\Radio_Buttonset( |
989 | - [ |
|
990 | - 'settings' => 'kirki_demo_radio_buttonset', |
|
991 | - 'label' => esc_html__( 'Radio-Buttonset Control', 'kirki' ), |
|
992 | - 'description' => esc_html__( 'Sample of radio-buttonset control.', 'kirki' ), |
|
993 | - 'section' => 'radio_buttonset_section', |
|
994 | - 'default' => 'option-2', |
|
995 | - 'choices' => [ |
|
996 | - 'option-1' => esc_html__( 'Option 1', 'kirki' ), |
|
997 | - 'option-2' => esc_html__( 'Option 2', 'kirki' ), |
|
998 | - 'option-3' => esc_html__( 'Option 3', 'kirki' ), |
|
999 | - ], |
|
1000 | - ] |
|
989 | + [ |
|
990 | + 'settings' => 'kirki_demo_radio_buttonset', |
|
991 | + 'label' => esc_html__( 'Radio-Buttonset Control', 'kirki' ), |
|
992 | + 'description' => esc_html__( 'Sample of radio-buttonset control.', 'kirki' ), |
|
993 | + 'section' => 'radio_buttonset_section', |
|
994 | + 'default' => 'option-2', |
|
995 | + 'choices' => [ |
|
996 | + 'option-1' => esc_html__( 'Option 1', 'kirki' ), |
|
997 | + 'option-2' => esc_html__( 'Option 2', 'kirki' ), |
|
998 | + 'option-3' => esc_html__( 'Option 3', 'kirki' ), |
|
999 | + ], |
|
1000 | + ] |
|
1001 | 1001 | ); |
1002 | 1002 | |
1003 | 1003 | /** |
1004 | 1004 | * Radio-Image Control. |
1005 | 1005 | */ |
1006 | 1006 | new \Kirki\Field\Radio_Image( |
1007 | - [ |
|
1008 | - 'settings' => 'kirki_demo_radio_image', |
|
1009 | - 'label' => esc_html__( 'Radio-Image Control', 'kirki' ), |
|
1010 | - 'description' => esc_html__( 'Sample of radio image control.', 'kirki' ), |
|
1011 | - 'section' => 'radio_image_section', |
|
1012 | - 'default' => 'travel', |
|
1013 | - 'choices' => [ |
|
1014 | - 'moto' => 'https://jawordpressorg.github.io/wapuu/wapuu-archive/wapuu-moto.png', |
|
1015 | - 'cossack' => 'https://raw.githubusercontent.com/templatemonster/cossack-wapuula/master/cossack-wapuula.png', |
|
1016 | - 'travel' => 'https://jawordpressorg.github.io/wapuu/wapuu-archive/wapuu-travel.png', |
|
1017 | - ], |
|
1018 | - ] |
|
1007 | + [ |
|
1008 | + 'settings' => 'kirki_demo_radio_image', |
|
1009 | + 'label' => esc_html__( 'Radio-Image Control', 'kirki' ), |
|
1010 | + 'description' => esc_html__( 'Sample of radio image control.', 'kirki' ), |
|
1011 | + 'section' => 'radio_image_section', |
|
1012 | + 'default' => 'travel', |
|
1013 | + 'choices' => [ |
|
1014 | + 'moto' => 'https://jawordpressorg.github.io/wapuu/wapuu-archive/wapuu-moto.png', |
|
1015 | + 'cossack' => 'https://raw.githubusercontent.com/templatemonster/cossack-wapuula/master/cossack-wapuula.png', |
|
1016 | + 'travel' => 'https://jawordpressorg.github.io/wapuu/wapuu-archive/wapuu-travel.png', |
|
1017 | + ], |
|
1018 | + ] |
|
1019 | 1019 | ); |
1020 | 1020 | |
1021 | 1021 | /** |
1022 | 1022 | * Repeater Control. |
1023 | 1023 | */ |
1024 | 1024 | new \Kirki\Field\Repeater( |
1025 | - [ |
|
1026 | - 'settings' => 'kirki_demo_repeater', |
|
1027 | - 'label' => esc_html__( 'Repeater Control', 'kirki' ), |
|
1028 | - 'description' => esc_html__( 'Sample of repeater control.', 'kirki' ), |
|
1029 | - 'section' => 'repeater_section', |
|
1030 | - 'default' => [ |
|
1031 | - [ |
|
1032 | - 'link_text' => esc_html__( 'Kirki Site', 'kirki' ), |
|
1033 | - 'link_url' => 'https://kirki.org/', |
|
1034 | - 'link_target' => '_self', |
|
1035 | - 'checkbox' => false, |
|
1036 | - ], |
|
1037 | - [ |
|
1038 | - 'link_text' => esc_html__( 'Kirki Repository', 'kirki' ), |
|
1039 | - 'link_url' => 'https://github.com/aristath/kirki', |
|
1040 | - 'link_target' => '_self', |
|
1041 | - 'checkbox' => false, |
|
1042 | - ], |
|
1043 | - ], |
|
1044 | - 'fields' => [ |
|
1045 | - 'link_text' => [ |
|
1046 | - 'type' => 'text', |
|
1047 | - 'label' => esc_html__( 'Link Text', 'kirki' ), |
|
1048 | - 'description' => esc_html__( 'This will be the label for your link', 'kirki' ), |
|
1049 | - 'default' => '', |
|
1050 | - ], |
|
1051 | - 'link_url' => [ |
|
1052 | - 'type' => 'text', |
|
1053 | - 'label' => esc_html__( 'Link URL', 'kirki' ), |
|
1054 | - 'description' => esc_html__( 'This will be the link URL', 'kirki' ), |
|
1055 | - 'default' => '', |
|
1056 | - ], |
|
1057 | - 'link_target' => [ |
|
1058 | - 'type' => 'select', |
|
1059 | - 'label' => esc_html__( 'Link Target', 'kirki' ), |
|
1060 | - 'description' => esc_html__( 'This will be the link target', 'kirki' ), |
|
1061 | - 'default' => '_self', |
|
1062 | - 'choices' => [ |
|
1063 | - '_blank' => esc_html__( 'New Window', 'kirki' ), |
|
1064 | - '_self' => esc_html__( 'Same Frame', 'kirki' ), |
|
1065 | - ], |
|
1066 | - ], |
|
1067 | - 'checkbox' => [ |
|
1068 | - 'type' => 'checkbox', |
|
1069 | - 'label' => esc_html__( 'Checkbox', 'kirki' ), |
|
1070 | - 'default' => false, |
|
1071 | - ], |
|
1072 | - ], |
|
1073 | - ] |
|
1025 | + [ |
|
1026 | + 'settings' => 'kirki_demo_repeater', |
|
1027 | + 'label' => esc_html__( 'Repeater Control', 'kirki' ), |
|
1028 | + 'description' => esc_html__( 'Sample of repeater control.', 'kirki' ), |
|
1029 | + 'section' => 'repeater_section', |
|
1030 | + 'default' => [ |
|
1031 | + [ |
|
1032 | + 'link_text' => esc_html__( 'Kirki Site', 'kirki' ), |
|
1033 | + 'link_url' => 'https://kirki.org/', |
|
1034 | + 'link_target' => '_self', |
|
1035 | + 'checkbox' => false, |
|
1036 | + ], |
|
1037 | + [ |
|
1038 | + 'link_text' => esc_html__( 'Kirki Repository', 'kirki' ), |
|
1039 | + 'link_url' => 'https://github.com/aristath/kirki', |
|
1040 | + 'link_target' => '_self', |
|
1041 | + 'checkbox' => false, |
|
1042 | + ], |
|
1043 | + ], |
|
1044 | + 'fields' => [ |
|
1045 | + 'link_text' => [ |
|
1046 | + 'type' => 'text', |
|
1047 | + 'label' => esc_html__( 'Link Text', 'kirki' ), |
|
1048 | + 'description' => esc_html__( 'This will be the label for your link', 'kirki' ), |
|
1049 | + 'default' => '', |
|
1050 | + ], |
|
1051 | + 'link_url' => [ |
|
1052 | + 'type' => 'text', |
|
1053 | + 'label' => esc_html__( 'Link URL', 'kirki' ), |
|
1054 | + 'description' => esc_html__( 'This will be the link URL', 'kirki' ), |
|
1055 | + 'default' => '', |
|
1056 | + ], |
|
1057 | + 'link_target' => [ |
|
1058 | + 'type' => 'select', |
|
1059 | + 'label' => esc_html__( 'Link Target', 'kirki' ), |
|
1060 | + 'description' => esc_html__( 'This will be the link target', 'kirki' ), |
|
1061 | + 'default' => '_self', |
|
1062 | + 'choices' => [ |
|
1063 | + '_blank' => esc_html__( 'New Window', 'kirki' ), |
|
1064 | + '_self' => esc_html__( 'Same Frame', 'kirki' ), |
|
1065 | + ], |
|
1066 | + ], |
|
1067 | + 'checkbox' => [ |
|
1068 | + 'type' => 'checkbox', |
|
1069 | + 'label' => esc_html__( 'Checkbox', 'kirki' ), |
|
1070 | + 'default' => false, |
|
1071 | + ], |
|
1072 | + ], |
|
1073 | + ] |
|
1074 | 1074 | ); |
1075 | 1075 | |
1076 | 1076 | /** |
1077 | 1077 | * Select Control. |
1078 | 1078 | */ |
1079 | 1079 | new \Kirki\Field\Select( |
1080 | - [ |
|
1081 | - 'settings' => 'kirki_demo_select', |
|
1082 | - 'label' => esc_html__( 'Select Control', 'kirki' ), |
|
1083 | - 'description' => esc_html__( 'Sample of single mode select control.', 'kirki' ), |
|
1084 | - 'section' => 'select_section', |
|
1085 | - 'default' => 'option-3', |
|
1086 | - 'placeholder' => esc_html__( 'Select an option', 'kirki' ), |
|
1087 | - 'choices' => [ |
|
1088 | - 'option-1' => esc_html__( 'Option 1', 'kirki' ), |
|
1089 | - 'option-2' => esc_html__( 'Option 2', 'kirki' ), |
|
1090 | - 'option-3' => esc_html__( 'Option 3', 'kirki' ), |
|
1091 | - 'option-4' => esc_html__( 'Option 4', 'kirki' ), |
|
1092 | - 'option-5' => esc_html__( 'Option 5', 'kirki' ), |
|
1093 | - ], |
|
1094 | - ] |
|
1080 | + [ |
|
1081 | + 'settings' => 'kirki_demo_select', |
|
1082 | + 'label' => esc_html__( 'Select Control', 'kirki' ), |
|
1083 | + 'description' => esc_html__( 'Sample of single mode select control.', 'kirki' ), |
|
1084 | + 'section' => 'select_section', |
|
1085 | + 'default' => 'option-3', |
|
1086 | + 'placeholder' => esc_html__( 'Select an option', 'kirki' ), |
|
1087 | + 'choices' => [ |
|
1088 | + 'option-1' => esc_html__( 'Option 1', 'kirki' ), |
|
1089 | + 'option-2' => esc_html__( 'Option 2', 'kirki' ), |
|
1090 | + 'option-3' => esc_html__( 'Option 3', 'kirki' ), |
|
1091 | + 'option-4' => esc_html__( 'Option 4', 'kirki' ), |
|
1092 | + 'option-5' => esc_html__( 'Option 5', 'kirki' ), |
|
1093 | + ], |
|
1094 | + ] |
|
1095 | 1095 | ); |
1096 | 1096 | |
1097 | 1097 | new \Kirki\Field\Select( |
1098 | - [ |
|
1099 | - 'settings' => 'kirki_demo_select_multiple', |
|
1100 | - 'label' => esc_html__( 'Select Control', 'kirki' ), |
|
1101 | - 'description' => esc_html__( 'Sample of multiple mode select control.', 'kirki' ), |
|
1102 | - 'section' => 'select_section', |
|
1103 | - 'default' => 'option-3', |
|
1104 | - 'multiple' => 3, |
|
1105 | - 'choices' => [ |
|
1106 | - 'option-1' => esc_html__( 'Option 1', 'kirki' ), |
|
1107 | - 'option-2' => esc_html__( 'Option 2', 'kirki' ), |
|
1108 | - 'option-3' => esc_html__( 'Option 3', 'kirki' ), |
|
1109 | - 'option-4' => esc_html__( 'Option 4', 'kirki' ), |
|
1110 | - 'option-5' => esc_html__( 'Option 5', 'kirki' ), |
|
1111 | - ], |
|
1112 | - ] |
|
1098 | + [ |
|
1099 | + 'settings' => 'kirki_demo_select_multiple', |
|
1100 | + 'label' => esc_html__( 'Select Control', 'kirki' ), |
|
1101 | + 'description' => esc_html__( 'Sample of multiple mode select control.', 'kirki' ), |
|
1102 | + 'section' => 'select_section', |
|
1103 | + 'default' => 'option-3', |
|
1104 | + 'multiple' => 3, |
|
1105 | + 'choices' => [ |
|
1106 | + 'option-1' => esc_html__( 'Option 1', 'kirki' ), |
|
1107 | + 'option-2' => esc_html__( 'Option 2', 'kirki' ), |
|
1108 | + 'option-3' => esc_html__( 'Option 3', 'kirki' ), |
|
1109 | + 'option-4' => esc_html__( 'Option 4', 'kirki' ), |
|
1110 | + 'option-5' => esc_html__( 'Option 5', 'kirki' ), |
|
1111 | + ], |
|
1112 | + ] |
|
1113 | 1113 | ); |
1114 | 1114 | |
1115 | 1115 | /** |
1116 | 1116 | * Slider Control. |
1117 | 1117 | */ |
1118 | 1118 | new \Kirki\Field\Slider( |
1119 | - [ |
|
1120 | - 'settings' => 'kirki_demo_slider', |
|
1121 | - 'label' => esc_html__( 'Slider Control', 'kirki' ), |
|
1122 | - 'description' => esc_html__( 'Sample of slider control.', 'kirki' ), |
|
1123 | - 'section' => 'slider_section', |
|
1124 | - 'default' => '10', |
|
1125 | - 'transport' => 'postMessage', |
|
1126 | - 'tooltip' => esc_html__( 'This is the tooltip', 'kirki' ), |
|
1127 | - 'choices' => [ |
|
1128 | - 'min' => 0, |
|
1129 | - 'max' => 100, |
|
1130 | - 'step' => 1, |
|
1131 | - ], |
|
1132 | - ] |
|
1119 | + [ |
|
1120 | + 'settings' => 'kirki_demo_slider', |
|
1121 | + 'label' => esc_html__( 'Slider Control', 'kirki' ), |
|
1122 | + 'description' => esc_html__( 'Sample of slider control.', 'kirki' ), |
|
1123 | + 'section' => 'slider_section', |
|
1124 | + 'default' => '10', |
|
1125 | + 'transport' => 'postMessage', |
|
1126 | + 'tooltip' => esc_html__( 'This is the tooltip', 'kirki' ), |
|
1127 | + 'choices' => [ |
|
1128 | + 'min' => 0, |
|
1129 | + 'max' => 100, |
|
1130 | + 'step' => 1, |
|
1131 | + ], |
|
1132 | + ] |
|
1133 | 1133 | ); |
1134 | 1134 | |
1135 | 1135 | Kirki::add_field( |
1136 | - 'kirki_demo_config', |
|
1137 | - [ |
|
1138 | - 'type' => 'slider', |
|
1139 | - 'settings' => 'kirki_demo_slider_old', |
|
1140 | - 'label' => esc_html__( 'Slider Control — Using Old Way', 'kirki' ), |
|
1141 | - 'description' => 'Added using `Kirki::add_field` (the old Kirki API)', |
|
1142 | - 'section' => 'slider_section', |
|
1143 | - 'transport' => 'postMessage', |
|
1144 | - 'choices' => [ |
|
1145 | - 'min' => 0, |
|
1146 | - 'max' => 100, |
|
1147 | - 'step' => 0.5, |
|
1148 | - ], |
|
1149 | - ] |
|
1136 | + 'kirki_demo_config', |
|
1137 | + [ |
|
1138 | + 'type' => 'slider', |
|
1139 | + 'settings' => 'kirki_demo_slider_old', |
|
1140 | + 'label' => esc_html__( 'Slider Control — Using Old Way', 'kirki' ), |
|
1141 | + 'description' => 'Added using `Kirki::add_field` (the old Kirki API)', |
|
1142 | + 'section' => 'slider_section', |
|
1143 | + 'transport' => 'postMessage', |
|
1144 | + 'choices' => [ |
|
1145 | + 'min' => 0, |
|
1146 | + 'max' => 100, |
|
1147 | + 'step' => 0.5, |
|
1148 | + ], |
|
1149 | + ] |
|
1150 | 1150 | ); |
1151 | 1151 | |
1152 | 1152 | /** |
1153 | 1153 | * Sortable control. |
1154 | 1154 | */ |
1155 | 1155 | new \Kirki\Field\Sortable( |
1156 | - [ |
|
1157 | - 'settings' => 'kirki_demo_sortable', |
|
1158 | - 'label' => __( 'This is a sortable control.', 'kirki' ), |
|
1159 | - 'section' => 'sortable_section', |
|
1160 | - 'default' => [ 'option3', 'option1', 'option4' ], |
|
1161 | - 'choices' => [ |
|
1162 | - 'option1' => esc_html__( 'Option 1', 'kirki' ), |
|
1163 | - 'option2' => esc_html__( 'Option 2', 'kirki' ), |
|
1164 | - 'option3' => esc_html__( 'Option 3', 'kirki' ), |
|
1165 | - 'option4' => esc_html__( 'Option 4', 'kirki' ), |
|
1166 | - 'option5' => esc_html__( 'Option 5', 'kirki' ), |
|
1167 | - 'option6' => esc_html__( 'Option 6', 'kirki' ), |
|
1168 | - ], |
|
1169 | - ] |
|
1156 | + [ |
|
1157 | + 'settings' => 'kirki_demo_sortable', |
|
1158 | + 'label' => __( 'This is a sortable control.', 'kirki' ), |
|
1159 | + 'section' => 'sortable_section', |
|
1160 | + 'default' => [ 'option3', 'option1', 'option4' ], |
|
1161 | + 'choices' => [ |
|
1162 | + 'option1' => esc_html__( 'Option 1', 'kirki' ), |
|
1163 | + 'option2' => esc_html__( 'Option 2', 'kirki' ), |
|
1164 | + 'option3' => esc_html__( 'Option 3', 'kirki' ), |
|
1165 | + 'option4' => esc_html__( 'Option 4', 'kirki' ), |
|
1166 | + 'option5' => esc_html__( 'Option 5', 'kirki' ), |
|
1167 | + 'option6' => esc_html__( 'Option 6', 'kirki' ), |
|
1168 | + ], |
|
1169 | + ] |
|
1170 | 1170 | ); |
1171 | 1171 | |
1172 | 1172 | /** |
1173 | 1173 | * Switch control. |
1174 | 1174 | */ |
1175 | 1175 | new \Kirki\Field\Checkbox_Switch( |
1176 | - [ |
|
1177 | - 'settings' => 'kirki_demo_switch', |
|
1178 | - 'label' => esc_html__( 'Switch Field', 'kirki' ), |
|
1179 | - 'description' => esc_html__( 'Simple switch control', 'kirki' ), |
|
1180 | - 'section' => 'switch_section', |
|
1181 | - 'transport' => 'postMessage', |
|
1182 | - 'default' => true, |
|
1183 | - ] |
|
1176 | + [ |
|
1177 | + 'settings' => 'kirki_demo_switch', |
|
1178 | + 'label' => esc_html__( 'Switch Field', 'kirki' ), |
|
1179 | + 'description' => esc_html__( 'Simple switch control', 'kirki' ), |
|
1180 | + 'section' => 'switch_section', |
|
1181 | + 'transport' => 'postMessage', |
|
1182 | + 'default' => true, |
|
1183 | + ] |
|
1184 | 1184 | ); |
1185 | 1185 | |
1186 | 1186 | new \Kirki\Field\Checkbox_Switch( |
1187 | - [ |
|
1188 | - 'settings' => 'kirki_demo_switch_custom_label', |
|
1189 | - 'label' => esc_html__( 'Switch Field — With custom labels', 'kirki' ), |
|
1190 | - 'description' => esc_html__( 'Switch control using custom labels', 'kirki' ), |
|
1191 | - 'section' => 'switch_section', |
|
1192 | - 'default' => true, |
|
1193 | - 'choices' => [ |
|
1194 | - 'on' => esc_html__( 'Enabled', 'kirki' ), |
|
1195 | - 'off' => esc_html__( 'Disabled', 'kirki' ), |
|
1196 | - ], |
|
1197 | - 'active_callback' => [ |
|
1198 | - [ |
|
1199 | - 'setting' => 'kirki_demo_switch', |
|
1200 | - 'operator' => '==', |
|
1201 | - 'value' => true, |
|
1202 | - ], |
|
1203 | - ], |
|
1204 | - ] |
|
1187 | + [ |
|
1188 | + 'settings' => 'kirki_demo_switch_custom_label', |
|
1189 | + 'label' => esc_html__( 'Switch Field — With custom labels', 'kirki' ), |
|
1190 | + 'description' => esc_html__( 'Switch control using custom labels', 'kirki' ), |
|
1191 | + 'section' => 'switch_section', |
|
1192 | + 'default' => true, |
|
1193 | + 'choices' => [ |
|
1194 | + 'on' => esc_html__( 'Enabled', 'kirki' ), |
|
1195 | + 'off' => esc_html__( 'Disabled', 'kirki' ), |
|
1196 | + ], |
|
1197 | + 'active_callback' => [ |
|
1198 | + [ |
|
1199 | + 'setting' => 'kirki_demo_switch', |
|
1200 | + 'operator' => '==', |
|
1201 | + 'value' => true, |
|
1202 | + ], |
|
1203 | + ], |
|
1204 | + ] |
|
1205 | 1205 | ); |
1206 | 1206 | |
1207 | 1207 | /** |
1208 | 1208 | * Toggle control. |
1209 | 1209 | */ |
1210 | 1210 | Kirki::add_field( |
1211 | - 'kirki_demo_config', |
|
1212 | - [ |
|
1213 | - 'type' => 'toggle', |
|
1214 | - 'settings' => 'kirki_demo_toggle_setting', |
|
1215 | - 'label' => esc_html__( 'Toggle Field', 'kirki' ), |
|
1216 | - 'description' => esc_html__( 'Toggle is just utilizing switch control but aligned horizontally & without the text', 'kirki' ), |
|
1217 | - 'section' => 'toggle_section', |
|
1218 | - 'default' => '1', |
|
1219 | - 'priority' => 10, |
|
1220 | - 'transport' => 'postMessage', |
|
1221 | - ] |
|
1211 | + 'kirki_demo_config', |
|
1212 | + [ |
|
1213 | + 'type' => 'toggle', |
|
1214 | + 'settings' => 'kirki_demo_toggle_setting', |
|
1215 | + 'label' => esc_html__( 'Toggle Field', 'kirki' ), |
|
1216 | + 'description' => esc_html__( 'Toggle is just utilizing switch control but aligned horizontally & without the text', 'kirki' ), |
|
1217 | + 'section' => 'toggle_section', |
|
1218 | + 'default' => '1', |
|
1219 | + 'priority' => 10, |
|
1220 | + 'transport' => 'postMessage', |
|
1221 | + ] |
|
1222 | 1222 | ); |
1223 | 1223 | |
1224 | 1224 | /** |
1225 | 1225 | * Typography Control. |
1226 | 1226 | */ |
1227 | 1227 | new \Kirki\Field\Typography( |
1228 | - [ |
|
1229 | - 'settings' => 'kirki_demo_kirki_typography_setting', |
|
1230 | - 'label' => esc_html__( 'Typography Control', 'kirki' ), |
|
1231 | - 'description' => esc_html__( 'The full set of options.', 'kirki' ), |
|
1232 | - 'section' => 'typography_section', |
|
1233 | - 'priority' => 10, |
|
1234 | - 'transport' => 'postMessage', |
|
1235 | - 'default' => [ |
|
1236 | - 'font-family' => 'Roboto', |
|
1237 | - 'variant' => 'regular', |
|
1238 | - 'font-style' => 'normal', |
|
1239 | - 'color' => '#333333', |
|
1240 | - 'font-size' => '14px', |
|
1241 | - 'line-height' => '1.5', |
|
1242 | - 'letter-spacing' => '0', |
|
1243 | - 'text-transform' => 'none', |
|
1244 | - 'text-decoration' => 'none', |
|
1245 | - 'text-align' => 'left', |
|
1246 | - 'margin-top' => '0', |
|
1247 | - 'margin-bottom' => '0', |
|
1248 | - ], |
|
1249 | - 'output' => [ |
|
1250 | - [ |
|
1251 | - 'element' => 'body, p', |
|
1252 | - ], |
|
1253 | - ], |
|
1254 | - 'choices' => [ |
|
1255 | - 'fonts' => [ |
|
1256 | - 'google' => [ 'popularity', 60 ], |
|
1257 | - 'families' => [ |
|
1258 | - 'custom' => [ |
|
1259 | - 'text' => 'My Custom Fonts (demo only)', |
|
1260 | - 'children' => [ |
|
1261 | - [ |
|
1262 | - 'id' => 'helvetica-neue', |
|
1263 | - 'text' => 'Helvetica Neue', |
|
1264 | - ], |
|
1265 | - [ |
|
1266 | - 'id' => 'linotype-authentic', |
|
1267 | - 'text' => 'Linotype Authentic', |
|
1268 | - ], |
|
1269 | - ], |
|
1270 | - ], |
|
1271 | - ], |
|
1272 | - 'variants' => [ |
|
1273 | - 'helvetica-neue' => [ 'regular', '900' ], |
|
1274 | - 'linotype-authentic' => [ 'regular', '100', '300' ], |
|
1275 | - ], |
|
1276 | - ], |
|
1277 | - ], |
|
1278 | - ] |
|
1228 | + [ |
|
1229 | + 'settings' => 'kirki_demo_kirki_typography_setting', |
|
1230 | + 'label' => esc_html__( 'Typography Control', 'kirki' ), |
|
1231 | + 'description' => esc_html__( 'The full set of options.', 'kirki' ), |
|
1232 | + 'section' => 'typography_section', |
|
1233 | + 'priority' => 10, |
|
1234 | + 'transport' => 'postMessage', |
|
1235 | + 'default' => [ |
|
1236 | + 'font-family' => 'Roboto', |
|
1237 | + 'variant' => 'regular', |
|
1238 | + 'font-style' => 'normal', |
|
1239 | + 'color' => '#333333', |
|
1240 | + 'font-size' => '14px', |
|
1241 | + 'line-height' => '1.5', |
|
1242 | + 'letter-spacing' => '0', |
|
1243 | + 'text-transform' => 'none', |
|
1244 | + 'text-decoration' => 'none', |
|
1245 | + 'text-align' => 'left', |
|
1246 | + 'margin-top' => '0', |
|
1247 | + 'margin-bottom' => '0', |
|
1248 | + ], |
|
1249 | + 'output' => [ |
|
1250 | + [ |
|
1251 | + 'element' => 'body, p', |
|
1252 | + ], |
|
1253 | + ], |
|
1254 | + 'choices' => [ |
|
1255 | + 'fonts' => [ |
|
1256 | + 'google' => [ 'popularity', 60 ], |
|
1257 | + 'families' => [ |
|
1258 | + 'custom' => [ |
|
1259 | + 'text' => 'My Custom Fonts (demo only)', |
|
1260 | + 'children' => [ |
|
1261 | + [ |
|
1262 | + 'id' => 'helvetica-neue', |
|
1263 | + 'text' => 'Helvetica Neue', |
|
1264 | + ], |
|
1265 | + [ |
|
1266 | + 'id' => 'linotype-authentic', |
|
1267 | + 'text' => 'Linotype Authentic', |
|
1268 | + ], |
|
1269 | + ], |
|
1270 | + ], |
|
1271 | + ], |
|
1272 | + 'variants' => [ |
|
1273 | + 'helvetica-neue' => [ 'regular', '900' ], |
|
1274 | + 'linotype-authentic' => [ 'regular', '100', '300' ], |
|
1275 | + ], |
|
1276 | + ], |
|
1277 | + ], |
|
1278 | + ] |
|
1279 | 1279 | ); |
1280 | 1280 | |
1281 | 1281 | new \Kirki\Field\Typography( |
1282 | - [ |
|
1283 | - 'settings' => 'kirki_demo_typography_setting_1', |
|
1284 | - 'label' => esc_html__( 'Typography Control', 'kirki' ), |
|
1285 | - 'description' => esc_html__( 'Just the font-family and font-weight.', 'kirki' ), |
|
1286 | - 'section' => 'typography_section', |
|
1287 | - 'priority' => 10, |
|
1288 | - 'transport' => 'auto', |
|
1289 | - 'default' => [ |
|
1290 | - 'font-family' => 'Roboto', |
|
1291 | - ], |
|
1292 | - 'output' => [ |
|
1293 | - [ |
|
1294 | - 'element' => [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ], |
|
1295 | - ], |
|
1296 | - ], |
|
1297 | - ] |
|
1282 | + [ |
|
1283 | + 'settings' => 'kirki_demo_typography_setting_1', |
|
1284 | + 'label' => esc_html__( 'Typography Control', 'kirki' ), |
|
1285 | + 'description' => esc_html__( 'Just the font-family and font-weight.', 'kirki' ), |
|
1286 | + 'section' => 'typography_section', |
|
1287 | + 'priority' => 10, |
|
1288 | + 'transport' => 'auto', |
|
1289 | + 'default' => [ |
|
1290 | + 'font-family' => 'Roboto', |
|
1291 | + ], |
|
1292 | + 'output' => [ |
|
1293 | + [ |
|
1294 | + 'element' => [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ], |
|
1295 | + ], |
|
1296 | + ], |
|
1297 | + ] |
|
1298 | 1298 | ); |
1299 | 1299 | |
1300 | 1300 | /** |
@@ -1303,27 +1303,27 @@ discard block |
||
1303 | 1303 | * @return void |
1304 | 1304 | */ |
1305 | 1305 | function kirki_sidebars_select_example() { |
1306 | - $sidebars = []; |
|
1307 | - if ( isset( $GLOBALS['wp_registered_sidebars'] ) ) { |
|
1308 | - $sidebars = $GLOBALS['wp_registered_sidebars']; |
|
1309 | - } |
|
1310 | - $sidebars_choices = []; |
|
1311 | - foreach ( $sidebars as $sidebar ) { |
|
1312 | - $sidebars_choices[ $sidebar['id'] ] = $sidebar['name']; |
|
1313 | - } |
|
1314 | - if ( ! class_exists( 'Kirki' ) ) { |
|
1315 | - return; |
|
1316 | - } |
|
1317 | - new \Kirki\Field\Select( |
|
1318 | - [ |
|
1319 | - 'settings' => 'kirki_demo_sidebars_select', |
|
1320 | - 'label' => esc_html__( 'Sidebars Select', 'kirki' ), |
|
1321 | - 'description' => esc_html__( 'An example of how to implement sidebars selection.', 'kirki' ), |
|
1322 | - 'section' => 'select_section', |
|
1323 | - 'default' => 'primary', |
|
1324 | - 'choices' => $sidebars_choices, |
|
1325 | - 'priority' => 30, |
|
1326 | - ] |
|
1327 | - ); |
|
1306 | + $sidebars = []; |
|
1307 | + if ( isset( $GLOBALS['wp_registered_sidebars'] ) ) { |
|
1308 | + $sidebars = $GLOBALS['wp_registered_sidebars']; |
|
1309 | + } |
|
1310 | + $sidebars_choices = []; |
|
1311 | + foreach ( $sidebars as $sidebar ) { |
|
1312 | + $sidebars_choices[ $sidebar['id'] ] = $sidebar['name']; |
|
1313 | + } |
|
1314 | + if ( ! class_exists( 'Kirki' ) ) { |
|
1315 | + return; |
|
1316 | + } |
|
1317 | + new \Kirki\Field\Select( |
|
1318 | + [ |
|
1319 | + 'settings' => 'kirki_demo_sidebars_select', |
|
1320 | + 'label' => esc_html__( 'Sidebars Select', 'kirki' ), |
|
1321 | + 'description' => esc_html__( 'An example of how to implement sidebars selection.', 'kirki' ), |
|
1322 | + 'section' => 'select_section', |
|
1323 | + 'default' => 'primary', |
|
1324 | + 'choices' => $sidebars_choices, |
|
1325 | + 'priority' => 30, |
|
1326 | + ] |
|
1327 | + ); |
|
1328 | 1328 | } |
1329 | 1329 | add_action( 'init', 'kirki_sidebars_select_example', 999 ); |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | // Exit if accessed directly. |
17 | 17 | if ( ! defined( 'ABSPATH' ) ) { |
18 | - exit; |
|
18 | + exit; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -23,320 +23,320 @@ discard block |
||
23 | 23 | */ |
24 | 24 | final class Kirki_Color extends ariColor { |
25 | 25 | |
26 | - /** |
|
27 | - * A proxy for the sanitize_color method. |
|
28 | - * |
|
29 | - * @param string|array $color The color. |
|
30 | - * @param bool $hash Whether we want to include a hash (#) at the beginning or not. |
|
31 | - * @return string The sanitized hex color. |
|
32 | - */ |
|
33 | - public static function sanitize_hex( $color = '#FFFFFF', $hash = true ) { |
|
34 | - if ( ! $hash ) { |
|
35 | - return ltrim( self::sanitize_color( $color, 'hex' ), '#' ); |
|
36 | - } |
|
37 | - return self::sanitize_color( $color, 'hex' ); |
|
38 | - } |
|
26 | + /** |
|
27 | + * A proxy for the sanitize_color method. |
|
28 | + * |
|
29 | + * @param string|array $color The color. |
|
30 | + * @param bool $hash Whether we want to include a hash (#) at the beginning or not. |
|
31 | + * @return string The sanitized hex color. |
|
32 | + */ |
|
33 | + public static function sanitize_hex( $color = '#FFFFFF', $hash = true ) { |
|
34 | + if ( ! $hash ) { |
|
35 | + return ltrim( self::sanitize_color( $color, 'hex' ), '#' ); |
|
36 | + } |
|
37 | + return self::sanitize_color( $color, 'hex' ); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * A proxy the sanitize_color method. |
|
42 | - * |
|
43 | - * @static |
|
44 | - * @access public |
|
45 | - * @param string $color The color. |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public static function sanitize_rgba( $color ) { |
|
49 | - return self::sanitize_color( $color, 'rgba' ); |
|
50 | - } |
|
40 | + /** |
|
41 | + * A proxy the sanitize_color method. |
|
42 | + * |
|
43 | + * @static |
|
44 | + * @access public |
|
45 | + * @param string $color The color. |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public static function sanitize_rgba( $color ) { |
|
49 | + return self::sanitize_color( $color, 'rgba' ); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Sanitize colors. |
|
54 | - * Determine if the current value is a hex or an rgba color and call the appropriate method. |
|
55 | - * |
|
56 | - * @static |
|
57 | - * @access public |
|
58 | - * @since 0.8.5 |
|
59 | - * @param string|array $color The color. |
|
60 | - * @param string $mode The mode to be used. |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public static function sanitize_color( $color = '', $mode = 'auto' ) { |
|
64 | - if ( is_string( $color ) && 'transparent' == trim( $color ) ) { |
|
65 | - return 'transparent'; |
|
66 | - } |
|
67 | - $obj = ariColor::newColor( $color ); |
|
68 | - if ( 'auto' == $mode ) { |
|
69 | - $mode = $obj->mode; |
|
70 | - } |
|
71 | - return $obj->toCSS( $mode ); |
|
72 | - } |
|
52 | + /** |
|
53 | + * Sanitize colors. |
|
54 | + * Determine if the current value is a hex or an rgba color and call the appropriate method. |
|
55 | + * |
|
56 | + * @static |
|
57 | + * @access public |
|
58 | + * @since 0.8.5 |
|
59 | + * @param string|array $color The color. |
|
60 | + * @param string $mode The mode to be used. |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public static function sanitize_color( $color = '', $mode = 'auto' ) { |
|
64 | + if ( is_string( $color ) && 'transparent' == trim( $color ) ) { |
|
65 | + return 'transparent'; |
|
66 | + } |
|
67 | + $obj = ariColor::newColor( $color ); |
|
68 | + if ( 'auto' == $mode ) { |
|
69 | + $mode = $obj->mode; |
|
70 | + } |
|
71 | + return $obj->toCSS( $mode ); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Gets the rgb value of a color. |
|
76 | - * |
|
77 | - * @static |
|
78 | - * @access public |
|
79 | - * @param string $color The color. |
|
80 | - * @param boolean $implode Whether we want to implode the values or not. |
|
81 | - * @return array|string |
|
82 | - */ |
|
83 | - public static function get_rgb( $color, $implode = false ) { |
|
84 | - $obj = ariColor::newColor( $color ); |
|
85 | - if ( $implode ) { |
|
86 | - return $obj->toCSS( 'rgb' ); |
|
87 | - } |
|
88 | - return array( $obj->red, $obj->green, $obj->blue ); |
|
89 | - } |
|
74 | + /** |
|
75 | + * Gets the rgb value of a color. |
|
76 | + * |
|
77 | + * @static |
|
78 | + * @access public |
|
79 | + * @param string $color The color. |
|
80 | + * @param boolean $implode Whether we want to implode the values or not. |
|
81 | + * @return array|string |
|
82 | + */ |
|
83 | + public static function get_rgb( $color, $implode = false ) { |
|
84 | + $obj = ariColor::newColor( $color ); |
|
85 | + if ( $implode ) { |
|
86 | + return $obj->toCSS( 'rgb' ); |
|
87 | + } |
|
88 | + return array( $obj->red, $obj->green, $obj->blue ); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * A proxy for the sanitize_color method. |
|
93 | - * |
|
94 | - * @static |
|
95 | - * @access public |
|
96 | - * @param string|array $color The color to convert. |
|
97 | - * @return string The hex value of the color. |
|
98 | - */ |
|
99 | - public static function rgba2hex( $color ) { |
|
100 | - return self::sanitize_color( $color, 'hex' ); |
|
101 | - } |
|
91 | + /** |
|
92 | + * A proxy for the sanitize_color method. |
|
93 | + * |
|
94 | + * @static |
|
95 | + * @access public |
|
96 | + * @param string|array $color The color to convert. |
|
97 | + * @return string The hex value of the color. |
|
98 | + */ |
|
99 | + public static function rgba2hex( $color ) { |
|
100 | + return self::sanitize_color( $color, 'hex' ); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Get the alpha channel from an rgba color. |
|
105 | - * |
|
106 | - * @static |
|
107 | - * @access public |
|
108 | - * @param string $color The rgba color formatted like rgba(r,g,b,a). |
|
109 | - * @return int|float The alpha value of the color. |
|
110 | - */ |
|
111 | - public static function get_alpha_from_rgba( $color ) { |
|
112 | - $obj = ariColor::newColor( $color ); |
|
113 | - return $obj->alpha; |
|
114 | - } |
|
103 | + /** |
|
104 | + * Get the alpha channel from an rgba color. |
|
105 | + * |
|
106 | + * @static |
|
107 | + * @access public |
|
108 | + * @param string $color The rgba color formatted like rgba(r,g,b,a). |
|
109 | + * @return int|float The alpha value of the color. |
|
110 | + */ |
|
111 | + public static function get_alpha_from_rgba( $color ) { |
|
112 | + $obj = ariColor::newColor( $color ); |
|
113 | + return $obj->alpha; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Gets the rgba value of the $color. |
|
118 | - * |
|
119 | - * @static |
|
120 | - * @access public |
|
121 | - * @param string $color The hex value of a color. |
|
122 | - * @param int|float $alpha Opacity level (0-1). |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public static function get_rgba( $color = '#fff', $alpha = 1 ) { |
|
126 | - $obj = ariColor::newColor( $color ); |
|
127 | - if ( 1 == $alpha ) { |
|
128 | - return $obj->toCSS( 'rgba' ); |
|
129 | - } |
|
130 | - // Make sure that opacity is properly formatted. |
|
131 | - // Converts 1-100 values to 0-1. |
|
132 | - if ( $alpha > 1 || $alpha < -1 ) { |
|
133 | - // Divide by 100. |
|
134 | - $alpha /= 100; |
|
135 | - } |
|
136 | - // Get absolute value. |
|
137 | - $alpha = abs( $alpha ); |
|
138 | - // Max 1. |
|
139 | - if ( 1 < $alpha ) { |
|
140 | - $alpha = 1; |
|
141 | - } |
|
142 | - $new_obj = $obj->getNew( 'alpha', $alpha ); |
|
143 | - return $new_obj->toCSS( 'rgba' ); |
|
144 | - } |
|
116 | + /** |
|
117 | + * Gets the rgba value of the $color. |
|
118 | + * |
|
119 | + * @static |
|
120 | + * @access public |
|
121 | + * @param string $color The hex value of a color. |
|
122 | + * @param int|float $alpha Opacity level (0-1). |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public static function get_rgba( $color = '#fff', $alpha = 1 ) { |
|
126 | + $obj = ariColor::newColor( $color ); |
|
127 | + if ( 1 == $alpha ) { |
|
128 | + return $obj->toCSS( 'rgba' ); |
|
129 | + } |
|
130 | + // Make sure that opacity is properly formatted. |
|
131 | + // Converts 1-100 values to 0-1. |
|
132 | + if ( $alpha > 1 || $alpha < -1 ) { |
|
133 | + // Divide by 100. |
|
134 | + $alpha /= 100; |
|
135 | + } |
|
136 | + // Get absolute value. |
|
137 | + $alpha = abs( $alpha ); |
|
138 | + // Max 1. |
|
139 | + if ( 1 < $alpha ) { |
|
140 | + $alpha = 1; |
|
141 | + } |
|
142 | + $new_obj = $obj->getNew( 'alpha', $alpha ); |
|
143 | + return $new_obj->toCSS( 'rgba' ); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Strips the alpha value from an RGBA color string. |
|
148 | - * |
|
149 | - * @static |
|
150 | - * @access public |
|
151 | - * @param string $color The RGBA color string. |
|
152 | - * @return string The corresponding RGB string. |
|
153 | - */ |
|
154 | - public static function rgba_to_rgb( $color ) { |
|
155 | - $obj = ariColor::newColor( $color ); |
|
156 | - return $obj->toCSS( 'rgb' ); |
|
157 | - } |
|
146 | + /** |
|
147 | + * Strips the alpha value from an RGBA color string. |
|
148 | + * |
|
149 | + * @static |
|
150 | + * @access public |
|
151 | + * @param string $color The RGBA color string. |
|
152 | + * @return string The corresponding RGB string. |
|
153 | + */ |
|
154 | + public static function rgba_to_rgb( $color ) { |
|
155 | + $obj = ariColor::newColor( $color ); |
|
156 | + return $obj->toCSS( 'rgb' ); |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Gets the brightness of the $hex color. |
|
161 | - * |
|
162 | - * @static |
|
163 | - * @access public |
|
164 | - * @param string $hex The hex value of a color. |
|
165 | - * @return int Value between 0 and 255. |
|
166 | - */ |
|
167 | - public static function get_brightness( $hex ) { |
|
168 | - $hex = self::sanitize_hex( $hex, false ); |
|
159 | + /** |
|
160 | + * Gets the brightness of the $hex color. |
|
161 | + * |
|
162 | + * @static |
|
163 | + * @access public |
|
164 | + * @param string $hex The hex value of a color. |
|
165 | + * @return int Value between 0 and 255. |
|
166 | + */ |
|
167 | + public static function get_brightness( $hex ) { |
|
168 | + $hex = self::sanitize_hex( $hex, false ); |
|
169 | 169 | |
170 | - // Returns brightness value from 0 to 255. |
|
171 | - return intval( ( ( hexdec( substr( $hex, 0, 2 ) ) * 299 ) + ( hexdec( substr( $hex, 2, 2 ) ) * 587 ) + ( hexdec( substr( $hex, 4, 2 ) ) * 114 ) ) / 1000 ); |
|
172 | - } |
|
170 | + // Returns brightness value from 0 to 255. |
|
171 | + return intval( ( ( hexdec( substr( $hex, 0, 2 ) ) * 299 ) + ( hexdec( substr( $hex, 2, 2 ) ) * 587 ) + ( hexdec( substr( $hex, 4, 2 ) ) * 114 ) ) / 1000 ); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Adjusts brightness of the $hex color. |
|
176 | - * |
|
177 | - * @static |
|
178 | - * @access public |
|
179 | - * @param string $hex The hex value of a color. |
|
180 | - * @param integer $steps Should be between -255 and 255. Negative = darker, positive = lighter. |
|
181 | - * @return string Returns hex color. |
|
182 | - */ |
|
183 | - public static function adjust_brightness( $hex, $steps ) { |
|
184 | - $hex = self::sanitize_hex( $hex, false ); |
|
185 | - $steps = max( -255, min( 255, $steps ) ); |
|
174 | + /** |
|
175 | + * Adjusts brightness of the $hex color. |
|
176 | + * |
|
177 | + * @static |
|
178 | + * @access public |
|
179 | + * @param string $hex The hex value of a color. |
|
180 | + * @param integer $steps Should be between -255 and 255. Negative = darker, positive = lighter. |
|
181 | + * @return string Returns hex color. |
|
182 | + */ |
|
183 | + public static function adjust_brightness( $hex, $steps ) { |
|
184 | + $hex = self::sanitize_hex( $hex, false ); |
|
185 | + $steps = max( -255, min( 255, $steps ) ); |
|
186 | 186 | |
187 | - // Adjust number of steps and keep it inside 0 to 255. |
|
188 | - $red = max( 0, min( 255, hexdec( substr( $hex, 0, 2 ) ) + $steps ) ); |
|
189 | - $green = max( 0, min( 255, hexdec( substr( $hex, 2, 2 ) ) + $steps ) ); |
|
190 | - $blue = max( 0, min( 255, hexdec( substr( $hex, 4, 2 ) ) + $steps ) ); |
|
187 | + // Adjust number of steps and keep it inside 0 to 255. |
|
188 | + $red = max( 0, min( 255, hexdec( substr( $hex, 0, 2 ) ) + $steps ) ); |
|
189 | + $green = max( 0, min( 255, hexdec( substr( $hex, 2, 2 ) ) + $steps ) ); |
|
190 | + $blue = max( 0, min( 255, hexdec( substr( $hex, 4, 2 ) ) + $steps ) ); |
|
191 | 191 | |
192 | - $red_hex = str_pad( dechex( $red ), 2, '0', STR_PAD_LEFT ); |
|
193 | - $green_hex = str_pad( dechex( $green ), 2, '0', STR_PAD_LEFT ); |
|
194 | - $blue_hex = str_pad( dechex( $blue ), 2, '0', STR_PAD_LEFT ); |
|
195 | - return self::sanitize_hex( $red_hex . $green_hex . $blue_hex ); |
|
196 | - } |
|
192 | + $red_hex = str_pad( dechex( $red ), 2, '0', STR_PAD_LEFT ); |
|
193 | + $green_hex = str_pad( dechex( $green ), 2, '0', STR_PAD_LEFT ); |
|
194 | + $blue_hex = str_pad( dechex( $blue ), 2, '0', STR_PAD_LEFT ); |
|
195 | + return self::sanitize_hex( $red_hex . $green_hex . $blue_hex ); |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
199 | - * Mixes 2 hex colors. |
|
200 | - * The "percentage" variable is the percent of the first color. |
|
201 | - * to be used it the mix. default is 50 (equal mix). |
|
202 | - * |
|
203 | - * @static |
|
204 | - * @access public |
|
205 | - * @param string|false $hex1 Color. |
|
206 | - * @param string|false $hex2 Color. |
|
207 | - * @param int $percentage A value between 0 and 100. |
|
208 | - * @return string Returns hex color. |
|
209 | - */ |
|
210 | - public static function mix_colors( $hex1, $hex2, $percentage ) { |
|
211 | - $hex1 = self::sanitize_hex( $hex1, false ); |
|
212 | - $hex2 = self::sanitize_hex( $hex2, false ); |
|
213 | - $red = ( $percentage * hexdec( substr( $hex1, 0, 2 ) ) + ( 100 - $percentage ) * hexdec( substr( $hex2, 0, 2 ) ) ) / 100; |
|
214 | - $green = ( $percentage * hexdec( substr( $hex1, 2, 2 ) ) + ( 100 - $percentage ) * hexdec( substr( $hex2, 2, 2 ) ) ) / 100; |
|
215 | - $blue = ( $percentage * hexdec( substr( $hex1, 4, 2 ) ) + ( 100 - $percentage ) * hexdec( substr( $hex2, 4, 2 ) ) ) / 100; |
|
216 | - $red_hex = str_pad( dechex( $red ), 2, '0', STR_PAD_LEFT ); |
|
217 | - $green_hex = str_pad( dechex( $green ), 2, '0', STR_PAD_LEFT ); |
|
218 | - $blue_hex = str_pad( dechex( $blue ), 2, '0', STR_PAD_LEFT ); |
|
219 | - return self::sanitize_hex( $red_hex . $green_hex . $blue_hex ); |
|
220 | - } |
|
198 | + /** |
|
199 | + * Mixes 2 hex colors. |
|
200 | + * The "percentage" variable is the percent of the first color. |
|
201 | + * to be used it the mix. default is 50 (equal mix). |
|
202 | + * |
|
203 | + * @static |
|
204 | + * @access public |
|
205 | + * @param string|false $hex1 Color. |
|
206 | + * @param string|false $hex2 Color. |
|
207 | + * @param int $percentage A value between 0 and 100. |
|
208 | + * @return string Returns hex color. |
|
209 | + */ |
|
210 | + public static function mix_colors( $hex1, $hex2, $percentage ) { |
|
211 | + $hex1 = self::sanitize_hex( $hex1, false ); |
|
212 | + $hex2 = self::sanitize_hex( $hex2, false ); |
|
213 | + $red = ( $percentage * hexdec( substr( $hex1, 0, 2 ) ) + ( 100 - $percentage ) * hexdec( substr( $hex2, 0, 2 ) ) ) / 100; |
|
214 | + $green = ( $percentage * hexdec( substr( $hex1, 2, 2 ) ) + ( 100 - $percentage ) * hexdec( substr( $hex2, 2, 2 ) ) ) / 100; |
|
215 | + $blue = ( $percentage * hexdec( substr( $hex1, 4, 2 ) ) + ( 100 - $percentage ) * hexdec( substr( $hex2, 4, 2 ) ) ) / 100; |
|
216 | + $red_hex = str_pad( dechex( $red ), 2, '0', STR_PAD_LEFT ); |
|
217 | + $green_hex = str_pad( dechex( $green ), 2, '0', STR_PAD_LEFT ); |
|
218 | + $blue_hex = str_pad( dechex( $blue ), 2, '0', STR_PAD_LEFT ); |
|
219 | + return self::sanitize_hex( $red_hex . $green_hex . $blue_hex ); |
|
220 | + } |
|
221 | 221 | |
222 | - /** |
|
223 | - * Convert hex color to hsv. |
|
224 | - * |
|
225 | - * @static |
|
226 | - * @access public |
|
227 | - * @param string $hex The hex value of color 1. |
|
228 | - * @return array Returns array( 'h', 's', 'v' ). |
|
229 | - */ |
|
230 | - public static function hex_to_hsv( $hex ) { |
|
231 | - $rgb = (array) (array) self::get_rgb( self::sanitize_hex( $hex, false ) ); |
|
232 | - return self::rgb_to_hsv( $rgb ); |
|
233 | - } |
|
222 | + /** |
|
223 | + * Convert hex color to hsv. |
|
224 | + * |
|
225 | + * @static |
|
226 | + * @access public |
|
227 | + * @param string $hex The hex value of color 1. |
|
228 | + * @return array Returns array( 'h', 's', 'v' ). |
|
229 | + */ |
|
230 | + public static function hex_to_hsv( $hex ) { |
|
231 | + $rgb = (array) (array) self::get_rgb( self::sanitize_hex( $hex, false ) ); |
|
232 | + return self::rgb_to_hsv( $rgb ); |
|
233 | + } |
|
234 | 234 | |
235 | - /** |
|
236 | - * Convert hex color to hsv. |
|
237 | - * |
|
238 | - * @static |
|
239 | - * @access public |
|
240 | - * @param string $color The rgb color to convert array( 'r', 'g', 'b' ). |
|
241 | - * @return array Returns array( 'h', 's', 'v' ). |
|
242 | - */ |
|
243 | - public static function rgb_to_hsv( $color = array() ) { |
|
244 | - $var_r = ( $color[0] / 255 ); |
|
245 | - $var_g = ( $color[1] / 255 ); |
|
246 | - $var_b = ( $color[2] / 255 ); |
|
247 | - $var_min = min( $var_r, $var_g, $var_b ); |
|
248 | - $var_max = max( $var_r, $var_g, $var_b ); |
|
249 | - $del_max = $var_max - $var_min; |
|
250 | - $h = 0; |
|
251 | - $s = 0; |
|
252 | - $v = $var_max; |
|
253 | - if ( 0 != $del_max ) { |
|
254 | - $s = $del_max / $var_max; |
|
255 | - $del_r = ( ( ( $var_max - $var_r ) / 6 ) + ( $del_max / 2 ) ) / $del_max; |
|
256 | - $del_g = ( ( ( $var_max - $var_g ) / 6 ) + ( $del_max / 2 ) ) / $del_max; |
|
257 | - $del_b = ( ( ( $var_max - $var_b ) / 6 ) + ( $del_max / 2 ) ) / $del_max; |
|
258 | - if ( $var_r == $var_max ) { |
|
259 | - $h = $del_b - $del_g; |
|
260 | - } elseif ( $var_g == $var_max ) { |
|
261 | - $h = ( 1 / 3 ) + $del_r - $del_b; |
|
262 | - } elseif ( $var_b == $var_max ) { |
|
263 | - $h = ( 2 / 3 ) + $del_g - $del_r; |
|
264 | - } |
|
265 | - if ( $h < 0 ) { |
|
266 | - $h++; |
|
267 | - } |
|
268 | - if ( $h > 1 ) { |
|
269 | - $h--; |
|
270 | - } |
|
271 | - } |
|
272 | - return array( |
|
273 | - 'h' => round( $h, 2 ), |
|
274 | - 's' => round( $s, 2 ), |
|
275 | - 'v' => round( $v, 2 ), |
|
276 | - ); |
|
277 | - } |
|
235 | + /** |
|
236 | + * Convert hex color to hsv. |
|
237 | + * |
|
238 | + * @static |
|
239 | + * @access public |
|
240 | + * @param string $color The rgb color to convert array( 'r', 'g', 'b' ). |
|
241 | + * @return array Returns array( 'h', 's', 'v' ). |
|
242 | + */ |
|
243 | + public static function rgb_to_hsv( $color = array() ) { |
|
244 | + $var_r = ( $color[0] / 255 ); |
|
245 | + $var_g = ( $color[1] / 255 ); |
|
246 | + $var_b = ( $color[2] / 255 ); |
|
247 | + $var_min = min( $var_r, $var_g, $var_b ); |
|
248 | + $var_max = max( $var_r, $var_g, $var_b ); |
|
249 | + $del_max = $var_max - $var_min; |
|
250 | + $h = 0; |
|
251 | + $s = 0; |
|
252 | + $v = $var_max; |
|
253 | + if ( 0 != $del_max ) { |
|
254 | + $s = $del_max / $var_max; |
|
255 | + $del_r = ( ( ( $var_max - $var_r ) / 6 ) + ( $del_max / 2 ) ) / $del_max; |
|
256 | + $del_g = ( ( ( $var_max - $var_g ) / 6 ) + ( $del_max / 2 ) ) / $del_max; |
|
257 | + $del_b = ( ( ( $var_max - $var_b ) / 6 ) + ( $del_max / 2 ) ) / $del_max; |
|
258 | + if ( $var_r == $var_max ) { |
|
259 | + $h = $del_b - $del_g; |
|
260 | + } elseif ( $var_g == $var_max ) { |
|
261 | + $h = ( 1 / 3 ) + $del_r - $del_b; |
|
262 | + } elseif ( $var_b == $var_max ) { |
|
263 | + $h = ( 2 / 3 ) + $del_g - $del_r; |
|
264 | + } |
|
265 | + if ( $h < 0 ) { |
|
266 | + $h++; |
|
267 | + } |
|
268 | + if ( $h > 1 ) { |
|
269 | + $h--; |
|
270 | + } |
|
271 | + } |
|
272 | + return array( |
|
273 | + 'h' => round( $h, 2 ), |
|
274 | + 's' => round( $s, 2 ), |
|
275 | + 'v' => round( $v, 2 ), |
|
276 | + ); |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * This is a very simple algorithm that works by summing up the differences between the three color components red, green and blue. |
|
281 | - * A value higher than 500 is recommended for good readability. |
|
282 | - * |
|
283 | - * @static |
|
284 | - * @access public |
|
285 | - * @param string $color_1 The 1st color. |
|
286 | - * @param string $color_2 The 2nd color. |
|
287 | - * @return string |
|
288 | - */ |
|
289 | - public static function color_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { |
|
290 | - $color_1 = self::sanitize_hex( $color_1, false ); |
|
291 | - $color_2 = self::sanitize_hex( $color_2, false ); |
|
292 | - $color_1_rgb = self::get_rgb( $color_1 ); |
|
293 | - $color_2_rgb = self::get_rgb( $color_2 ); |
|
294 | - $r_diff = max( $color_1_rgb[0], $color_2_rgb[0] ) - min( $color_1_rgb[0], $color_2_rgb[0] ); |
|
295 | - $g_diff = max( $color_1_rgb[1], $color_2_rgb[1] ) - min( $color_1_rgb[1], $color_2_rgb[1] ); |
|
296 | - $b_diff = max( $color_1_rgb[2], $color_2_rgb[2] ) - min( $color_1_rgb[2], $color_2_rgb[2] ); |
|
297 | - $color_diff = $r_diff + $g_diff + $b_diff; |
|
298 | - return $color_diff; |
|
299 | - } |
|
279 | + /** |
|
280 | + * This is a very simple algorithm that works by summing up the differences between the three color components red, green and blue. |
|
281 | + * A value higher than 500 is recommended for good readability. |
|
282 | + * |
|
283 | + * @static |
|
284 | + * @access public |
|
285 | + * @param string $color_1 The 1st color. |
|
286 | + * @param string $color_2 The 2nd color. |
|
287 | + * @return string |
|
288 | + */ |
|
289 | + public static function color_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { |
|
290 | + $color_1 = self::sanitize_hex( $color_1, false ); |
|
291 | + $color_2 = self::sanitize_hex( $color_2, false ); |
|
292 | + $color_1_rgb = self::get_rgb( $color_1 ); |
|
293 | + $color_2_rgb = self::get_rgb( $color_2 ); |
|
294 | + $r_diff = max( $color_1_rgb[0], $color_2_rgb[0] ) - min( $color_1_rgb[0], $color_2_rgb[0] ); |
|
295 | + $g_diff = max( $color_1_rgb[1], $color_2_rgb[1] ) - min( $color_1_rgb[1], $color_2_rgb[1] ); |
|
296 | + $b_diff = max( $color_1_rgb[2], $color_2_rgb[2] ) - min( $color_1_rgb[2], $color_2_rgb[2] ); |
|
297 | + $color_diff = $r_diff + $g_diff + $b_diff; |
|
298 | + return $color_diff; |
|
299 | + } |
|
300 | 300 | |
301 | - /** |
|
302 | - * This function tries to compare the brightness of the colors. |
|
303 | - * A return value of more than 125 is recommended. |
|
304 | - * Combining it with the color_difference function above might make sense. |
|
305 | - * |
|
306 | - * @static |
|
307 | - * @access public |
|
308 | - * @param string $color_1 The 1st color. |
|
309 | - * @param string $color_2 The 2nd color. |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public static function brightness_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { |
|
313 | - $color_1 = self::sanitize_hex( $color_1, false ); |
|
314 | - $color_2 = self::sanitize_hex( $color_2, false ); |
|
315 | - $color_1_rgb = self::get_rgb( $color_1 ); |
|
316 | - $color_2_rgb = self::get_rgb( $color_2 ); |
|
317 | - $br_1 = ( 299 * $color_1_rgb[0] + 587 * $color_1_rgb[1] + 114 * $color_1_rgb[2] ) / 1000; |
|
318 | - $br_2 = ( 299 * $color_2_rgb[0] + 587 * $color_2_rgb[1] + 114 * $color_2_rgb[2] ) / 1000; |
|
319 | - return intval( abs( $br_1 - $br_2 ) ); |
|
320 | - } |
|
301 | + /** |
|
302 | + * This function tries to compare the brightness of the colors. |
|
303 | + * A return value of more than 125 is recommended. |
|
304 | + * Combining it with the color_difference function above might make sense. |
|
305 | + * |
|
306 | + * @static |
|
307 | + * @access public |
|
308 | + * @param string $color_1 The 1st color. |
|
309 | + * @param string $color_2 The 2nd color. |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public static function brightness_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { |
|
313 | + $color_1 = self::sanitize_hex( $color_1, false ); |
|
314 | + $color_2 = self::sanitize_hex( $color_2, false ); |
|
315 | + $color_1_rgb = self::get_rgb( $color_1 ); |
|
316 | + $color_2_rgb = self::get_rgb( $color_2 ); |
|
317 | + $br_1 = ( 299 * $color_1_rgb[0] + 587 * $color_1_rgb[1] + 114 * $color_1_rgb[2] ) / 1000; |
|
318 | + $br_2 = ( 299 * $color_2_rgb[0] + 587 * $color_2_rgb[1] + 114 * $color_2_rgb[2] ) / 1000; |
|
319 | + return intval( abs( $br_1 - $br_2 ) ); |
|
320 | + } |
|
321 | 321 | |
322 | - /** |
|
323 | - * Uses the luminosity to calculate the difference between the given colors. |
|
324 | - * The returned value should be bigger than 5 for best readability. |
|
325 | - * |
|
326 | - * @static |
|
327 | - * @access public |
|
328 | - * @param string $color_1 The 1st color. |
|
329 | - * @param string $color_2 The 2nd color. |
|
330 | - * @return string |
|
331 | - */ |
|
332 | - public static function lumosity_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { |
|
333 | - $color_1 = self::sanitize_hex( $color_1, false ); |
|
334 | - $color_2 = self::sanitize_hex( $color_2, false ); |
|
335 | - $color_1_rgb = self::get_rgb( $color_1 ); |
|
336 | - $color_2_rgb = self::get_rgb( $color_2 ); |
|
337 | - $l1 = 0.2126 * pow( $color_1_rgb[0] / 255, 2.2 ) + 0.7152 * pow( $color_1_rgb[1] / 255, 2.2 ) + 0.0722 * pow( $color_1_rgb[2] / 255, 2.2 ); |
|
338 | - $l2 = 0.2126 * pow( $color_2_rgb[0] / 255, 2.2 ) + 0.7152 * pow( $color_2_rgb[1] / 255, 2.2 ) + 0.0722 * pow( $color_2_rgb[2] / 255, 2.2 ); |
|
339 | - $lum_diff = ( $l1 > $l2 ) ? ( $l1 + 0.05 ) / ( $l2 + 0.05 ) : ( $l2 + 0.05 ) / ( $l1 + 0.05 ); |
|
340 | - return round( $lum_diff, 2 ); |
|
341 | - } |
|
322 | + /** |
|
323 | + * Uses the luminosity to calculate the difference between the given colors. |
|
324 | + * The returned value should be bigger than 5 for best readability. |
|
325 | + * |
|
326 | + * @static |
|
327 | + * @access public |
|
328 | + * @param string $color_1 The 1st color. |
|
329 | + * @param string $color_2 The 2nd color. |
|
330 | + * @return string |
|
331 | + */ |
|
332 | + public static function lumosity_difference( $color_1 = '#ffffff', $color_2 = '#000000' ) { |
|
333 | + $color_1 = self::sanitize_hex( $color_1, false ); |
|
334 | + $color_2 = self::sanitize_hex( $color_2, false ); |
|
335 | + $color_1_rgb = self::get_rgb( $color_1 ); |
|
336 | + $color_2_rgb = self::get_rgb( $color_2 ); |
|
337 | + $l1 = 0.2126 * pow( $color_1_rgb[0] / 255, 2.2 ) + 0.7152 * pow( $color_1_rgb[1] / 255, 2.2 ) + 0.0722 * pow( $color_1_rgb[2] / 255, 2.2 ); |
|
338 | + $l2 = 0.2126 * pow( $color_2_rgb[0] / 255, 2.2 ) + 0.7152 * pow( $color_2_rgb[1] / 255, 2.2 ) + 0.0722 * pow( $color_2_rgb[2] / 255, 2.2 ); |
|
339 | + $lum_diff = ( $l1 > $l2 ) ? ( $l1 + 0.05 ) / ( $l2 + 0.05 ) : ( $l2 + 0.05 ) / ( $l1 + 0.05 ); |
|
340 | + return round( $lum_diff, 2 ); |
|
341 | + } |
|
342 | 342 | } |
@@ -3,980 +3,980 @@ |
||
3 | 3 | |
4 | 4 | // Exit if accessed directly. |
5 | 5 | if ( ! defined( 'ABSPATH' ) ) { |
6 | - exit; |
|
6 | + exit; |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | if ( ! class_exists( 'ariColor' ) ) { |
10 | - /** |
|
11 | - * The color calculations class. |
|
12 | - */ |
|
13 | - class ariColor { |
|
14 | - |
|
15 | - /** |
|
16 | - * An array of our instances. |
|
17 | - * |
|
18 | - * @static |
|
19 | - * @access public |
|
20 | - * @since 1.0.0 |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - public static $instances = array(); |
|
24 | - |
|
25 | - /** |
|
26 | - * The color initially set. |
|
27 | - * |
|
28 | - * @access public |
|
29 | - * @since 1.0.0 |
|
30 | - * @var mixed |
|
31 | - */ |
|
32 | - public $color; |
|
33 | - |
|
34 | - /** |
|
35 | - * A fallback color in case of failure. |
|
36 | - * |
|
37 | - * @access public |
|
38 | - * @since 1.0.0 |
|
39 | - * @var mixed |
|
40 | - */ |
|
41 | - public $fallback = '#ffffff'; |
|
42 | - |
|
43 | - /** |
|
44 | - * Fallback object from the fallback color. |
|
45 | - * |
|
46 | - * @access public |
|
47 | - * @since 1.0.0 |
|
48 | - * @var object |
|
49 | - */ |
|
50 | - public $fallback_obj; |
|
51 | - |
|
52 | - /** |
|
53 | - * The mode we're using for this color. |
|
54 | - * |
|
55 | - * @access public |
|
56 | - * @since 1.0.0 |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - public $mode = 'hex'; |
|
60 | - |
|
61 | - /** |
|
62 | - * An array containing all word-colors (white/blue/red etc) |
|
63 | - * and their corresponding HEX codes. |
|
64 | - * |
|
65 | - * @access public |
|
66 | - * @since 1.0.0 |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - public $word_colors = array(); |
|
70 | - |
|
71 | - /** |
|
72 | - * The hex code of the color. |
|
73 | - * |
|
74 | - * @access public |
|
75 | - * @since 1.0.0 |
|
76 | - * @var string |
|
77 | - */ |
|
78 | - public $hex; |
|
79 | - |
|
80 | - /** |
|
81 | - * Red value. |
|
82 | - * |
|
83 | - * @access public |
|
84 | - * @since 1.0.0 |
|
85 | - * @var int |
|
86 | - */ |
|
87 | - public $red = 0; |
|
88 | - |
|
89 | - /** |
|
90 | - * Green value. |
|
91 | - * |
|
92 | - * @access public |
|
93 | - * @since 1.0.0 |
|
94 | - * @var int |
|
95 | - */ |
|
96 | - public $green = 0; |
|
97 | - |
|
98 | - /** |
|
99 | - * Blue value. |
|
100 | - * |
|
101 | - * @access public |
|
102 | - * @since 1.0.0 |
|
103 | - * @var int |
|
104 | - */ |
|
105 | - public $blue = 0; |
|
106 | - |
|
107 | - /** |
|
108 | - * Alpha value (min:0, max: 1) |
|
109 | - * |
|
110 | - * @access public |
|
111 | - * @since 1.0.0 |
|
112 | - * @var float |
|
113 | - */ |
|
114 | - public $alpha = 1; |
|
115 | - |
|
116 | - /** |
|
117 | - * Hue value. |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @since 1.0.0 |
|
121 | - * @var float |
|
122 | - */ |
|
123 | - public $hue; |
|
124 | - |
|
125 | - /** |
|
126 | - * Saturation value. |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @since 1.0.0 |
|
130 | - * @var float |
|
131 | - */ |
|
132 | - public $saturation; |
|
133 | - |
|
134 | - /** |
|
135 | - * Lightness value. |
|
136 | - * |
|
137 | - * @access public |
|
138 | - * @since 1.0.0 |
|
139 | - * @var float |
|
140 | - */ |
|
141 | - public $lightness; |
|
142 | - |
|
143 | - /** |
|
144 | - * Chroma value. |
|
145 | - * |
|
146 | - * @access public |
|
147 | - * @since 1.0.0 |
|
148 | - * @var float |
|
149 | - */ |
|
150 | - public $chroma; |
|
151 | - |
|
152 | - /** |
|
153 | - * An array containing brightnesses. |
|
154 | - * |
|
155 | - * @access public |
|
156 | - * @since 1.0.0 |
|
157 | - * @var array |
|
158 | - */ |
|
159 | - public $brightness = array(); |
|
160 | - |
|
161 | - /** |
|
162 | - * Luminance value. |
|
163 | - * |
|
164 | - * @access public |
|
165 | - * @since 1.0.0 |
|
166 | - * @var float |
|
167 | - */ |
|
168 | - public $luminance; |
|
169 | - |
|
170 | - /** |
|
171 | - * The class constructor. |
|
172 | - * |
|
173 | - * @access protected |
|
174 | - * @since 1.0.0 |
|
175 | - * @param string|array $color The color. |
|
176 | - * @param string $mode The color mode. Leave empty to auto-detect. |
|
177 | - */ |
|
178 | - protected function __construct( $color = '', $mode = 'auto' ) { |
|
179 | - $this->color = $color; |
|
180 | - |
|
181 | - if ( is_array( $color ) && isset( $color['fallback'] ) ) { |
|
182 | - $this->fallback = $color['fallback']; |
|
183 | - $this->fallback_obj = self::newColor( $this->fallback ); |
|
184 | - } |
|
185 | - |
|
186 | - if ( ! method_exists( $this, 'from_' . $mode ) ) { |
|
187 | - $mode = $this->get_mode( $color ); |
|
188 | - } |
|
189 | - |
|
190 | - $this->mode = $mode; |
|
191 | - |
|
192 | - if ( ! $mode ) { |
|
193 | - return; |
|
194 | - } |
|
195 | - |
|
196 | - $this->mode = $mode; |
|
197 | - $method = 'from_' . $mode; |
|
198 | - // Call the from_{$color_mode} method. |
|
199 | - $this->$method(); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Gets an instance for this color. |
|
204 | - * We use a separate instance per color |
|
205 | - * because there's no need to create a completely new instance each time we call this class. |
|
206 | - * Instead using instances helps us improve performance & footprint. |
|
207 | - * |
|
208 | - * @static |
|
209 | - * @access public |
|
210 | - * @since 1.0.0 |
|
211 | - * @param string|array $color The color. |
|
212 | - * @param string $mode Mode to be used. |
|
213 | - * @return ariColor (object) |
|
214 | - */ |
|
215 | - public static function newColor( $color, $mode = 'auto' ) { |
|
216 | - |
|
217 | - // Get an md5 for this color. |
|
218 | - $color_md5 = ( is_array( $color ) ) ? md5( wp_json_encode( $color ) . $mode ) : md5( $color . $mode ); |
|
219 | - // Set the instance if it does not already exist. |
|
220 | - if ( ! isset( self::$instances[ $color_md5 ] ) ) { |
|
221 | - self::$instances[ $color_md5 ] = new self( $color, $mode ); |
|
222 | - } |
|
223 | - return self::$instances[ $color_md5 ]; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Alias of the newColor method. |
|
228 | - * |
|
229 | - * @static |
|
230 | - * @access public |
|
231 | - * @since 1.1 |
|
232 | - * @param string|array $color The color. |
|
233 | - * @param string $mode Mode to be used. |
|
234 | - * @return ariColor (object) |
|
235 | - */ |
|
236 | - public static function new_color( $color, $mode = 'auto' ) { |
|
237 | - return self::newColor( $color, $mode ); |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * Allows us to get a new instance by modifying a property of the existing one. |
|
242 | - * |
|
243 | - * @access public |
|
244 | - * @since 1.0.0 |
|
245 | - * @param string $property Can be one of the following: |
|
246 | - * red, |
|
247 | - * green, |
|
248 | - * blue, |
|
249 | - * alpha, |
|
250 | - * hue, |
|
251 | - * saturation, |
|
252 | - * lightness, |
|
253 | - * brightness. |
|
254 | - * @param int|float|string $value The new value. |
|
255 | - * @return ariColor|null |
|
256 | - */ |
|
257 | - public function getNew( $property = '', $value = '' ) { |
|
258 | - |
|
259 | - if ( in_array( $property, array( 'red', 'green', 'blue', 'alpha' ), true ) ) { |
|
260 | - // Check if we're changing any of the rgba values. |
|
261 | - $value = max( 0, min( 255, $value ) ); |
|
262 | - if ( 'red' === $property ) { |
|
263 | - return self::new_color( 'rgba(' . $value . ',' . $this->green . ',' . $this->blue . ',' . $this->alpha . ')', 'rgba' ); |
|
264 | - } elseif ( 'green' === $property ) { |
|
265 | - return self::new_color( 'rgba(' . $this->red . ',' . $value . ',' . $this->blue . ',' . $this->alpha . ')', 'rgba' ); |
|
266 | - } elseif ( 'blue' === $property ) { |
|
267 | - return self::new_color( 'rgba(' . $this->red . ',' . $this->green . ',' . $value . ',' . $this->alpha . ')', 'rgba' ); |
|
268 | - } elseif ( 'alpha' === $property ) { |
|
269 | - return self::new_color( 'rgba(' . $this->red . ',' . $this->green . ',' . $this->blue . ',' . $value . ')', 'rgba' ); |
|
270 | - } |
|
271 | - } elseif ( in_array( $property, array( 'hue', 'saturation', 'lightness' ), true ) ) { |
|
272 | - // Check if we're changing any of the hsl values. |
|
273 | - $value = ( 'hue' === $property ) ? max( 0, min( 360, $value ) ) : max( 0, min( 100, $value ) ); |
|
274 | - |
|
275 | - if ( 'hue' === $property ) { |
|
276 | - return self::new_color( 'hsla(' . $value . ',' . $this->saturation . '%,' . $this->lightness . '%,' . $this->alpha . ')', 'hsla' ); |
|
277 | - } elseif ( 'saturation' === $property ) { |
|
278 | - return self::new_color( 'hsla(' . $this->hue . ',' . $value . '%,' . $this->lightness . '%,' . $this->alpha . ')', 'hsla' ); |
|
279 | - } elseif ( 'lightness' === $property ) { |
|
280 | - return self::new_color( 'hsla(' . $this->hue . ',' . $this->saturation . '%,' . $value . '%,' . $this->alpha . ')', 'hsla' ); |
|
281 | - } |
|
282 | - } elseif ( 'brightness' === $property ) { |
|
283 | - // Check if we're changing the brightness. |
|
284 | - if ( $value < $this->brightness['total'] ) { |
|
285 | - $red = max( 0, min( 255, $this->red - ( $this->brightness['total'] - $value ) ) ); |
|
286 | - $green = max( 0, min( 255, $this->green - ( $this->brightness['total'] - $value ) ) ); |
|
287 | - $blue = max( 0, min( 255, $this->blue - ( $this->brightness['total'] - $value ) ) ); |
|
288 | - } elseif ( $value > $this->brightness['total'] ) { |
|
289 | - $red = max( 0, min( 255, $this->red + ( $value - $this->brightness['total'] ) ) ); |
|
290 | - $green = max( 0, min( 255, $this->green + ( $value - $this->brightness['total'] ) ) ); |
|
291 | - $blue = max( 0, min( 255, $this->blue + ( $value - $this->brightness['total'] ) ) ); |
|
292 | - } else { |
|
293 | - // If it's not smaller and it's not greater, then it's equal. |
|
294 | - return $this; |
|
295 | - } |
|
296 | - return self::new_color( 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $this->alpha . ')', 'rgba' ); |
|
297 | - } |
|
298 | - return null; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Allias for the getNew method. |
|
303 | - * |
|
304 | - * @access public |
|
305 | - * @since 1.1.0 |
|
306 | - * @param string $property Can be one of the following: |
|
307 | - * red, |
|
308 | - * green, |
|
309 | - * blue, |
|
310 | - * alpha, |
|
311 | - * hue, |
|
312 | - * saturation, |
|
313 | - * lightness, |
|
314 | - * brightness. |
|
315 | - * @param int|float|string $value The new value. |
|
316 | - * @return ariColor|null |
|
317 | - */ |
|
318 | - public function get_new( $property = '', $value = '' ) { |
|
319 | - return $this->getNew( $property, $value ); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Figure out what mode we're using. |
|
324 | - * |
|
325 | - * @access public |
|
326 | - * @since 1.0.0 |
|
327 | - * @param string|array $color The color we're querying. |
|
328 | - * @return string |
|
329 | - */ |
|
330 | - public function get_mode( $color ) { |
|
331 | - |
|
332 | - // Check if value is an array. |
|
333 | - if ( is_array( $color ) ) { |
|
334 | - // Does the array have an 'rgba' key? |
|
335 | - if ( isset( $color['rgba'] ) ) { |
|
336 | - $this->color = $color['rgba']; |
|
337 | - return 'rgba'; |
|
338 | - } elseif ( isset( $color['color'] ) ) { |
|
339 | - // Does the array have a 'color' key? |
|
340 | - $this->color = $color['color']; |
|
341 | - if ( is_string( $color['color'] ) && false !== strpos( $color['color'], 'rgba' ) ) { |
|
342 | - return 'rgba'; |
|
343 | - } |
|
344 | - return 'hex'; |
|
345 | - } |
|
346 | - // Is this a simple array with 4 items? |
|
347 | - if ( 4 === count( $color ) && isset( $color[0] ) && isset( $color[1] ) && isset( $color[2] ) && isset( $color[3] ) ) { |
|
348 | - $this->color = 'rgba(' . intval( $color[0] ) . ',' . intval( $color[1] ) . ',' . intval( $color[2] ) . ',' . intval( $color[3] ) . ')'; |
|
349 | - return 'rgba'; |
|
350 | - } elseif ( 3 === count( $color ) && isset( $color[0] ) && isset( $color[1] ) && isset( $color[2] ) ) { |
|
351 | - // Is this a simple array with 3 items? |
|
352 | - $this->color = 'rgba(' . intval( $color[0] ) . ',' . intval( $color[1] ) . ',' . intval( $color[2] ) . ',1)'; |
|
353 | - return 'rgba'; |
|
354 | - } |
|
355 | - |
|
356 | - // Check for other keys in the array and get values from there. |
|
357 | - $finders_keepers = array( |
|
358 | - 'r' => 'red', |
|
359 | - 'g' => 'green', |
|
360 | - 'b' => 'blue', |
|
361 | - 'a' => 'alpha', |
|
362 | - 'red' => 'red', |
|
363 | - 'green' => 'green', |
|
364 | - 'blue' => 'blue', |
|
365 | - 'alpha' => 'alpha', |
|
366 | - 'opacity' => 'alpha', |
|
367 | - ); |
|
368 | - $found = false; |
|
369 | - foreach ( $finders_keepers as $finder => $keeper ) { |
|
370 | - if ( isset( $color[ $finder ] ) ) { |
|
371 | - $found = true; |
|
372 | - $this->$keeper = $color[ $finder ]; |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - // We failed, use fallback. |
|
377 | - if ( ! $found ) { |
|
378 | - $this->from_fallback(); |
|
379 | - return $this->mode; |
|
380 | - } |
|
381 | - |
|
382 | - // We did not fail, so use rgba values recovered above. |
|
383 | - $this->color = 'rgba(' . $this->red . ',' . $this->green . ',' . $this->blue . ',' . $this->alpha . ')'; |
|
384 | - return 'rgba'; |
|
385 | - } |
|
386 | - |
|
387 | - // If a string and 3 or 6 characters long, add # since it's a hex. |
|
388 | - if ( 3 === strlen( $this->color ) || 6 === strlen( $this->color ) && false === strpos( $this->color, '#' ) ) { |
|
389 | - $this->color = '#' . $this->color; |
|
390 | - $color = $this->color; |
|
391 | - } |
|
392 | - |
|
393 | - // If we got this far, it's not an array. |
|
394 | - // Check for key identifiers in the value. |
|
395 | - $finders_keepers = array( |
|
396 | - '#' => 'hex', |
|
397 | - 'rgba' => 'rgba', |
|
398 | - 'rgb' => 'rgb', |
|
399 | - 'hsla' => 'hsla', |
|
400 | - 'hsl' => 'hsl', |
|
401 | - ); |
|
402 | - foreach ( $finders_keepers as $finder => $keeper ) { |
|
403 | - if ( false !== strrpos( $color, $finder ) ) { |
|
404 | - |
|
405 | - // Make sure hex colors have 6 digits and not more. |
|
406 | - if ( '#' === $finder && 7 < strlen( $color ) ) { |
|
407 | - $this->color = substr( $color, 0, 7 ); |
|
408 | - } |
|
409 | - |
|
410 | - return $keeper; |
|
411 | - } |
|
412 | - } |
|
413 | - // Perhaps we're using a word like "orange"? |
|
414 | - $wordcolors = $this->get_word_colors(); |
|
415 | - if ( is_string( $color ) && array_key_exists( $color, $wordcolors ) ) { |
|
416 | - $this->color = '#' . $wordcolors[ $color ]; |
|
417 | - return 'hex'; |
|
418 | - } |
|
419 | - // Fallback to hex. |
|
420 | - |
|
421 | - $this->color = $this->fallback; |
|
422 | - return 'hex'; |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * Starts with a HEX color and calculates all other properties. |
|
427 | - * |
|
428 | - * @access protected |
|
429 | - * @since 1.0.0 |
|
430 | - * @return null |
|
431 | - */ |
|
432 | - protected function from_hex() { |
|
433 | - |
|
434 | - if ( ! function_exists( 'sanitize_hex_color' ) ) { |
|
435 | - require_once wp_normalize_path( ABSPATH . WPINC . '/class-wp-customize-manager.php' ); |
|
436 | - } |
|
437 | - // Is this perhaps a word-color? |
|
438 | - $word_colors = $this->get_word_colors(); |
|
439 | - if ( array_key_exists( $this->color, $word_colors ) ) { |
|
440 | - $this->color = '#' . $word_colors[ $this->color ]; |
|
441 | - } |
|
442 | - // Sanitize color. |
|
443 | - $this->hex = sanitize_hex_color( maybe_hash_hex_color( $this->color ) ); |
|
444 | - $hex = ltrim( $this->hex, '#' ); |
|
445 | - |
|
446 | - // Fallback if needed. |
|
447 | - if ( ! $hex || 3 > strlen( $hex ) ) { |
|
448 | - $this->from_fallback(); |
|
449 | - return; |
|
450 | - } |
|
451 | - // Make sure we have 6 digits for the below calculations. |
|
452 | - if ( 3 === strlen( $hex ) ) { |
|
453 | - $hex = ltrim( $this->hex, '#' ); |
|
454 | - $hex = substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) . substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) . substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ); |
|
455 | - } |
|
456 | - |
|
457 | - // Set red, green, blue. |
|
458 | - $this->red = hexdec( substr( $hex, 0, 2 ) ); |
|
459 | - $this->green = hexdec( substr( $hex, 2, 2 ) ); |
|
460 | - $this->blue = hexdec( substr( $hex, 4, 2 ) ); |
|
461 | - $this->alpha = 1; |
|
462 | - // Set other color properties. |
|
463 | - $this->set_brightness(); |
|
464 | - $this->set_hsl(); |
|
465 | - $this->set_luminance(); |
|
466 | - |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * Starts with an RGB color and calculates all other properties. |
|
471 | - * |
|
472 | - * @access protected |
|
473 | - * @since 1.0.0 |
|
474 | - * @return null |
|
475 | - */ |
|
476 | - protected function from_rgb() { |
|
477 | - $value = explode( ',', str_replace( array( ' ', 'rgb', '(', ')' ), '', $this->color ) ); |
|
478 | - // Set red, green, blue. |
|
479 | - $this->red = ( isset( $value[0] ) ) ? intval( $value[0] ) : 255; |
|
480 | - $this->green = ( isset( $value[1] ) ) ? intval( $value[1] ) : 255; |
|
481 | - $this->blue = ( isset( $value[2] ) ) ? intval( $value[2] ) : 255; |
|
482 | - $this->alpha = 1; |
|
483 | - // Set the hex. |
|
484 | - $this->hex = $this->rgb_to_hex( $this->red, $this->green, $this->blue ); |
|
485 | - // Set other color properties. |
|
486 | - $this->set_brightness(); |
|
487 | - $this->set_hsl(); |
|
488 | - $this->set_luminance(); |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * Starts with an RGBA color and calculates all other properties. |
|
493 | - * |
|
494 | - * @access protected |
|
495 | - * @since 1.0.0 |
|
496 | - * @return null |
|
497 | - */ |
|
498 | - protected function from_rgba() { |
|
499 | - // Set r, g, b, a properties. |
|
500 | - $value = explode( ',', str_replace( array( ' ', 'rgba', '(', ')' ), '', $this->color ) ); |
|
501 | - $this->red = ( isset( $value[0] ) ) ? intval( $value[0] ) : 255; |
|
502 | - $this->green = ( isset( $value[1] ) ) ? intval( $value[1] ) : 255; |
|
503 | - $this->blue = ( isset( $value[2] ) ) ? intval( $value[2] ) : 255; |
|
504 | - $this->alpha = ( isset( $value[3] ) ) ? filter_var( $value[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : 1; |
|
505 | - // Limit values in the range of 0 - 255. |
|
506 | - $this->red = max( 0, min( 255, $this->red ) ); |
|
507 | - $this->green = max( 0, min( 255, $this->green ) ); |
|
508 | - $this->blue = max( 0, min( 255, $this->blue ) ); |
|
509 | - // Limit values 0 - 1. |
|
510 | - $this->alpha = max( 0, min( 1, $this->alpha ) ); |
|
511 | - // Set hex. |
|
512 | - $this->hex = $this->rgb_to_hex( $this->red, $this->green, $this->blue ); |
|
513 | - // Set other color properties. |
|
514 | - $this->set_brightness(); |
|
515 | - $this->set_hsl(); |
|
516 | - $this->set_luminance(); |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * Starts with an HSL color and calculates all other properties. |
|
521 | - * |
|
522 | - * @access protected |
|
523 | - * @since 1.0.0 |
|
524 | - * @return null |
|
525 | - */ |
|
526 | - protected function from_hsl() { |
|
527 | - $value = explode( ',', str_replace( array( ' ', 'hsl', '(', ')', '%' ), '', $this->color ) ); |
|
528 | - $this->hue = $value[0]; |
|
529 | - $this->saturation = $value[1]; |
|
530 | - $this->lightness = $value[2]; |
|
531 | - $this->from_hsl_array(); |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * Starts with an HSLA color and calculates all other properties. |
|
536 | - * |
|
537 | - * @access protected |
|
538 | - * @since 1.0.0 |
|
539 | - * @return null |
|
540 | - */ |
|
541 | - protected function from_hsla() { |
|
542 | - $value = explode( ',', str_replace( array( ' ', 'hsla', '(', ')', '%' ), '', $this->color ) ); |
|
543 | - $this->hue = $value[0]; |
|
544 | - $this->saturation = $value[1]; |
|
545 | - $this->lightness = $value[2]; |
|
546 | - $this->alpha = $value[3]; |
|
547 | - $this->from_hsl_array(); |
|
548 | - } |
|
549 | - |
|
550 | - /** |
|
551 | - * Generates the HEX value of a color given values for $red, $green, $blue. |
|
552 | - * |
|
553 | - * @access protected |
|
554 | - * @since 1.0.0 |
|
555 | - * @param int|string $red The red value of this color. |
|
556 | - * @param int|string $green The green value of this color. |
|
557 | - * @param int|string $blue The blue value of this color. |
|
558 | - * @return string |
|
559 | - */ |
|
560 | - protected function rgb_to_hex( $red, $green, $blue ) { |
|
561 | - // Get hex values properly formatted. |
|
562 | - $hex_red = $this->dexhex_double_digit( $red ); |
|
563 | - $hex_green = $this->dexhex_double_digit( $green ); |
|
564 | - $hex_blue = $this->dexhex_double_digit( $blue ); |
|
565 | - return '#' . $hex_red . $hex_green . $hex_blue; |
|
566 | - } |
|
567 | - |
|
568 | - /** |
|
569 | - * Convert a decimal value to hex and make sure it's 2 characters. |
|
570 | - * |
|
571 | - * @access protected |
|
572 | - * @since 1.0.0 |
|
573 | - * @param int|string $value The value to convert. |
|
574 | - * @return string |
|
575 | - */ |
|
576 | - protected function dexhex_double_digit( $value ) { |
|
577 | - $value = dechex( $value ); |
|
578 | - if ( 1 === strlen( $value ) ) { |
|
579 | - $value = '0' . $value; |
|
580 | - } |
|
581 | - return $value; |
|
582 | - } |
|
583 | - |
|
584 | - /** |
|
585 | - * Calculates the red, green, blue values of an HSL color. |
|
586 | - * |
|
587 | - * @access protected |
|
588 | - * @since 1.0.0 |
|
589 | - * @see https://gist.github.com/brandonheyer/5254516 |
|
590 | - */ |
|
591 | - protected function from_hsl_array() { |
|
592 | - $h = $this->hue / 360; |
|
593 | - $s = $this->saturation / 100; |
|
594 | - $l = $this->lightness / 100; |
|
595 | - |
|
596 | - $r = $l; |
|
597 | - $g = $l; |
|
598 | - $b = $l; |
|
599 | - $v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s ); |
|
600 | - if ( $v > 0 ) { |
|
601 | - $m = $l + $l - $v; |
|
602 | - $sv = ( $v - $m ) / $v; |
|
603 | - $h *= 6.0; |
|
604 | - $sextant = floor( $h ); |
|
605 | - $fract = $h - $sextant; |
|
606 | - $vsf = $v * $sv * $fract; |
|
607 | - $mid1 = $m + $vsf; |
|
608 | - $mid2 = $v - $vsf; |
|
609 | - switch ( $sextant ) { |
|
610 | - case 0: |
|
611 | - $r = $v; |
|
612 | - $g = $mid1; |
|
613 | - $b = $m; |
|
614 | - break; |
|
615 | - case 1: |
|
616 | - $r = $mid2; |
|
617 | - $g = $v; |
|
618 | - $b = $m; |
|
619 | - break; |
|
620 | - case 2: |
|
621 | - $r = $m; |
|
622 | - $g = $v; |
|
623 | - $b = $mid1; |
|
624 | - break; |
|
625 | - case 3: |
|
626 | - $r = $m; |
|
627 | - $g = $mid2; |
|
628 | - $b = $v; |
|
629 | - break; |
|
630 | - case 4: |
|
631 | - $r = $mid1; |
|
632 | - $g = $m; |
|
633 | - $b = $v; |
|
634 | - break; |
|
635 | - case 5: |
|
636 | - $r = $v; |
|
637 | - $g = $m; |
|
638 | - $b = $mid2; |
|
639 | - break; |
|
640 | - } |
|
641 | - } |
|
642 | - $this->red = round( $r * 255, 0 ); |
|
643 | - $this->green = round( $g * 255, 0 ); |
|
644 | - $this->blue = round( $b * 255, 0 ); |
|
645 | - |
|
646 | - $this->hex = $this->rgb_to_hex( $this->red, $this->green, $this->blue ); |
|
647 | - $this->set_luminance(); |
|
648 | - } |
|
649 | - |
|
650 | - /** |
|
651 | - * Returns a CSS-formatted value for colors. |
|
652 | - * |
|
653 | - * @access public |
|
654 | - * @since 1.0.0 |
|
655 | - * @param string $mode The mode we're using. |
|
656 | - * @return string |
|
657 | - */ |
|
658 | - public function toCSS( $mode = 'hex' ) { |
|
659 | - |
|
660 | - $value = ''; |
|
661 | - |
|
662 | - switch ( $mode ) { |
|
663 | - case 'hex': |
|
664 | - $value = strtolower( $this->hex ); |
|
665 | - break; |
|
666 | - case 'rgba': |
|
667 | - $value = 'rgba(' . $this->red . ',' . $this->green . ',' . $this->blue . ',' . $this->alpha . ')'; |
|
668 | - break; |
|
669 | - case 'rgb': |
|
670 | - $value = 'rgb(' . $this->red . ',' . $this->green . ',' . $this->blue . ')'; |
|
671 | - break; |
|
672 | - case 'hsl': |
|
673 | - $value = 'hsl(' . $this->hue . ',' . round( $this->saturation ) . '%,' . round( $this->lightness ) . '%)'; |
|
674 | - break; |
|
675 | - case 'hsla': |
|
676 | - $value = 'hsla(' . $this->hue . ',' . round( $this->saturation ) . '%,' . round( $this->lightness ) . '%,' . $this->alpha . ')'; |
|
677 | - break; |
|
678 | - } |
|
679 | - return $value; |
|
680 | - } |
|
681 | - |
|
682 | - /** |
|
683 | - * Alias for the toCSS method. |
|
684 | - * |
|
685 | - * @access public |
|
686 | - * @since 1.1 |
|
687 | - * @param string $mode The mode we're using. |
|
688 | - * @return string |
|
689 | - */ |
|
690 | - public function to_css( $mode = 'hex' ) { |
|
691 | - return $this->toCSS( $mode ); |
|
692 | - } |
|
693 | - |
|
694 | - /** |
|
695 | - * Sets the HSL values of a color based on the values of red, green, blue. |
|
696 | - * |
|
697 | - * @access public |
|
698 | - * @since 1.0.0 |
|
699 | - */ |
|
700 | - protected function set_hsl() { |
|
701 | - $red = $this->red / 255; |
|
702 | - $green = $this->green / 255; |
|
703 | - $blue = $this->blue / 255; |
|
704 | - |
|
705 | - $max = max( $red, $green, $blue ); |
|
706 | - $min = min( $red, $green, $blue ); |
|
707 | - |
|
708 | - $lightness = ( $max + $min ) / 2; |
|
709 | - $difference = $max - $min; |
|
710 | - |
|
711 | - if ( ! $difference ) { |
|
712 | - $hue = $saturation = 0; // Achromatic. |
|
713 | - } else { |
|
714 | - $saturation = $difference / ( 1 - abs( 2 * $lightness - 1 ) ); |
|
715 | - switch ( $max ) { |
|
716 | - case $red: |
|
717 | - $hue = 60 * fmod( ( ( $green - $blue ) / $difference ), 6 ); |
|
718 | - if ( $blue > $green ) { |
|
719 | - $hue += 360; |
|
720 | - } |
|
721 | - break; |
|
722 | - case $green: |
|
723 | - $hue = 60 * ( ( $blue - $red ) / $difference + 2 ); |
|
724 | - break; |
|
725 | - case $blue: |
|
726 | - $hue = 60 * ( ( $red - $green ) / $difference + 4 ); |
|
727 | - break; |
|
728 | - } |
|
729 | - } |
|
730 | - |
|
731 | - $this->hue = round( $hue ); |
|
732 | - $this->saturation = round( $saturation * 100 ); |
|
733 | - $this->lightness = round( $lightness * 100 ); |
|
734 | - } |
|
735 | - |
|
736 | - /** |
|
737 | - * Sets the brightness of a color based on the values of red, green, blue. |
|
738 | - * |
|
739 | - * @access protected |
|
740 | - * @since 1.0.0 |
|
741 | - */ |
|
742 | - protected function set_brightness() { |
|
743 | - $this->brightness = array( |
|
744 | - 'red' => round( $this->red * .299 ), |
|
745 | - 'green' => round( $this->green * .587 ), |
|
746 | - 'blue' => round( $this->blue * .114 ), |
|
747 | - 'total' => intval( ( $this->red * .299 ) + ( $this->green * .587 ) + ( $this->blue * .114 ) ), |
|
748 | - ); |
|
749 | - } |
|
750 | - |
|
751 | - /** |
|
752 | - * Sets the luminance of a color (range:0-255) based on the values of red, green, blue. |
|
753 | - * |
|
754 | - * @access protected |
|
755 | - * @since 1.0.0 |
|
756 | - */ |
|
757 | - protected function set_luminance() { |
|
758 | - $lum = ( 0.2126 * $this->red ) + ( 0.7152 * $this->green ) + ( 0.0722 * $this->blue ); |
|
759 | - $this->luminance = round( $lum ); |
|
760 | - } |
|
761 | - |
|
762 | - /** |
|
763 | - * Gets an array of all the wordcolors. |
|
764 | - * |
|
765 | - * @access protected |
|
766 | - * @since 1.0.0 |
|
767 | - * @return array |
|
768 | - */ |
|
769 | - protected function get_word_colors() { |
|
770 | - return array( |
|
771 | - 'aliceblue' => 'F0F8FF', |
|
772 | - 'antiquewhite' => 'FAEBD7', |
|
773 | - 'aqua' => '00FFFF', |
|
774 | - 'aquamarine' => '7FFFD4', |
|
775 | - 'azure' => 'F0FFFF', |
|
776 | - 'beige' => 'F5F5DC', |
|
777 | - 'bisque' => 'FFE4C4', |
|
778 | - 'black' => '000000', |
|
779 | - 'blanchedalmond' => 'FFEBCD', |
|
780 | - 'blue' => '0000FF', |
|
781 | - 'blueviolet' => '8A2BE2', |
|
782 | - 'brown' => 'A52A2A', |
|
783 | - 'burlywood' => 'DEB887', |
|
784 | - 'cadetblue' => '5F9EA0', |
|
785 | - 'chartreuse' => '7FFF00', |
|
786 | - 'chocolate' => 'D2691E', |
|
787 | - 'coral' => 'FF7F50', |
|
788 | - 'cornflowerblue' => '6495ED', |
|
789 | - 'cornsilk' => 'FFF8DC', |
|
790 | - 'crimson' => 'DC143C', |
|
791 | - 'cyan' => '00FFFF', |
|
792 | - 'darkblue' => '00008B', |
|
793 | - 'darkcyan' => '008B8B', |
|
794 | - 'darkgoldenrod' => 'B8860B', |
|
795 | - 'darkgray' => 'A9A9A9', |
|
796 | - 'darkgreen' => '006400', |
|
797 | - 'darkgrey' => 'A9A9A9', |
|
798 | - 'darkkhaki' => 'BDB76B', |
|
799 | - 'darkmagenta' => '8B008B', |
|
800 | - 'darkolivegreen' => '556B2F', |
|
801 | - 'darkorange' => 'FF8C00', |
|
802 | - 'darkorchid' => '9932CC', |
|
803 | - 'darkred' => '8B0000', |
|
804 | - 'darksalmon' => 'E9967A', |
|
805 | - 'darkseagreen' => '8FBC8F', |
|
806 | - 'darkslateblue' => '483D8B', |
|
807 | - 'darkslategray' => '2F4F4F', |
|
808 | - 'darkslategrey' => '2F4F4F', |
|
809 | - 'darkturquoise' => '00CED1', |
|
810 | - 'darkviolet' => '9400D3', |
|
811 | - 'deeppink' => 'FF1493', |
|
812 | - 'deepskyblue' => '00BFFF', |
|
813 | - 'dimgray' => '696969', |
|
814 | - 'dimgrey' => '696969', |
|
815 | - 'dodgerblue' => '1E90FF', |
|
816 | - 'firebrick' => 'B22222', |
|
817 | - 'floralwhite' => 'FFFAF0', |
|
818 | - 'forestgreen' => '228B22', |
|
819 | - 'fuchsia' => 'FF00FF', |
|
820 | - 'gainsboro' => 'DCDCDC', |
|
821 | - 'ghostwhite' => 'F8F8FF', |
|
822 | - 'gold' => 'FFD700', |
|
823 | - 'goldenrod' => 'DAA520', |
|
824 | - 'gray' => '808080', |
|
825 | - 'green' => '008000', |
|
826 | - 'greenyellow' => 'ADFF2F', |
|
827 | - 'grey' => '808080', |
|
828 | - 'honeydew' => 'F0FFF0', |
|
829 | - 'hotpink' => 'FF69B4', |
|
830 | - 'indianred' => 'CD5C5C', |
|
831 | - 'indigo' => '4B0082', |
|
832 | - 'ivory' => 'FFFFF0', |
|
833 | - 'khaki' => 'F0E68C', |
|
834 | - 'lavender' => 'E6E6FA', |
|
835 | - 'lavenderblush' => 'FFF0F5', |
|
836 | - 'lawngreen' => '7CFC00', |
|
837 | - 'lemonchiffon' => 'FFFACD', |
|
838 | - 'lightblue' => 'ADD8E6', |
|
839 | - 'lightcoral' => 'F08080', |
|
840 | - 'lightcyan' => 'E0FFFF', |
|
841 | - 'lightgoldenrodyellow' => 'FAFAD2', |
|
842 | - 'lightgray' => 'D3D3D3', |
|
843 | - 'lightgreen' => '90EE90', |
|
844 | - 'lightgrey' => 'D3D3D3', |
|
845 | - 'lightpink' => 'FFB6C1', |
|
846 | - 'lightsalmon' => 'FFA07A', |
|
847 | - 'lightseagreen' => '20B2AA', |
|
848 | - 'lightskyblue' => '87CEFA', |
|
849 | - 'lightslategray' => '778899', |
|
850 | - 'lightslategrey' => '778899', |
|
851 | - 'lightsteelblue' => 'B0C4DE', |
|
852 | - 'lightyellow' => 'FFFFE0', |
|
853 | - 'lime' => '00FF00', |
|
854 | - 'limegreen' => '32CD32', |
|
855 | - 'linen' => 'FAF0E6', |
|
856 | - 'magenta' => 'FF00FF', |
|
857 | - 'maroon' => '800000', |
|
858 | - 'mediumaquamarine' => '66CDAA', |
|
859 | - 'mediumblue' => '0000CD', |
|
860 | - 'mediumorchid' => 'BA55D3', |
|
861 | - 'mediumpurple' => '9370D0', |
|
862 | - 'mediumseagreen' => '3CB371', |
|
863 | - 'mediumslateblue' => '7B68EE', |
|
864 | - 'mediumspringgreen' => '00FA9A', |
|
865 | - 'mediumturquoise' => '48D1CC', |
|
866 | - 'mediumvioletred' => 'C71585', |
|
867 | - 'midnightblue' => '191970', |
|
868 | - 'mintcream' => 'F5FFFA', |
|
869 | - 'mistyrose' => 'FFE4E1', |
|
870 | - 'moccasin' => 'FFE4B5', |
|
871 | - 'navajowhite' => 'FFDEAD', |
|
872 | - 'navy' => '000080', |
|
873 | - 'oldlace' => 'FDF5E6', |
|
874 | - 'olive' => '808000', |
|
875 | - 'olivedrab' => '6B8E23', |
|
876 | - 'orange' => 'FFA500', |
|
877 | - 'orangered' => 'FF4500', |
|
878 | - 'orchid' => 'DA70D6', |
|
879 | - 'palegoldenrod' => 'EEE8AA', |
|
880 | - 'palegreen' => '98FB98', |
|
881 | - 'paleturquoise' => 'AFEEEE', |
|
882 | - 'palevioletred' => 'DB7093', |
|
883 | - 'papayawhip' => 'FFEFD5', |
|
884 | - 'peachpuff' => 'FFDAB9', |
|
885 | - 'peru' => 'CD853F', |
|
886 | - 'pink' => 'FFC0CB', |
|
887 | - 'plum' => 'DDA0DD', |
|
888 | - 'powderblue' => 'B0E0E6', |
|
889 | - 'purple' => '800080', |
|
890 | - 'red' => 'FF0000', |
|
891 | - 'rosybrown' => 'BC8F8F', |
|
892 | - 'royalblue' => '4169E1', |
|
893 | - 'saddlebrown' => '8B4513', |
|
894 | - 'salmon' => 'FA8072', |
|
895 | - 'sandybrown' => 'F4A460', |
|
896 | - 'seagreen' => '2E8B57', |
|
897 | - 'seashell' => 'FFF5EE', |
|
898 | - 'sienna' => 'A0522D', |
|
899 | - 'silver' => 'C0C0C0', |
|
900 | - 'skyblue' => '87CEEB', |
|
901 | - 'slateblue' => '6A5ACD', |
|
902 | - 'slategray' => '708090', |
|
903 | - 'slategrey' => '708090', |
|
904 | - 'snow' => 'FFFAFA', |
|
905 | - 'springgreen' => '00FF7F', |
|
906 | - 'steelblue' => '4682B4', |
|
907 | - 'tan' => 'D2B48C', |
|
908 | - 'teal' => '008080', |
|
909 | - 'thistle' => 'D8BFD8', |
|
910 | - 'tomato' => 'FF6347', |
|
911 | - 'turquoise' => '40E0D0', |
|
912 | - 'violet' => 'EE82EE', |
|
913 | - 'wheat' => 'F5DEB3', |
|
914 | - 'white' => 'FFFFFF', |
|
915 | - 'whitesmoke' => 'F5F5F5', |
|
916 | - 'yellow' => 'FFFF00', |
|
917 | - 'yellowgreen' => '9ACD32', |
|
918 | - ); |
|
919 | - |
|
920 | - } |
|
921 | - |
|
922 | - /** |
|
923 | - * Use fallback object. |
|
924 | - * |
|
925 | - * @access protected |
|
926 | - * @since 1.2.0 |
|
927 | - */ |
|
928 | - protected function from_fallback() { |
|
929 | - $this->color = $this->fallback; |
|
930 | - |
|
931 | - if ( ! $this->fallback_obj ) { |
|
932 | - $this->fallback_obj = self::newColor( $this->fallback ); |
|
933 | - } |
|
934 | - $this->color = $this->fallback_obj->color; |
|
935 | - $this->mode = $this->fallback_obj->mode; |
|
936 | - $this->red = $this->fallback_obj->red; |
|
937 | - $this->green = $this->fallback_obj->green; |
|
938 | - $this->blue = $this->fallback_obj->blue; |
|
939 | - $this->alpha = $this->fallback_obj->alpha; |
|
940 | - $this->hue = $this->fallback_obj->hue; |
|
941 | - $this->saturation = $this->fallback_obj->saturation; |
|
942 | - $this->lightness = $this->fallback_obj->lightness; |
|
943 | - $this->luminance = $this->fallback_obj->luminance; |
|
944 | - $this->hex = $this->fallback_obj->hex; |
|
945 | - } |
|
946 | - |
|
947 | - /** |
|
948 | - * Handle non-existing public methods. |
|
949 | - * |
|
950 | - * @access public |
|
951 | - * @since 1.1.0 |
|
952 | - * @param string $name The method name. |
|
953 | - * @param mixed $arguments The method arguments. |
|
954 | - * @return mixed |
|
955 | - */ |
|
956 | - public function __call( $name, $arguments ) { |
|
957 | - if ( method_exists( $this, $name ) ) { |
|
958 | - call_user_func( array( $this, $name ), $arguments ); |
|
959 | - } else { |
|
960 | - return $arguments; |
|
961 | - } |
|
962 | - } |
|
963 | - |
|
964 | - /** |
|
965 | - * Handle non-existing public static methods. |
|
966 | - * |
|
967 | - * @static |
|
968 | - * @access public |
|
969 | - * @since 1.1.0 |
|
970 | - * @param string $name The method name. |
|
971 | - * @param mixed $arguments The method arguments. |
|
972 | - * @return mixed |
|
973 | - */ |
|
974 | - public static function __callStatic( $name, $arguments ) { |
|
975 | - if ( method_exists( __CLASS__, $name ) ) { |
|
976 | - call_user_func( array( __CLASS__, $name ), $arguments ); |
|
977 | - } else { |
|
978 | - return $arguments; |
|
979 | - } |
|
980 | - } |
|
981 | - } |
|
10 | + /** |
|
11 | + * The color calculations class. |
|
12 | + */ |
|
13 | + class ariColor { |
|
14 | + |
|
15 | + /** |
|
16 | + * An array of our instances. |
|
17 | + * |
|
18 | + * @static |
|
19 | + * @access public |
|
20 | + * @since 1.0.0 |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + public static $instances = array(); |
|
24 | + |
|
25 | + /** |
|
26 | + * The color initially set. |
|
27 | + * |
|
28 | + * @access public |
|
29 | + * @since 1.0.0 |
|
30 | + * @var mixed |
|
31 | + */ |
|
32 | + public $color; |
|
33 | + |
|
34 | + /** |
|
35 | + * A fallback color in case of failure. |
|
36 | + * |
|
37 | + * @access public |
|
38 | + * @since 1.0.0 |
|
39 | + * @var mixed |
|
40 | + */ |
|
41 | + public $fallback = '#ffffff'; |
|
42 | + |
|
43 | + /** |
|
44 | + * Fallback object from the fallback color. |
|
45 | + * |
|
46 | + * @access public |
|
47 | + * @since 1.0.0 |
|
48 | + * @var object |
|
49 | + */ |
|
50 | + public $fallback_obj; |
|
51 | + |
|
52 | + /** |
|
53 | + * The mode we're using for this color. |
|
54 | + * |
|
55 | + * @access public |
|
56 | + * @since 1.0.0 |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + public $mode = 'hex'; |
|
60 | + |
|
61 | + /** |
|
62 | + * An array containing all word-colors (white/blue/red etc) |
|
63 | + * and their corresponding HEX codes. |
|
64 | + * |
|
65 | + * @access public |
|
66 | + * @since 1.0.0 |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + public $word_colors = array(); |
|
70 | + |
|
71 | + /** |
|
72 | + * The hex code of the color. |
|
73 | + * |
|
74 | + * @access public |
|
75 | + * @since 1.0.0 |
|
76 | + * @var string |
|
77 | + */ |
|
78 | + public $hex; |
|
79 | + |
|
80 | + /** |
|
81 | + * Red value. |
|
82 | + * |
|
83 | + * @access public |
|
84 | + * @since 1.0.0 |
|
85 | + * @var int |
|
86 | + */ |
|
87 | + public $red = 0; |
|
88 | + |
|
89 | + /** |
|
90 | + * Green value. |
|
91 | + * |
|
92 | + * @access public |
|
93 | + * @since 1.0.0 |
|
94 | + * @var int |
|
95 | + */ |
|
96 | + public $green = 0; |
|
97 | + |
|
98 | + /** |
|
99 | + * Blue value. |
|
100 | + * |
|
101 | + * @access public |
|
102 | + * @since 1.0.0 |
|
103 | + * @var int |
|
104 | + */ |
|
105 | + public $blue = 0; |
|
106 | + |
|
107 | + /** |
|
108 | + * Alpha value (min:0, max: 1) |
|
109 | + * |
|
110 | + * @access public |
|
111 | + * @since 1.0.0 |
|
112 | + * @var float |
|
113 | + */ |
|
114 | + public $alpha = 1; |
|
115 | + |
|
116 | + /** |
|
117 | + * Hue value. |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @since 1.0.0 |
|
121 | + * @var float |
|
122 | + */ |
|
123 | + public $hue; |
|
124 | + |
|
125 | + /** |
|
126 | + * Saturation value. |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @since 1.0.0 |
|
130 | + * @var float |
|
131 | + */ |
|
132 | + public $saturation; |
|
133 | + |
|
134 | + /** |
|
135 | + * Lightness value. |
|
136 | + * |
|
137 | + * @access public |
|
138 | + * @since 1.0.0 |
|
139 | + * @var float |
|
140 | + */ |
|
141 | + public $lightness; |
|
142 | + |
|
143 | + /** |
|
144 | + * Chroma value. |
|
145 | + * |
|
146 | + * @access public |
|
147 | + * @since 1.0.0 |
|
148 | + * @var float |
|
149 | + */ |
|
150 | + public $chroma; |
|
151 | + |
|
152 | + /** |
|
153 | + * An array containing brightnesses. |
|
154 | + * |
|
155 | + * @access public |
|
156 | + * @since 1.0.0 |
|
157 | + * @var array |
|
158 | + */ |
|
159 | + public $brightness = array(); |
|
160 | + |
|
161 | + /** |
|
162 | + * Luminance value. |
|
163 | + * |
|
164 | + * @access public |
|
165 | + * @since 1.0.0 |
|
166 | + * @var float |
|
167 | + */ |
|
168 | + public $luminance; |
|
169 | + |
|
170 | + /** |
|
171 | + * The class constructor. |
|
172 | + * |
|
173 | + * @access protected |
|
174 | + * @since 1.0.0 |
|
175 | + * @param string|array $color The color. |
|
176 | + * @param string $mode The color mode. Leave empty to auto-detect. |
|
177 | + */ |
|
178 | + protected function __construct( $color = '', $mode = 'auto' ) { |
|
179 | + $this->color = $color; |
|
180 | + |
|
181 | + if ( is_array( $color ) && isset( $color['fallback'] ) ) { |
|
182 | + $this->fallback = $color['fallback']; |
|
183 | + $this->fallback_obj = self::newColor( $this->fallback ); |
|
184 | + } |
|
185 | + |
|
186 | + if ( ! method_exists( $this, 'from_' . $mode ) ) { |
|
187 | + $mode = $this->get_mode( $color ); |
|
188 | + } |
|
189 | + |
|
190 | + $this->mode = $mode; |
|
191 | + |
|
192 | + if ( ! $mode ) { |
|
193 | + return; |
|
194 | + } |
|
195 | + |
|
196 | + $this->mode = $mode; |
|
197 | + $method = 'from_' . $mode; |
|
198 | + // Call the from_{$color_mode} method. |
|
199 | + $this->$method(); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Gets an instance for this color. |
|
204 | + * We use a separate instance per color |
|
205 | + * because there's no need to create a completely new instance each time we call this class. |
|
206 | + * Instead using instances helps us improve performance & footprint. |
|
207 | + * |
|
208 | + * @static |
|
209 | + * @access public |
|
210 | + * @since 1.0.0 |
|
211 | + * @param string|array $color The color. |
|
212 | + * @param string $mode Mode to be used. |
|
213 | + * @return ariColor (object) |
|
214 | + */ |
|
215 | + public static function newColor( $color, $mode = 'auto' ) { |
|
216 | + |
|
217 | + // Get an md5 for this color. |
|
218 | + $color_md5 = ( is_array( $color ) ) ? md5( wp_json_encode( $color ) . $mode ) : md5( $color . $mode ); |
|
219 | + // Set the instance if it does not already exist. |
|
220 | + if ( ! isset( self::$instances[ $color_md5 ] ) ) { |
|
221 | + self::$instances[ $color_md5 ] = new self( $color, $mode ); |
|
222 | + } |
|
223 | + return self::$instances[ $color_md5 ]; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Alias of the newColor method. |
|
228 | + * |
|
229 | + * @static |
|
230 | + * @access public |
|
231 | + * @since 1.1 |
|
232 | + * @param string|array $color The color. |
|
233 | + * @param string $mode Mode to be used. |
|
234 | + * @return ariColor (object) |
|
235 | + */ |
|
236 | + public static function new_color( $color, $mode = 'auto' ) { |
|
237 | + return self::newColor( $color, $mode ); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Allows us to get a new instance by modifying a property of the existing one. |
|
242 | + * |
|
243 | + * @access public |
|
244 | + * @since 1.0.0 |
|
245 | + * @param string $property Can be one of the following: |
|
246 | + * red, |
|
247 | + * green, |
|
248 | + * blue, |
|
249 | + * alpha, |
|
250 | + * hue, |
|
251 | + * saturation, |
|
252 | + * lightness, |
|
253 | + * brightness. |
|
254 | + * @param int|float|string $value The new value. |
|
255 | + * @return ariColor|null |
|
256 | + */ |
|
257 | + public function getNew( $property = '', $value = '' ) { |
|
258 | + |
|
259 | + if ( in_array( $property, array( 'red', 'green', 'blue', 'alpha' ), true ) ) { |
|
260 | + // Check if we're changing any of the rgba values. |
|
261 | + $value = max( 0, min( 255, $value ) ); |
|
262 | + if ( 'red' === $property ) { |
|
263 | + return self::new_color( 'rgba(' . $value . ',' . $this->green . ',' . $this->blue . ',' . $this->alpha . ')', 'rgba' ); |
|
264 | + } elseif ( 'green' === $property ) { |
|
265 | + return self::new_color( 'rgba(' . $this->red . ',' . $value . ',' . $this->blue . ',' . $this->alpha . ')', 'rgba' ); |
|
266 | + } elseif ( 'blue' === $property ) { |
|
267 | + return self::new_color( 'rgba(' . $this->red . ',' . $this->green . ',' . $value . ',' . $this->alpha . ')', 'rgba' ); |
|
268 | + } elseif ( 'alpha' === $property ) { |
|
269 | + return self::new_color( 'rgba(' . $this->red . ',' . $this->green . ',' . $this->blue . ',' . $value . ')', 'rgba' ); |
|
270 | + } |
|
271 | + } elseif ( in_array( $property, array( 'hue', 'saturation', 'lightness' ), true ) ) { |
|
272 | + // Check if we're changing any of the hsl values. |
|
273 | + $value = ( 'hue' === $property ) ? max( 0, min( 360, $value ) ) : max( 0, min( 100, $value ) ); |
|
274 | + |
|
275 | + if ( 'hue' === $property ) { |
|
276 | + return self::new_color( 'hsla(' . $value . ',' . $this->saturation . '%,' . $this->lightness . '%,' . $this->alpha . ')', 'hsla' ); |
|
277 | + } elseif ( 'saturation' === $property ) { |
|
278 | + return self::new_color( 'hsla(' . $this->hue . ',' . $value . '%,' . $this->lightness . '%,' . $this->alpha . ')', 'hsla' ); |
|
279 | + } elseif ( 'lightness' === $property ) { |
|
280 | + return self::new_color( 'hsla(' . $this->hue . ',' . $this->saturation . '%,' . $value . '%,' . $this->alpha . ')', 'hsla' ); |
|
281 | + } |
|
282 | + } elseif ( 'brightness' === $property ) { |
|
283 | + // Check if we're changing the brightness. |
|
284 | + if ( $value < $this->brightness['total'] ) { |
|
285 | + $red = max( 0, min( 255, $this->red - ( $this->brightness['total'] - $value ) ) ); |
|
286 | + $green = max( 0, min( 255, $this->green - ( $this->brightness['total'] - $value ) ) ); |
|
287 | + $blue = max( 0, min( 255, $this->blue - ( $this->brightness['total'] - $value ) ) ); |
|
288 | + } elseif ( $value > $this->brightness['total'] ) { |
|
289 | + $red = max( 0, min( 255, $this->red + ( $value - $this->brightness['total'] ) ) ); |
|
290 | + $green = max( 0, min( 255, $this->green + ( $value - $this->brightness['total'] ) ) ); |
|
291 | + $blue = max( 0, min( 255, $this->blue + ( $value - $this->brightness['total'] ) ) ); |
|
292 | + } else { |
|
293 | + // If it's not smaller and it's not greater, then it's equal. |
|
294 | + return $this; |
|
295 | + } |
|
296 | + return self::new_color( 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $this->alpha . ')', 'rgba' ); |
|
297 | + } |
|
298 | + return null; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * Allias for the getNew method. |
|
303 | + * |
|
304 | + * @access public |
|
305 | + * @since 1.1.0 |
|
306 | + * @param string $property Can be one of the following: |
|
307 | + * red, |
|
308 | + * green, |
|
309 | + * blue, |
|
310 | + * alpha, |
|
311 | + * hue, |
|
312 | + * saturation, |
|
313 | + * lightness, |
|
314 | + * brightness. |
|
315 | + * @param int|float|string $value The new value. |
|
316 | + * @return ariColor|null |
|
317 | + */ |
|
318 | + public function get_new( $property = '', $value = '' ) { |
|
319 | + return $this->getNew( $property, $value ); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Figure out what mode we're using. |
|
324 | + * |
|
325 | + * @access public |
|
326 | + * @since 1.0.0 |
|
327 | + * @param string|array $color The color we're querying. |
|
328 | + * @return string |
|
329 | + */ |
|
330 | + public function get_mode( $color ) { |
|
331 | + |
|
332 | + // Check if value is an array. |
|
333 | + if ( is_array( $color ) ) { |
|
334 | + // Does the array have an 'rgba' key? |
|
335 | + if ( isset( $color['rgba'] ) ) { |
|
336 | + $this->color = $color['rgba']; |
|
337 | + return 'rgba'; |
|
338 | + } elseif ( isset( $color['color'] ) ) { |
|
339 | + // Does the array have a 'color' key? |
|
340 | + $this->color = $color['color']; |
|
341 | + if ( is_string( $color['color'] ) && false !== strpos( $color['color'], 'rgba' ) ) { |
|
342 | + return 'rgba'; |
|
343 | + } |
|
344 | + return 'hex'; |
|
345 | + } |
|
346 | + // Is this a simple array with 4 items? |
|
347 | + if ( 4 === count( $color ) && isset( $color[0] ) && isset( $color[1] ) && isset( $color[2] ) && isset( $color[3] ) ) { |
|
348 | + $this->color = 'rgba(' . intval( $color[0] ) . ',' . intval( $color[1] ) . ',' . intval( $color[2] ) . ',' . intval( $color[3] ) . ')'; |
|
349 | + return 'rgba'; |
|
350 | + } elseif ( 3 === count( $color ) && isset( $color[0] ) && isset( $color[1] ) && isset( $color[2] ) ) { |
|
351 | + // Is this a simple array with 3 items? |
|
352 | + $this->color = 'rgba(' . intval( $color[0] ) . ',' . intval( $color[1] ) . ',' . intval( $color[2] ) . ',1)'; |
|
353 | + return 'rgba'; |
|
354 | + } |
|
355 | + |
|
356 | + // Check for other keys in the array and get values from there. |
|
357 | + $finders_keepers = array( |
|
358 | + 'r' => 'red', |
|
359 | + 'g' => 'green', |
|
360 | + 'b' => 'blue', |
|
361 | + 'a' => 'alpha', |
|
362 | + 'red' => 'red', |
|
363 | + 'green' => 'green', |
|
364 | + 'blue' => 'blue', |
|
365 | + 'alpha' => 'alpha', |
|
366 | + 'opacity' => 'alpha', |
|
367 | + ); |
|
368 | + $found = false; |
|
369 | + foreach ( $finders_keepers as $finder => $keeper ) { |
|
370 | + if ( isset( $color[ $finder ] ) ) { |
|
371 | + $found = true; |
|
372 | + $this->$keeper = $color[ $finder ]; |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + // We failed, use fallback. |
|
377 | + if ( ! $found ) { |
|
378 | + $this->from_fallback(); |
|
379 | + return $this->mode; |
|
380 | + } |
|
381 | + |
|
382 | + // We did not fail, so use rgba values recovered above. |
|
383 | + $this->color = 'rgba(' . $this->red . ',' . $this->green . ',' . $this->blue . ',' . $this->alpha . ')'; |
|
384 | + return 'rgba'; |
|
385 | + } |
|
386 | + |
|
387 | + // If a string and 3 or 6 characters long, add # since it's a hex. |
|
388 | + if ( 3 === strlen( $this->color ) || 6 === strlen( $this->color ) && false === strpos( $this->color, '#' ) ) { |
|
389 | + $this->color = '#' . $this->color; |
|
390 | + $color = $this->color; |
|
391 | + } |
|
392 | + |
|
393 | + // If we got this far, it's not an array. |
|
394 | + // Check for key identifiers in the value. |
|
395 | + $finders_keepers = array( |
|
396 | + '#' => 'hex', |
|
397 | + 'rgba' => 'rgba', |
|
398 | + 'rgb' => 'rgb', |
|
399 | + 'hsla' => 'hsla', |
|
400 | + 'hsl' => 'hsl', |
|
401 | + ); |
|
402 | + foreach ( $finders_keepers as $finder => $keeper ) { |
|
403 | + if ( false !== strrpos( $color, $finder ) ) { |
|
404 | + |
|
405 | + // Make sure hex colors have 6 digits and not more. |
|
406 | + if ( '#' === $finder && 7 < strlen( $color ) ) { |
|
407 | + $this->color = substr( $color, 0, 7 ); |
|
408 | + } |
|
409 | + |
|
410 | + return $keeper; |
|
411 | + } |
|
412 | + } |
|
413 | + // Perhaps we're using a word like "orange"? |
|
414 | + $wordcolors = $this->get_word_colors(); |
|
415 | + if ( is_string( $color ) && array_key_exists( $color, $wordcolors ) ) { |
|
416 | + $this->color = '#' . $wordcolors[ $color ]; |
|
417 | + return 'hex'; |
|
418 | + } |
|
419 | + // Fallback to hex. |
|
420 | + |
|
421 | + $this->color = $this->fallback; |
|
422 | + return 'hex'; |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * Starts with a HEX color and calculates all other properties. |
|
427 | + * |
|
428 | + * @access protected |
|
429 | + * @since 1.0.0 |
|
430 | + * @return null |
|
431 | + */ |
|
432 | + protected function from_hex() { |
|
433 | + |
|
434 | + if ( ! function_exists( 'sanitize_hex_color' ) ) { |
|
435 | + require_once wp_normalize_path( ABSPATH . WPINC . '/class-wp-customize-manager.php' ); |
|
436 | + } |
|
437 | + // Is this perhaps a word-color? |
|
438 | + $word_colors = $this->get_word_colors(); |
|
439 | + if ( array_key_exists( $this->color, $word_colors ) ) { |
|
440 | + $this->color = '#' . $word_colors[ $this->color ]; |
|
441 | + } |
|
442 | + // Sanitize color. |
|
443 | + $this->hex = sanitize_hex_color( maybe_hash_hex_color( $this->color ) ); |
|
444 | + $hex = ltrim( $this->hex, '#' ); |
|
445 | + |
|
446 | + // Fallback if needed. |
|
447 | + if ( ! $hex || 3 > strlen( $hex ) ) { |
|
448 | + $this->from_fallback(); |
|
449 | + return; |
|
450 | + } |
|
451 | + // Make sure we have 6 digits for the below calculations. |
|
452 | + if ( 3 === strlen( $hex ) ) { |
|
453 | + $hex = ltrim( $this->hex, '#' ); |
|
454 | + $hex = substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) . substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) . substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ); |
|
455 | + } |
|
456 | + |
|
457 | + // Set red, green, blue. |
|
458 | + $this->red = hexdec( substr( $hex, 0, 2 ) ); |
|
459 | + $this->green = hexdec( substr( $hex, 2, 2 ) ); |
|
460 | + $this->blue = hexdec( substr( $hex, 4, 2 ) ); |
|
461 | + $this->alpha = 1; |
|
462 | + // Set other color properties. |
|
463 | + $this->set_brightness(); |
|
464 | + $this->set_hsl(); |
|
465 | + $this->set_luminance(); |
|
466 | + |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * Starts with an RGB color and calculates all other properties. |
|
471 | + * |
|
472 | + * @access protected |
|
473 | + * @since 1.0.0 |
|
474 | + * @return null |
|
475 | + */ |
|
476 | + protected function from_rgb() { |
|
477 | + $value = explode( ',', str_replace( array( ' ', 'rgb', '(', ')' ), '', $this->color ) ); |
|
478 | + // Set red, green, blue. |
|
479 | + $this->red = ( isset( $value[0] ) ) ? intval( $value[0] ) : 255; |
|
480 | + $this->green = ( isset( $value[1] ) ) ? intval( $value[1] ) : 255; |
|
481 | + $this->blue = ( isset( $value[2] ) ) ? intval( $value[2] ) : 255; |
|
482 | + $this->alpha = 1; |
|
483 | + // Set the hex. |
|
484 | + $this->hex = $this->rgb_to_hex( $this->red, $this->green, $this->blue ); |
|
485 | + // Set other color properties. |
|
486 | + $this->set_brightness(); |
|
487 | + $this->set_hsl(); |
|
488 | + $this->set_luminance(); |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Starts with an RGBA color and calculates all other properties. |
|
493 | + * |
|
494 | + * @access protected |
|
495 | + * @since 1.0.0 |
|
496 | + * @return null |
|
497 | + */ |
|
498 | + protected function from_rgba() { |
|
499 | + // Set r, g, b, a properties. |
|
500 | + $value = explode( ',', str_replace( array( ' ', 'rgba', '(', ')' ), '', $this->color ) ); |
|
501 | + $this->red = ( isset( $value[0] ) ) ? intval( $value[0] ) : 255; |
|
502 | + $this->green = ( isset( $value[1] ) ) ? intval( $value[1] ) : 255; |
|
503 | + $this->blue = ( isset( $value[2] ) ) ? intval( $value[2] ) : 255; |
|
504 | + $this->alpha = ( isset( $value[3] ) ) ? filter_var( $value[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : 1; |
|
505 | + // Limit values in the range of 0 - 255. |
|
506 | + $this->red = max( 0, min( 255, $this->red ) ); |
|
507 | + $this->green = max( 0, min( 255, $this->green ) ); |
|
508 | + $this->blue = max( 0, min( 255, $this->blue ) ); |
|
509 | + // Limit values 0 - 1. |
|
510 | + $this->alpha = max( 0, min( 1, $this->alpha ) ); |
|
511 | + // Set hex. |
|
512 | + $this->hex = $this->rgb_to_hex( $this->red, $this->green, $this->blue ); |
|
513 | + // Set other color properties. |
|
514 | + $this->set_brightness(); |
|
515 | + $this->set_hsl(); |
|
516 | + $this->set_luminance(); |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * Starts with an HSL color and calculates all other properties. |
|
521 | + * |
|
522 | + * @access protected |
|
523 | + * @since 1.0.0 |
|
524 | + * @return null |
|
525 | + */ |
|
526 | + protected function from_hsl() { |
|
527 | + $value = explode( ',', str_replace( array( ' ', 'hsl', '(', ')', '%' ), '', $this->color ) ); |
|
528 | + $this->hue = $value[0]; |
|
529 | + $this->saturation = $value[1]; |
|
530 | + $this->lightness = $value[2]; |
|
531 | + $this->from_hsl_array(); |
|
532 | + } |
|
533 | + |
|
534 | + /** |
|
535 | + * Starts with an HSLA color and calculates all other properties. |
|
536 | + * |
|
537 | + * @access protected |
|
538 | + * @since 1.0.0 |
|
539 | + * @return null |
|
540 | + */ |
|
541 | + protected function from_hsla() { |
|
542 | + $value = explode( ',', str_replace( array( ' ', 'hsla', '(', ')', '%' ), '', $this->color ) ); |
|
543 | + $this->hue = $value[0]; |
|
544 | + $this->saturation = $value[1]; |
|
545 | + $this->lightness = $value[2]; |
|
546 | + $this->alpha = $value[3]; |
|
547 | + $this->from_hsl_array(); |
|
548 | + } |
|
549 | + |
|
550 | + /** |
|
551 | + * Generates the HEX value of a color given values for $red, $green, $blue. |
|
552 | + * |
|
553 | + * @access protected |
|
554 | + * @since 1.0.0 |
|
555 | + * @param int|string $red The red value of this color. |
|
556 | + * @param int|string $green The green value of this color. |
|
557 | + * @param int|string $blue The blue value of this color. |
|
558 | + * @return string |
|
559 | + */ |
|
560 | + protected function rgb_to_hex( $red, $green, $blue ) { |
|
561 | + // Get hex values properly formatted. |
|
562 | + $hex_red = $this->dexhex_double_digit( $red ); |
|
563 | + $hex_green = $this->dexhex_double_digit( $green ); |
|
564 | + $hex_blue = $this->dexhex_double_digit( $blue ); |
|
565 | + return '#' . $hex_red . $hex_green . $hex_blue; |
|
566 | + } |
|
567 | + |
|
568 | + /** |
|
569 | + * Convert a decimal value to hex and make sure it's 2 characters. |
|
570 | + * |
|
571 | + * @access protected |
|
572 | + * @since 1.0.0 |
|
573 | + * @param int|string $value The value to convert. |
|
574 | + * @return string |
|
575 | + */ |
|
576 | + protected function dexhex_double_digit( $value ) { |
|
577 | + $value = dechex( $value ); |
|
578 | + if ( 1 === strlen( $value ) ) { |
|
579 | + $value = '0' . $value; |
|
580 | + } |
|
581 | + return $value; |
|
582 | + } |
|
583 | + |
|
584 | + /** |
|
585 | + * Calculates the red, green, blue values of an HSL color. |
|
586 | + * |
|
587 | + * @access protected |
|
588 | + * @since 1.0.0 |
|
589 | + * @see https://gist.github.com/brandonheyer/5254516 |
|
590 | + */ |
|
591 | + protected function from_hsl_array() { |
|
592 | + $h = $this->hue / 360; |
|
593 | + $s = $this->saturation / 100; |
|
594 | + $l = $this->lightness / 100; |
|
595 | + |
|
596 | + $r = $l; |
|
597 | + $g = $l; |
|
598 | + $b = $l; |
|
599 | + $v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s ); |
|
600 | + if ( $v > 0 ) { |
|
601 | + $m = $l + $l - $v; |
|
602 | + $sv = ( $v - $m ) / $v; |
|
603 | + $h *= 6.0; |
|
604 | + $sextant = floor( $h ); |
|
605 | + $fract = $h - $sextant; |
|
606 | + $vsf = $v * $sv * $fract; |
|
607 | + $mid1 = $m + $vsf; |
|
608 | + $mid2 = $v - $vsf; |
|
609 | + switch ( $sextant ) { |
|
610 | + case 0: |
|
611 | + $r = $v; |
|
612 | + $g = $mid1; |
|
613 | + $b = $m; |
|
614 | + break; |
|
615 | + case 1: |
|
616 | + $r = $mid2; |
|
617 | + $g = $v; |
|
618 | + $b = $m; |
|
619 | + break; |
|
620 | + case 2: |
|
621 | + $r = $m; |
|
622 | + $g = $v; |
|
623 | + $b = $mid1; |
|
624 | + break; |
|
625 | + case 3: |
|
626 | + $r = $m; |
|
627 | + $g = $mid2; |
|
628 | + $b = $v; |
|
629 | + break; |
|
630 | + case 4: |
|
631 | + $r = $mid1; |
|
632 | + $g = $m; |
|
633 | + $b = $v; |
|
634 | + break; |
|
635 | + case 5: |
|
636 | + $r = $v; |
|
637 | + $g = $m; |
|
638 | + $b = $mid2; |
|
639 | + break; |
|
640 | + } |
|
641 | + } |
|
642 | + $this->red = round( $r * 255, 0 ); |
|
643 | + $this->green = round( $g * 255, 0 ); |
|
644 | + $this->blue = round( $b * 255, 0 ); |
|
645 | + |
|
646 | + $this->hex = $this->rgb_to_hex( $this->red, $this->green, $this->blue ); |
|
647 | + $this->set_luminance(); |
|
648 | + } |
|
649 | + |
|
650 | + /** |
|
651 | + * Returns a CSS-formatted value for colors. |
|
652 | + * |
|
653 | + * @access public |
|
654 | + * @since 1.0.0 |
|
655 | + * @param string $mode The mode we're using. |
|
656 | + * @return string |
|
657 | + */ |
|
658 | + public function toCSS( $mode = 'hex' ) { |
|
659 | + |
|
660 | + $value = ''; |
|
661 | + |
|
662 | + switch ( $mode ) { |
|
663 | + case 'hex': |
|
664 | + $value = strtolower( $this->hex ); |
|
665 | + break; |
|
666 | + case 'rgba': |
|
667 | + $value = 'rgba(' . $this->red . ',' . $this->green . ',' . $this->blue . ',' . $this->alpha . ')'; |
|
668 | + break; |
|
669 | + case 'rgb': |
|
670 | + $value = 'rgb(' . $this->red . ',' . $this->green . ',' . $this->blue . ')'; |
|
671 | + break; |
|
672 | + case 'hsl': |
|
673 | + $value = 'hsl(' . $this->hue . ',' . round( $this->saturation ) . '%,' . round( $this->lightness ) . '%)'; |
|
674 | + break; |
|
675 | + case 'hsla': |
|
676 | + $value = 'hsla(' . $this->hue . ',' . round( $this->saturation ) . '%,' . round( $this->lightness ) . '%,' . $this->alpha . ')'; |
|
677 | + break; |
|
678 | + } |
|
679 | + return $value; |
|
680 | + } |
|
681 | + |
|
682 | + /** |
|
683 | + * Alias for the toCSS method. |
|
684 | + * |
|
685 | + * @access public |
|
686 | + * @since 1.1 |
|
687 | + * @param string $mode The mode we're using. |
|
688 | + * @return string |
|
689 | + */ |
|
690 | + public function to_css( $mode = 'hex' ) { |
|
691 | + return $this->toCSS( $mode ); |
|
692 | + } |
|
693 | + |
|
694 | + /** |
|
695 | + * Sets the HSL values of a color based on the values of red, green, blue. |
|
696 | + * |
|
697 | + * @access public |
|
698 | + * @since 1.0.0 |
|
699 | + */ |
|
700 | + protected function set_hsl() { |
|
701 | + $red = $this->red / 255; |
|
702 | + $green = $this->green / 255; |
|
703 | + $blue = $this->blue / 255; |
|
704 | + |
|
705 | + $max = max( $red, $green, $blue ); |
|
706 | + $min = min( $red, $green, $blue ); |
|
707 | + |
|
708 | + $lightness = ( $max + $min ) / 2; |
|
709 | + $difference = $max - $min; |
|
710 | + |
|
711 | + if ( ! $difference ) { |
|
712 | + $hue = $saturation = 0; // Achromatic. |
|
713 | + } else { |
|
714 | + $saturation = $difference / ( 1 - abs( 2 * $lightness - 1 ) ); |
|
715 | + switch ( $max ) { |
|
716 | + case $red: |
|
717 | + $hue = 60 * fmod( ( ( $green - $blue ) / $difference ), 6 ); |
|
718 | + if ( $blue > $green ) { |
|
719 | + $hue += 360; |
|
720 | + } |
|
721 | + break; |
|
722 | + case $green: |
|
723 | + $hue = 60 * ( ( $blue - $red ) / $difference + 2 ); |
|
724 | + break; |
|
725 | + case $blue: |
|
726 | + $hue = 60 * ( ( $red - $green ) / $difference + 4 ); |
|
727 | + break; |
|
728 | + } |
|
729 | + } |
|
730 | + |
|
731 | + $this->hue = round( $hue ); |
|
732 | + $this->saturation = round( $saturation * 100 ); |
|
733 | + $this->lightness = round( $lightness * 100 ); |
|
734 | + } |
|
735 | + |
|
736 | + /** |
|
737 | + * Sets the brightness of a color based on the values of red, green, blue. |
|
738 | + * |
|
739 | + * @access protected |
|
740 | + * @since 1.0.0 |
|
741 | + */ |
|
742 | + protected function set_brightness() { |
|
743 | + $this->brightness = array( |
|
744 | + 'red' => round( $this->red * .299 ), |
|
745 | + 'green' => round( $this->green * .587 ), |
|
746 | + 'blue' => round( $this->blue * .114 ), |
|
747 | + 'total' => intval( ( $this->red * .299 ) + ( $this->green * .587 ) + ( $this->blue * .114 ) ), |
|
748 | + ); |
|
749 | + } |
|
750 | + |
|
751 | + /** |
|
752 | + * Sets the luminance of a color (range:0-255) based on the values of red, green, blue. |
|
753 | + * |
|
754 | + * @access protected |
|
755 | + * @since 1.0.0 |
|
756 | + */ |
|
757 | + protected function set_luminance() { |
|
758 | + $lum = ( 0.2126 * $this->red ) + ( 0.7152 * $this->green ) + ( 0.0722 * $this->blue ); |
|
759 | + $this->luminance = round( $lum ); |
|
760 | + } |
|
761 | + |
|
762 | + /** |
|
763 | + * Gets an array of all the wordcolors. |
|
764 | + * |
|
765 | + * @access protected |
|
766 | + * @since 1.0.0 |
|
767 | + * @return array |
|
768 | + */ |
|
769 | + protected function get_word_colors() { |
|
770 | + return array( |
|
771 | + 'aliceblue' => 'F0F8FF', |
|
772 | + 'antiquewhite' => 'FAEBD7', |
|
773 | + 'aqua' => '00FFFF', |
|
774 | + 'aquamarine' => '7FFFD4', |
|
775 | + 'azure' => 'F0FFFF', |
|
776 | + 'beige' => 'F5F5DC', |
|
777 | + 'bisque' => 'FFE4C4', |
|
778 | + 'black' => '000000', |
|
779 | + 'blanchedalmond' => 'FFEBCD', |
|
780 | + 'blue' => '0000FF', |
|
781 | + 'blueviolet' => '8A2BE2', |
|
782 | + 'brown' => 'A52A2A', |
|
783 | + 'burlywood' => 'DEB887', |
|
784 | + 'cadetblue' => '5F9EA0', |
|
785 | + 'chartreuse' => '7FFF00', |
|
786 | + 'chocolate' => 'D2691E', |
|
787 | + 'coral' => 'FF7F50', |
|
788 | + 'cornflowerblue' => '6495ED', |
|
789 | + 'cornsilk' => 'FFF8DC', |
|
790 | + 'crimson' => 'DC143C', |
|
791 | + 'cyan' => '00FFFF', |
|
792 | + 'darkblue' => '00008B', |
|
793 | + 'darkcyan' => '008B8B', |
|
794 | + 'darkgoldenrod' => 'B8860B', |
|
795 | + 'darkgray' => 'A9A9A9', |
|
796 | + 'darkgreen' => '006400', |
|
797 | + 'darkgrey' => 'A9A9A9', |
|
798 | + 'darkkhaki' => 'BDB76B', |
|
799 | + 'darkmagenta' => '8B008B', |
|
800 | + 'darkolivegreen' => '556B2F', |
|
801 | + 'darkorange' => 'FF8C00', |
|
802 | + 'darkorchid' => '9932CC', |
|
803 | + 'darkred' => '8B0000', |
|
804 | + 'darksalmon' => 'E9967A', |
|
805 | + 'darkseagreen' => '8FBC8F', |
|
806 | + 'darkslateblue' => '483D8B', |
|
807 | + 'darkslategray' => '2F4F4F', |
|
808 | + 'darkslategrey' => '2F4F4F', |
|
809 | + 'darkturquoise' => '00CED1', |
|
810 | + 'darkviolet' => '9400D3', |
|
811 | + 'deeppink' => 'FF1493', |
|
812 | + 'deepskyblue' => '00BFFF', |
|
813 | + 'dimgray' => '696969', |
|
814 | + 'dimgrey' => '696969', |
|
815 | + 'dodgerblue' => '1E90FF', |
|
816 | + 'firebrick' => 'B22222', |
|
817 | + 'floralwhite' => 'FFFAF0', |
|
818 | + 'forestgreen' => '228B22', |
|
819 | + 'fuchsia' => 'FF00FF', |
|
820 | + 'gainsboro' => 'DCDCDC', |
|
821 | + 'ghostwhite' => 'F8F8FF', |
|
822 | + 'gold' => 'FFD700', |
|
823 | + 'goldenrod' => 'DAA520', |
|
824 | + 'gray' => '808080', |
|
825 | + 'green' => '008000', |
|
826 | + 'greenyellow' => 'ADFF2F', |
|
827 | + 'grey' => '808080', |
|
828 | + 'honeydew' => 'F0FFF0', |
|
829 | + 'hotpink' => 'FF69B4', |
|
830 | + 'indianred' => 'CD5C5C', |
|
831 | + 'indigo' => '4B0082', |
|
832 | + 'ivory' => 'FFFFF0', |
|
833 | + 'khaki' => 'F0E68C', |
|
834 | + 'lavender' => 'E6E6FA', |
|
835 | + 'lavenderblush' => 'FFF0F5', |
|
836 | + 'lawngreen' => '7CFC00', |
|
837 | + 'lemonchiffon' => 'FFFACD', |
|
838 | + 'lightblue' => 'ADD8E6', |
|
839 | + 'lightcoral' => 'F08080', |
|
840 | + 'lightcyan' => 'E0FFFF', |
|
841 | + 'lightgoldenrodyellow' => 'FAFAD2', |
|
842 | + 'lightgray' => 'D3D3D3', |
|
843 | + 'lightgreen' => '90EE90', |
|
844 | + 'lightgrey' => 'D3D3D3', |
|
845 | + 'lightpink' => 'FFB6C1', |
|
846 | + 'lightsalmon' => 'FFA07A', |
|
847 | + 'lightseagreen' => '20B2AA', |
|
848 | + 'lightskyblue' => '87CEFA', |
|
849 | + 'lightslategray' => '778899', |
|
850 | + 'lightslategrey' => '778899', |
|
851 | + 'lightsteelblue' => 'B0C4DE', |
|
852 | + 'lightyellow' => 'FFFFE0', |
|
853 | + 'lime' => '00FF00', |
|
854 | + 'limegreen' => '32CD32', |
|
855 | + 'linen' => 'FAF0E6', |
|
856 | + 'magenta' => 'FF00FF', |
|
857 | + 'maroon' => '800000', |
|
858 | + 'mediumaquamarine' => '66CDAA', |
|
859 | + 'mediumblue' => '0000CD', |
|
860 | + 'mediumorchid' => 'BA55D3', |
|
861 | + 'mediumpurple' => '9370D0', |
|
862 | + 'mediumseagreen' => '3CB371', |
|
863 | + 'mediumslateblue' => '7B68EE', |
|
864 | + 'mediumspringgreen' => '00FA9A', |
|
865 | + 'mediumturquoise' => '48D1CC', |
|
866 | + 'mediumvioletred' => 'C71585', |
|
867 | + 'midnightblue' => '191970', |
|
868 | + 'mintcream' => 'F5FFFA', |
|
869 | + 'mistyrose' => 'FFE4E1', |
|
870 | + 'moccasin' => 'FFE4B5', |
|
871 | + 'navajowhite' => 'FFDEAD', |
|
872 | + 'navy' => '000080', |
|
873 | + 'oldlace' => 'FDF5E6', |
|
874 | + 'olive' => '808000', |
|
875 | + 'olivedrab' => '6B8E23', |
|
876 | + 'orange' => 'FFA500', |
|
877 | + 'orangered' => 'FF4500', |
|
878 | + 'orchid' => 'DA70D6', |
|
879 | + 'palegoldenrod' => 'EEE8AA', |
|
880 | + 'palegreen' => '98FB98', |
|
881 | + 'paleturquoise' => 'AFEEEE', |
|
882 | + 'palevioletred' => 'DB7093', |
|
883 | + 'papayawhip' => 'FFEFD5', |
|
884 | + 'peachpuff' => 'FFDAB9', |
|
885 | + 'peru' => 'CD853F', |
|
886 | + 'pink' => 'FFC0CB', |
|
887 | + 'plum' => 'DDA0DD', |
|
888 | + 'powderblue' => 'B0E0E6', |
|
889 | + 'purple' => '800080', |
|
890 | + 'red' => 'FF0000', |
|
891 | + 'rosybrown' => 'BC8F8F', |
|
892 | + 'royalblue' => '4169E1', |
|
893 | + 'saddlebrown' => '8B4513', |
|
894 | + 'salmon' => 'FA8072', |
|
895 | + 'sandybrown' => 'F4A460', |
|
896 | + 'seagreen' => '2E8B57', |
|
897 | + 'seashell' => 'FFF5EE', |
|
898 | + 'sienna' => 'A0522D', |
|
899 | + 'silver' => 'C0C0C0', |
|
900 | + 'skyblue' => '87CEEB', |
|
901 | + 'slateblue' => '6A5ACD', |
|
902 | + 'slategray' => '708090', |
|
903 | + 'slategrey' => '708090', |
|
904 | + 'snow' => 'FFFAFA', |
|
905 | + 'springgreen' => '00FF7F', |
|
906 | + 'steelblue' => '4682B4', |
|
907 | + 'tan' => 'D2B48C', |
|
908 | + 'teal' => '008080', |
|
909 | + 'thistle' => 'D8BFD8', |
|
910 | + 'tomato' => 'FF6347', |
|
911 | + 'turquoise' => '40E0D0', |
|
912 | + 'violet' => 'EE82EE', |
|
913 | + 'wheat' => 'F5DEB3', |
|
914 | + 'white' => 'FFFFFF', |
|
915 | + 'whitesmoke' => 'F5F5F5', |
|
916 | + 'yellow' => 'FFFF00', |
|
917 | + 'yellowgreen' => '9ACD32', |
|
918 | + ); |
|
919 | + |
|
920 | + } |
|
921 | + |
|
922 | + /** |
|
923 | + * Use fallback object. |
|
924 | + * |
|
925 | + * @access protected |
|
926 | + * @since 1.2.0 |
|
927 | + */ |
|
928 | + protected function from_fallback() { |
|
929 | + $this->color = $this->fallback; |
|
930 | + |
|
931 | + if ( ! $this->fallback_obj ) { |
|
932 | + $this->fallback_obj = self::newColor( $this->fallback ); |
|
933 | + } |
|
934 | + $this->color = $this->fallback_obj->color; |
|
935 | + $this->mode = $this->fallback_obj->mode; |
|
936 | + $this->red = $this->fallback_obj->red; |
|
937 | + $this->green = $this->fallback_obj->green; |
|
938 | + $this->blue = $this->fallback_obj->blue; |
|
939 | + $this->alpha = $this->fallback_obj->alpha; |
|
940 | + $this->hue = $this->fallback_obj->hue; |
|
941 | + $this->saturation = $this->fallback_obj->saturation; |
|
942 | + $this->lightness = $this->fallback_obj->lightness; |
|
943 | + $this->luminance = $this->fallback_obj->luminance; |
|
944 | + $this->hex = $this->fallback_obj->hex; |
|
945 | + } |
|
946 | + |
|
947 | + /** |
|
948 | + * Handle non-existing public methods. |
|
949 | + * |
|
950 | + * @access public |
|
951 | + * @since 1.1.0 |
|
952 | + * @param string $name The method name. |
|
953 | + * @param mixed $arguments The method arguments. |
|
954 | + * @return mixed |
|
955 | + */ |
|
956 | + public function __call( $name, $arguments ) { |
|
957 | + if ( method_exists( $this, $name ) ) { |
|
958 | + call_user_func( array( $this, $name ), $arguments ); |
|
959 | + } else { |
|
960 | + return $arguments; |
|
961 | + } |
|
962 | + } |
|
963 | + |
|
964 | + /** |
|
965 | + * Handle non-existing public static methods. |
|
966 | + * |
|
967 | + * @static |
|
968 | + * @access public |
|
969 | + * @since 1.1.0 |
|
970 | + * @param string $name The method name. |
|
971 | + * @param mixed $arguments The method arguments. |
|
972 | + * @return mixed |
|
973 | + */ |
|
974 | + public static function __callStatic( $name, $arguments ) { |
|
975 | + if ( method_exists( __CLASS__, $name ) ) { |
|
976 | + call_user_func( array( __CLASS__, $name ), $arguments ); |
|
977 | + } else { |
|
978 | + return $arguments; |
|
979 | + } |
|
980 | + } |
|
981 | + } |
|
982 | 982 | } |
@@ -18,37 +18,37 @@ |
||
18 | 18 | */ |
19 | 19 | class Image extends Output { |
20 | 20 | |
21 | - /** |
|
22 | - * Processes a single item from the `output` array. |
|
23 | - * |
|
24 | - * @access protected |
|
25 | - * @param array $output The `output` item. |
|
26 | - * @param array $value The field's value. |
|
27 | - */ |
|
28 | - protected function process_output( $output, $value ) { |
|
29 | - if ( ! isset( $output['element'] ) || ! isset( $output['property'] ) ) { |
|
30 | - return; |
|
31 | - } |
|
32 | - $output = wp_parse_args( |
|
33 | - $output, |
|
34 | - [ |
|
35 | - 'media_query' => 'global', |
|
36 | - 'prefix' => '', |
|
37 | - 'units' => '', |
|
38 | - 'suffix' => '', |
|
39 | - ] |
|
40 | - ); |
|
41 | - if ( is_array( $value ) ) { |
|
42 | - if ( isset( $output['choice'] ) && $output['choice'] ) { |
|
43 | - $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value[ $output['choice'] ] ) . $output['units'] . $output['suffix']; |
|
44 | - return; |
|
45 | - } |
|
46 | - if ( isset( $value['url'] ) ) { |
|
47 | - $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value['url'] ) . $output['units'] . $output['suffix']; |
|
48 | - return; |
|
49 | - } |
|
50 | - return; |
|
51 | - } |
|
52 | - $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value ) . $output['units'] . $output['suffix']; |
|
53 | - } |
|
21 | + /** |
|
22 | + * Processes a single item from the `output` array. |
|
23 | + * |
|
24 | + * @access protected |
|
25 | + * @param array $output The `output` item. |
|
26 | + * @param array $value The field's value. |
|
27 | + */ |
|
28 | + protected function process_output( $output, $value ) { |
|
29 | + if ( ! isset( $output['element'] ) || ! isset( $output['property'] ) ) { |
|
30 | + return; |
|
31 | + } |
|
32 | + $output = wp_parse_args( |
|
33 | + $output, |
|
34 | + [ |
|
35 | + 'media_query' => 'global', |
|
36 | + 'prefix' => '', |
|
37 | + 'units' => '', |
|
38 | + 'suffix' => '', |
|
39 | + ] |
|
40 | + ); |
|
41 | + if ( is_array( $value ) ) { |
|
42 | + if ( isset( $output['choice'] ) && $output['choice'] ) { |
|
43 | + $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value[ $output['choice'] ] ) . $output['units'] . $output['suffix']; |
|
44 | + return; |
|
45 | + } |
|
46 | + if ( isset( $value['url'] ) ) { |
|
47 | + $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value['url'] ) . $output['units'] . $output['suffix']; |
|
48 | + return; |
|
49 | + } |
|
50 | + return; |
|
51 | + } |
|
52 | + $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value ) . $output['units'] . $output['suffix']; |
|
53 | + } |
|
54 | 54 | } |
@@ -17,150 +17,150 @@ |
||
17 | 17 | */ |
18 | 18 | class Image 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-image'; |
|
20 | + /** |
|
21 | + * The field type. |
|
22 | + * |
|
23 | + * @access public |
|
24 | + * @since 1.0 |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + public $type = 'kirki-image'; |
|
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\Image'; |
|
29 | + /** |
|
30 | + * The control class-name. |
|
31 | + * |
|
32 | + * @access protected |
|
33 | + * @since 0.1 |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $control_class = '\Kirki\Control\Image'; |
|
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 | - * Additional logic for this field. |
|
49 | - * |
|
50 | - * @access protected |
|
51 | - * @since 0.1 |
|
52 | - * @param array $args The field arguments. |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - protected function init( $args ) { |
|
56 | - add_filter( 'kirki_output_item_args', [ $this, 'output_item_args' ], 10, 4 ); |
|
57 | - add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] ); |
|
58 | - } |
|
47 | + /** |
|
48 | + * Additional logic for this field. |
|
49 | + * |
|
50 | + * @access protected |
|
51 | + * @since 0.1 |
|
52 | + * @param array $args The field arguments. |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + protected function init( $args ) { |
|
56 | + add_filter( 'kirki_output_item_args', [ $this, 'output_item_args' ], 10, 4 ); |
|
57 | + add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Filter arguments before creating the setting. |
|
62 | - * |
|
63 | - * @access public |
|
64 | - * @since 0.1 |
|
65 | - * @param array $args The field arguments. |
|
66 | - * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - public function filter_setting_args( $args, $wp_customize ) { |
|
70 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
71 | - $args = parent::filter_setting_args( $args, $wp_customize ); |
|
60 | + /** |
|
61 | + * Filter arguments before creating the setting. |
|
62 | + * |
|
63 | + * @access public |
|
64 | + * @since 0.1 |
|
65 | + * @param array $args The field arguments. |
|
66 | + * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + public function filter_setting_args( $args, $wp_customize ) { |
|
70 | + if ( $args['settings'] === $this->args['settings'] ) { |
|
71 | + $args = parent::filter_setting_args( $args, $wp_customize ); |
|
72 | 72 | |
73 | - // Set the sanitize-callback if none is defined. |
|
74 | - if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
75 | - $args['sanitize_callback'] = function( $value ) { |
|
76 | - if ( isset( $this->args['choices']['save_as'] ) && 'array' === $this->args['choices']['save_as'] ) { |
|
77 | - return [ |
|
78 | - 'id' => ( isset( $value['id'] ) && '' !== $value['id'] ) ? (int) $value['id'] : '', |
|
79 | - 'url' => ( isset( $value['url'] ) && '' !== $value['url'] ) ? esc_url_raw( $value['url'] ) : '', |
|
80 | - 'width' => ( isset( $value['width'] ) && '' !== $value['width'] ) ? (int) $value['width'] : '', |
|
81 | - 'height' => ( isset( $value['height'] ) && '' !== $value['height'] ) ? (int) $value['height'] : '', |
|
82 | - ]; |
|
83 | - } |
|
84 | - if ( isset( $this->args['choices']['save_as'] ) && 'id' === $this->args['choices']['save_as'] ) { |
|
85 | - return absint( $value ); |
|
86 | - } |
|
87 | - return ( is_string( $value ) ) ? esc_url_raw( $value ) : $value; |
|
88 | - }; |
|
89 | - } |
|
90 | - } |
|
91 | - return $args; |
|
92 | - } |
|
73 | + // Set the sanitize-callback if none is defined. |
|
74 | + if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
75 | + $args['sanitize_callback'] = function( $value ) { |
|
76 | + if ( isset( $this->args['choices']['save_as'] ) && 'array' === $this->args['choices']['save_as'] ) { |
|
77 | + return [ |
|
78 | + 'id' => ( isset( $value['id'] ) && '' !== $value['id'] ) ? (int) $value['id'] : '', |
|
79 | + 'url' => ( isset( $value['url'] ) && '' !== $value['url'] ) ? esc_url_raw( $value['url'] ) : '', |
|
80 | + 'width' => ( isset( $value['width'] ) && '' !== $value['width'] ) ? (int) $value['width'] : '', |
|
81 | + 'height' => ( isset( $value['height'] ) && '' !== $value['height'] ) ? (int) $value['height'] : '', |
|
82 | + ]; |
|
83 | + } |
|
84 | + if ( isset( $this->args['choices']['save_as'] ) && 'id' === $this->args['choices']['save_as'] ) { |
|
85 | + return absint( $value ); |
|
86 | + } |
|
87 | + return ( is_string( $value ) ) ? esc_url_raw( $value ) : $value; |
|
88 | + }; |
|
89 | + } |
|
90 | + } |
|
91 | + return $args; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Filter arguments before creating the control. |
|
96 | - * |
|
97 | - * @access public |
|
98 | - * @since 0.1 |
|
99 | - * @param array $args The field arguments. |
|
100 | - * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public function filter_control_args( $args, $wp_customize ) { |
|
104 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
105 | - $args = parent::filter_control_args( $args, $wp_customize ); |
|
94 | + /** |
|
95 | + * Filter arguments before creating the control. |
|
96 | + * |
|
97 | + * @access public |
|
98 | + * @since 0.1 |
|
99 | + * @param array $args The field arguments. |
|
100 | + * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public function filter_control_args( $args, $wp_customize ) { |
|
104 | + if ( $args['settings'] === $this->args['settings'] ) { |
|
105 | + $args = parent::filter_control_args( $args, $wp_customize ); |
|
106 | 106 | |
107 | - $args['button_labels'] = isset( $args['button_labels'] ) ? $args['button_labels'] : []; |
|
108 | - $args['button_labels'] = wp_parse_args( |
|
109 | - $args['button_labels'], |
|
110 | - [ |
|
111 | - 'select' => esc_html__( 'Select image', 'kirki' ), |
|
112 | - 'change' => esc_html__( 'Change image', 'kirki' ), |
|
113 | - 'default' => esc_html__( 'Default', 'kirki' ), |
|
114 | - 'remove' => esc_html__( 'Remove', 'kirki' ), |
|
115 | - 'placeholder' => esc_html__( 'No image selected', 'kirki' ), |
|
116 | - 'frame_title' => esc_html__( 'Select image', 'kirki' ), |
|
117 | - 'frame_button' => esc_html__( 'Choose image', 'kirki' ), |
|
118 | - ] |
|
119 | - ); |
|
107 | + $args['button_labels'] = isset( $args['button_labels'] ) ? $args['button_labels'] : []; |
|
108 | + $args['button_labels'] = wp_parse_args( |
|
109 | + $args['button_labels'], |
|
110 | + [ |
|
111 | + 'select' => esc_html__( 'Select image', 'kirki' ), |
|
112 | + 'change' => esc_html__( 'Change image', 'kirki' ), |
|
113 | + 'default' => esc_html__( 'Default', 'kirki' ), |
|
114 | + 'remove' => esc_html__( 'Remove', 'kirki' ), |
|
115 | + 'placeholder' => esc_html__( 'No image selected', 'kirki' ), |
|
116 | + 'frame_title' => esc_html__( 'Select image', 'kirki' ), |
|
117 | + 'frame_button' => esc_html__( 'Choose image', 'kirki' ), |
|
118 | + ] |
|
119 | + ); |
|
120 | 120 | |
121 | - $args['choices'] = isset( $args['choices'] ) ? (array) $args['choices'] : []; |
|
122 | - $args['choices']['save_as'] = isset( $args['choices']['save_as'] ) ? $args['choices']['save_as'] : 'url'; |
|
123 | - $args['choices']['labels'] = isset( $args['choices']['labels'] ) ? $args['choices']['labels'] : []; |
|
124 | - $args['choices']['labels'] = wp_parse_args( $args['choices']['labels'], $args['button_labels'] ); |
|
121 | + $args['choices'] = isset( $args['choices'] ) ? (array) $args['choices'] : []; |
|
122 | + $args['choices']['save_as'] = isset( $args['choices']['save_as'] ) ? $args['choices']['save_as'] : 'url'; |
|
123 | + $args['choices']['labels'] = isset( $args['choices']['labels'] ) ? $args['choices']['labels'] : []; |
|
124 | + $args['choices']['labels'] = wp_parse_args( $args['choices']['labels'], $args['button_labels'] ); |
|
125 | 125 | |
126 | - // Set the control-type. |
|
127 | - $args['type'] = 'kirki-image'; |
|
128 | - } |
|
129 | - return $args; |
|
130 | - } |
|
126 | + // Set the control-type. |
|
127 | + $args['type'] = 'kirki-image'; |
|
128 | + } |
|
129 | + return $args; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Filter for output argument used by the kirki-framework/module-css module. |
|
134 | - * |
|
135 | - * @access public |
|
136 | - * @since 1.0 |
|
137 | - * @param array $output A single output item. |
|
138 | - * @param mixed $value The value. |
|
139 | - * @param array $all_outputs All field output args. |
|
140 | - * @param array $field The field arguments. |
|
141 | - * @return array |
|
142 | - */ |
|
143 | - public function output_item_args( $output, $value, $all_outputs, $field ) { |
|
144 | - if ( $field['settings'] === $this->args['settings'] ) { |
|
145 | - if ( isset( $output['property'] ) && in_array( [ 'background', 'background-image' ], $output['property'], true ) ) { |
|
146 | - if ( ! isset( $output['value_pattern'] ) || empty( $output['value_pattern'] ) || '$' === $output['value_pattern'] ) { |
|
147 | - $output['value_pattern'] = 'url("$")'; |
|
148 | - } |
|
149 | - } |
|
150 | - } |
|
151 | - return $output; |
|
152 | - } |
|
132 | + /** |
|
133 | + * Filter for output argument used by the kirki-framework/module-css module. |
|
134 | + * |
|
135 | + * @access public |
|
136 | + * @since 1.0 |
|
137 | + * @param array $output A single output item. |
|
138 | + * @param mixed $value The value. |
|
139 | + * @param array $all_outputs All field output args. |
|
140 | + * @param array $field The field arguments. |
|
141 | + * @return array |
|
142 | + */ |
|
143 | + public function output_item_args( $output, $value, $all_outputs, $field ) { |
|
144 | + if ( $field['settings'] === $this->args['settings'] ) { |
|
145 | + if ( isset( $output['property'] ) && in_array( [ 'background', 'background-image' ], $output['property'], true ) ) { |
|
146 | + if ( ! isset( $output['value_pattern'] ) || empty( $output['value_pattern'] ) || '$' === $output['value_pattern'] ) { |
|
147 | + $output['value_pattern'] = 'url("$")'; |
|
148 | + } |
|
149 | + } |
|
150 | + } |
|
151 | + return $output; |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * Adds a custom output class for typography fields. |
|
156 | - * |
|
157 | - * @access public |
|
158 | - * @since 1.0 |
|
159 | - * @param array $classnames The array of classnames. |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - public function output_control_classnames( $classnames ) { |
|
163 | - $classnames['kirki-image'] = '\Kirki\Field\CSS\Image'; |
|
164 | - return $classnames; |
|
165 | - } |
|
154 | + /** |
|
155 | + * Adds a custom output class for typography fields. |
|
156 | + * |
|
157 | + * @access public |
|
158 | + * @since 1.0 |
|
159 | + * @param array $classnames The array of classnames. |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + public function output_control_classnames( $classnames ) { |
|
163 | + $classnames['kirki-image'] = '\Kirki\Field\CSS\Image'; |
|
164 | + return $classnames; |
|
165 | + } |
|
166 | 166 | } |
@@ -20,52 +20,52 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class Image extends Base { |
22 | 22 | |
23 | - /** |
|
24 | - * The control type. |
|
25 | - * |
|
26 | - * @access public |
|
27 | - * @since 1.0 |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - public $type = 'kirki-image'; |
|
23 | + /** |
|
24 | + * The control type. |
|
25 | + * |
|
26 | + * @access public |
|
27 | + * @since 1.0 |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + public $type = 'kirki-image'; |
|
31 | 31 | |
32 | - /** |
|
33 | - * The version. Used in scripts & styles for cache-busting. |
|
34 | - * |
|
35 | - * @static |
|
36 | - * @access public |
|
37 | - * @since 1.0 |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - public static $control_ver = '1.0.2'; |
|
32 | + /** |
|
33 | + * The version. Used in scripts & styles for cache-busting. |
|
34 | + * |
|
35 | + * @static |
|
36 | + * @access public |
|
37 | + * @since 1.0 |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + public static $control_ver = '1.0.2'; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Enqueue control related scripts/styles. |
|
44 | - * |
|
45 | - * @access public |
|
46 | - */ |
|
47 | - public function enqueue() { |
|
48 | - parent::enqueue(); |
|
42 | + /** |
|
43 | + * Enqueue control related scripts/styles. |
|
44 | + * |
|
45 | + * @access public |
|
46 | + */ |
|
47 | + public function enqueue() { |
|
48 | + parent::enqueue(); |
|
49 | 49 | |
50 | - // Enqueue the script. |
|
51 | - wp_enqueue_script( 'kirki-control-image', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base', 'wp-mediaelement', 'media-upload', 'wp-i18n' ], self::$control_ver, false ); |
|
52 | - wp_set_script_translations( 'kirki-control-image', 'kirki' ); |
|
53 | - } |
|
50 | + // Enqueue the script. |
|
51 | + wp_enqueue_script( 'kirki-control-image', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'jquery', 'customize-base', 'kirki-control-base', 'wp-mediaelement', 'media-upload', 'wp-i18n' ], self::$control_ver, false ); |
|
52 | + wp_set_script_translations( 'kirki-control-image', 'kirki' ); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * An Underscore (JS) template for this control's content (but not its container). |
|
57 | - * |
|
58 | - * Class variables for this control class are available in the `data` JS object; |
|
59 | - * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
|
60 | - * |
|
61 | - * @see WP_Customize_Control::print_template() |
|
62 | - * |
|
63 | - * @access protected |
|
64 | - * @since 1.1 |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - protected function content_template() { |
|
68 | - ?> |
|
55 | + /** |
|
56 | + * An Underscore (JS) template for this control's content (but not its container). |
|
57 | + * |
|
58 | + * Class variables for this control class are available in the `data` JS object; |
|
59 | + * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
|
60 | + * |
|
61 | + * @see WP_Customize_Control::print_template() |
|
62 | + * |
|
63 | + * @access protected |
|
64 | + * @since 1.1 |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + protected function content_template() { |
|
68 | + ?> |
|
69 | 69 | <label> |
70 | 70 | <span class="customize-control-title">{{{ data.label }}}</span> |
71 | 71 | <# if ( data.description ) { #> |
@@ -90,5 +90,5 @@ discard block |
||
90 | 90 | </div> |
91 | 91 | </div> |
92 | 92 | <?php |
93 | - } |
|
93 | + } |
|
94 | 94 | } |
@@ -17,25 +17,25 @@ |
||
17 | 17 | */ |
18 | 18 | class Preset extends Select { |
19 | 19 | |
20 | - /** |
|
21 | - * Filter arguments before creating the control. |
|
22 | - * |
|
23 | - * @access public |
|
24 | - * @since 0.1 |
|
25 | - * @param array $args The field arguments. |
|
26 | - * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public function filter_control_args( $args, $wp_customize ) { |
|
30 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
31 | - $args = parent::filter_control_args( $args, $wp_customize ); |
|
20 | + /** |
|
21 | + * Filter arguments before creating the control. |
|
22 | + * |
|
23 | + * @access public |
|
24 | + * @since 0.1 |
|
25 | + * @param array $args The field arguments. |
|
26 | + * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public function filter_control_args( $args, $wp_customize ) { |
|
30 | + if ( $args['settings'] === $this->args['settings'] ) { |
|
31 | + $args = parent::filter_control_args( $args, $wp_customize ); |
|
32 | 32 | |
33 | - $args['multiple'] = 1; |
|
34 | - $args['preset'] = $args['choices']; |
|
35 | - foreach ( $args['choices'] as $key => $args ) { |
|
36 | - $args['choices'][ $key ] = $args['label']; |
|
37 | - } |
|
38 | - } |
|
39 | - return $args; |
|
40 | - } |
|
33 | + $args['multiple'] = 1; |
|
34 | + $args['preset'] = $args['choices']; |
|
35 | + foreach ( $args['choices'] as $key => $args ) { |
|
36 | + $args['choices'][ $key ] = $args['label']; |
|
37 | + } |
|
38 | + } |
|
39 | + return $args; |
|
40 | + } |
|
41 | 41 | } |