PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.1.2
Adminify – White Label, Admin Menu Editor, Login Customizer v3.1.2
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / lib / adminify-framework / fields / background / background.php

background.php in Adminify – White Label, Admin Menu Editor, Login Customizer 3.1.2, at lib/adminify-framework/fields/background/background.php

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