PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.2.0
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.2.0
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 / admin / ta-framework / fields / background / background.php

background.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 1.2.0, at admin/ta-framework/fields/background/background.php

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