PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.4.9
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.4.9
2.1.3 2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 trunk 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 All 57 releases
darkify / src / Admin / Framework / fields / background / background.php

background.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 1.4.9, at src/Admin/Framework/fields/background/background.php

399 lines 12.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use ThemeAtelier\Darkify\Admin\Framework\Classes\Darkify;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 die; } // Cannot access directly.
7 /**
8 *
9 * Field: background
10 *
11 * @since 1.0.0
12 * @version 1.0.0
13 */
14 if ( ! class_exists( 'DarkifyField_background' ) ) {
15 class DarkifyField_background extends DarkifyFields {
16
17 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
18 parent::__construct( $field, $value, $unique, $where, $parent );
19 }
20
21 public function render() {
22
23 $args = wp_parse_args(
24 $this->field,
25 array(
26 'background_color' => true,
27 'background_image' => true,
28 'background_position' => true,
29 'background_repeat' => true,
30 'background_attachment' => true,
31 'background_size' => true,
32 'background_origin' => false,
33 'background_clip' => false,
34 'background_blend_mode' => false,
35 'background_gradient' => false,
36 'background_gradient_color' => true,
37 'background_gradient_direction' => true,
38 'background_image_preview' => true,
39 'background_auto_attributes' => false,
40 'compact' => false,
41 'background_image_library' => 'image',
42 'background_image_placeholder' => esc_html__( 'Not selected', 'darkify' ),
43 )
44 );
45
46 if ( $args['compact'] ) {
47 $args['background_color'] = false;
48 $args['background_auto_attributes'] = true;
49 }
50
51 $default_value = array(
52 'background-color' => '',
53 'background-image' => '',
54 'background-position' => '',
55 'background-repeat' => '',
56 'background-attachment' => '',
57 'background-size' => '',
58 'background-origin' => '',
59 'background-clip' => '',
60 'background-blend-mode' => '',
61 'background-gradient-color' => '',
62 'background-gradient-direction' => '',
63 );
64
65 $default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value;
66
67 $this->value = wp_parse_args( $this->value, $default_value );
68
69 echo wp_kses_post( $this->field_before() );
70
71 echo '<div class="darkify--background-colors">';
72
73 //
74 // Background Color
75 if ( ! empty( $args['background_color'] ) ) {
76
77 echo '<div class="darkify--color">';
78
79 echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="darkify--title">' . esc_html__( 'From', 'darkify' ) . '</div>' : '';
80
81 Darkify::field(
82 array(
83 'id' => 'background-color',
84 'type' => 'color',
85 'default' => $default_value['background-color'],
86 ),
87 $this->value['background-color'],
88 $this->field_name(),
89 'field/background'
90 );
91
92 echo '</div>';
93
94 }
95
96 //
97 // Background Gradient Color
98 if ( ! empty( $args['background_gradient_color'] ) && ! empty( $args['background_gradient'] ) ) {
99
100 echo '<div class="darkify--color">';
101
102 echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="darkify--title">' . esc_html__( 'To', 'darkify' ) . '</div>' : '';
103
104 Darkify::field(
105 array(
106 'id' => 'background-gradient-color',
107 'type' => 'color',
108 'default' => $default_value['background-gradient-color'],
109 ),
110 $this->value['background-gradient-color'],
111 $this->field_name(),
112 'field/background'
113 );
114
115 echo '</div>';
116
117 }
118
119 //
120 // Background Gradient Direction
121 if ( ! empty( $args['background_gradient_direction'] ) && ! empty( $args['background_gradient'] ) ) {
122
123 echo '<div class="darkify--color">';
124
125 echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="darkify---title">' . esc_html__( 'Direction', 'darkify' ) . '</div>' : '';
126
127 Darkify::field(
128 array(
129 'id' => 'background-gradient-direction',
130 'type' => 'select',
131 'options' => array(
132 '' => esc_html__( 'Gradient Direction', 'darkify' ),
133 'to bottom' => esc_html__( '&#8659; top to bottom', 'darkify' ),
134 'to right' => esc_html__( '&#8658; left to right', 'darkify' ),
135 '135deg' => esc_html__( '&#8664; corner top to right', 'darkify' ),
136 '-135deg' => esc_html__( '&#8665; corner top to left', 'darkify' ),
137 ),
138 ),
139 $this->value['background-gradient-direction'],
140 $this->field_name(),
141 'field/background'
142 );
143
144 echo '</div>';
145
146 }
147
148 echo '</div>';
149
150 //
151 // Background Image
152 if ( ! empty( $args['background_image'] ) ) {
153
154 echo '<div class="darkify--background-image">';
155
156 Darkify::field(
157 array(
158 'id' => 'background-image',
159 'type' => 'media',
160 'class' => 'darkify-assign-field-background',
161 'library' => $args['background_image_library'],
162 'preview' => $args['background_image_preview'],
163 'placeholder' => $args['background_image_placeholder'],
164 'attributes' => array( 'data-depend-id' => $this->field['id'] ),
165 ),
166 $this->value['background-image'],
167 $this->field_name(),
168 'field/background'
169 );
170
171 echo '</div>';
172
173 }
174
175 $auto_class = ( ! empty( $args['background_auto_attributes'] ) ) ? ' darkify--auto-attributes' : '';
176 $hidden_class = ( ! empty( $args['background_auto_attributes'] ) && empty( $this->value['background-image']['url'] ) ) ? ' darkify--attributes-hidden' : '';
177
178 echo '<div class="darkify--background-attributes' . esc_attr( $auto_class . $hidden_class ) . '">';
179
180 //
181 // Background Position
182 if ( ! empty( $args['background_position'] ) ) {
183
184 Darkify::field(
185 array(
186 'id' => 'background-position',
187 'type' => 'select',
188 'options' => array(
189 '' => esc_html__( 'Background Position', 'darkify' ),
190 'left top' => esc_html__( 'Left Top', 'darkify' ),
191 'left center' => esc_html__( 'Left Center', 'darkify' ),
192 'left bottom' => esc_html__( 'Left Bottom', 'darkify' ),
193 'center top' => esc_html__( 'Center Top', 'darkify' ),
194 'center center' => esc_html__( 'Center Center', 'darkify' ),
195 'center bottom' => esc_html__( 'Center Bottom', 'darkify' ),
196 'right top' => esc_html__( 'Right Top', 'darkify' ),
197 'right center' => esc_html__( 'Right Center', 'darkify' ),
198 'right bottom' => esc_html__( 'Right Bottom', 'darkify' ),
199 ),
200 ),
201 $this->value['background-position'],
202 $this->field_name(),
203 'field/background'
204 );
205
206 }
207
208 //
209 // Background Repeat
210 if ( ! empty( $args['background_repeat'] ) ) {
211
212 Darkify::field(
213 array(
214 'id' => 'background-repeat',
215 'type' => 'select',
216 'options' => array(
217 '' => esc_html__( 'Background Repeat', 'darkify' ),
218 'repeat' => esc_html__( 'Repeat', 'darkify' ),
219 'no-repeat' => esc_html__( 'No Repeat', 'darkify' ),
220 'repeat-x' => esc_html__( 'Repeat Horizontally', 'darkify' ),
221 'repeat-y' => esc_html__( 'Repeat Vertically', 'darkify' ),
222 ),
223 ),
224 $this->value['background-repeat'],
225 $this->field_name(),
226 'field/background'
227 );
228
229 }
230
231 //
232 // Background Attachment
233 if ( ! empty( $args['background_attachment'] ) ) {
234
235 Darkify::field(
236 array(
237 'id' => 'background-attachment',
238 'type' => 'select',
239 'options' => array(
240 '' => esc_html__( 'Background Attachment', 'darkify' ),
241 'scroll' => esc_html__( 'Scroll', 'darkify' ),
242 'fixed' => esc_html__( 'Fixed', 'darkify' ),
243 ),
244 ),
245 $this->value['background-attachment'],
246 $this->field_name(),
247 'field/background'
248 );
249
250 }
251
252 //
253 // Background Size
254 if ( ! empty( $args['background_size'] ) ) {
255
256 Darkify::field(
257 array(
258 'id' => 'background-size',
259 'type' => 'select',
260 'options' => array(
261 '' => esc_html__( 'Background Size', 'darkify' ),
262 'cover' => esc_html__( 'Cover', 'darkify' ),
263 'contain' => esc_html__( 'Contain', 'darkify' ),
264 'auto' => esc_html__( 'Auto', 'darkify' ),
265 ),
266 ),
267 $this->value['background-size'],
268 $this->field_name(),
269 'field/background'
270 );
271
272 }
273
274 //
275 // Background Origin
276 if ( ! empty( $args['background_origin'] ) ) {
277
278 Darkify::field(
279 array(
280 'id' => 'background-origin',
281 'type' => 'select',
282 'options' => array(
283 '' => esc_html__( 'Background Origin', 'darkify' ),
284 'padding-box' => esc_html__( 'Padding Box', 'darkify' ),
285 'border-box' => esc_html__( 'Border Box', 'darkify' ),
286 'content-box' => esc_html__( 'Content Box', 'darkify' ),
287 ),
288 ),
289 $this->value['background-origin'],
290 $this->field_name(),
291 'field/background'
292 );
293
294 }
295
296 //
297 // Background Clip
298 if ( ! empty( $args['background_clip'] ) ) {
299
300 Darkify::field(
301 array(
302 'id' => 'background-clip',
303 'type' => 'select',
304 'options' => array(
305 '' => esc_html__( 'Background Clip', 'darkify' ),
306 'border-box' => esc_html__( 'Border Box', 'darkify' ),
307 'padding-box' => esc_html__( 'Padding Box', 'darkify' ),
308 'content-box' => esc_html__( 'Content Box', 'darkify' ),
309 ),
310 ),
311 $this->value['background-clip'],
312 $this->field_name(),
313 'field/background'
314 );
315
316 }
317
318 //
319 // Background Blend Mode
320 if ( ! empty( $args['background_blend_mode'] ) ) {
321
322 Darkify::field(
323 array(
324 'id' => 'background-blend-mode',
325 'type' => 'select',
326 'options' => array(
327 '' => esc_html__( 'Background Blend Mode', 'darkify' ),
328 'normal' => esc_html__( 'Normal', 'darkify' ),
329 'multiply' => esc_html__( 'Multiply', 'darkify' ),
330 'screen' => esc_html__( 'Screen', 'darkify' ),
331 'overlay' => esc_html__( 'Overlay', 'darkify' ),
332 'darken' => esc_html__( 'Darken', 'darkify' ),
333 'lighten' => esc_html__( 'Lighten', 'darkify' ),
334 'color-dodge' => esc_html__( 'Color Dodge', 'darkify' ),
335 'saturation' => esc_html__( 'Saturation', 'darkify' ),
336 'color' => esc_html__( 'Color', 'darkify' ),
337 'luminosity' => esc_html__( 'Luminosity', 'darkify' ),
338 ),
339 ),
340 $this->value['background-blend-mode'],
341 $this->field_name(),
342 'field/background'
343 );
344
345 }
346
347 echo '</div>';
348
349 echo wp_kses_post( $this->field_after() );
350 }
351
352 public function output() {
353
354 $output = '';
355 $bg_image = array();
356 $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
357 $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
358
359 // Background image and gradient
360 $background_color = ( ! empty( $this->value['background-color'] ) ) ? $this->value['background-color'] : '';
361 $background_gd_color = ( ! empty( $this->value['background-gradient-color'] ) ) ? $this->value['background-gradient-color'] : '';
362 $background_gd_direction = ( ! empty( $this->value['background-gradient-direction'] ) ) ? $this->value['background-gradient-direction'] : '';
363 $background_image = ( ! empty( $this->value['background-image']['url'] ) ) ? $this->value['background-image']['url'] : '';
364
365 if ( $background_color && $background_gd_color ) {
366 $gd_direction = ( $background_gd_direction ) ? $background_gd_direction . ',' : '';
367 $bg_image[] = 'linear-gradient(' . $gd_direction . $background_color . ',' . $background_gd_color . ')';
368 unset( $this->value['background-color'] );
369 }
370
371 if ( $background_image ) {
372 $bg_image[] = 'url(' . $background_image . ')';
373 }
374
375 if ( ! empty( $bg_image ) ) {
376 $output .= 'background-image:' . implode( ',', $bg_image ) . $important . ';';
377 }
378
379 // Common background properties
380 $properties = array( 'color', 'position', 'repeat', 'attachment', 'size', 'origin', 'clip', 'blend-mode' );
381
382 foreach ( $properties as $property ) {
383 $property = 'background-' . $property;
384 if ( ! empty( $this->value[ $property ] ) ) {
385 $output .= $property . ':' . $this->value[ $property ] . $important . ';';
386 }
387 }
388
389 if ( $output ) {
390 $output = $element . '{' . $output . '}';
391 }
392
393 $this->parent->output_css .= $output;
394
395 return $output;
396 }
397 }
398 }
399