Completed
Push — master ( c4cd1f...963c86 )
by
unknown
36s
created
redux-core/inc/extensions/taxonomy/class-redux-taxonomy-api.php 2 patches
Indentation   +627 added lines, -627 removed lines patch added patch discarded remove patch
@@ -13,631 +13,631 @@
 block discarded – undo
13 13
 // Don't duplicate me!
14 14
 if ( ! class_exists( 'Redux_Taxonomy' ) ) {
15 15
 
16
-	/**
17
-	 * Redux Taxonomy API Class
18
-	 * Simple API for Redux Framework
19
-	 *
20
-	 * @since       1.0.0
21
-	 */
22
-	class Redux_Taxonomy {
23
-
24
-		/**
25
-		 * Terms array.
26
-		 *
27
-		 * @var array
28
-		 */
29
-		public static array $terms = array();
30
-
31
-		/**
32
-		 * Sections array.
33
-		 *
34
-		 * @var array
35
-		 */
36
-		public static array $sections = array();
37
-
38
-		/**
39
-		 * Fields array.
40
-		 *
41
-		 * @var array
42
-		 */
43
-		public static array $fields = array();
44
-
45
-		/**
46
-		 * Priority array.
47
-		 *
48
-		 * @var array
49
-		 */
50
-		public static array $priority = array();
51
-
52
-		/**
53
-		 * Errors array.
54
-		 *
55
-		 * @var array
56
-		 */
57
-		public static array $errors = array();
58
-
59
-		/**
60
-		 * Init array.
61
-		 *
62
-		 * @var array
63
-		 */
64
-		public static array $init = array();
65
-
66
-		/**
67
-		 * Args array.
68
-		 *
69
-		 * @var array
70
-		 */
71
-		public static array $args = array();
72
-
73
-		/**
74
-		 * Load.
75
-		 */
76
-		public static function load() {
77
-			add_action( 'init', array( 'Redux_Taxonomy', 'enqueue' ), 99 );
78
-		}
79
-
80
-		/**
81
-		 * Enqueue support files and fields.
82
-		 *
83
-		 * @throws ReflectionException Exception.
84
-		 */
85
-		public static function enqueue() {
86
-			global $pagenow;
87
-
88
-			// Check and run instances of Redux where the opt_name hasn't been run.
89
-			$pagenows = array( 'edit-tags.php', 'term.php' );
90
-
91
-			if ( ! empty( self::$sections ) && in_array( $pagenow, $pagenows, true ) ) {
92
-				$instances = Redux::all_instances();
93
-
94
-				foreach ( self::$fields as $opt_name => $fields ) {
95
-					if ( ! isset( $instances[ $opt_name ] ) ) {
96
-						Redux::set_args( $opt_name, array( 'menu_type' => 'hidden' ) );
97
-
98
-						Redux::set_sections(
99
-							$opt_name,
100
-							array(
101
-								array(
102
-									'id'     => 'EXTENSION_TAXONOMY_FAKE_ID' . $opt_name,
103
-									'fields' => $fields,
104
-									'title'  => 'N/A',
105
-								),
106
-							)
107
-						);
108
-
109
-						Redux::init( $opt_name );
110
-
111
-						$instances = ReduxFrameworkInstances::get_all_instances();
112
-					}
113
-
114
-					self::check_opt_name( $opt_name );
115
-
116
-					Redux::set_args( $opt_name, self::$args[ $opt_name ] );
117
-				}
118
-			}
119
-		}
120
-
121
-		/**
122
-		 * Construct Args.
123
-		 *
124
-		 * @param string $opt_name Panel opt_name.
125
-		 *
126
-		 * @return mixed
127
-		 */
128
-		public static function construct_args( string $opt_name ) {
129
-			$args             = self::$args[ $opt_name ];
130
-			$args['opt_name'] = $opt_name;
131
-
132
-			if ( ! isset( $args['menu_title'] ) ) {
133
-				$args['menu_title'] = ucfirst( $opt_name ) . ' Options';
134
-			}
135
-
136
-			if ( ! isset( $args['page_title'] ) ) {
137
-				$args['page_title'] = ucfirst( $opt_name ) . ' Options';
138
-			}
139
-
140
-			if ( ! isset( $args['page_slug'] ) ) {
141
-				$args['page_slug'] = $opt_name . '_options';
142
-			}
143
-
144
-			return $args;
145
-		}
146
-
147
-		/**
148
-		 * Construct Terms
149
-		 *
150
-		 * @param string $opt_name Panel opt_name.
151
-		 *
152
-		 * @return array
153
-		 */
154
-		public static function construct_terms( string $opt_name ): array {
155
-			$terms = array();
156
-
157
-			if ( ! isset( self::$terms[ $opt_name ] ) ) {
158
-				return $terms;
159
-			}
160
-
161
-			foreach ( self::$terms[ $opt_name ] as $term ) {
162
-				$term['sections'] = self::construct_sections( $opt_name, $term['id'] );
163
-				$terms[]          = $term;
164
-			}
165
-
166
-			ksort( $terms );
167
-
168
-			return $terms;
169
-		}
170
-
171
-		/**
172
-		 * Construct Sections.
173
-		 *
174
-		 * @param string $opt_name       Panel opt_name.
175
-		 * @param string $term_id        Term ID.
176
-		 *
177
-		 * @return array
178
-		 */
179
-		public static function construct_sections( string $opt_name, string $term_id ): array {
180
-			$sections = array();
181
-
182
-			if ( ! isset( self::$sections[ $opt_name ] ) ) {
183
-				return $sections;
184
-			}
185
-
186
-			foreach ( self::$sections[ $opt_name ] as $section_id => $section ) {
187
-				if ( $section['term_id'] === $term_id ) {
188
-					self::$sections[ $opt_name ][ $section_id ]['add_visibility'] = $section;
189
-
190
-					$p = $section['priority'];
191
-
192
-					while ( isset( $sections[ $p ] ) ) {
193
-						echo esc_html( $p++ );
194
-					}
195
-
196
-					$section['fields'] = self::construct_fields( $opt_name, $section_id );
197
-					$sections[ $p ]    = $section;
198
-				}
199
-			}
200
-
201
-			ksort( $sections );
202
-
203
-			return $sections;
204
-		}
205
-
206
-		/**
207
-		 * Construct Fields.
208
-		 *
209
-		 * @param string $opt_name       Panel opt_name.
210
-		 * @param string $section_id     Section ID.
211
-		 * @param bool   $permissions    Permissions.
212
-		 * @param bool   $add_visibility Add visibility.
213
-		 *
214
-		 * @return array
215
-		 */
216
-		public static function construct_fields( string $opt_name = '', string $section_id = '', bool $permissions = false, bool $add_visibility = false ): array {
217
-			$fields = array();
218
-
219
-			if ( ! isset( self::$fields[ $opt_name ] ) ) {
220
-				return $fields;
221
-			}
222
-
223
-			foreach ( self::$fields[ $opt_name ] as $key => $field ) {
224
-				// Nested permissions.
225
-				$field['permissions'] = $field['permissions'] ?? $permissions;
226
-
227
-				self::$fields[ $opt_name ][ $key ]['permissions'] = $field['permissions'];
228
-
229
-				// Nested add_visibility permissions.
230
-				$field['add_visibility'] = $field['add_visibility'] ?? $add_visibility;
231
-
232
-				self::$fields[ $opt_name ][ $key ]['add_visibility'] = $field['add_visibility'];
233
-
234
-				if ( $field['section_id'] === $section_id ) {
235
-					$p = $field['priority'];
236
-
237
-					while ( isset( $fields[ $p ] ) ) {
238
-						echo esc_html( $p++ );
239
-					}
240
-
241
-					$fields[ $p ] = $field;
242
-				}
243
-			}
244
-
245
-			ksort( $fields );
246
-
247
-			return $fields;
248
-		}
249
-
250
-		/**
251
-		 * Get Section.
252
-		 *
253
-		 * @param string $opt_name Panel opt_name.
254
-		 * @param string $id       ID.
255
-		 *
256
-		 * @return bool
257
-		 */
258
-		public static function get_section( string $opt_name = '', string $id = '' ): bool {
259
-			self::check_opt_name( $opt_name );
260
-
261
-			if ( ! empty( $opt_name ) && ! empty( $id ) ) {
262
-				if ( ! isset( self::$sections[ $opt_name ][ $id ] ) ) {
263
-					$id = strtolower( sanitize_html_class( $id ) );
264
-				}
265
-
266
-				return self::$sections[ $opt_name ][ $id ] ?? false;
267
-			}
268
-
269
-			return false;
270
-		}
271
-
272
-		/**
273
-		 * Set_section.
274
-		 *
275
-		 * @param string $opt_name Panel opt_name.
276
-		 * @param array  $section  Section array.
277
-		 */
278
-		public static function set_section( string $opt_name = '', array $section = array() ) {
279
-			self::check_opt_name( $opt_name );
280
-
281
-			if ( ! empty( $opt_name ) && is_array( $section ) && ! empty( $section ) ) {
282
-				if ( ! isset( $section['id'] ) ) {
283
-					if ( isset( $section['title'] ) ) {
284
-						$section['id'] = strtolower( sanitize_html_class( $section['title'] ) );
285
-					} else {
286
-						$section['id'] = 'section';
287
-					}
288
-
289
-					if ( isset( self::$sections[ $opt_name ][ $section['id'] ] ) ) {
290
-						$orig = $section['id'];
291
-						$i    = 0;
292
-
293
-						while ( isset( self::$sections[ $opt_name ][ $section['id'] ] ) ) {
294
-							$section['id'] = $orig . '_' . $i;
295
-						}
296
-					}
297
-				}
298
-
299
-				if ( ! isset( $section['priority'] ) ) {
300
-					$section['priority'] = self::get_priority( $opt_name, 'sections' );
301
-				}
302
-
303
-				if ( isset( $section['fields'] ) ) {
304
-					if ( ! empty( $section['fields'] ) && is_array( $section['fields'] ) ) {
305
-						if ( isset( $section['permissions'] ) || isset( $section['add_visibility'] ) ) {
306
-							foreach ( $section['fields'] as $key => $field ) {
307
-								if ( ! isset( $field['permissions'] ) && isset( $section['permissions'] ) ) {
308
-									$section['fields'][ $key ]['permissions'] = $section['permissions'];
309
-								}
310
-
311
-								if ( ! isset( $field['add_visibility'] ) && isset( $section['add_visibility'] ) ) {
312
-									$section['fields'][ $key ]['add_visibility'] = $section['add_visibility'];
313
-								}
314
-							}
315
-						}
316
-
317
-						self::process_fields_array( $opt_name, $section['id'], $section['fields'] );
318
-					}
319
-
320
-					unset( $section['fields'] );
321
-				}
322
-
323
-				self::$sections[ $opt_name ][ $section['id'] ] = $section;
324
-			} else {
325
-				self::$errors[ $opt_name ]['section']['empty'] = esc_html__( 'Unable to create a section due an empty section array or the section variable passed was not an array.', 'redux-framework' );
326
-			}
327
-		}
328
-
329
-		/**
330
-		 * Process Sections Array.
331
-		 *
332
-		 * @param string $opt_name Panel opt_name.
333
-		 * @param string $term_id  Term ID.
334
-		 * @param array  $sections Sections array.
335
-		 */
336
-		public static function process_sections_array( string $opt_name = '', string $term_id = '', array $sections = array() ) {
337
-			if ( ! empty( $opt_name ) && ! empty( $term_id ) && is_array( $sections ) && ! empty( $sections ) ) {
338
-				foreach ( $sections as $section ) {
339
-					if ( ! is_array( $section ) ) {
340
-						continue;
341
-					}
342
-
343
-					$section['term_id'] = $term_id;
344
-
345
-					if ( ! isset( $section['fields'] ) || ! is_array( $section['fields'] ) ) {
346
-						$section['fields'] = array();
347
-					}
348
-
349
-					self::set_section( $opt_name, $section );
350
-				}
351
-			}
352
-		}
353
-
354
-		/**
355
-		 * Process field array.
356
-		 *
357
-		 * @param string $opt_name   Panel opt_name.
358
-		 * @param string $section_id Section ID.
359
-		 * @param array  $fields     Fields array.
360
-		 */
361
-		public static function process_fields_array( string $opt_name = '', string $section_id = '', array $fields = array() ) {
362
-			if ( ! empty( $opt_name ) && ! empty( $section_id ) && is_array( $fields ) && ! empty( $fields ) ) {
363
-				foreach ( $fields as $field ) {
364
-					if ( ! is_array( $field ) ) {
365
-						continue;
366
-					}
367
-
368
-					$field['section_id'] = $section_id;
369
-
370
-					self::set_field( $opt_name, $field );
371
-				}
372
-			}
373
-		}
374
-
375
-		/**
376
-		 * Get field.
377
-		 *
378
-		 * @param string $opt_name Panel opt_name.
379
-		 * @param string $id       ID.
380
-		 *
381
-		 * @return bool
382
-		 */
383
-		public static function get_field( string $opt_name = '', string $id = '' ): bool {
384
-			self::check_opt_name( $opt_name );
385
-
386
-			if ( ! empty( $opt_name ) && ! empty( $id ) ) {
387
-				return self::$fields[ $opt_name ][ $id ] ?? false;
388
-			}
389
-
390
-			return false;
391
-		}
392
-
393
-		/**
394
-		 * Set field.
395
-		 *
396
-		 * @param string $opt_name Panel opt_name.
397
-		 * @param array  $field    Field array.
398
-		 */
399
-		public static function set_field( string $opt_name = '', array $field = array() ) {
400
-			self::check_opt_name( $opt_name );
401
-
402
-			if ( ! empty( $opt_name ) && is_array( $field ) && ! empty( $field ) ) {
403
-				if ( ! isset( $field['priority'] ) ) {
404
-					$field['priority'] = self::get_priority( $opt_name, 'fields' );
405
-				}
406
-
407
-				self::$fields[ $opt_name ][ $field['id'] ] = $field;
408
-			}
409
-		}
410
-
411
-		/**
412
-		 * Set args.
413
-		 *
414
-		 * @param string $opt_name Panel opt_name.
415
-		 * @param array  $args     Args array.
416
-		 */
417
-		public static function set_args( string $opt_name = '', array $args = array() ) {
418
-			self::check_opt_name( $opt_name );
419
-
420
-			if ( ! empty( $opt_name ) && is_array( $args ) && ! empty( $args ) ) {
421
-				self::$args[ $opt_name ] = self::$args[ $opt_name ] ?? array();
422
-				self::$args[ $opt_name ] = wp_parse_args( $args, self::$args[ $opt_name ] );
423
-			}
424
-		}
425
-
426
-		/**
427
-		 * Set term.
428
-		 *
429
-		 * @param string $opt_name Panel opt_name.
430
-		 * @param array  $term     Term array.
431
-		 */
432
-		public static function set_term( string $opt_name = '', array $term = array() ) {
433
-			self::check_opt_name( $opt_name );
434
-
435
-			if ( ! empty( $opt_name ) && is_array( $term ) && ! empty( $term ) ) {
436
-				if ( ! isset( $term['id'] ) ) {
437
-					if ( isset( $term['title'] ) ) {
438
-						$term['id'] = strtolower( sanitize_html_class( $term['title'] ) );
439
-					} else {
440
-						$term['id'] = 'term';
441
-					}
442
-
443
-					if ( isset( self::$terms[ $opt_name ][ $term['id'] ] ) ) {
444
-						$orig = $term['id'];
445
-						$i    = 0;
446
-
447
-						while ( isset( self::$terms[ $opt_name ][ $term['id'] ] ) ) {
448
-							$term['id'] = $orig . '_' . $i;
449
-						}
450
-					}
451
-				}
452
-
453
-				if ( isset( $term['sections'] ) ) {
454
-					if ( ! empty( $term['sections'] ) && is_array( $term['sections'] ) ) {
455
-						if ( isset( $term['permissions'] ) || isset( $term['add_visibility'] ) ) {
456
-							foreach ( $term['sections'] as $key => $section ) {
457
-								if ( ! isset( $section['permissions'] ) && isset( $term['permissions'] ) ) {
458
-									$term['sections'][ $key ]['permissions'] = $term['permissions'];
459
-								}
460
-
461
-								if ( ! isset( $section['add_visibility'] ) && isset( $term['add_visibility'] ) ) {
462
-									$term['sections'][ $key ]['add_visibility'] = $term['add_visibility'];
463
-								}
464
-							}
465
-						}
466
-
467
-						self::process_sections_array( $opt_name, $term['id'], $term['sections'] );
468
-					}
469
-
470
-					unset( $term['sections'] );
471
-				}
472
-
473
-				self::$terms[ $opt_name ][ $term['id'] ] = $term;
474
-			} else {
475
-				self::$errors[ $opt_name ]['term']['empty'] = esc_html__( 'Unable to create a term due an empty term array or the term variable passed was not an array.', 'redux-framework' );
476
-			}
477
-		}
478
-
479
-		/**
480
-		 * Get terms.
481
-		 *
482
-		 * @param string $opt_name Panel opt_name.
483
-		 *
484
-		 * @return mixed
485
-		 */
486
-		public static function get_terms( string $opt_name = '' ) {
487
-			self::check_opt_name( $opt_name );
488
-
489
-			if ( ! empty( $opt_name ) && ! empty( self::$terms[ $opt_name ] ) ) {
490
-				return self::$terms[ $opt_name ];
491
-			}
492
-
493
-			return false;
494
-		}
495
-
496
-		/**
497
-		 * Get priority.
498
-		 *
499
-		 * @param string $opt_name Panel opt_name.
500
-		 * @param string $type     Field type.
501
-		 *
502
-		 * @return mixed
503
-		 */
504
-		public static function get_priority( string $opt_name, string $type ) {
505
-			$priority                              = self::$priority[ $opt_name ][ $type ];
506
-			self::$priority[ $opt_name ][ $type ] += 1;
507
-
508
-			return $priority;
509
-		}
510
-
511
-		/**
512
-		 * Check opt_name.
513
-		 *
514
-		 * @param string $opt_name Panel opt_name.
515
-		 */
516
-		public static function check_opt_name( string $opt_name = '' ) {
517
-			if ( empty( $opt_name ) || is_array( $opt_name ) ) {
518
-				return;
519
-			}
520
-
521
-			if ( ! isset( self::$terms[ $opt_name ] ) ) {
522
-				self::$terms[ $opt_name ] = array();
523
-			}
524
-
525
-			if ( ! isset( self::$priority[ $opt_name ] ) ) {
526
-				self::$priority[ $opt_name ]['args'] = 1;
527
-			}
528
-
529
-			if ( ! isset( self::$sections[ $opt_name ] ) ) {
530
-				self::$sections[ $opt_name ]             = array();
531
-				self::$priority[ $opt_name ]['sections'] = 1;
532
-			}
533
-
534
-			if ( ! isset( self::$fields[ $opt_name ] ) ) {
535
-				self::$fields[ $opt_name ]             = array();
536
-				self::$priority[ $opt_name ]['fields'] = 1;
537
-			}
538
-
539
-			if ( ! isset( self::$errors[ $opt_name ] ) ) {
540
-				self::$errors[ $opt_name ] = array();
541
-			}
542
-
543
-			if ( ! isset( self::$init[ $opt_name ] ) ) {
544
-				self::$init[ $opt_name ] = false;
545
-			}
546
-
547
-			if ( ! isset( self::$args[ $opt_name ] ) ) {
548
-				self::$args[ $opt_name ] = false;
549
-			}
550
-		}
551
-
552
-		/**
553
-		 * Get field defaults.
554
-		 *
555
-		 * @param string $opt_name Panel opt_name.
556
-		 *
557
-		 * @return array|void
558
-		 */
559
-		public static function get_field_defaults( string $opt_name ) {
560
-			if ( empty( $opt_name ) ) {
561
-				return;
562
-			}
563
-
564
-			if ( ! isset( self::$fields[ $opt_name ] ) ) {
565
-				return array();
566
-			}
567
-
568
-			return array_map(
569
-				function ( $field ) {
570
-					return $field['default'] ?? '';
571
-				},
572
-				self::$fields[ $opt_name ]
573
-			);
574
-		}
575
-
576
-		/**
577
-		 * Get term meta.
578
-		 *
579
-		 * @param array $args Args array.
580
-		 *
581
-		 * @return array|mixed|string
582
-		 */
583
-		public static function get_term_meta( array $args = array() ) {
584
-			$default = array(
585
-				'key'      => '',
586
-				'opt_name' => '',
587
-				'taxonomy' => '',
588
-			);
589
-
590
-			$args = wp_parse_args( $args, $default );
591
-
592
-			// phpcs:ignore WordPress.PHP.DontExtract
593
-			extract( $args );
594
-
595
-			if ( empty( $taxonomy ) ) {
596
-				return array();
597
-			}
598
-
599
-			$single = ! empty( $key );
600
-
601
-			$meta = get_term_meta( $taxonomy, $key, $single );
602
-
603
-			// phpcs:ignore Generic.CodeAnalysis.EmptyStatement
604
-			if ( $single ) {
605
-				// Do nothing.
606
-			} elseif ( ! empty( $meta ) ) {
607
-				foreach ( $meta as $key => $value ) {
608
-					if ( is_array( $value ) ) {
609
-						$value = $value[0];
610
-					}
611
-
612
-					$meta[ $key ] = maybe_unserialize( $value );
613
-				}
614
-			}
615
-
616
-			if ( ! empty( $opt_name ) ) {
617
-				$defaults = self::get_field_defaults( $opt_name );
618
-
619
-				if ( $single ) {
620
-					$default_value = '';
621
-
622
-					if ( isset( $defaults[ $key ] ) ) {
623
-						$default_value = $defaults[ $key ];
624
-					}
625
-
626
-					if ( is_array( $meta ) ) {
627
-						if ( is_array( $default_value ) ) {
628
-							$meta = wp_parse_args( $meta, $default_value );
629
-						}
630
-					} elseif ( '' === $meta && '' !== $default_value ) {
631
-							$meta = $default_value;
632
-					}
633
-				} else {
634
-					$meta = wp_parse_args( $meta, $defaults );
635
-				}
636
-			}
637
-
638
-			return $meta;
639
-		}
640
-	}
641
-
642
-	Redux_Taxonomy::load();
16
+    /**
17
+     * Redux Taxonomy API Class
18
+     * Simple API for Redux Framework
19
+     *
20
+     * @since       1.0.0
21
+     */
22
+    class Redux_Taxonomy {
23
+
24
+        /**
25
+         * Terms array.
26
+         *
27
+         * @var array
28
+         */
29
+        public static array $terms = array();
30
+
31
+        /**
32
+         * Sections array.
33
+         *
34
+         * @var array
35
+         */
36
+        public static array $sections = array();
37
+
38
+        /**
39
+         * Fields array.
40
+         *
41
+         * @var array
42
+         */
43
+        public static array $fields = array();
44
+
45
+        /**
46
+         * Priority array.
47
+         *
48
+         * @var array
49
+         */
50
+        public static array $priority = array();
51
+
52
+        /**
53
+         * Errors array.
54
+         *
55
+         * @var array
56
+         */
57
+        public static array $errors = array();
58
+
59
+        /**
60
+         * Init array.
61
+         *
62
+         * @var array
63
+         */
64
+        public static array $init = array();
65
+
66
+        /**
67
+         * Args array.
68
+         *
69
+         * @var array
70
+         */
71
+        public static array $args = array();
72
+
73
+        /**
74
+         * Load.
75
+         */
76
+        public static function load() {
77
+            add_action( 'init', array( 'Redux_Taxonomy', 'enqueue' ), 99 );
78
+        }
79
+
80
+        /**
81
+         * Enqueue support files and fields.
82
+         *
83
+         * @throws ReflectionException Exception.
84
+         */
85
+        public static function enqueue() {
86
+            global $pagenow;
87
+
88
+            // Check and run instances of Redux where the opt_name hasn't been run.
89
+            $pagenows = array( 'edit-tags.php', 'term.php' );
90
+
91
+            if ( ! empty( self::$sections ) && in_array( $pagenow, $pagenows, true ) ) {
92
+                $instances = Redux::all_instances();
93
+
94
+                foreach ( self::$fields as $opt_name => $fields ) {
95
+                    if ( ! isset( $instances[ $opt_name ] ) ) {
96
+                        Redux::set_args( $opt_name, array( 'menu_type' => 'hidden' ) );
97
+
98
+                        Redux::set_sections(
99
+                            $opt_name,
100
+                            array(
101
+                                array(
102
+                                    'id'     => 'EXTENSION_TAXONOMY_FAKE_ID' . $opt_name,
103
+                                    'fields' => $fields,
104
+                                    'title'  => 'N/A',
105
+                                ),
106
+                            )
107
+                        );
108
+
109
+                        Redux::init( $opt_name );
110
+
111
+                        $instances = ReduxFrameworkInstances::get_all_instances();
112
+                    }
113
+
114
+                    self::check_opt_name( $opt_name );
115
+
116
+                    Redux::set_args( $opt_name, self::$args[ $opt_name ] );
117
+                }
118
+            }
119
+        }
120
+
121
+        /**
122
+         * Construct Args.
123
+         *
124
+         * @param string $opt_name Panel opt_name.
125
+         *
126
+         * @return mixed
127
+         */
128
+        public static function construct_args( string $opt_name ) {
129
+            $args             = self::$args[ $opt_name ];
130
+            $args['opt_name'] = $opt_name;
131
+
132
+            if ( ! isset( $args['menu_title'] ) ) {
133
+                $args['menu_title'] = ucfirst( $opt_name ) . ' Options';
134
+            }
135
+
136
+            if ( ! isset( $args['page_title'] ) ) {
137
+                $args['page_title'] = ucfirst( $opt_name ) . ' Options';
138
+            }
139
+
140
+            if ( ! isset( $args['page_slug'] ) ) {
141
+                $args['page_slug'] = $opt_name . '_options';
142
+            }
143
+
144
+            return $args;
145
+        }
146
+
147
+        /**
148
+         * Construct Terms
149
+         *
150
+         * @param string $opt_name Panel opt_name.
151
+         *
152
+         * @return array
153
+         */
154
+        public static function construct_terms( string $opt_name ): array {
155
+            $terms = array();
156
+
157
+            if ( ! isset( self::$terms[ $opt_name ] ) ) {
158
+                return $terms;
159
+            }
160
+
161
+            foreach ( self::$terms[ $opt_name ] as $term ) {
162
+                $term['sections'] = self::construct_sections( $opt_name, $term['id'] );
163
+                $terms[]          = $term;
164
+            }
165
+
166
+            ksort( $terms );
167
+
168
+            return $terms;
169
+        }
170
+
171
+        /**
172
+         * Construct Sections.
173
+         *
174
+         * @param string $opt_name       Panel opt_name.
175
+         * @param string $term_id        Term ID.
176
+         *
177
+         * @return array
178
+         */
179
+        public static function construct_sections( string $opt_name, string $term_id ): array {
180
+            $sections = array();
181
+
182
+            if ( ! isset( self::$sections[ $opt_name ] ) ) {
183
+                return $sections;
184
+            }
185
+
186
+            foreach ( self::$sections[ $opt_name ] as $section_id => $section ) {
187
+                if ( $section['term_id'] === $term_id ) {
188
+                    self::$sections[ $opt_name ][ $section_id ]['add_visibility'] = $section;
189
+
190
+                    $p = $section['priority'];
191
+
192
+                    while ( isset( $sections[ $p ] ) ) {
193
+                        echo esc_html( $p++ );
194
+                    }
195
+
196
+                    $section['fields'] = self::construct_fields( $opt_name, $section_id );
197
+                    $sections[ $p ]    = $section;
198
+                }
199
+            }
200
+
201
+            ksort( $sections );
202
+
203
+            return $sections;
204
+        }
205
+
206
+        /**
207
+         * Construct Fields.
208
+         *
209
+         * @param string $opt_name       Panel opt_name.
210
+         * @param string $section_id     Section ID.
211
+         * @param bool   $permissions    Permissions.
212
+         * @param bool   $add_visibility Add visibility.
213
+         *
214
+         * @return array
215
+         */
216
+        public static function construct_fields( string $opt_name = '', string $section_id = '', bool $permissions = false, bool $add_visibility = false ): array {
217
+            $fields = array();
218
+
219
+            if ( ! isset( self::$fields[ $opt_name ] ) ) {
220
+                return $fields;
221
+            }
222
+
223
+            foreach ( self::$fields[ $opt_name ] as $key => $field ) {
224
+                // Nested permissions.
225
+                $field['permissions'] = $field['permissions'] ?? $permissions;
226
+
227
+                self::$fields[ $opt_name ][ $key ]['permissions'] = $field['permissions'];
228
+
229
+                // Nested add_visibility permissions.
230
+                $field['add_visibility'] = $field['add_visibility'] ?? $add_visibility;
231
+
232
+                self::$fields[ $opt_name ][ $key ]['add_visibility'] = $field['add_visibility'];
233
+
234
+                if ( $field['section_id'] === $section_id ) {
235
+                    $p = $field['priority'];
236
+
237
+                    while ( isset( $fields[ $p ] ) ) {
238
+                        echo esc_html( $p++ );
239
+                    }
240
+
241
+                    $fields[ $p ] = $field;
242
+                }
243
+            }
244
+
245
+            ksort( $fields );
246
+
247
+            return $fields;
248
+        }
249
+
250
+        /**
251
+         * Get Section.
252
+         *
253
+         * @param string $opt_name Panel opt_name.
254
+         * @param string $id       ID.
255
+         *
256
+         * @return bool
257
+         */
258
+        public static function get_section( string $opt_name = '', string $id = '' ): bool {
259
+            self::check_opt_name( $opt_name );
260
+
261
+            if ( ! empty( $opt_name ) && ! empty( $id ) ) {
262
+                if ( ! isset( self::$sections[ $opt_name ][ $id ] ) ) {
263
+                    $id = strtolower( sanitize_html_class( $id ) );
264
+                }
265
+
266
+                return self::$sections[ $opt_name ][ $id ] ?? false;
267
+            }
268
+
269
+            return false;
270
+        }
271
+
272
+        /**
273
+         * Set_section.
274
+         *
275
+         * @param string $opt_name Panel opt_name.
276
+         * @param array  $section  Section array.
277
+         */
278
+        public static function set_section( string $opt_name = '', array $section = array() ) {
279
+            self::check_opt_name( $opt_name );
280
+
281
+            if ( ! empty( $opt_name ) && is_array( $section ) && ! empty( $section ) ) {
282
+                if ( ! isset( $section['id'] ) ) {
283
+                    if ( isset( $section['title'] ) ) {
284
+                        $section['id'] = strtolower( sanitize_html_class( $section['title'] ) );
285
+                    } else {
286
+                        $section['id'] = 'section';
287
+                    }
288
+
289
+                    if ( isset( self::$sections[ $opt_name ][ $section['id'] ] ) ) {
290
+                        $orig = $section['id'];
291
+                        $i    = 0;
292
+
293
+                        while ( isset( self::$sections[ $opt_name ][ $section['id'] ] ) ) {
294
+                            $section['id'] = $orig . '_' . $i;
295
+                        }
296
+                    }
297
+                }
298
+
299
+                if ( ! isset( $section['priority'] ) ) {
300
+                    $section['priority'] = self::get_priority( $opt_name, 'sections' );
301
+                }
302
+
303
+                if ( isset( $section['fields'] ) ) {
304
+                    if ( ! empty( $section['fields'] ) && is_array( $section['fields'] ) ) {
305
+                        if ( isset( $section['permissions'] ) || isset( $section['add_visibility'] ) ) {
306
+                            foreach ( $section['fields'] as $key => $field ) {
307
+                                if ( ! isset( $field['permissions'] ) && isset( $section['permissions'] ) ) {
308
+                                    $section['fields'][ $key ]['permissions'] = $section['permissions'];
309
+                                }
310
+
311
+                                if ( ! isset( $field['add_visibility'] ) && isset( $section['add_visibility'] ) ) {
312
+                                    $section['fields'][ $key ]['add_visibility'] = $section['add_visibility'];
313
+                                }
314
+                            }
315
+                        }
316
+
317
+                        self::process_fields_array( $opt_name, $section['id'], $section['fields'] );
318
+                    }
319
+
320
+                    unset( $section['fields'] );
321
+                }
322
+
323
+                self::$sections[ $opt_name ][ $section['id'] ] = $section;
324
+            } else {
325
+                self::$errors[ $opt_name ]['section']['empty'] = esc_html__( 'Unable to create a section due an empty section array or the section variable passed was not an array.', 'redux-framework' );
326
+            }
327
+        }
328
+
329
+        /**
330
+         * Process Sections Array.
331
+         *
332
+         * @param string $opt_name Panel opt_name.
333
+         * @param string $term_id  Term ID.
334
+         * @param array  $sections Sections array.
335
+         */
336
+        public static function process_sections_array( string $opt_name = '', string $term_id = '', array $sections = array() ) {
337
+            if ( ! empty( $opt_name ) && ! empty( $term_id ) && is_array( $sections ) && ! empty( $sections ) ) {
338
+                foreach ( $sections as $section ) {
339
+                    if ( ! is_array( $section ) ) {
340
+                        continue;
341
+                    }
342
+
343
+                    $section['term_id'] = $term_id;
344
+
345
+                    if ( ! isset( $section['fields'] ) || ! is_array( $section['fields'] ) ) {
346
+                        $section['fields'] = array();
347
+                    }
348
+
349
+                    self::set_section( $opt_name, $section );
350
+                }
351
+            }
352
+        }
353
+
354
+        /**
355
+         * Process field array.
356
+         *
357
+         * @param string $opt_name   Panel opt_name.
358
+         * @param string $section_id Section ID.
359
+         * @param array  $fields     Fields array.
360
+         */
361
+        public static function process_fields_array( string $opt_name = '', string $section_id = '', array $fields = array() ) {
362
+            if ( ! empty( $opt_name ) && ! empty( $section_id ) && is_array( $fields ) && ! empty( $fields ) ) {
363
+                foreach ( $fields as $field ) {
364
+                    if ( ! is_array( $field ) ) {
365
+                        continue;
366
+                    }
367
+
368
+                    $field['section_id'] = $section_id;
369
+
370
+                    self::set_field( $opt_name, $field );
371
+                }
372
+            }
373
+        }
374
+
375
+        /**
376
+         * Get field.
377
+         *
378
+         * @param string $opt_name Panel opt_name.
379
+         * @param string $id       ID.
380
+         *
381
+         * @return bool
382
+         */
383
+        public static function get_field( string $opt_name = '', string $id = '' ): bool {
384
+            self::check_opt_name( $opt_name );
385
+
386
+            if ( ! empty( $opt_name ) && ! empty( $id ) ) {
387
+                return self::$fields[ $opt_name ][ $id ] ?? false;
388
+            }
389
+
390
+            return false;
391
+        }
392
+
393
+        /**
394
+         * Set field.
395
+         *
396
+         * @param string $opt_name Panel opt_name.
397
+         * @param array  $field    Field array.
398
+         */
399
+        public static function set_field( string $opt_name = '', array $field = array() ) {
400
+            self::check_opt_name( $opt_name );
401
+
402
+            if ( ! empty( $opt_name ) && is_array( $field ) && ! empty( $field ) ) {
403
+                if ( ! isset( $field['priority'] ) ) {
404
+                    $field['priority'] = self::get_priority( $opt_name, 'fields' );
405
+                }
406
+
407
+                self::$fields[ $opt_name ][ $field['id'] ] = $field;
408
+            }
409
+        }
410
+
411
+        /**
412
+         * Set args.
413
+         *
414
+         * @param string $opt_name Panel opt_name.
415
+         * @param array  $args     Args array.
416
+         */
417
+        public static function set_args( string $opt_name = '', array $args = array() ) {
418
+            self::check_opt_name( $opt_name );
419
+
420
+            if ( ! empty( $opt_name ) && is_array( $args ) && ! empty( $args ) ) {
421
+                self::$args[ $opt_name ] = self::$args[ $opt_name ] ?? array();
422
+                self::$args[ $opt_name ] = wp_parse_args( $args, self::$args[ $opt_name ] );
423
+            }
424
+        }
425
+
426
+        /**
427
+         * Set term.
428
+         *
429
+         * @param string $opt_name Panel opt_name.
430
+         * @param array  $term     Term array.
431
+         */
432
+        public static function set_term( string $opt_name = '', array $term = array() ) {
433
+            self::check_opt_name( $opt_name );
434
+
435
+            if ( ! empty( $opt_name ) && is_array( $term ) && ! empty( $term ) ) {
436
+                if ( ! isset( $term['id'] ) ) {
437
+                    if ( isset( $term['title'] ) ) {
438
+                        $term['id'] = strtolower( sanitize_html_class( $term['title'] ) );
439
+                    } else {
440
+                        $term['id'] = 'term';
441
+                    }
442
+
443
+                    if ( isset( self::$terms[ $opt_name ][ $term['id'] ] ) ) {
444
+                        $orig = $term['id'];
445
+                        $i    = 0;
446
+
447
+                        while ( isset( self::$terms[ $opt_name ][ $term['id'] ] ) ) {
448
+                            $term['id'] = $orig . '_' . $i;
449
+                        }
450
+                    }
451
+                }
452
+
453
+                if ( isset( $term['sections'] ) ) {
454
+                    if ( ! empty( $term['sections'] ) && is_array( $term['sections'] ) ) {
455
+                        if ( isset( $term['permissions'] ) || isset( $term['add_visibility'] ) ) {
456
+                            foreach ( $term['sections'] as $key => $section ) {
457
+                                if ( ! isset( $section['permissions'] ) && isset( $term['permissions'] ) ) {
458
+                                    $term['sections'][ $key ]['permissions'] = $term['permissions'];
459
+                                }
460
+
461
+                                if ( ! isset( $section['add_visibility'] ) && isset( $term['add_visibility'] ) ) {
462
+                                    $term['sections'][ $key ]['add_visibility'] = $term['add_visibility'];
463
+                                }
464
+                            }
465
+                        }
466
+
467
+                        self::process_sections_array( $opt_name, $term['id'], $term['sections'] );
468
+                    }
469
+
470
+                    unset( $term['sections'] );
471
+                }
472
+
473
+                self::$terms[ $opt_name ][ $term['id'] ] = $term;
474
+            } else {
475
+                self::$errors[ $opt_name ]['term']['empty'] = esc_html__( 'Unable to create a term due an empty term array or the term variable passed was not an array.', 'redux-framework' );
476
+            }
477
+        }
478
+
479
+        /**
480
+         * Get terms.
481
+         *
482
+         * @param string $opt_name Panel opt_name.
483
+         *
484
+         * @return mixed
485
+         */
486
+        public static function get_terms( string $opt_name = '' ) {
487
+            self::check_opt_name( $opt_name );
488
+
489
+            if ( ! empty( $opt_name ) && ! empty( self::$terms[ $opt_name ] ) ) {
490
+                return self::$terms[ $opt_name ];
491
+            }
492
+
493
+            return false;
494
+        }
495
+
496
+        /**
497
+         * Get priority.
498
+         *
499
+         * @param string $opt_name Panel opt_name.
500
+         * @param string $type     Field type.
501
+         *
502
+         * @return mixed
503
+         */
504
+        public static function get_priority( string $opt_name, string $type ) {
505
+            $priority                              = self::$priority[ $opt_name ][ $type ];
506
+            self::$priority[ $opt_name ][ $type ] += 1;
507
+
508
+            return $priority;
509
+        }
510
+
511
+        /**
512
+         * Check opt_name.
513
+         *
514
+         * @param string $opt_name Panel opt_name.
515
+         */
516
+        public static function check_opt_name( string $opt_name = '' ) {
517
+            if ( empty( $opt_name ) || is_array( $opt_name ) ) {
518
+                return;
519
+            }
520
+
521
+            if ( ! isset( self::$terms[ $opt_name ] ) ) {
522
+                self::$terms[ $opt_name ] = array();
523
+            }
524
+
525
+            if ( ! isset( self::$priority[ $opt_name ] ) ) {
526
+                self::$priority[ $opt_name ]['args'] = 1;
527
+            }
528
+
529
+            if ( ! isset( self::$sections[ $opt_name ] ) ) {
530
+                self::$sections[ $opt_name ]             = array();
531
+                self::$priority[ $opt_name ]['sections'] = 1;
532
+            }
533
+
534
+            if ( ! isset( self::$fields[ $opt_name ] ) ) {
535
+                self::$fields[ $opt_name ]             = array();
536
+                self::$priority[ $opt_name ]['fields'] = 1;
537
+            }
538
+
539
+            if ( ! isset( self::$errors[ $opt_name ] ) ) {
540
+                self::$errors[ $opt_name ] = array();
541
+            }
542
+
543
+            if ( ! isset( self::$init[ $opt_name ] ) ) {
544
+                self::$init[ $opt_name ] = false;
545
+            }
546
+
547
+            if ( ! isset( self::$args[ $opt_name ] ) ) {
548
+                self::$args[ $opt_name ] = false;
549
+            }
550
+        }
551
+
552
+        /**
553
+         * Get field defaults.
554
+         *
555
+         * @param string $opt_name Panel opt_name.
556
+         *
557
+         * @return array|void
558
+         */
559
+        public static function get_field_defaults( string $opt_name ) {
560
+            if ( empty( $opt_name ) ) {
561
+                return;
562
+            }
563
+
564
+            if ( ! isset( self::$fields[ $opt_name ] ) ) {
565
+                return array();
566
+            }
567
+
568
+            return array_map(
569
+                function ( $field ) {
570
+                    return $field['default'] ?? '';
571
+                },
572
+                self::$fields[ $opt_name ]
573
+            );
574
+        }
575
+
576
+        /**
577
+         * Get term meta.
578
+         *
579
+         * @param array $args Args array.
580
+         *
581
+         * @return array|mixed|string
582
+         */
583
+        public static function get_term_meta( array $args = array() ) {
584
+            $default = array(
585
+                'key'      => '',
586
+                'opt_name' => '',
587
+                'taxonomy' => '',
588
+            );
589
+
590
+            $args = wp_parse_args( $args, $default );
591
+
592
+            // phpcs:ignore WordPress.PHP.DontExtract
593
+            extract( $args );
594
+
595
+            if ( empty( $taxonomy ) ) {
596
+                return array();
597
+            }
598
+
599
+            $single = ! empty( $key );
600
+
601
+            $meta = get_term_meta( $taxonomy, $key, $single );
602
+
603
+            // phpcs:ignore Generic.CodeAnalysis.EmptyStatement
604
+            if ( $single ) {
605
+                // Do nothing.
606
+            } elseif ( ! empty( $meta ) ) {
607
+                foreach ( $meta as $key => $value ) {
608
+                    if ( is_array( $value ) ) {
609
+                        $value = $value[0];
610
+                    }
611
+
612
+                    $meta[ $key ] = maybe_unserialize( $value );
613
+                }
614
+            }
615
+
616
+            if ( ! empty( $opt_name ) ) {
617
+                $defaults = self::get_field_defaults( $opt_name );
618
+
619
+                if ( $single ) {
620
+                    $default_value = '';
621
+
622
+                    if ( isset( $defaults[ $key ] ) ) {
623
+                        $default_value = $defaults[ $key ];
624
+                    }
625
+
626
+                    if ( is_array( $meta ) ) {
627
+                        if ( is_array( $default_value ) ) {
628
+                            $meta = wp_parse_args( $meta, $default_value );
629
+                        }
630
+                    } elseif ( '' === $meta && '' !== $default_value ) {
631
+                            $meta = $default_value;
632
+                    }
633
+                } else {
634
+                    $meta = wp_parse_args( $meta, $defaults );
635
+                }
636
+            }
637
+
638
+            return $meta;
639
+        }
640
+    }
641
+
642
+    Redux_Taxonomy::load();
643 643
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 				$instances = Redux::all_instances();
93 93
 
94 94
 				foreach ( self::$fields as $opt_name => $fields ) {
95
-					if ( ! isset( $instances[ $opt_name ] ) ) {
95
+					if ( ! isset( $instances[$opt_name] ) ) {
96 96
 						Redux::set_args( $opt_name, array( 'menu_type' => 'hidden' ) );
97 97
 
98 98
 						Redux::set_sections(
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 
114 114
 					self::check_opt_name( $opt_name );
115 115
 
116
-					Redux::set_args( $opt_name, self::$args[ $opt_name ] );
116
+					Redux::set_args( $opt_name, self::$args[$opt_name] );
117 117
 				}
118 118
 			}
119 119
 		}
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		 * @return mixed
127 127
 		 */
128 128
 		public static function construct_args( string $opt_name ) {
129
-			$args             = self::$args[ $opt_name ];
129
+			$args             = self::$args[$opt_name];
130 130
 			$args['opt_name'] = $opt_name;
131 131
 
132 132
 			if ( ! isset( $args['menu_title'] ) ) {
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
 		public static function construct_terms( string $opt_name ): array {
155 155
 			$terms = array();
156 156
 
157
-			if ( ! isset( self::$terms[ $opt_name ] ) ) {
157
+			if ( ! isset( self::$terms[$opt_name] ) ) {
158 158
 				return $terms;
159 159
 			}
160 160
 
161
-			foreach ( self::$terms[ $opt_name ] as $term ) {
161
+			foreach ( self::$terms[$opt_name] as $term ) {
162 162
 				$term['sections'] = self::construct_sections( $opt_name, $term['id'] );
163 163
 				$terms[]          = $term;
164 164
 			}
@@ -179,22 +179,22 @@  discard block
 block discarded – undo
179 179
 		public static function construct_sections( string $opt_name, string $term_id ): array {
180 180
 			$sections = array();
181 181
 
182
-			if ( ! isset( self::$sections[ $opt_name ] ) ) {
182
+			if ( ! isset( self::$sections[$opt_name] ) ) {
183 183
 				return $sections;
184 184
 			}
185 185
 
186
-			foreach ( self::$sections[ $opt_name ] as $section_id => $section ) {
186
+			foreach ( self::$sections[$opt_name] as $section_id => $section ) {
187 187
 				if ( $section['term_id'] === $term_id ) {
188
-					self::$sections[ $opt_name ][ $section_id ]['add_visibility'] = $section;
188
+					self::$sections[$opt_name][$section_id]['add_visibility'] = $section;
189 189
 
190 190
 					$p = $section['priority'];
191 191
 
192
-					while ( isset( $sections[ $p ] ) ) {
192
+					while ( isset( $sections[$p] ) ) {
193 193
 						echo esc_html( $p++ );
194 194
 					}
195 195
 
196 196
 					$section['fields'] = self::construct_fields( $opt_name, $section_id );
197
-					$sections[ $p ]    = $section;
197
+					$sections[$p]    = $section;
198 198
 				}
199 199
 			}
200 200
 
@@ -216,29 +216,29 @@  discard block
 block discarded – undo
216 216
 		public static function construct_fields( string $opt_name = '', string $section_id = '', bool $permissions = false, bool $add_visibility = false ): array {
217 217
 			$fields = array();
218 218
 
219
-			if ( ! isset( self::$fields[ $opt_name ] ) ) {
219
+			if ( ! isset( self::$fields[$opt_name] ) ) {
220 220
 				return $fields;
221 221
 			}
222 222
 
223
-			foreach ( self::$fields[ $opt_name ] as $key => $field ) {
223
+			foreach ( self::$fields[$opt_name] as $key => $field ) {
224 224
 				// Nested permissions.
225 225
 				$field['permissions'] = $field['permissions'] ?? $permissions;
226 226
 
227
-				self::$fields[ $opt_name ][ $key ]['permissions'] = $field['permissions'];
227
+				self::$fields[$opt_name][$key]['permissions'] = $field['permissions'];
228 228
 
229 229
 				// Nested add_visibility permissions.
230 230
 				$field['add_visibility'] = $field['add_visibility'] ?? $add_visibility;
231 231
 
232
-				self::$fields[ $opt_name ][ $key ]['add_visibility'] = $field['add_visibility'];
232
+				self::$fields[$opt_name][$key]['add_visibility'] = $field['add_visibility'];
233 233
 
234 234
 				if ( $field['section_id'] === $section_id ) {
235 235
 					$p = $field['priority'];
236 236
 
237
-					while ( isset( $fields[ $p ] ) ) {
237
+					while ( isset( $fields[$p] ) ) {
238 238
 						echo esc_html( $p++ );
239 239
 					}
240 240
 
241
-					$fields[ $p ] = $field;
241
+					$fields[$p] = $field;
242 242
 				}
243 243
 			}
244 244
 
@@ -259,11 +259,11 @@  discard block
 block discarded – undo
259 259
 			self::check_opt_name( $opt_name );
260 260
 
261 261
 			if ( ! empty( $opt_name ) && ! empty( $id ) ) {
262
-				if ( ! isset( self::$sections[ $opt_name ][ $id ] ) ) {
262
+				if ( ! isset( self::$sections[$opt_name][$id] ) ) {
263 263
 					$id = strtolower( sanitize_html_class( $id ) );
264 264
 				}
265 265
 
266
-				return self::$sections[ $opt_name ][ $id ] ?? false;
266
+				return self::$sections[$opt_name][$id] ?? false;
267 267
 			}
268 268
 
269 269
 			return false;
@@ -286,11 +286,11 @@  discard block
 block discarded – undo
286 286
 						$section['id'] = 'section';
287 287
 					}
288 288
 
289
-					if ( isset( self::$sections[ $opt_name ][ $section['id'] ] ) ) {
289
+					if ( isset( self::$sections[$opt_name][$section['id']] ) ) {
290 290
 						$orig = $section['id'];
291 291
 						$i    = 0;
292 292
 
293
-						while ( isset( self::$sections[ $opt_name ][ $section['id'] ] ) ) {
293
+						while ( isset( self::$sections[$opt_name][$section['id']] ) ) {
294 294
 							$section['id'] = $orig . '_' . $i;
295 295
 						}
296 296
 					}
@@ -305,11 +305,11 @@  discard block
 block discarded – undo
305 305
 						if ( isset( $section['permissions'] ) || isset( $section['add_visibility'] ) ) {
306 306
 							foreach ( $section['fields'] as $key => $field ) {
307 307
 								if ( ! isset( $field['permissions'] ) && isset( $section['permissions'] ) ) {
308
-									$section['fields'][ $key ]['permissions'] = $section['permissions'];
308
+									$section['fields'][$key]['permissions'] = $section['permissions'];
309 309
 								}
310 310
 
311 311
 								if ( ! isset( $field['add_visibility'] ) && isset( $section['add_visibility'] ) ) {
312
-									$section['fields'][ $key ]['add_visibility'] = $section['add_visibility'];
312
+									$section['fields'][$key]['add_visibility'] = $section['add_visibility'];
313 313
 								}
314 314
 							}
315 315
 						}
@@ -320,9 +320,9 @@  discard block
 block discarded – undo
320 320
 					unset( $section['fields'] );
321 321
 				}
322 322
 
323
-				self::$sections[ $opt_name ][ $section['id'] ] = $section;
323
+				self::$sections[$opt_name][$section['id']] = $section;
324 324
 			} else {
325
-				self::$errors[ $opt_name ]['section']['empty'] = esc_html__( 'Unable to create a section due an empty section array or the section variable passed was not an array.', 'redux-framework' );
325
+				self::$errors[$opt_name]['section']['empty'] = esc_html__( 'Unable to create a section due an empty section array or the section variable passed was not an array.', 'redux-framework' );
326 326
 			}
327 327
 		}
328 328
 
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 			self::check_opt_name( $opt_name );
385 385
 
386 386
 			if ( ! empty( $opt_name ) && ! empty( $id ) ) {
387
-				return self::$fields[ $opt_name ][ $id ] ?? false;
387
+				return self::$fields[$opt_name][$id] ?? false;
388 388
 			}
389 389
 
390 390
 			return false;
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 					$field['priority'] = self::get_priority( $opt_name, 'fields' );
405 405
 				}
406 406
 
407
-				self::$fields[ $opt_name ][ $field['id'] ] = $field;
407
+				self::$fields[$opt_name][$field['id']] = $field;
408 408
 			}
409 409
 		}
410 410
 
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 			self::check_opt_name( $opt_name );
419 419
 
420 420
 			if ( ! empty( $opt_name ) && is_array( $args ) && ! empty( $args ) ) {
421
-				self::$args[ $opt_name ] = self::$args[ $opt_name ] ?? array();
422
-				self::$args[ $opt_name ] = wp_parse_args( $args, self::$args[ $opt_name ] );
421
+				self::$args[$opt_name] = self::$args[$opt_name] ?? array();
422
+				self::$args[$opt_name] = wp_parse_args( $args, self::$args[$opt_name] );
423 423
 			}
424 424
 		}
425 425
 
@@ -440,11 +440,11 @@  discard block
 block discarded – undo
440 440
 						$term['id'] = 'term';
441 441
 					}
442 442
 
443
-					if ( isset( self::$terms[ $opt_name ][ $term['id'] ] ) ) {
443
+					if ( isset( self::$terms[$opt_name][$term['id']] ) ) {
444 444
 						$orig = $term['id'];
445 445
 						$i    = 0;
446 446
 
447
-						while ( isset( self::$terms[ $opt_name ][ $term['id'] ] ) ) {
447
+						while ( isset( self::$terms[$opt_name][$term['id']] ) ) {
448 448
 							$term['id'] = $orig . '_' . $i;
449 449
 						}
450 450
 					}
@@ -455,11 +455,11 @@  discard block
 block discarded – undo
455 455
 						if ( isset( $term['permissions'] ) || isset( $term['add_visibility'] ) ) {
456 456
 							foreach ( $term['sections'] as $key => $section ) {
457 457
 								if ( ! isset( $section['permissions'] ) && isset( $term['permissions'] ) ) {
458
-									$term['sections'][ $key ]['permissions'] = $term['permissions'];
458
+									$term['sections'][$key]['permissions'] = $term['permissions'];
459 459
 								}
460 460
 
461 461
 								if ( ! isset( $section['add_visibility'] ) && isset( $term['add_visibility'] ) ) {
462
-									$term['sections'][ $key ]['add_visibility'] = $term['add_visibility'];
462
+									$term['sections'][$key]['add_visibility'] = $term['add_visibility'];
463 463
 								}
464 464
 							}
465 465
 						}
@@ -470,9 +470,9 @@  discard block
 block discarded – undo
470 470
 					unset( $term['sections'] );
471 471
 				}
472 472
 
473
-				self::$terms[ $opt_name ][ $term['id'] ] = $term;
473
+				self::$terms[$opt_name][$term['id']] = $term;
474 474
 			} else {
475
-				self::$errors[ $opt_name ]['term']['empty'] = esc_html__( 'Unable to create a term due an empty term array or the term variable passed was not an array.', 'redux-framework' );
475
+				self::$errors[$opt_name]['term']['empty'] = esc_html__( 'Unable to create a term due an empty term array or the term variable passed was not an array.', 'redux-framework' );
476 476
 			}
477 477
 		}
478 478
 
@@ -486,8 +486,8 @@  discard block
 block discarded – undo
486 486
 		public static function get_terms( string $opt_name = '' ) {
487 487
 			self::check_opt_name( $opt_name );
488 488
 
489
-			if ( ! empty( $opt_name ) && ! empty( self::$terms[ $opt_name ] ) ) {
490
-				return self::$terms[ $opt_name ];
489
+			if ( ! empty( $opt_name ) && ! empty( self::$terms[$opt_name] ) ) {
490
+				return self::$terms[$opt_name];
491 491
 			}
492 492
 
493 493
 			return false;
@@ -502,8 +502,8 @@  discard block
 block discarded – undo
502 502
 		 * @return mixed
503 503
 		 */
504 504
 		public static function get_priority( string $opt_name, string $type ) {
505
-			$priority                              = self::$priority[ $opt_name ][ $type ];
506
-			self::$priority[ $opt_name ][ $type ] += 1;
505
+			$priority                              = self::$priority[$opt_name][$type];
506
+			self::$priority[$opt_name][$type] += 1;
507 507
 
508 508
 			return $priority;
509 509
 		}
@@ -518,34 +518,34 @@  discard block
 block discarded – undo
518 518
 				return;
519 519
 			}
520 520
 
521
-			if ( ! isset( self::$terms[ $opt_name ] ) ) {
522
-				self::$terms[ $opt_name ] = array();
521
+			if ( ! isset( self::$terms[$opt_name] ) ) {
522
+				self::$terms[$opt_name] = array();
523 523
 			}
524 524
 
525
-			if ( ! isset( self::$priority[ $opt_name ] ) ) {
526
-				self::$priority[ $opt_name ]['args'] = 1;
525
+			if ( ! isset( self::$priority[$opt_name] ) ) {
526
+				self::$priority[$opt_name]['args'] = 1;
527 527
 			}
528 528
 
529
-			if ( ! isset( self::$sections[ $opt_name ] ) ) {
530
-				self::$sections[ $opt_name ]             = array();
531
-				self::$priority[ $opt_name ]['sections'] = 1;
529
+			if ( ! isset( self::$sections[$opt_name] ) ) {
530
+				self::$sections[$opt_name]             = array();
531
+				self::$priority[$opt_name]['sections'] = 1;
532 532
 			}
533 533
 
534
-			if ( ! isset( self::$fields[ $opt_name ] ) ) {
535
-				self::$fields[ $opt_name ]             = array();
536
-				self::$priority[ $opt_name ]['fields'] = 1;
534
+			if ( ! isset( self::$fields[$opt_name] ) ) {
535
+				self::$fields[$opt_name]             = array();
536
+				self::$priority[$opt_name]['fields'] = 1;
537 537
 			}
538 538
 
539
-			if ( ! isset( self::$errors[ $opt_name ] ) ) {
540
-				self::$errors[ $opt_name ] = array();
539
+			if ( ! isset( self::$errors[$opt_name] ) ) {
540
+				self::$errors[$opt_name] = array();
541 541
 			}
542 542
 
543
-			if ( ! isset( self::$init[ $opt_name ] ) ) {
544
-				self::$init[ $opt_name ] = false;
543
+			if ( ! isset( self::$init[$opt_name] ) ) {
544
+				self::$init[$opt_name] = false;
545 545
 			}
546 546
 
547
-			if ( ! isset( self::$args[ $opt_name ] ) ) {
548
-				self::$args[ $opt_name ] = false;
547
+			if ( ! isset( self::$args[$opt_name] ) ) {
548
+				self::$args[$opt_name] = false;
549 549
 			}
550 550
 		}
551 551
 
@@ -561,15 +561,15 @@  discard block
 block discarded – undo
561 561
 				return;
562 562
 			}
563 563
 
564
-			if ( ! isset( self::$fields[ $opt_name ] ) ) {
564
+			if ( ! isset( self::$fields[$opt_name] ) ) {
565 565
 				return array();
566 566
 			}
567 567
 
568 568
 			return array_map(
569
-				function ( $field ) {
569
+				function( $field ) {
570 570
 					return $field['default'] ?? '';
571 571
 				},
572
-				self::$fields[ $opt_name ]
572
+				self::$fields[$opt_name]
573 573
 			);
574 574
 		}
575 575
 
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 						$value = $value[0];
610 610
 					}
611 611
 
612
-					$meta[ $key ] = maybe_unserialize( $value );
612
+					$meta[$key] = maybe_unserialize( $value );
613 613
 				}
614 614
 			}
615 615
 
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
 				if ( $single ) {
620 620
 					$default_value = '';
621 621
 
622
-					if ( isset( $defaults[ $key ] ) ) {
623
-						$default_value = $defaults[ $key ];
622
+					if ( isset( $defaults[$key] ) ) {
623
+						$default_value = $defaults[$key];
624 624
 					}
625 625
 
626 626
 					if ( is_array( $meta ) ) {
Please login to merge, or discard this patch.
redux-core/inc/extensions/customizer/class-redux-extension-customizer.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 		 *
56 56
 		 * @var array|null
57 57
 		 */
58
-		private static ?array $post_values = array();
58
+		private static ? array $post_values = array();
59 59
 
60 60
 		/**
61 61
 		 * Options array.
@@ -316,10 +316,10 @@  discard block
 block discarded – undo
316 316
 				foreach ( $the_data as $key => $value ) {
317 317
 					if ( strpos( wp_json_encode( $value ), 'data' ) > 0 ) {
318 318
 						foreach ( $value as $k => $v ) {
319
-							$decode           = (array) json_decode( rawurldecode( $v['data'] ) );
319
+							$decode           = ( array ) json_decode( rawurldecode( $v['data'] ) );
320 320
 							$v                = $decode;
321
-							$dumb_array[ $k ] = $v;
322
-							$the_data[ $key ] = $dumb_array;
321
+							$dumb_array[$k] = $v;
322
+							$the_data[$key] = $dumb_array;
323 323
 						}
324 324
 					}
325 325
 				}
@@ -343,10 +343,10 @@  discard block
 block discarded – undo
343 343
 					foreach ( self::$post_values as $key => $value ) {
344 344
 						if ( strpos( $key, $this->parent->args['opt_name'] ) !== false ) {
345 345
 							$key          = str_replace( $this->parent->args['opt_name'] . '[', '', rtrim( $key, ']' ) );
346
-							$data[ $key ] = $value;
346
+							$data[$key] = $value;
347 347
 
348
-							$GLOBALS[ $this->parent->args['global_variable'] ][ $key ] = $value;
349
-							$this->parent->options[ $key ]                             = $value;
348
+							$GLOBALS[$this->parent->args['global_variable']][$key] = $value;
349
+							$this->parent->options[$key]                             = $value;
350 350
 						}
351 351
 					}
352 352
 				}
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 		 */
363 363
 		public function render( object $control ) {
364 364
 			$field_id = str_replace( $this->parent->args['opt_name'] . '-', '', $control->redux_id );
365
-			$field    = $this->options[ $field_id ];
365
+			$field    = $this->options[$field_id];
366 366
 
367 367
 			if ( ! empty( $field['compiler'] ) ) {
368 368
 				echo '<tr class="compiler">';
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 				echo '<tr>';
371 371
 			}
372 372
 
373
-			echo '<th scope="row">' . wp_kses_post( $this->parent->field_head[ $field['id'] ] ) . '</th>';
373
+			echo '<th scope="row">' . wp_kses_post( $this->parent->field_head[$field['id']] ) . '</th>';
374 374
 			echo '<td>';
375 375
 
376 376
 			$field['name'] = $field['id'];
@@ -414,8 +414,8 @@  discard block
 block discarded – undo
414 414
 			do_action( 'redux/extension/customizer/control/includes' );
415 415
 
416 416
 			$order = array(
417
-				'heading' => - 500,
418
-				'option'  => - 500,
417
+				'heading' => -500,
418
+				'option'  => -500,
419 419
 			);
420 420
 
421 421
 			$panel = '';
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 					$parent_section_id = null;
455 455
 					$new_parent        = true;
456 456
 				}
457
-				if ( isset( $parent_section_id ) && ( isset( $this->parent->sections[ $parent_section_id ]['customizer'] ) && false === $this->parent->sections[ $parent_section_id ]['customizer'] ) ) {
457
+				if ( isset( $parent_section_id ) && ( isset( $this->parent->sections[$parent_section_id]['customizer'] ) && false === $this->parent->sections[$parent_section_id]['customizer'] ) ) {
458 458
 					continue;
459 459
 				}
460 460
 
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 				}
488 488
 				$section['id'] = $this->parent->args['opt_name'] . '-' . $section['id'];
489 489
 
490
-				if ( method_exists( $wp_customize, 'add_panel' ) && ( ! isset( $section['subsection'] ) || ( true !== $section['subsection'] ) ) && isset( $this->parent->sections[ ( $key + 1 ) ]['subsection'] ) && $this->parent->sections[ ( $key + 1 ) ]['subsection'] ) {
490
+				if ( method_exists( $wp_customize, 'add_panel' ) && ( ! isset( $section['subsection'] ) || ( true !== $section['subsection'] ) ) && isset( $this->parent->sections[( $key + 1 )]['subsection'] ) && $this->parent->sections[( $key + 1 )]['subsection'] ) {
491 491
 					$this->add_panel(
492 492
 						$this->parent->args['opt_name'] . '-' . $section['id'],
493 493
 						array(
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 						continue;
551 551
 					}
552 552
 
553
-					$this->options[ $option['id'] ] = $option;
553
+					$this->options[$option['id']] = $option;
554 554
 					add_action( 'redux/customizer/control/render/' . $this->parent->args['opt_name'] . '-' . $option['id'], array( $this, 'render' ) );
555 555
 
556 556
 					$option['permissions'] = $option['permissions'] ?? 'edit_theme_options';
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 						++$order['option'];
562 562
 					}
563 563
 
564
-					if ( ! empty( $this->options_defaults[ $option['id'] ] ) ) {
564
+					if ( ! empty( $this->options_defaults[$option['id']] ) ) {
565 565
 						$option['default'] = $this->options_defaults['option']['id'];
566 566
 					}
567 567
 
@@ -634,12 +634,12 @@  discard block
 block discarded – undo
634 634
 						)
635 635
 					);
636 636
 
637
-					$section['fields'][ $skey ]['name'] = $option['id'];
638
-					if ( ! isset( $section['fields'][ $skey ]['class'] ) ) { // No errors please.
639
-						$section['fields'][ $skey ]['class'] = '';
637
+					$section['fields'][$skey]['name'] = $option['id'];
638
+					if ( ! isset( $section['fields'][$skey]['class'] ) ) { // No errors please.
639
+						$section['fields'][$skey]['class'] = '';
640 640
 					}
641 641
 
642
-					$this->controls[ $section['fields'][ $skey ]['id'] ] = $section['fields'][ $skey ];
642
+					$this->controls[$section['fields'][$skey]['id']] = $section['fields'][$skey];
643 643
 				}
644 644
 			}
645 645
 		}
@@ -706,11 +706,11 @@  discard block
 block discarded – undo
706 706
 					if ( strpos( $key, $this->parent->args['opt_name'] ) !== false ) {
707 707
 						$key = str_replace( $this->parent->args['opt_name'] . '[', '', rtrim( $key, ']' ) );
708 708
 
709
-						if ( ! isset( $this->orig_options[ $key ] ) || $value !== $this->orig_options[ $key ] || ( isset( $this->orig_options[ $key ] ) && ! empty( $this->orig_options[ $key ] ) && empty( $value ) ) ) {
710
-							$this->parent->options[ $key ] = $value;
709
+						if ( ! isset( $this->orig_options[$key] ) || $value !== $this->orig_options[$key] || ( isset( $this->orig_options[$key] ) && ! empty( $this->orig_options[$key] ) && empty( $value ) ) ) {
710
+							$this->parent->options[$key] = $value;
711 711
 							$changed                       = true;
712 712
 
713
-							if ( isset( $this->parent->compiler_fields[ $key ] ) ) {
713
+							if ( isset( $this->parent->compiler_fields[$key] ) ) {
714 714
 								$compiler = true;
715 715
 							}
716 716
 						}
@@ -813,8 +813,8 @@  discard block
 block discarded – undo
813 813
 			if ( strpos( wp_json_encode( $value ), 'data' ) > 0 ) {
814 814
 				$replace = $value;
815 815
 				foreach ( $replace as $sub_array ) {
816
-					$cs_array                 = (array) json_decode( rawurldecode( $sub_array['data'] ) );
817
-					$value[ $cs_array['id'] ] = $cs_array;
816
+					$cs_array                 = ( array ) json_decode( rawurldecode( $sub_array['data'] ) );
817
+					$value[$cs_array['id']] = $cs_array;
818 818
 				}
819 819
 			}
820 820
 
Please login to merge, or discard this patch.
Indentation   +819 added lines, -819 removed lines patch added patch discarded remove patch
@@ -14,828 +14,828 @@
 block discarded – undo
14 14
 // Don't duplicate me!
15 15
 if ( ! class_exists( 'Redux_Extension_Customizer', false ) ) {
16 16
 
17
-	/**
18
-	 * Main ReduxFramework customizer extension class
19
-	 *
20
-	 * @since       1.0.0
21
-	 */
22
-	class Redux_Extension_Customizer extends Redux_Extension_Abstract {
23
-
24
-		/**
25
-		 * Set extension version.
26
-		 *
27
-		 * @var string
28
-		 */
29
-		public static $version = '4.5.1';
30
-
31
-		/**
32
-		 * Set the name of the field.  Ideally, this will also be your extension's name.
33
-		 * Please use underscores and NOT dashes.
34
-		 *
35
-		 * @var string
36
-		 */
37
-		public string $field_name = 'customizer';
38
-
39
-		/**
40
-		 * Set the friendly name of the extension.  This is for display purposes.  No underscores or dashes are required.
41
-		 *
42
-		 * @var string
43
-		 */
44
-		public string $extension_name = 'Customizer';
45
-
46
-		/**
47
-		 * Original options.
48
-		 *
49
-		 * @var array|null
50
-		 */
51
-		private ?array $orig_options = array();
52
-
53
-		/**
54
-		 * Post values.
55
-		 *
56
-		 * @var array|null
57
-		 */
58
-		private static ?array $post_values = array();
59
-
60
-		/**
61
-		 * Options array.
62
-		 *
63
-		 * @var array|null
64
-		 */
65
-		public ?array $options = array();
66
-
67
-		/**
68
-		 * Controls array.
69
-		 *
70
-		 * @var array|null
71
-		 */
72
-		public ?array $controls = array();
73
-
74
-		/**
75
-		 * Before save array.
76
-		 *
77
-		 * @var array|null
78
-		 */
79
-		public ?array $before_save = array();
80
-
81
-		/**
82
-		 * Redux object.
83
-		 *
84
-		 * @var ReduxFramework|null
85
-		 */
86
-		protected ?ReduxFramework $redux;
87
-
88
-		/**
89
-		 * Field array.
90
-		 *
91
-		 * @var array|null
92
-		 */
93
-		private ?array $redux_fields = array();
94
-
95
-		/**
96
-		 * Redux_Extension_my_extension constructor.
97
-		 *
98
-		 * @param ReduxFramework $redux ReduxFramework pointer.
99
-		 */
100
-		public function __construct( $redux ) {
101
-			global $pagenow;
102
-			global $wp_customize;
103
-
104
-			parent::__construct( $redux, __FILE__ );
105
-
106
-			if ( is_admin() && ! isset( $wp_customize ) && 'customize.php' !== $pagenow && 'admin-ajax.php' !== $pagenow ) {
107
-				return;
108
-			}
109
-
110
-			$this->add_field( 'customizer' );
111
-
112
-			$this->load();
113
-		}
114
-
115
-		/**
116
-		 * The customizer load code
117
-		 */
118
-		private function load() {
119
-			global $pagenow, $wp_customize;
120
-
121
-			if ( false === $this->parent->args['customizer'] ) {
122
-				return;
123
-			}
124
-
125
-			// Override the Redux_Core class.
126
-			add_filter( "redux/extension/{$this->parent->args['opt_name']}/customizer", array( $this, 'remove_core_customizer_class' ) );
127
-
128
-			if ( ! isset( $wp_customize ) && 'customize.php' !== $pagenow && 'admin-ajax.php' !== $pagenow ) {
129
-				return;
130
-			}
131
-
132
-			self::get_post_values();
133
-
134
-			if ( isset( $_POST['wp_customize'] ) && 'on' === $_POST['wp_customize'] ) { // phpcs:ignore WordPress.Security.NonceVerification
135
-				$this->parent->args['customizer_only'] = true;
136
-			}
137
-
138
-			if ( isset( $_POST['wp_customize'] ) && 'on' === $_POST['wp_customize'] && ! empty( $_POST['customized'] ) && ! isset( $_POST['action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
139
-				add_action( "redux/options/{$this->parent->args['opt_name']}/options", array( $this, 'override_values' ), 100 );
140
-			}
141
-
142
-			add_action( 'customize_register', array( $this, 'register_customizer_controls' ) ); // Create controls.
143
-			add_action( 'wp_head', array( $this, 'customize_preview_init' ) );
144
-
145
-			add_action( 'customize_save_after', array( &$this, 'customizer_save_after' ) ); // After save.
146
-
147
-			// Add global controls CSS file.
148
-			add_action( 'customize_controls_print_scripts', array( $this, 'enqueue_controls_css' ) );
149
-			add_action( 'customize_controls_init', array( $this, 'enqueue_panel_css' ) );
150
-			add_action( 'wp_enqueue_styles', array( $this, 'custom_css' ), 11 );
151
-
152
-			add_action( 'redux/extension/customizer/control_init', array( $this, 'create_field_classes' ), 1, 2 );
153
-
154
-			add_action( 'wp_ajax_' . $this->parent->args['opt_name'] . '_customizer_save', array( $this, 'customizer' ) );
155
-			add_action( 'customize_controls_print_styles', array( $this, 'add_nonce_html' ) );
156
-		}
157
-
158
-		/**
159
-		 * Add nonce HTML for AJAX.
160
-		 */
161
-		public function add_nonce_html() {
162
-			$nonce = wp_create_nonce( 'redux_customer_nonce' );
163
-
164
-			?>
17
+    /**
18
+     * Main ReduxFramework customizer extension class
19
+     *
20
+     * @since       1.0.0
21
+     */
22
+    class Redux_Extension_Customizer extends Redux_Extension_Abstract {
23
+
24
+        /**
25
+         * Set extension version.
26
+         *
27
+         * @var string
28
+         */
29
+        public static $version = '4.5.1';
30
+
31
+        /**
32
+         * Set the name of the field.  Ideally, this will also be your extension's name.
33
+         * Please use underscores and NOT dashes.
34
+         *
35
+         * @var string
36
+         */
37
+        public string $field_name = 'customizer';
38
+
39
+        /**
40
+         * Set the friendly name of the extension.  This is for display purposes.  No underscores or dashes are required.
41
+         *
42
+         * @var string
43
+         */
44
+        public string $extension_name = 'Customizer';
45
+
46
+        /**
47
+         * Original options.
48
+         *
49
+         * @var array|null
50
+         */
51
+        private ?array $orig_options = array();
52
+
53
+        /**
54
+         * Post values.
55
+         *
56
+         * @var array|null
57
+         */
58
+        private static ?array $post_values = array();
59
+
60
+        /**
61
+         * Options array.
62
+         *
63
+         * @var array|null
64
+         */
65
+        public ?array $options = array();
66
+
67
+        /**
68
+         * Controls array.
69
+         *
70
+         * @var array|null
71
+         */
72
+        public ?array $controls = array();
73
+
74
+        /**
75
+         * Before save array.
76
+         *
77
+         * @var array|null
78
+         */
79
+        public ?array $before_save = array();
80
+
81
+        /**
82
+         * Redux object.
83
+         *
84
+         * @var ReduxFramework|null
85
+         */
86
+        protected ?ReduxFramework $redux;
87
+
88
+        /**
89
+         * Field array.
90
+         *
91
+         * @var array|null
92
+         */
93
+        private ?array $redux_fields = array();
94
+
95
+        /**
96
+         * Redux_Extension_my_extension constructor.
97
+         *
98
+         * @param ReduxFramework $redux ReduxFramework pointer.
99
+         */
100
+        public function __construct( $redux ) {
101
+            global $pagenow;
102
+            global $wp_customize;
103
+
104
+            parent::__construct( $redux, __FILE__ );
105
+
106
+            if ( is_admin() && ! isset( $wp_customize ) && 'customize.php' !== $pagenow && 'admin-ajax.php' !== $pagenow ) {
107
+                return;
108
+            }
109
+
110
+            $this->add_field( 'customizer' );
111
+
112
+            $this->load();
113
+        }
114
+
115
+        /**
116
+         * The customizer load code
117
+         */
118
+        private function load() {
119
+            global $pagenow, $wp_customize;
120
+
121
+            if ( false === $this->parent->args['customizer'] ) {
122
+                return;
123
+            }
124
+
125
+            // Override the Redux_Core class.
126
+            add_filter( "redux/extension/{$this->parent->args['opt_name']}/customizer", array( $this, 'remove_core_customizer_class' ) );
127
+
128
+            if ( ! isset( $wp_customize ) && 'customize.php' !== $pagenow && 'admin-ajax.php' !== $pagenow ) {
129
+                return;
130
+            }
131
+
132
+            self::get_post_values();
133
+
134
+            if ( isset( $_POST['wp_customize'] ) && 'on' === $_POST['wp_customize'] ) { // phpcs:ignore WordPress.Security.NonceVerification
135
+                $this->parent->args['customizer_only'] = true;
136
+            }
137
+
138
+            if ( isset( $_POST['wp_customize'] ) && 'on' === $_POST['wp_customize'] && ! empty( $_POST['customized'] ) && ! isset( $_POST['action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
139
+                add_action( "redux/options/{$this->parent->args['opt_name']}/options", array( $this, 'override_values' ), 100 );
140
+            }
141
+
142
+            add_action( 'customize_register', array( $this, 'register_customizer_controls' ) ); // Create controls.
143
+            add_action( 'wp_head', array( $this, 'customize_preview_init' ) );
144
+
145
+            add_action( 'customize_save_after', array( &$this, 'customizer_save_after' ) ); // After save.
146
+
147
+            // Add global controls CSS file.
148
+            add_action( 'customize_controls_print_scripts', array( $this, 'enqueue_controls_css' ) );
149
+            add_action( 'customize_controls_init', array( $this, 'enqueue_panel_css' ) );
150
+            add_action( 'wp_enqueue_styles', array( $this, 'custom_css' ), 11 );
151
+
152
+            add_action( 'redux/extension/customizer/control_init', array( $this, 'create_field_classes' ), 1, 2 );
153
+
154
+            add_action( 'wp_ajax_' . $this->parent->args['opt_name'] . '_customizer_save', array( $this, 'customizer' ) );
155
+            add_action( 'customize_controls_print_styles', array( $this, 'add_nonce_html' ) );
156
+        }
157
+
158
+        /**
159
+         * Add nonce HTML for AJAX.
160
+         */
161
+        public function add_nonce_html() {
162
+            $nonce = wp_create_nonce( 'redux_customer_nonce' );
163
+
164
+            ?>
165 165
 			<div class="redux-customizer-nonce" data-nonce="<?php echo esc_attr( $nonce ); ?>"></div>
166 166
 			<?php
167
-		}
168
-
169
-		/**
170
-		 * AJAX callback for customizer save...to make sanitize/validate work.
171
-		 */
172
-		public function customizer() {
173
-			try {
174
-				$return_array = array();
175
-
176
-				if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['nonce'] ) ), 'redux_customer_nonce' ) && isset( $_POST['opt_name'] ) && '' !== $_POST['opt_name'] ) {
177
-					$redux = Redux::instance( sanitize_text_field( wp_unslash( $_POST['opt_name'] ) ) );
178
-
179
-					$post_data = wp_unslash( $_POST['data'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
180
-
181
-					// New method to avoid input_var nonsense.  Thanks @harunbasic.
182
-					$values = Redux_Functions_Ex::parse_str( $post_data );
183
-
184
-					$all_options = get_option( sanitize_text_field( wp_unslash( $_POST['opt_name'] ) ) );
185
-
186
-					$values = wp_parse_args( $values, $all_options );
187
-
188
-					$redux->options_class->set( $redux->options_class->validate_options( $values ) );
189
-
190
-					$redux->enqueue_class->get_warnings_and_errors_array();
191
-
192
-					$return_array = array(
193
-						'status'   => 'success',
194
-						'options'  => $redux->options,
195
-						'errors'   => $redux->enqueue_class->localize_data['errors'] ?? null,
196
-						'warnings' => $redux->enqueue_class->localize_data['warnings'] ?? null,
197
-						'sanitize' => $redux->enqueue_class->localize_data['sanitize'] ?? null,
198
-					);
199
-				}
200
-			} catch ( Exception $e ) {
201
-				$return_array = array( 'status' => $e->getMessage() );
202
-			}
203
-
204
-			echo wp_json_encode( $return_array );
205
-
206
-			die;
207
-		}
208
-
209
-		/**
210
-		 * Field classes.
211
-		 *
212
-		 * @param array $option Option.
213
-		 */
214
-		public function create_field_classes( array $option ) {
215
-			if ( empty( $this->redux_fields ) ) {
216
-				$file_paths = glob( Redux_Core::$dir . 'inc/fields/*' );
217
-
218
-				foreach ( $file_paths as $file ) {
219
-					if ( 'section' !== $file && 'divide' !== $file && 'editor' !== $file ) {
220
-						$this->redux_fields[] = str_replace( Redux_Core::$dir . 'inc/fields/', '', $file );
221
-					}
222
-				}
223
-
224
-				$file_paths = glob( Redux_Core::$dir . 'inc/extensions/*' );
225
-
226
-				foreach ( $file_paths as $file ) {
227
-					if ( 'section' !== $file && 'divide' !== $file && 'editor' !== $file ) {
228
-						$this->redux_fields[] = str_replace( Redux_Core::$dir . 'inc/extensions/', '', $file );
229
-					}
230
-				}
231
-			}
232
-
233
-			$class_name = 'Redux_Customizer_Control_' . $option['type'];
234
-
235
-			if ( ! class_exists( $class_name ) && ( in_array( $option['type'], $this->redux_fields, true ) || ( isset( $option['customizer_enabled'] ) && $option['customizer_enabled'] ) ) ) {
236
-				$upload_dir = Redux_Core::$upload_dir;
237
-
238
-				if ( ! file_exists( $upload_dir . $option['type'] . '.php' ) ) {
239
-					if ( ! is_dir( $upload_dir ) ) {
240
-						Redux_Core::$filesystem->execute( 'mkdir', $upload_dir );
241
-					}
242
-
243
-					$template = str_replace( '{{type}}', $option['type'], '<?php' . PHP_EOL . '   class Redux_Customizer_Control_{{type}} extends Redux_Customizer_Control {' . PHP_EOL . '     public $type = "redux-{{type}}";' . PHP_EOL . '   }' );
244
-
245
-					Redux_Core::$filesystem->execute( 'put_contents', $upload_dir . $option['type'] . '.php', array( 'content' => $template ) );
246
-				}
247
-
248
-				if ( file_exists( $upload_dir . $option['type'] . '.php' ) ) {
249
-					include_once $upload_dir . $option['type'] . '.php';
250
-				}
251
-			}
252
-		}
253
-
254
-		/**
255
-		 * Enqueue extension scripts/styles.
256
-		 */
257
-		public function enqueue_controls_css() {
258
-			$this->parent->enqueue_class->get_warnings_and_errors_array();
259
-			$this->parent->enqueue_class->init();
260
-
261
-			if ( $this->parent->args['dev_mode'] ) {
262
-				wp_enqueue_style(
263
-					'redux-extension-customizer',
264
-					$this->extension_url . 'redux-extension-customizer.css',
265
-					array(),
266
-					self::$version
267
-				);
268
-			}
269
-
270
-			wp_enqueue_script(
271
-				'redux-extension-customizer',
272
-				$this->extension_url . 'redux-extension-customizer' . Redux_Functions::is_min() . '.js',
273
-				array( 'jquery', 'redux-js' ),
274
-				self::$version,
275
-				true
276
-			);
277
-
278
-			wp_localize_script(
279
-				'redux-extension-customizer',
280
-				'redux_customizer',
281
-				array(
282
-					'body_class' => sanitize_html_class( 'admin-color-' . get_user_option( 'admin_color' ), 'fresh' ),
283
-				)
284
-			);
285
-		}
286
-
287
-		/**
288
-		 * Enqueue panel CSS>
289
-		 */
290
-		public function enqueue_panel_css() {}
291
-
292
-		/**
293
-		 * Remove core customizer class.
294
-		 *
295
-		 * @return string
296
-		 */
297
-		public function remove_core_customizer_class(): string {
298
-			return '';
299
-		}
300
-
301
-		/**
302
-		 * Customize preview init.
303
-		 */
304
-		public function customize_preview_init() {
305
-			// phpcs:ignore WordPress.NamingConventions.ValidHookName
306
-			do_action( 'redux/customizer/live_preview' );
307
-		}
308
-
309
-		/**
310
-		 * Get post values.
311
-		 */
312
-		protected static function get_post_values() {
313
-			if ( empty( self::$post_values ) && ! empty( $_POST['customized'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
314
-				$the_data = json_decode( stripslashes_deep( ( wp_unslash( $_POST['customized'] ) ) ), true ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput
315
-
316
-				foreach ( $the_data as $key => $value ) {
317
-					if ( strpos( wp_json_encode( $value ), 'data' ) > 0 ) {
318
-						foreach ( $value as $k => $v ) {
319
-							$decode           = (array) json_decode( rawurldecode( $v['data'] ) );
320
-							$v                = $decode;
321
-							$dumb_array[ $k ] = $v;
322
-							$the_data[ $key ] = $dumb_array;
323
-						}
324
-					}
325
-				}
326
-
327
-				self::$post_values = $the_data;
328
-			}
329
-		}
330
-
331
-		/**
332
-		 * Override customizer values.
333
-		 *
334
-		 * @param array $data Values.
335
-		 *
336
-		 * @return array
337
-		 */
338
-		public function override_values( array $data ): array {
339
-			self::get_post_values();
340
-
341
-			if ( isset( $_POST['customized'] ) && ! empty( self::$post_values ) ) { // phpcs:ignore WordPress.Security.NonceVerification
342
-				if ( is_array( self::$post_values ) ) {
343
-					foreach ( self::$post_values as $key => $value ) {
344
-						if ( strpos( $key, $this->parent->args['opt_name'] ) !== false ) {
345
-							$key          = str_replace( $this->parent->args['opt_name'] . '[', '', rtrim( $key, ']' ) );
346
-							$data[ $key ] = $value;
347
-
348
-							$GLOBALS[ $this->parent->args['global_variable'] ][ $key ] = $value;
349
-							$this->parent->options[ $key ]                             = $value;
350
-						}
351
-					}
352
-				}
353
-			}
354
-
355
-			return $data;
356
-		}
357
-
358
-		/**
359
-		 * Render Redux fields.
360
-		 *
361
-		 * @param object $control .
362
-		 */
363
-		public function render( object $control ) {
364
-			$field_id = str_replace( $this->parent->args['opt_name'] . '-', '', $control->redux_id );
365
-			$field    = $this->options[ $field_id ];
366
-
367
-			if ( ! empty( $field['compiler'] ) ) {
368
-				echo '<tr class="compiler">';
369
-			} else {
370
-				echo '<tr>';
371
-			}
372
-
373
-			echo '<th scope="row">' . wp_kses_post( $this->parent->field_head[ $field['id'] ] ) . '</th>';
374
-			echo '<td>';
375
-
376
-			$field['name'] = $field['id'];
377
-			$this->parent->render_class->field_input( $field );
378
-
379
-			echo '</td>';
380
-			echo '</tr>';
381
-		}
382
-
383
-		// All sections, settings, and controls will be added here.
384
-
385
-		/**
386
-		 * Register customizer controls.
387
-		 *
388
-		 * @param WP_Customize_Manager $wp_customize .
389
-		 *
390
-		 * @throws ReflectionException Exception.
391
-		 */
392
-		public function register_customizer_controls( WP_Customize_Manager $wp_customize ) {
393
-			if ( ! class_exists( 'Redux_Customizer_Section' ) ) {
394
-				require_once __DIR__ . '/inc/class-redux-customizer-section.php';
395
-
396
-				if ( method_exists( $wp_customize, 'register_section_type' ) ) {
397
-					$wp_customize->register_section_type( 'Redux_Customizer_Section' );
398
-				}
399
-			}
400
-
401
-			if ( ! class_exists( 'Redux_Customizer_Panel' ) ) {
402
-				require_once __DIR__ . '/inc/class-redux-customizer-panel.php';
403
-
404
-				if ( method_exists( $wp_customize, 'register_panel_type' ) ) {
405
-					$wp_customize->register_panel_type( 'Redux_Customizer_Panel' );
406
-				}
407
-			}
408
-
409
-			if ( ! class_exists( 'Redux_Customizer_Control' ) ) {
410
-				require_once __DIR__ . '/inc/class-redux-customizer-control.php';
411
-			}
412
-
413
-			// phpcs:ignore WordPress.NamingConventions.ValidHookName
414
-			do_action( 'redux/extension/customizer/control/includes' );
415
-
416
-			$order = array(
417
-				'heading' => - 500,
418
-				'option'  => - 500,
419
-			);
420
-
421
-			$panel = '';
422
-
423
-			$this->parent->args['options_api'] = false;
424
-			$this->parent->options_class->register();
425
-
426
-			$parent_section_id = null;
427
-			$new_parent        = true;
428
-
429
-			foreach ( $this->parent->sections as $key => $section ) {
430
-				// Not a type that should go on the customizer.
431
-
432
-				foreach ( $section['fields'] as $field ) {
433
-					if ( 'color_scheme' === $field['type'] || 'divide' === $field['type'] ) {
434
-						continue 2;
435
-					}
436
-				}
437
-
438
-				if ( isset( $section['id'] ) && 'import/export' === $section['id'] ) {
439
-					continue;
440
-				}
441
-
442
-				// If section customizer is set to false.
443
-				if ( isset( $section['customizer'] ) && false === $section['customizer'] ) {
444
-					continue;
445
-				}
446
-
447
-				// if we are in a subsection and parent is set to customizer false !!!
448
-				if ( ( isset( $section['subsection'] ) && $section['subsection'] ) ) {
449
-					if ( $new_parent ) {
450
-						$new_parent        = false;
451
-						$parent_section_id = ( $key - 1 );
452
-					}
453
-				} else { // not a subsection reset.
454
-					$parent_section_id = null;
455
-					$new_parent        = true;
456
-				}
457
-				if ( isset( $parent_section_id ) && ( isset( $this->parent->sections[ $parent_section_id ]['customizer'] ) && false === $this->parent->sections[ $parent_section_id ]['customizer'] ) ) {
458
-					continue;
459
-				}
460
-
461
-				$section['permissions'] = $section['permissions'] ?? 'edit_theme_options';
462
-
463
-				// No errors please.
464
-				if ( ! isset( $section['desc'] ) ) {
465
-					$section['desc'] = '';
466
-				}
467
-
468
-				// Fill the description if there is a subtitle.
469
-				if ( empty( $section['desc'] ) && ! empty( $section['subtitle'] ) ) {
470
-					$section['desc'] = $section['subtitle'];
471
-				}
472
-
473
-				// No title is present, let's show what section is missing a title.
474
-				if ( ! isset( $section['title'] ) ) {
475
-					$section['title'] = '';
476
-				}
477
-
478
-				// Let's make a section ID from the title.
479
-				if ( empty( $section['id'] ) ) {
480
-					$section['id'] = Redux_Core::strtolower( str_replace( ' ', '', $section['title'] ) );
481
-				}
482
-
483
-				// Let's set a default priority.
484
-				if ( empty( $section['priority'] ) ) {
485
-					$section['priority'] = $order['heading'];
486
-					++$order['heading'];
487
-				}
488
-				$section['id'] = $this->parent->args['opt_name'] . '-' . $section['id'];
489
-
490
-				if ( method_exists( $wp_customize, 'add_panel' ) && ( ! isset( $section['subsection'] ) || ( true !== $section['subsection'] ) ) && isset( $this->parent->sections[ ( $key + 1 ) ]['subsection'] ) && $this->parent->sections[ ( $key + 1 ) ]['subsection'] ) {
491
-					$this->add_panel(
492
-						$this->parent->args['opt_name'] . '-' . $section['id'],
493
-						array(
494
-							'priority'    => $section['priority'],
495
-							'capability'  => $section['permissions'],
496
-							'title'       => $section['title'],
497
-							'section'     => $section,
498
-							'opt_name'    => $this->parent->args['opt_name'],
499
-							'description' => '',
500
-						),
501
-						$wp_customize
502
-					);
503
-
504
-					$panel = $this->parent->args['opt_name'] . '-' . $section['id'];
505
-
506
-					$this->add_section(
507
-						$section['id'],
508
-						array(
509
-							'title'       => $section['title'],
510
-							'priority'    => $section['priority'],
511
-							'description' => $section['desc'],
512
-							'section'     => $section,
513
-							'opt_name'    => $this->parent->args['opt_name'],
514
-							'capability'  => $section['permissions'],
515
-							'panel'       => $panel,
516
-						),
517
-						$wp_customize
518
-					);
519
-				} else {
520
-					if ( ! isset( $section['subsection'] ) || ( true !== $section['subsection'] ) ) {
521
-						$panel = '';
522
-					}
523
-
524
-					$this->add_section(
525
-						$section['id'],
526
-						array(
527
-							'title'       => $section['title'],
528
-							'priority'    => $section['priority'],
529
-							'description' => $section['desc'],
530
-							'opt_name'    => $this->parent->args['opt_name'],
531
-							'section'     => $section,
532
-							'capability'  => $section['permissions'],
533
-							'panel'       => $panel,
534
-						),
535
-						$wp_customize
536
-					);
537
-				}
538
-
539
-				if ( ( empty( $section['fields'] ) ) ) {
540
-					continue;
541
-				}
542
-
543
-				foreach ( $section['fields'] as $skey => $option ) {
544
-
545
-					if ( isset( $option['customizer'] ) && false === $option['customizer'] ) {
546
-						continue;
547
-					}
548
-
549
-					if ( false === $this->parent->args['customizer'] && ( ! isset( $option['customizer'] ) || true !== $option['customizer'] ) ) {
550
-						continue;
551
-					}
552
-
553
-					$this->options[ $option['id'] ] = $option;
554
-					add_action( 'redux/customizer/control/render/' . $this->parent->args['opt_name'] . '-' . $option['id'], array( $this, 'render' ) );
555
-
556
-					$option['permissions'] = $option['permissions'] ?? 'edit_theme_options';
557
-
558
-					// Change the item priority if not set.
559
-					if ( 'heading' !== $option['type'] && ! isset( $option['priority'] ) ) {
560
-						$option['priority'] = $order['option'];
561
-						++$order['option'];
562
-					}
563
-
564
-					if ( ! empty( $this->options_defaults[ $option['id'] ] ) ) {
565
-						$option['default'] = $this->options_defaults['option']['id'];
566
-					}
567
-
568
-					if ( ! isset( $option['default'] ) ) {
569
-						$option['default'] = '';
570
-					}
571
-					if ( ! isset( $option['title'] ) ) {
572
-						$option['title'] = '';
573
-					}
574
-
575
-					$option['id'] = $this->parent->args['opt_name'] . '[' . $option['id'] . ']';
576
-
577
-					if ( 'heading' !== $option['type'] && 'import_export' !== $option['type'] && ! empty( $option['type'] ) ) {
578
-
579
-						$wp_customize->add_setting(
580
-							$option['id'],
581
-							array(
582
-								'default'           => $option['default'],
583
-								'transport'         => 'refresh',
584
-								'opt_name'          => $this->parent->args['opt_name'],
585
-								'sanitize_callback' => array( $this, 'field_validation' ),
586
-							)
587
-						);
588
-					}
589
-
590
-					if ( ! empty( $option['data'] ) && empty( $option['options'] ) ) {
591
-						if ( empty( $option['args'] ) ) {
592
-							$option['args'] = array();
593
-						}
594
-
595
-						if ( 'elusive-icons' === $option['data'] || 'elusive-icon' === $option['data'] || 'elusive' === $option['data'] ) {
596
-							$icons_file = Redux_Core::$dir . 'inc/fields/select/elusive-icons.php';
597
-
598
-							// phpcs:ignore WordPress.NamingConventions.ValidHookName
599
-							$icons_file = apply_filters( 'redux-font-icons-file', $icons_file );
600
-
601
-							if ( file_exists( $icons_file ) ) {
602
-								require_once $icons_file;
603
-							}
604
-						}
605
-						$option['options'] = $this->parent->wordpress_data->get( $option['data'], $option['args'] );
606
-					}
607
-
608
-					$class_name = 'Redux_Customizer_Control_' . $option['type'];
609
-
610
-					// phpcs:ignore WordPress.NamingConventions.ValidHookName
611
-					do_action( 'redux/extension/customizer/control_init', $option );
612
-
613
-					if ( ! class_exists( $class_name ) ) {
614
-						continue;
615
-					}
616
-
617
-					$wp_customize->add_control(
618
-						new $class_name(
619
-							$wp_customize,
620
-							$option['id'],
621
-							array(
622
-								'label'           => $option['title'],
623
-								'section'         => $section['id'],
624
-								'settings'        => $option['id'],
625
-								'type'            => 'redux-' . $option['type'],
626
-								'field'           => $option,
627
-								'ReduxFramework'  => $this->parent,
628
-								'active_callback' => ( isset( $option['required'] ) && class_exists( 'Redux_Customizer_Active_Callback' ) ) ? array(
629
-									'Redux_Customizer_Active_Callback',
630
-									'evaluate',
631
-								) : '__return_true',
632
-								'priority'        => $option['priority'],
633
-							)
634
-						)
635
-					);
636
-
637
-					$section['fields'][ $skey ]['name'] = $option['id'];
638
-					if ( ! isset( $section['fields'][ $skey ]['class'] ) ) { // No errors please.
639
-						$section['fields'][ $skey ]['class'] = '';
640
-					}
641
-
642
-					$this->controls[ $section['fields'][ $skey ]['id'] ] = $section['fields'][ $skey ];
643
-				}
644
-			}
645
-		}
646
-
647
-		/**
648
-		 * Add customizer section.
649
-		 *
650
-		 * @param string               $id           ID.
651
-		 * @param array                $args         Args.
652
-		 * @param WP_Customize_Manager $wp_customize .
653
-		 */
654
-		public function add_section( string $id, array $args, WP_Customize_Manager $wp_customize ) {
655
-
656
-			if ( is_a( $id, 'WP_Customize_Section' ) ) {
657
-				$section = $id;
658
-			} else {
659
-				$section = new Redux_Customizer_Section( $wp_customize, $id, $args );
660
-			}
661
-
662
-			$wp_customize->add_section( $section, $args );
663
-		}
664
-
665
-		/**
666
-		 * Add a customize panel.
667
-		 *
668
-		 * @param WP_Customize_Panel|string $id           Customize Panel object, or Panel ID.
669
-		 * @param array                     $args         Optional. Panel arguments. Default empty array.
670
-		 * @param WP_Customize_Manager      $wp_customize .
671
-		 *
672
-		 * @since  4.0.0
673
-		 * @access public
674
-		 */
675
-		public function add_panel( $id, array $args, WP_Customize_Manager $wp_customize ) {
676
-			if ( is_a( $id, 'WP_Customize_Panel' ) ) {
677
-				$panel = $id;
678
-			} else {
679
-				$panel = new Redux_Customizer_Panel( $wp_customize, $id, $args );
680
-			}
681
-
682
-			$wp_customize->add_panel( $panel, $args );
683
-		}
684
-
685
-		/**
686
-		 * Actions to take after customizer save.
687
-		 *
688
-		 * @throws ReflectionException Exception.
689
-		 */
690
-		public function customizer_save_after() {
691
-			if ( empty( $this->parent->options ) ) {
692
-				$this->parent->get_options();
693
-			}
694
-
695
-			if ( empty( $this->orig_options ) && ! empty( $this->parent->options ) ) {
696
-				$this->orig_options = $this->parent->options;
697
-			}
698
-
699
-			if ( isset( $_POST['customized'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
700
-				$options = json_decode( sanitize_text_field( wp_unslash( $_POST['customized'] ) ), true ); // phpcs:ignore WordPress.Security.NonceVerification
701
-
702
-				$compiler = false;
703
-				$changed  = false;
704
-
705
-				foreach ( $options as $key => $value ) {
706
-					if ( strpos( $key, $this->parent->args['opt_name'] ) !== false ) {
707
-						$key = str_replace( $this->parent->args['opt_name'] . '[', '', rtrim( $key, ']' ) );
708
-
709
-						if ( ! isset( $this->orig_options[ $key ] ) || $value !== $this->orig_options[ $key ] || ( isset( $this->orig_options[ $key ] ) && ! empty( $this->orig_options[ $key ] ) && empty( $value ) ) ) {
710
-							$this->parent->options[ $key ] = $value;
711
-							$changed                       = true;
712
-
713
-							if ( isset( $this->parent->compiler_fields[ $key ] ) ) {
714
-								$compiler = true;
715
-							}
716
-						}
717
-					}
718
-				}
719
-
720
-				if ( $changed ) {
721
-					$this->parent->options_class->set( $this->parent->options );
722
-					if ( $compiler ) {
723
-						// Have to set this to stop the output of the CSS and typography stuff.
724
-						Redux_Core::$no_output = true;
725
-						$this->parent->output_class->enqueue();
726
-
727
-						// phpcs:ignore WordPress.NamingConventions.ValidHookName
728
-						do_action( "redux/options/{$this->parent->args['opt_name']}/compiler", $this->parent->options, $this->parent->compilerCSS );
729
-
730
-						// phpcs:ignore WordPress.NamingConventions.ValidHookName
731
-						do_action( "redux/options/{$this->parent->args['opt_name']}/compiler/advanced", $this->parent );
732
-					}
733
-				}
734
-			}
735
-		}
736
-
737
-		/**
738
-		 * Enqueue CSS/JS for the customizer controls
739
-		 *
740
-		 * @since       1.0.0
741
-		 * @access      public
742
-		 * @global      $wp_styles
743
-		 * @return      void
744
-		 */
745
-		public function enqueue() {
746
-			$localize = array(
747
-				'save_pending'   => esc_html__( 'You have changes that are not saved.  Would you like to save them now?', 'redux-framework' ),
748
-				'reset_confirm'  => esc_html__( 'Are you sure?  Resetting will lose all custom values.', 'redux-framework' ),
749
-				'preset_confirm' => esc_html__( 'Your current options will be replaced with the values of this preset.  Would you like to proceed?', 'redux-framework' ),
750
-				'opt_name'       => $this->parent->args['opt_name'],
751
-				'field'          => $this->parent->options,
752
-				'defaults'       => $this->parent->options_defaults,
753
-				'folds'          => Redux_Core::$folds,
754
-			);
755
-
756
-			// Values used by the javascript.
757
-			wp_localize_script( 'redux-js', 'redux_opts', $localize );
758
-
759
-			// phpcs:ignore WordPress.NamingConventions.ValidHookName
760
-			do_action( 'redux-enqueue-' . $this->parent->args['opt_name'] );
761
-
762
-			foreach ( $this->parent->sections as $section ) {
763
-				if ( isset( $section['fields'] ) ) {
764
-					foreach ( $section['fields'] as $field ) {
765
-						if ( isset( $field['type'] ) ) {
766
-							$field_classes = array( 'Redux_' . $field['type'], 'ReduxFramework_' . $field['type'] );
767
-
768
-							$field_class = Redux_Functions::class_exists_ex( $field_classes );
769
-
770
-							if ( false === $field_class ) {
771
-
772
-								// phpcs:ignore WordPress.NamingConventions.ValidHookName
773
-								$class_file = apply_filters( 'redux-typeclass-load', $this->path . 'inc/fields/' . $field['type'] . '/field_' . $field['type'] . '.php', $field_class );
774
-
775
-								if ( $class_file ) {
776
-									require_once $class_file;
777
-
778
-									$field_class = Redux_Functions::class_exists_ex( $field_classes );
779
-
780
-								}
781
-							}
782
-
783
-							if ( class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) {
784
-								$enqueue = new $field_class( '', '', $this );
785
-								$enqueue->enqueue();
786
-							}
787
-						}
788
-					}
789
-				}
790
-			}
791
-		}
792
-
793
-		/**
794
-		 * Register Option for use
795
-		 *
796
-		 * @since       1.0.0
797
-		 * @access      public
798
-		 * @return      void
799
-		 */
800
-		public function register_setting() {
801
-		}
802
-
803
-		/**
804
-		 * Validate the options before insertion
805
-		 *
806
-		 * @param array|string $value The options array.
807
-		 *
808
-		 * @return array|string $value
809
-		 * @since       3.0.0
810
-		 * @access      public
811
-		 */
812
-		public function field_validation( $value ) {
813
-			if ( strpos( wp_json_encode( $value ), 'data' ) > 0 ) {
814
-				$replace = $value;
815
-				foreach ( $replace as $sub_array ) {
816
-					$cs_array                 = (array) json_decode( rawurldecode( $sub_array['data'] ) );
817
-					$value[ $cs_array['id'] ] = $cs_array;
818
-				}
819
-			}
820
-
821
-			return $value;
822
-		}
823
-	}
824
-
825
-	if ( ! function_exists( 'redux_customizer_custom_validation' ) ) {
826
-		/**
827
-		 * Custom validation.
828
-		 *
829
-		 * @param mixed $field Field.
830
-		 *
831
-		 * @return mixed
832
-		 */
833
-		function redux_customizer_custom_validation( $field ) {
834
-			return $field;
835
-		}
836
-	}
167
+        }
168
+
169
+        /**
170
+         * AJAX callback for customizer save...to make sanitize/validate work.
171
+         */
172
+        public function customizer() {
173
+            try {
174
+                $return_array = array();
175
+
176
+                if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['nonce'] ) ), 'redux_customer_nonce' ) && isset( $_POST['opt_name'] ) && '' !== $_POST['opt_name'] ) {
177
+                    $redux = Redux::instance( sanitize_text_field( wp_unslash( $_POST['opt_name'] ) ) );
178
+
179
+                    $post_data = wp_unslash( $_POST['data'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
180
+
181
+                    // New method to avoid input_var nonsense.  Thanks @harunbasic.
182
+                    $values = Redux_Functions_Ex::parse_str( $post_data );
183
+
184
+                    $all_options = get_option( sanitize_text_field( wp_unslash( $_POST['opt_name'] ) ) );
185
+
186
+                    $values = wp_parse_args( $values, $all_options );
187
+
188
+                    $redux->options_class->set( $redux->options_class->validate_options( $values ) );
189
+
190
+                    $redux->enqueue_class->get_warnings_and_errors_array();
191
+
192
+                    $return_array = array(
193
+                        'status'   => 'success',
194
+                        'options'  => $redux->options,
195
+                        'errors'   => $redux->enqueue_class->localize_data['errors'] ?? null,
196
+                        'warnings' => $redux->enqueue_class->localize_data['warnings'] ?? null,
197
+                        'sanitize' => $redux->enqueue_class->localize_data['sanitize'] ?? null,
198
+                    );
199
+                }
200
+            } catch ( Exception $e ) {
201
+                $return_array = array( 'status' => $e->getMessage() );
202
+            }
203
+
204
+            echo wp_json_encode( $return_array );
205
+
206
+            die;
207
+        }
208
+
209
+        /**
210
+         * Field classes.
211
+         *
212
+         * @param array $option Option.
213
+         */
214
+        public function create_field_classes( array $option ) {
215
+            if ( empty( $this->redux_fields ) ) {
216
+                $file_paths = glob( Redux_Core::$dir . 'inc/fields/*' );
217
+
218
+                foreach ( $file_paths as $file ) {
219
+                    if ( 'section' !== $file && 'divide' !== $file && 'editor' !== $file ) {
220
+                        $this->redux_fields[] = str_replace( Redux_Core::$dir . 'inc/fields/', '', $file );
221
+                    }
222
+                }
223
+
224
+                $file_paths = glob( Redux_Core::$dir . 'inc/extensions/*' );
225
+
226
+                foreach ( $file_paths as $file ) {
227
+                    if ( 'section' !== $file && 'divide' !== $file && 'editor' !== $file ) {
228
+                        $this->redux_fields[] = str_replace( Redux_Core::$dir . 'inc/extensions/', '', $file );
229
+                    }
230
+                }
231
+            }
232
+
233
+            $class_name = 'Redux_Customizer_Control_' . $option['type'];
234
+
235
+            if ( ! class_exists( $class_name ) && ( in_array( $option['type'], $this->redux_fields, true ) || ( isset( $option['customizer_enabled'] ) && $option['customizer_enabled'] ) ) ) {
236
+                $upload_dir = Redux_Core::$upload_dir;
237
+
238
+                if ( ! file_exists( $upload_dir . $option['type'] . '.php' ) ) {
239
+                    if ( ! is_dir( $upload_dir ) ) {
240
+                        Redux_Core::$filesystem->execute( 'mkdir', $upload_dir );
241
+                    }
242
+
243
+                    $template = str_replace( '{{type}}', $option['type'], '<?php' . PHP_EOL . '   class Redux_Customizer_Control_{{type}} extends Redux_Customizer_Control {' . PHP_EOL . '     public $type = "redux-{{type}}";' . PHP_EOL . '   }' );
244
+
245
+                    Redux_Core::$filesystem->execute( 'put_contents', $upload_dir . $option['type'] . '.php', array( 'content' => $template ) );
246
+                }
247
+
248
+                if ( file_exists( $upload_dir . $option['type'] . '.php' ) ) {
249
+                    include_once $upload_dir . $option['type'] . '.php';
250
+                }
251
+            }
252
+        }
253
+
254
+        /**
255
+         * Enqueue extension scripts/styles.
256
+         */
257
+        public function enqueue_controls_css() {
258
+            $this->parent->enqueue_class->get_warnings_and_errors_array();
259
+            $this->parent->enqueue_class->init();
260
+
261
+            if ( $this->parent->args['dev_mode'] ) {
262
+                wp_enqueue_style(
263
+                    'redux-extension-customizer',
264
+                    $this->extension_url . 'redux-extension-customizer.css',
265
+                    array(),
266
+                    self::$version
267
+                );
268
+            }
269
+
270
+            wp_enqueue_script(
271
+                'redux-extension-customizer',
272
+                $this->extension_url . 'redux-extension-customizer' . Redux_Functions::is_min() . '.js',
273
+                array( 'jquery', 'redux-js' ),
274
+                self::$version,
275
+                true
276
+            );
277
+
278
+            wp_localize_script(
279
+                'redux-extension-customizer',
280
+                'redux_customizer',
281
+                array(
282
+                    'body_class' => sanitize_html_class( 'admin-color-' . get_user_option( 'admin_color' ), 'fresh' ),
283
+                )
284
+            );
285
+        }
286
+
287
+        /**
288
+         * Enqueue panel CSS>
289
+         */
290
+        public function enqueue_panel_css() {}
291
+
292
+        /**
293
+         * Remove core customizer class.
294
+         *
295
+         * @return string
296
+         */
297
+        public function remove_core_customizer_class(): string {
298
+            return '';
299
+        }
300
+
301
+        /**
302
+         * Customize preview init.
303
+         */
304
+        public function customize_preview_init() {
305
+            // phpcs:ignore WordPress.NamingConventions.ValidHookName
306
+            do_action( 'redux/customizer/live_preview' );
307
+        }
308
+
309
+        /**
310
+         * Get post values.
311
+         */
312
+        protected static function get_post_values() {
313
+            if ( empty( self::$post_values ) && ! empty( $_POST['customized'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
314
+                $the_data = json_decode( stripslashes_deep( ( wp_unslash( $_POST['customized'] ) ) ), true ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput
315
+
316
+                foreach ( $the_data as $key => $value ) {
317
+                    if ( strpos( wp_json_encode( $value ), 'data' ) > 0 ) {
318
+                        foreach ( $value as $k => $v ) {
319
+                            $decode           = (array) json_decode( rawurldecode( $v['data'] ) );
320
+                            $v                = $decode;
321
+                            $dumb_array[ $k ] = $v;
322
+                            $the_data[ $key ] = $dumb_array;
323
+                        }
324
+                    }
325
+                }
326
+
327
+                self::$post_values = $the_data;
328
+            }
329
+        }
330
+
331
+        /**
332
+         * Override customizer values.
333
+         *
334
+         * @param array $data Values.
335
+         *
336
+         * @return array
337
+         */
338
+        public function override_values( array $data ): array {
339
+            self::get_post_values();
340
+
341
+            if ( isset( $_POST['customized'] ) && ! empty( self::$post_values ) ) { // phpcs:ignore WordPress.Security.NonceVerification
342
+                if ( is_array( self::$post_values ) ) {
343
+                    foreach ( self::$post_values as $key => $value ) {
344
+                        if ( strpos( $key, $this->parent->args['opt_name'] ) !== false ) {
345
+                            $key          = str_replace( $this->parent->args['opt_name'] . '[', '', rtrim( $key, ']' ) );
346
+                            $data[ $key ] = $value;
347
+
348
+                            $GLOBALS[ $this->parent->args['global_variable'] ][ $key ] = $value;
349
+                            $this->parent->options[ $key ]                             = $value;
350
+                        }
351
+                    }
352
+                }
353
+            }
354
+
355
+            return $data;
356
+        }
357
+
358
+        /**
359
+         * Render Redux fields.
360
+         *
361
+         * @param object $control .
362
+         */
363
+        public function render( object $control ) {
364
+            $field_id = str_replace( $this->parent->args['opt_name'] . '-', '', $control->redux_id );
365
+            $field    = $this->options[ $field_id ];
366
+
367
+            if ( ! empty( $field['compiler'] ) ) {
368
+                echo '<tr class="compiler">';
369
+            } else {
370
+                echo '<tr>';
371
+            }
372
+
373
+            echo '<th scope="row">' . wp_kses_post( $this->parent->field_head[ $field['id'] ] ) . '</th>';
374
+            echo '<td>';
375
+
376
+            $field['name'] = $field['id'];
377
+            $this->parent->render_class->field_input( $field );
378
+
379
+            echo '</td>';
380
+            echo '</tr>';
381
+        }
382
+
383
+        // All sections, settings, and controls will be added here.
384
+
385
+        /**
386
+         * Register customizer controls.
387
+         *
388
+         * @param WP_Customize_Manager $wp_customize .
389
+         *
390
+         * @throws ReflectionException Exception.
391
+         */
392
+        public function register_customizer_controls( WP_Customize_Manager $wp_customize ) {
393
+            if ( ! class_exists( 'Redux_Customizer_Section' ) ) {
394
+                require_once __DIR__ . '/inc/class-redux-customizer-section.php';
395
+
396
+                if ( method_exists( $wp_customize, 'register_section_type' ) ) {
397
+                    $wp_customize->register_section_type( 'Redux_Customizer_Section' );
398
+                }
399
+            }
400
+
401
+            if ( ! class_exists( 'Redux_Customizer_Panel' ) ) {
402
+                require_once __DIR__ . '/inc/class-redux-customizer-panel.php';
403
+
404
+                if ( method_exists( $wp_customize, 'register_panel_type' ) ) {
405
+                    $wp_customize->register_panel_type( 'Redux_Customizer_Panel' );
406
+                }
407
+            }
408
+
409
+            if ( ! class_exists( 'Redux_Customizer_Control' ) ) {
410
+                require_once __DIR__ . '/inc/class-redux-customizer-control.php';
411
+            }
412
+
413
+            // phpcs:ignore WordPress.NamingConventions.ValidHookName
414
+            do_action( 'redux/extension/customizer/control/includes' );
415
+
416
+            $order = array(
417
+                'heading' => - 500,
418
+                'option'  => - 500,
419
+            );
420
+
421
+            $panel = '';
422
+
423
+            $this->parent->args['options_api'] = false;
424
+            $this->parent->options_class->register();
425
+
426
+            $parent_section_id = null;
427
+            $new_parent        = true;
428
+
429
+            foreach ( $this->parent->sections as $key => $section ) {
430
+                // Not a type that should go on the customizer.
431
+
432
+                foreach ( $section['fields'] as $field ) {
433
+                    if ( 'color_scheme' === $field['type'] || 'divide' === $field['type'] ) {
434
+                        continue 2;
435
+                    }
436
+                }
437
+
438
+                if ( isset( $section['id'] ) && 'import/export' === $section['id'] ) {
439
+                    continue;
440
+                }
441
+
442
+                // If section customizer is set to false.
443
+                if ( isset( $section['customizer'] ) && false === $section['customizer'] ) {
444
+                    continue;
445
+                }
446
+
447
+                // if we are in a subsection and parent is set to customizer false !!!
448
+                if ( ( isset( $section['subsection'] ) && $section['subsection'] ) ) {
449
+                    if ( $new_parent ) {
450
+                        $new_parent        = false;
451
+                        $parent_section_id = ( $key - 1 );
452
+                    }
453
+                } else { // not a subsection reset.
454
+                    $parent_section_id = null;
455
+                    $new_parent        = true;
456
+                }
457
+                if ( isset( $parent_section_id ) && ( isset( $this->parent->sections[ $parent_section_id ]['customizer'] ) && false === $this->parent->sections[ $parent_section_id ]['customizer'] ) ) {
458
+                    continue;
459
+                }
460
+
461
+                $section['permissions'] = $section['permissions'] ?? 'edit_theme_options';
462
+
463
+                // No errors please.
464
+                if ( ! isset( $section['desc'] ) ) {
465
+                    $section['desc'] = '';
466
+                }
467
+
468
+                // Fill the description if there is a subtitle.
469
+                if ( empty( $section['desc'] ) && ! empty( $section['subtitle'] ) ) {
470
+                    $section['desc'] = $section['subtitle'];
471
+                }
472
+
473
+                // No title is present, let's show what section is missing a title.
474
+                if ( ! isset( $section['title'] ) ) {
475
+                    $section['title'] = '';
476
+                }
477
+
478
+                // Let's make a section ID from the title.
479
+                if ( empty( $section['id'] ) ) {
480
+                    $section['id'] = Redux_Core::strtolower( str_replace( ' ', '', $section['title'] ) );
481
+                }
482
+
483
+                // Let's set a default priority.
484
+                if ( empty( $section['priority'] ) ) {
485
+                    $section['priority'] = $order['heading'];
486
+                    ++$order['heading'];
487
+                }
488
+                $section['id'] = $this->parent->args['opt_name'] . '-' . $section['id'];
489
+
490
+                if ( method_exists( $wp_customize, 'add_panel' ) && ( ! isset( $section['subsection'] ) || ( true !== $section['subsection'] ) ) && isset( $this->parent->sections[ ( $key + 1 ) ]['subsection'] ) && $this->parent->sections[ ( $key + 1 ) ]['subsection'] ) {
491
+                    $this->add_panel(
492
+                        $this->parent->args['opt_name'] . '-' . $section['id'],
493
+                        array(
494
+                            'priority'    => $section['priority'],
495
+                            'capability'  => $section['permissions'],
496
+                            'title'       => $section['title'],
497
+                            'section'     => $section,
498
+                            'opt_name'    => $this->parent->args['opt_name'],
499
+                            'description' => '',
500
+                        ),
501
+                        $wp_customize
502
+                    );
503
+
504
+                    $panel = $this->parent->args['opt_name'] . '-' . $section['id'];
505
+
506
+                    $this->add_section(
507
+                        $section['id'],
508
+                        array(
509
+                            'title'       => $section['title'],
510
+                            'priority'    => $section['priority'],
511
+                            'description' => $section['desc'],
512
+                            'section'     => $section,
513
+                            'opt_name'    => $this->parent->args['opt_name'],
514
+                            'capability'  => $section['permissions'],
515
+                            'panel'       => $panel,
516
+                        ),
517
+                        $wp_customize
518
+                    );
519
+                } else {
520
+                    if ( ! isset( $section['subsection'] ) || ( true !== $section['subsection'] ) ) {
521
+                        $panel = '';
522
+                    }
523
+
524
+                    $this->add_section(
525
+                        $section['id'],
526
+                        array(
527
+                            'title'       => $section['title'],
528
+                            'priority'    => $section['priority'],
529
+                            'description' => $section['desc'],
530
+                            'opt_name'    => $this->parent->args['opt_name'],
531
+                            'section'     => $section,
532
+                            'capability'  => $section['permissions'],
533
+                            'panel'       => $panel,
534
+                        ),
535
+                        $wp_customize
536
+                    );
537
+                }
538
+
539
+                if ( ( empty( $section['fields'] ) ) ) {
540
+                    continue;
541
+                }
542
+
543
+                foreach ( $section['fields'] as $skey => $option ) {
544
+
545
+                    if ( isset( $option['customizer'] ) && false === $option['customizer'] ) {
546
+                        continue;
547
+                    }
548
+
549
+                    if ( false === $this->parent->args['customizer'] && ( ! isset( $option['customizer'] ) || true !== $option['customizer'] ) ) {
550
+                        continue;
551
+                    }
552
+
553
+                    $this->options[ $option['id'] ] = $option;
554
+                    add_action( 'redux/customizer/control/render/' . $this->parent->args['opt_name'] . '-' . $option['id'], array( $this, 'render' ) );
555
+
556
+                    $option['permissions'] = $option['permissions'] ?? 'edit_theme_options';
557
+
558
+                    // Change the item priority if not set.
559
+                    if ( 'heading' !== $option['type'] && ! isset( $option['priority'] ) ) {
560
+                        $option['priority'] = $order['option'];
561
+                        ++$order['option'];
562
+                    }
563
+
564
+                    if ( ! empty( $this->options_defaults[ $option['id'] ] ) ) {
565
+                        $option['default'] = $this->options_defaults['option']['id'];
566
+                    }
567
+
568
+                    if ( ! isset( $option['default'] ) ) {
569
+                        $option['default'] = '';
570
+                    }
571
+                    if ( ! isset( $option['title'] ) ) {
572
+                        $option['title'] = '';
573
+                    }
574
+
575
+                    $option['id'] = $this->parent->args['opt_name'] . '[' . $option['id'] . ']';
576
+
577
+                    if ( 'heading' !== $option['type'] && 'import_export' !== $option['type'] && ! empty( $option['type'] ) ) {
578
+
579
+                        $wp_customize->add_setting(
580
+                            $option['id'],
581
+                            array(
582
+                                'default'           => $option['default'],
583
+                                'transport'         => 'refresh',
584
+                                'opt_name'          => $this->parent->args['opt_name'],
585
+                                'sanitize_callback' => array( $this, 'field_validation' ),
586
+                            )
587
+                        );
588
+                    }
589
+
590
+                    if ( ! empty( $option['data'] ) && empty( $option['options'] ) ) {
591
+                        if ( empty( $option['args'] ) ) {
592
+                            $option['args'] = array();
593
+                        }
594
+
595
+                        if ( 'elusive-icons' === $option['data'] || 'elusive-icon' === $option['data'] || 'elusive' === $option['data'] ) {
596
+                            $icons_file = Redux_Core::$dir . 'inc/fields/select/elusive-icons.php';
597
+
598
+                            // phpcs:ignore WordPress.NamingConventions.ValidHookName
599
+                            $icons_file = apply_filters( 'redux-font-icons-file', $icons_file );
600
+
601
+                            if ( file_exists( $icons_file ) ) {
602
+                                require_once $icons_file;
603
+                            }
604
+                        }
605
+                        $option['options'] = $this->parent->wordpress_data->get( $option['data'], $option['args'] );
606
+                    }
607
+
608
+                    $class_name = 'Redux_Customizer_Control_' . $option['type'];
609
+
610
+                    // phpcs:ignore WordPress.NamingConventions.ValidHookName
611
+                    do_action( 'redux/extension/customizer/control_init', $option );
612
+
613
+                    if ( ! class_exists( $class_name ) ) {
614
+                        continue;
615
+                    }
616
+
617
+                    $wp_customize->add_control(
618
+                        new $class_name(
619
+                            $wp_customize,
620
+                            $option['id'],
621
+                            array(
622
+                                'label'           => $option['title'],
623
+                                'section'         => $section['id'],
624
+                                'settings'        => $option['id'],
625
+                                'type'            => 'redux-' . $option['type'],
626
+                                'field'           => $option,
627
+                                'ReduxFramework'  => $this->parent,
628
+                                'active_callback' => ( isset( $option['required'] ) && class_exists( 'Redux_Customizer_Active_Callback' ) ) ? array(
629
+                                    'Redux_Customizer_Active_Callback',
630
+                                    'evaluate',
631
+                                ) : '__return_true',
632
+                                'priority'        => $option['priority'],
633
+                            )
634
+                        )
635
+                    );
636
+
637
+                    $section['fields'][ $skey ]['name'] = $option['id'];
638
+                    if ( ! isset( $section['fields'][ $skey ]['class'] ) ) { // No errors please.
639
+                        $section['fields'][ $skey ]['class'] = '';
640
+                    }
641
+
642
+                    $this->controls[ $section['fields'][ $skey ]['id'] ] = $section['fields'][ $skey ];
643
+                }
644
+            }
645
+        }
646
+
647
+        /**
648
+         * Add customizer section.
649
+         *
650
+         * @param string               $id           ID.
651
+         * @param array                $args         Args.
652
+         * @param WP_Customize_Manager $wp_customize .
653
+         */
654
+        public function add_section( string $id, array $args, WP_Customize_Manager $wp_customize ) {
655
+
656
+            if ( is_a( $id, 'WP_Customize_Section' ) ) {
657
+                $section = $id;
658
+            } else {
659
+                $section = new Redux_Customizer_Section( $wp_customize, $id, $args );
660
+            }
661
+
662
+            $wp_customize->add_section( $section, $args );
663
+        }
664
+
665
+        /**
666
+         * Add a customize panel.
667
+         *
668
+         * @param WP_Customize_Panel|string $id           Customize Panel object, or Panel ID.
669
+         * @param array                     $args         Optional. Panel arguments. Default empty array.
670
+         * @param WP_Customize_Manager      $wp_customize .
671
+         *
672
+         * @since  4.0.0
673
+         * @access public
674
+         */
675
+        public function add_panel( $id, array $args, WP_Customize_Manager $wp_customize ) {
676
+            if ( is_a( $id, 'WP_Customize_Panel' ) ) {
677
+                $panel = $id;
678
+            } else {
679
+                $panel = new Redux_Customizer_Panel( $wp_customize, $id, $args );
680
+            }
681
+
682
+            $wp_customize->add_panel( $panel, $args );
683
+        }
684
+
685
+        /**
686
+         * Actions to take after customizer save.
687
+         *
688
+         * @throws ReflectionException Exception.
689
+         */
690
+        public function customizer_save_after() {
691
+            if ( empty( $this->parent->options ) ) {
692
+                $this->parent->get_options();
693
+            }
694
+
695
+            if ( empty( $this->orig_options ) && ! empty( $this->parent->options ) ) {
696
+                $this->orig_options = $this->parent->options;
697
+            }
698
+
699
+            if ( isset( $_POST['customized'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
700
+                $options = json_decode( sanitize_text_field( wp_unslash( $_POST['customized'] ) ), true ); // phpcs:ignore WordPress.Security.NonceVerification
701
+
702
+                $compiler = false;
703
+                $changed  = false;
704
+
705
+                foreach ( $options as $key => $value ) {
706
+                    if ( strpos( $key, $this->parent->args['opt_name'] ) !== false ) {
707
+                        $key = str_replace( $this->parent->args['opt_name'] . '[', '', rtrim( $key, ']' ) );
708
+
709
+                        if ( ! isset( $this->orig_options[ $key ] ) || $value !== $this->orig_options[ $key ] || ( isset( $this->orig_options[ $key ] ) && ! empty( $this->orig_options[ $key ] ) && empty( $value ) ) ) {
710
+                            $this->parent->options[ $key ] = $value;
711
+                            $changed                       = true;
712
+
713
+                            if ( isset( $this->parent->compiler_fields[ $key ] ) ) {
714
+                                $compiler = true;
715
+                            }
716
+                        }
717
+                    }
718
+                }
719
+
720
+                if ( $changed ) {
721
+                    $this->parent->options_class->set( $this->parent->options );
722
+                    if ( $compiler ) {
723
+                        // Have to set this to stop the output of the CSS and typography stuff.
724
+                        Redux_Core::$no_output = true;
725
+                        $this->parent->output_class->enqueue();
726
+
727
+                        // phpcs:ignore WordPress.NamingConventions.ValidHookName
728
+                        do_action( "redux/options/{$this->parent->args['opt_name']}/compiler", $this->parent->options, $this->parent->compilerCSS );
729
+
730
+                        // phpcs:ignore WordPress.NamingConventions.ValidHookName
731
+                        do_action( "redux/options/{$this->parent->args['opt_name']}/compiler/advanced", $this->parent );
732
+                    }
733
+                }
734
+            }
735
+        }
736
+
737
+        /**
738
+         * Enqueue CSS/JS for the customizer controls
739
+         *
740
+         * @since       1.0.0
741
+         * @access      public
742
+         * @global      $wp_styles
743
+         * @return      void
744
+         */
745
+        public function enqueue() {
746
+            $localize = array(
747
+                'save_pending'   => esc_html__( 'You have changes that are not saved.  Would you like to save them now?', 'redux-framework' ),
748
+                'reset_confirm'  => esc_html__( 'Are you sure?  Resetting will lose all custom values.', 'redux-framework' ),
749
+                'preset_confirm' => esc_html__( 'Your current options will be replaced with the values of this preset.  Would you like to proceed?', 'redux-framework' ),
750
+                'opt_name'       => $this->parent->args['opt_name'],
751
+                'field'          => $this->parent->options,
752
+                'defaults'       => $this->parent->options_defaults,
753
+                'folds'          => Redux_Core::$folds,
754
+            );
755
+
756
+            // Values used by the javascript.
757
+            wp_localize_script( 'redux-js', 'redux_opts', $localize );
758
+
759
+            // phpcs:ignore WordPress.NamingConventions.ValidHookName
760
+            do_action( 'redux-enqueue-' . $this->parent->args['opt_name'] );
761
+
762
+            foreach ( $this->parent->sections as $section ) {
763
+                if ( isset( $section['fields'] ) ) {
764
+                    foreach ( $section['fields'] as $field ) {
765
+                        if ( isset( $field['type'] ) ) {
766
+                            $field_classes = array( 'Redux_' . $field['type'], 'ReduxFramework_' . $field['type'] );
767
+
768
+                            $field_class = Redux_Functions::class_exists_ex( $field_classes );
769
+
770
+                            if ( false === $field_class ) {
771
+
772
+                                // phpcs:ignore WordPress.NamingConventions.ValidHookName
773
+                                $class_file = apply_filters( 'redux-typeclass-load', $this->path . 'inc/fields/' . $field['type'] . '/field_' . $field['type'] . '.php', $field_class );
774
+
775
+                                if ( $class_file ) {
776
+                                    require_once $class_file;
777
+
778
+                                    $field_class = Redux_Functions::class_exists_ex( $field_classes );
779
+
780
+                                }
781
+                            }
782
+
783
+                            if ( class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) {
784
+                                $enqueue = new $field_class( '', '', $this );
785
+                                $enqueue->enqueue();
786
+                            }
787
+                        }
788
+                    }
789
+                }
790
+            }
791
+        }
792
+
793
+        /**
794
+         * Register Option for use
795
+         *
796
+         * @since       1.0.0
797
+         * @access      public
798
+         * @return      void
799
+         */
800
+        public function register_setting() {
801
+        }
802
+
803
+        /**
804
+         * Validate the options before insertion
805
+         *
806
+         * @param array|string $value The options array.
807
+         *
808
+         * @return array|string $value
809
+         * @since       3.0.0
810
+         * @access      public
811
+         */
812
+        public function field_validation( $value ) {
813
+            if ( strpos( wp_json_encode( $value ), 'data' ) > 0 ) {
814
+                $replace = $value;
815
+                foreach ( $replace as $sub_array ) {
816
+                    $cs_array                 = (array) json_decode( rawurldecode( $sub_array['data'] ) );
817
+                    $value[ $cs_array['id'] ] = $cs_array;
818
+                }
819
+            }
820
+
821
+            return $value;
822
+        }
823
+    }
824
+
825
+    if ( ! function_exists( 'redux_customizer_custom_validation' ) ) {
826
+        /**
827
+         * Custom validation.
828
+         *
829
+         * @param mixed $field Field.
830
+         *
831
+         * @return mixed
832
+         */
833
+        function redux_customizer_custom_validation( $field ) {
834
+            return $field;
835
+        }
836
+    }
837 837
 }
838 838
 
839 839
 if ( ! class_exists( 'ReduxFramework_extension_customizer' ) ) {
840
-	class_alias( 'Redux_Extension_Customizer', 'ReduxFramework_extension_customizer' );
840
+    class_alias( 'Redux_Extension_Customizer', 'ReduxFramework_extension_customizer' );
841 841
 }
Please login to merge, or discard this patch.
redux-core/inc/extensions/customizer/inc/class-redux-customizer-control.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -10,40 +10,40 @@  discard block
 block discarded – undo
10 10
 
11 11
 if ( ! class_exists( 'Redux_Customizer_Control', false ) ) {
12 12
 
13
-	/**
14
-	 * Class Redux_Customizer_Control
15
-	 */
16
-	class Redux_Customizer_Control extends WP_Customize_Control {
13
+    /**
14
+     * Class Redux_Customizer_Control
15
+     */
16
+    class Redux_Customizer_Control extends WP_Customize_Control {
17 17
 
18
-		/**
19
-		 * Redux ID.
20
-		 *
21
-		 * @var string
22
-		 */
23
-		public string $redux_id = '';
18
+        /**
19
+         * Redux ID.
20
+         *
21
+         * @var string
22
+         */
23
+        public string $redux_id = '';
24 24
 
25
-		/**
26
-		 * Field render.
27
-		 */
28
-		public function render() {
25
+        /**
26
+         * Field render.
27
+         */
28
+        public function render() {
29 29
 
30
-			$this->redux_id = str_replace( 'customize-control-', '', 'customize-control-' . str_replace( '[', '-', str_replace( ']', '', $this->id ) ) );
31
-			$class          = 'customize-control redux-group-tab redux-field customize-control-' . $this->type;
32
-			$opt_name_arr   = explode( '[', $this->id );
33
-			$opt_name       = $opt_name_arr[0];
34
-			$field_id       = str_replace( ']', '', $opt_name_arr[1] );
30
+            $this->redux_id = str_replace( 'customize-control-', '', 'customize-control-' . str_replace( '[', '-', str_replace( ']', '', $this->id ) ) );
31
+            $class          = 'customize-control redux-group-tab redux-field customize-control-' . $this->type;
32
+            $opt_name_arr   = explode( '[', $this->id );
33
+            $opt_name       = $opt_name_arr[0];
34
+            $field_id       = str_replace( ']', '', $opt_name_arr[1] );
35 35
 
36
-			$section = Redux_Helpers::section_from_field_id( $opt_name, $field_id );
36
+            $section = Redux_Helpers::section_from_field_id( $opt_name, $field_id );
37 37
 
38
-			if ( isset( $section['disabled'] ) && true === $section['disabled'] ) {
39
-				$class .= ' disabled';
40
-			}
38
+            if ( isset( $section['disabled'] ) && true === $section['disabled'] ) {
39
+                $class .= ' disabled';
40
+            }
41 41
 
42
-			if ( isset( $section['hidden'] ) && true === $section['hidden'] ) {
43
-				$class .= ' hidden';
44
-			}
42
+            if ( isset( $section['hidden'] ) && true === $section['hidden'] ) {
43
+                $class .= ' hidden';
44
+            }
45 45
 
46
-			?>
46
+            ?>
47 47
 			<li id="<?php echo esc_attr( $this->redux_id ); ?>-li" class="<?php echo esc_attr( $class ); ?>">
48 48
 				<?php if ( 'repeater' !== $this->type ) { ?>
49 49
 					<input
@@ -57,42 +57,42 @@  discard block
 block discarded – undo
57 57
 				<?php $this->render_content(); ?>
58 58
 			</li>
59 59
 			<?php
60
-		}
60
+        }
61 61
 
62
-		/**
63
-		 * Render content hook.
64
-		 */
65
-		public function render_content() {
66
-			// phpcs:ignore WordPress.NamingConventions.ValidHookName
67
-			do_action( 'redux/customizer/control/render/' . $this->redux_id, $this );
68
-		}
62
+        /**
63
+         * Render content hook.
64
+         */
65
+        public function render_content() {
66
+            // phpcs:ignore WordPress.NamingConventions.ValidHookName
67
+            do_action( 'redux/customizer/control/render/' . $this->redux_id, $this );
68
+        }
69 69
 
70
-		/**
71
-		 * Label output.
72
-		 */
73
-		public function label() {
74
-			// The label has already been sanitized in the Fields class, no need to re-sanitize it.
75
-			echo( $this->label ); // phpcs:ignore WordPress.Security.EscapeOutput
76
-		}
70
+        /**
71
+         * Label output.
72
+         */
73
+        public function label() {
74
+            // The label has already been sanitized in the Fields class, no need to re-sanitize it.
75
+            echo( $this->label ); // phpcs:ignore WordPress.Security.EscapeOutput
76
+        }
77 77
 
78
-		/**
79
-		 * Description output.
80
-		 */
81
-		public function description() {
82
-			if ( ! empty( $this->description ) ) {
83
-				// The description has already been sanitized in the Fields class, no need to re-sanitize it.
84
-				echo '<span class="description customize-control-description">' . esc_html( $this->description ) . '</span>';
85
-			}
86
-		}
78
+        /**
79
+         * Description output.
80
+         */
81
+        public function description() {
82
+            if ( ! empty( $this->description ) ) {
83
+                // The description has already been sanitized in the Fields class, no need to re-sanitize it.
84
+                echo '<span class="description customize-control-description">' . esc_html( $this->description ) . '</span>';
85
+            }
86
+        }
87 87
 
88
-		/**
89
-		 * Title output.
90
-		 */
91
-		public function title() {
92
-			echo '<span class="customize-control-title">';
93
-			$this->label();
94
-			$this->description();
95
-			echo '</span>';
96
-		}
97
-	}
88
+        /**
89
+         * Title output.
90
+         */
91
+        public function title() {
92
+            echo '<span class="customize-control-title">';
93
+            $this->label();
94
+            $this->description();
95
+            echo '</span>';
96
+        }
97
+    }
98 98
 }
Please login to merge, or discard this patch.
redux-core/inc/fields/background/class-redux-background.php 1 patch
Indentation   +423 added lines, -423 removed lines patch added patch discarded remove patch
@@ -12,429 +12,429 @@
 block discarded – undo
12 12
 // Don't duplicate me!
13 13
 if ( ! class_exists( 'Redux_Background', false ) ) {
14 14
 
15
-	/**
16
-	 * Main Redux_background class
17
-	 *
18
-	 * @since       3.1.5
19
-	 */
20
-	class Redux_Background extends Redux_Field {
21
-
22
-		/**
23
-		 * Set field and value defaults.
24
-		 */
25
-		public function set_defaults() {
26
-			$defaults = array(
27
-				'background-color'      => true,
28
-				'background-repeat'     => true,
29
-				'background-attachment' => true,
30
-				'background-position'   => true,
31
-				'background-image'      => true,
32
-				'background-gradient'   => false,
33
-				'background-clip'       => false,
34
-				'background-origin'     => false,
35
-				'background-size'       => true,
36
-				'preview_media'         => false,
37
-				'preview'               => true,
38
-				'preview_height'        => '200px',
39
-				'transparent'           => true,
40
-			);
41
-
42
-			$this->field = wp_parse_args( $this->field, $defaults );
43
-
44
-			// No errors please.
45
-			$defaults = array(
46
-				'background-color'      => '',
47
-				'background-repeat'     => '',
48
-				'background-attachment' => '',
49
-				'background-position'   => '',
50
-				'background-image'      => '',
51
-				'background-clip'       => '',
52
-				'background-origin'     => '',
53
-				'background-size'       => '',
54
-				'media'                 => array(),
55
-			);
56
-
57
-			$this->value = wp_parse_args( $this->value, $defaults );
58
-
59
-			$defaults = array(
60
-				'id'        => '',
61
-				'width'     => '',
62
-				'height'    => '',
63
-				'thumbnail' => '',
64
-			);
65
-
66
-			$this->value['media'] = wp_parse_args( $this->value['media'], $defaults );
67
-		}
68
-
69
-		/**
70
-		 * Field Render Function.
71
-		 * Takes the vars and outputs the HTML for the field in the settings
72
-		 *
73
-		 * @since       1.0.0
74
-		 * @access      public
75
-		 * @return      void
76
-		 */
77
-		public function render() {
78
-			$this->select2_config['allowClear'] = true;
79
-
80
-			if ( isset( $this->field['select2'] ) ) {
81
-				$this->field['select2'] = wp_parse_args( $this->field['select2'], $this->select2_config );
82
-			} else {
83
-				$this->field['select2'] = $this->select2_config;
84
-			}
85
-
86
-			$this->field['select2'] = Redux_Functions::sanitize_camel_case_array_keys( $this->field['select2'] );
87
-
88
-			$select2_data = Redux_Functions::create_data_string( $this->field['select2'] );
89
-
90
-			if ( true === $this->field['background-color'] ) {
91
-				if ( isset( $this->value['color'] ) && empty( $this->value['background-color'] ) ) {
92
-					$this->value['background-color'] = $this->value['color'];
93
-				}
94
-
95
-				$def_bg_color = $this->field['default']['background-color'] ?? '';
96
-
97
-				echo '<input ';
98
-				echo 'data-id="' . esc_attr( $this->field['id'] ) . '"';
99
-				echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-color]"';
100
-				echo 'id="' . esc_attr( $this->field['id'] ) . '-color"';
101
-				echo 'class="color-picker redux-color redux-background-input redux-color-init ' . esc_attr( $this->field['class'] ) . '"';
102
-				echo 'type="text" value="' . esc_attr( $this->value['background-color'] ) . '"';
103
-				echo 'data-default-color="' . esc_attr( $def_bg_color ) . '"';
104
-
105
-				$data = array(
106
-					'field' => $this->field,
107
-					'index' => 'color',
108
-				);
109
-
110
-				echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput
111
-
112
-				echo '>';
113
-
114
-				echo '<input type="hidden" class="redux-saved-color" id="' . esc_attr( $this->field['id'] ) . '-saved-color" value="">';
115
-
116
-				if ( ! isset( $this->field['transparent'] ) || false !== $this->field['transparent'] ) {
117
-					$is_checked = '';
118
-					if ( 'transparent' === $this->value['background-color'] ) {
119
-						$is_checked = ' checked="checked"';
120
-					}
121
-					echo '<label for="' . esc_attr( $this->field['id'] ) . '-transparency" class="color-transparency-check"><input type="checkbox" class="checkbox color-transparency redux-background-input ' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $this->field['id'] ) . '-transparency" data-id="' . esc_attr( $this->field['id'] ) . '-color" value="1" ' . esc_html( $is_checked ) . '> ' . esc_html__( 'Transparent', 'redux-framework' ) . '</label>';
122
-				}
123
-
124
-				if ( true === $this->field['background-repeat'] || true === $this->field['background-position'] || true === $this->field['background-attachment'] ) {
125
-					echo '<br />';
126
-				}
127
-			}
128
-
129
-			if ( true === $this->field['background-repeat'] ) {
130
-				$array = array(
131
-					'no-repeat' => esc_html__( 'No Repeat', 'redux-framework' ),
132
-					'repeat'    => esc_html__( 'Repeat All', 'redux-framework' ),
133
-					'repeat-x'  => esc_html__( 'Repeat Horizontally', 'redux-framework' ),
134
-					'repeat-y'  => esc_html__( 'Repeat Vertically', 'redux-framework' ),
135
-					'inherit'   => esc_html__( 'Inherit', 'redux-framework' ),
136
-				);
137
-
138
-				echo '<select id="' . esc_attr( $this->field['id'] ) . '-repeat-select" data-placeholder="' . esc_html__( 'Background Repeat', 'redux-framework' ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-repeat]" class="redux-select-item redux-background-input redux-background-repeat ' . esc_attr( $this->field['class'] ) . '"' . esc_attr( $select2_data ) . '>';
139
-				echo '<option></option>';
140
-
141
-				foreach ( $array as $k => $v ) {
142
-					echo '<option value="' . esc_attr( $k ) . '" ' . selected( $this->value['background-repeat'], $k, false ) . '>' . esc_html( $v ) . '</option>';
143
-				}
144
-
145
-				echo '</select>';
146
-			}
147
-
148
-			if ( true === $this->field['background-clip'] ) {
149
-				$array = array(
150
-					'inherit'     => esc_html__( 'Inherit', 'redux-framework' ),
151
-					'border-box'  => esc_html__( 'Border Box', 'redux-framework' ),
152
-					'content-box' => esc_html__( 'Content Box', 'redux-framework' ),
153
-					'padding-box' => esc_html__( 'Padding Box', 'redux-framework' ),
154
-				);
155
-
156
-				echo '<select id="' . esc_attr( $this->field['id'] ) . '-clip-select" data-placeholder="' . esc_html__( 'Background Clip', 'redux-framework' ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-clip]" class="redux-select-item redux-background-input redux-background-clip ' . esc_attr( $this->field['class'] ) . '"' . esc_attr( $select2_data ) . '>';
157
-				echo '<option></option>';
158
-
159
-				foreach ( $array as $k => $v ) {
160
-					echo '<option value="' . esc_attr( $k ) . '" ' . selected( $this->value['background-clip'], $k, false ) . '>' . esc_html( $v ) . '</option>';
161
-				}
162
-
163
-				echo '</select>';
164
-			}
165
-
166
-			if ( true === $this->field['background-origin'] ) {
167
-				$array = array(
168
-					'inherit'     => esc_html__( 'Inherit', 'redux-framework' ),
169
-					'border-box'  => esc_html__( 'Border Box', 'redux-framework' ),
170
-					'content-box' => esc_html__( 'Content Box', 'redux-framework' ),
171
-					'padding-box' => esc_html__( 'Padding Box', 'redux-framework' ),
172
-				);
173
-
174
-				echo '<select id="' . esc_attr( $this->field['id'] ) . '-origin-select" data-placeholder="' . esc_html__( 'Background Origin', 'redux-framework' ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-origin]" class="redux-select-item redux-background-input redux-background-origin ' . esc_attr( $this->field['class'] ) . '"' . esc_attr( $select2_data ) . '>';
175
-				echo '<option></option>';
176
-
177
-				foreach ( $array as $k => $v ) {
178
-					echo '<option value="' . esc_attr( $k ) . '" ' . selected( $this->value['background-origin'], $k, false ) . '>' . esc_html( $v ) . '</option>';
179
-				}
180
-
181
-				echo '</select>';
182
-			}
183
-
184
-			if ( true === $this->field['background-size'] ) {
185
-				$array = array(
186
-					'inherit' => esc_html__( 'Inherit', 'redux-framework' ),
187
-					'cover'   => esc_html__( 'Cover', 'redux-framework' ),
188
-					'contain' => esc_html__( 'Contain', 'redux-framework' ),
189
-				);
190
-
191
-				echo '<select id="' . esc_attr( $this->field['id'] ) . '-size-select" data-placeholder="' . esc_html__( 'Background Size', 'redux-framework' ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-size]" class="redux-select-item redux-background-input redux-background-size ' . esc_attr( $this->field['class'] ) . '"' . esc_attr( $select2_data ) . '>';
192
-				echo '<option></option>';
193
-
194
-				foreach ( $array as $k => $v ) {
195
-					echo '<option value="' . esc_attr( $k ) . '" ' . selected( $this->value['background-size'], $k, false ) . '>' . esc_html( $v ) . '</option>';
196
-				}
197
-
198
-				echo '</select>';
199
-			}
200
-
201
-			if ( true === $this->field['background-attachment'] ) {
202
-				$array = array(
203
-					'fixed'   => esc_html__( 'Fixed', 'redux-framework' ),
204
-					'scroll'  => esc_html__( 'Scroll', 'redux-framework' ),
205
-					'inherit' => esc_html__( 'Inherit', 'redux-framework' ),
206
-				);
207
-
208
-				echo '<select id="' . esc_attr( $this->field['id'] ) . '-attachment-select" data-placeholder="' . esc_html__( 'Background Attachment', 'redux-framework' ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-attachment]" class="redux-select-item redux-background-input redux-background-attachment ' . esc_attr( $this->field['class'] ) . '"' . esc_attr( $select2_data ) . '>';
209
-				echo '<option></option>';
210
-
211
-				foreach ( $array as $k => $v ) {
212
-					echo '<option value="' . esc_attr( $k ) . '" ' . selected( $this->value['background-attachment'], $k, false ) . '>' . esc_html( $v ) . '</option>';
213
-				}
214
-
215
-				echo '</select>';
216
-			}
217
-
218
-			if ( true === $this->field['background-position'] ) {
219
-				$array = array(
220
-					'left top'      => esc_html__( 'Left Top', 'redux-framework' ),
221
-					'left center'   => esc_html__( 'Left center', 'redux-framework' ),
222
-					'left bottom'   => esc_html__( 'Left Bottom', 'redux-framework' ),
223
-					'center top'    => esc_html__( 'Center Top', 'redux-framework' ),
224
-					'center center' => esc_html__( 'Center Center', 'redux-framework' ),
225
-					'center bottom' => esc_html__( 'Center Bottom', 'redux-framework' ),
226
-					'right top'     => esc_html__( 'Right Top', 'redux-framework' ),
227
-					'right center'  => esc_html__( 'Right center', 'redux-framework' ),
228
-					'right bottom'  => esc_html__( 'Right Bottom', 'redux-framework' ),
229
-				);
230
-
231
-				echo '<select id="' . esc_attr( $this->field['id'] ) . '-position-select" data-placeholder="' . esc_html__( 'Background Position', 'redux-framework' ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-position]" class="redux-select-item redux-background-input redux-background-position ' . esc_attr( $this->field['class'] ) . '"' . esc_attr( $select2_data ) . '>';
232
-				echo '<option></option>';
233
-
234
-				foreach ( $array as $k => $v ) {
235
-					echo '<option value="' . esc_attr( $k ) . '" ' . selected( $this->value['background-position'], $k, false ) . '>' . esc_html( $v ) . '</option>';
236
-				}
237
-
238
-				echo '</select>';
239
-			}
240
-
241
-			if ( $this->field['background-image'] ) {
242
-				echo '<br />';
243
-
244
-				if ( empty( $this->value ) && ! empty( $this->field['default'] ) ) {
245
-					if ( is_array( $this->field['default'] ) ) {
246
-						if ( ! empty( $this->field['default']['media']['id'] ) ) {
247
-							$this->value['media']['id'] = $this->field['default']['media']['id'];
248
-						} elseif ( ! empty( $this->field['default']['id'] ) ) {
249
-							$this->value['media']['id'] = $this->field['default']['id'];
250
-						}
251
-
252
-						if ( ! empty( $this->field['default']['url'] ) ) {
253
-							$this->value['background-image'] = $this->field['default']['url'];
254
-						} elseif ( ! empty( $this->field['default']['media']['url'] ) ) {
255
-							$this->value['background-image'] = $this->field['default']['media']['url'];
256
-						} elseif ( ! empty( $this->field['default']['background-image'] ) ) {
257
-							$this->value['background-image'] = $this->field['default']['background-image'];
258
-						}
259
-					} elseif ( is_numeric( $this->field['default'] ) ) {
260
-						// Check if it's an attachment ID.
261
-							$this->value['media']['id'] = $this->field['default'];
262
-					} else { // Must be a URL.
263
-						$this->value['background-image'] = $this->field['default'];
264
-					}
265
-				}
266
-
267
-				if ( empty( $this->value['background-image'] ) && ! empty( $this->value['media']['id'] ) ) {
268
-					$img                             = wp_get_attachment_image_src( $this->value['media']['id'], 'full' );
269
-					$this->value['background-image'] = $img[0];
270
-					$this->value['media']['width']   = $img[1];
271
-					$this->value['media']['height']  = $img[2];
272
-				}
273
-
274
-				$hide = 'hide ';
275
-
276
-				if ( ( isset( $this->field['preview_media'] ) && false === $this->field['preview_media'] ) ) {
277
-					$this->field['class'] .= ' noPreview';
278
-				}
279
-
280
-				if ( ( ! empty( $this->field['background-image'] ) && true === $this->field['background-image'] ) || ( isset( $this->field['preview'] ) && false === $this->field['preview'] ) ) {
281
-					$hide = '';
282
-				}
283
-
284
-				$placeholder = $this->field['placeholder'] ?? esc_html__( 'No media selected', 'redux-framework' );
285
-
286
-				echo '<input placeholder="' . esc_html( $placeholder ) . '" type="text" class="redux-background-input ' . esc_attr( $hide ) . 'upload ' . esc_attr( $this->field['class'] ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-image]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][background-image]" value="' . esc_url( $this->value['background-image'] ) . '" />';
287
-				echo '<input type="hidden" class="upload-id ' . esc_attr( $this->field['class'] ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[media][id]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][media][id]" value="' . esc_attr( $this->value['media']['id'] ) . '" />';
288
-				echo '<input type="hidden" class="upload-height" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[media][height]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][media][height]" value="' . esc_attr( $this->value['media']['height'] ) . '" />';
289
-				echo '<input type="hidden" class="upload-width" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[media][width]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][media][width]" value="' . esc_attr( $this->value['media']['width'] ) . '" />';
290
-				echo '<input type="hidden" class="upload-thumbnail" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[media][thumbnail]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][media][thumbnail]" value="' . esc_url( $this->value['media']['thumbnail'] ) . '" />';
291
-
292
-				// Preview.
293
-				$hide = '';
294
-
295
-				if ( ( isset( $this->field['preview_media'] ) && false === $this->field['preview_media'] ) || empty( $this->value['background-image'] ) ) {
296
-					$hide = 'hide ';
297
-				}
298
-
299
-				if ( empty( $this->value['media']['thumbnail'] ) && ! empty( $this->value['background-image'] ) ) { // Just in case.
300
-					if ( ! empty( $this->value['media']['id'] ) ) {
301
-						$image = wp_get_attachment_image_src(
302
-							$this->value['media']['id'],
303
-							array(
304
-								150,
305
-								150,
306
-							)
307
-						);
308
-
309
-						$this->value['media']['thumbnail'] = $image[0];
310
-					} else {
311
-						$this->value['media']['thumbnail'] = $this->value['background-image'];
312
-					}
313
-				}
314
-
315
-				echo '<div class="' . esc_attr( $hide ) . 'screenshot">';
316
-				echo '<a class="of-uploaded-image" href="' . esc_url( $this->value['background-image'] ) . '" target="_blank">';
317
-
318
-				$alt = wp_prepare_attachment_for_js( $this->value['media']['id'] );
319
-				$alt = $alt['alt'] ?? '';
320
-
321
-				echo '<img class="redux-option-image" id="image_' . esc_attr( $this->value['media']['id'] ) . '" src="' . esc_url( $this->value['media']['thumbnail'] ) . '" alt="' . esc_attr( $alt ) . '" target="_blank" rel="external" />';
322
-				echo '</a>';
323
-				echo '</div>';
324
-
325
-				// Upload controls DIV.
326
-				echo '<div class="upload_button_div">';
327
-
328
-				// If the user has WP3.5+ show upload/remove button.
329
-				echo '<span class="button redux-background-upload" id="' . esc_attr( $this->field['id'] ) . '-media">' . esc_html__( 'Upload', 'redux-framework' ) . '</span>';
330
-
331
-				$hide = '';
332
-				if ( empty( $this->value['background-image'] ) || '' === $this->value['background-image'] ) {
333
-					$hide = ' hide';
334
-				}
335
-
336
-				echo '<span class="button removeCSS redux-remove-background' . esc_attr( $hide ) . '" id="reset_' . esc_attr( $this->field['id'] ) . '" rel="' . esc_attr( $this->field['id'] ) . '">' . esc_html__( 'Remove', 'redux-framework' ) . '</span>';
337
-
338
-				echo '</div>';
339
-			}
340
-
341
-			/**
342
-			 * Preview
343
-			 * */
344
-			if ( ! isset( $this->field['preview'] ) || false !== $this->field['preview'] ) {
345
-				$css = $this->css_style( $this->value );
346
-
347
-				$is_bg = strpos( $css, 'background-image' );
348
-
349
-				if ( empty( $css ) || ! $is_bg ) {
350
-					$css = 'display:none;';
351
-				}
352
-
353
-				$css .= 'height: ' . esc_attr( $this->field['preview_height'] ) . ';';
354
-				echo '<p class="clear ' . esc_attr( $this->field['id'] ) . '_previewer background-preview" style="' . esc_attr( $css ) . '">&nbsp;</p>';
355
-			}
356
-		}
357
-
358
-		/**
359
-		 * Enqueue Function.
360
-		 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
361
-		 *
362
-		 * @since       1.0.0
363
-		 * @access      public
364
-		 * @return      void
365
-		 */
366
-		public function enqueue() {
367
-			if ( function_exists( 'wp_enqueue_media' ) ) {
368
-				wp_enqueue_media();
369
-			} elseif ( ! wp_script_is( 'media-upload' ) ) {
370
-				wp_enqueue_script( 'media-upload' );
371
-			}
372
-
373
-			if ( ! wp_style_is( 'select2-css' ) ) {
374
-				wp_enqueue_style( 'select2-css' );
375
-			}
376
-
377
-			if ( ! wp_style_is( 'wp-color-picker' ) ) {
378
-				wp_enqueue_style( 'wp-color-picker' );
379
-			}
380
-
381
-			$dep_array = array( 'jquery', 'wp-color-picker', 'select2-js', 'redux-js' );
382
-
383
-			wp_enqueue_script(
384
-				'redux-field-background',
385
-				Redux_Core::$url . 'inc/fields/background/redux-background' . Redux_Functions::is_min() . '.js',
386
-				$dep_array,
387
-				$this->timestamp,
388
-				true
389
-			);
390
-
391
-			if ( $this->parent->args['dev_mode'] ) {
392
-				wp_enqueue_style(
393
-					'redux-field-background',
394
-					Redux_Core::$url . 'inc/fields/background/redux-background.css',
395
-					array(),
396
-					$this->timestamp
397
-				);
398
-
399
-				wp_enqueue_style( 'redux-color-picker' );
400
-			}
401
-		}
402
-
403
-		/**
404
-		 * Output CSS styling.
405
-		 *
406
-		 * @param array $data Value array.
407
-		 *
408
-		 * @return string
409
-		 */
410
-		public function css_style( $data = array() ): string {
411
-			$css = '';
412
-
413
-			if ( ! empty( $data ) && is_array( $data ) ) {
414
-				foreach ( $data as $key => $val ) {
415
-					if ( ! empty( $val ) && 'media' !== $key ) {
416
-						if ( 'background-image' === $key ) {
417
-							$css .= $key . ":url('" . esc_url( $val ) . "');";
418
-						} else {
419
-							$css .= $key . ':' . esc_attr( $val ) . ';';
420
-						}
421
-					}
422
-				}
423
-			}
424
-
425
-			return $css;
426
-		}
427
-
428
-		/**
429
-		 * Enable output_variables to be generated.
430
-		 *
431
-		 * @since       4.0.3
432
-		 * @return void
433
-		 */
434
-		public function output_variables() {
435
-			// No code needed, just defining the method is enough.
436
-		}
437
-	}
15
+    /**
16
+     * Main Redux_background class
17
+     *
18
+     * @since       3.1.5
19
+     */
20
+    class Redux_Background extends Redux_Field {
21
+
22
+        /**
23
+         * Set field and value defaults.
24
+         */
25
+        public function set_defaults() {
26
+            $defaults = array(
27
+                'background-color'      => true,
28
+                'background-repeat'     => true,
29
+                'background-attachment' => true,
30
+                'background-position'   => true,
31
+                'background-image'      => true,
32
+                'background-gradient'   => false,
33
+                'background-clip'       => false,
34
+                'background-origin'     => false,
35
+                'background-size'       => true,
36
+                'preview_media'         => false,
37
+                'preview'               => true,
38
+                'preview_height'        => '200px',
39
+                'transparent'           => true,
40
+            );
41
+
42
+            $this->field = wp_parse_args( $this->field, $defaults );
43
+
44
+            // No errors please.
45
+            $defaults = array(
46
+                'background-color'      => '',
47
+                'background-repeat'     => '',
48
+                'background-attachment' => '',
49
+                'background-position'   => '',
50
+                'background-image'      => '',
51
+                'background-clip'       => '',
52
+                'background-origin'     => '',
53
+                'background-size'       => '',
54
+                'media'                 => array(),
55
+            );
56
+
57
+            $this->value = wp_parse_args( $this->value, $defaults );
58
+
59
+            $defaults = array(
60
+                'id'        => '',
61
+                'width'     => '',
62
+                'height'    => '',
63
+                'thumbnail' => '',
64
+            );
65
+
66
+            $this->value['media'] = wp_parse_args( $this->value['media'], $defaults );
67
+        }
68
+
69
+        /**
70
+         * Field Render Function.
71
+         * Takes the vars and outputs the HTML for the field in the settings
72
+         *
73
+         * @since       1.0.0
74
+         * @access      public
75
+         * @return      void
76
+         */
77
+        public function render() {
78
+            $this->select2_config['allowClear'] = true;
79
+
80
+            if ( isset( $this->field['select2'] ) ) {
81
+                $this->field['select2'] = wp_parse_args( $this->field['select2'], $this->select2_config );
82
+            } else {
83
+                $this->field['select2'] = $this->select2_config;
84
+            }
85
+
86
+            $this->field['select2'] = Redux_Functions::sanitize_camel_case_array_keys( $this->field['select2'] );
87
+
88
+            $select2_data = Redux_Functions::create_data_string( $this->field['select2'] );
89
+
90
+            if ( true === $this->field['background-color'] ) {
91
+                if ( isset( $this->value['color'] ) && empty( $this->value['background-color'] ) ) {
92
+                    $this->value['background-color'] = $this->value['color'];
93
+                }
94
+
95
+                $def_bg_color = $this->field['default']['background-color'] ?? '';
96
+
97
+                echo '<input ';
98
+                echo 'data-id="' . esc_attr( $this->field['id'] ) . '"';
99
+                echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-color]"';
100
+                echo 'id="' . esc_attr( $this->field['id'] ) . '-color"';
101
+                echo 'class="color-picker redux-color redux-background-input redux-color-init ' . esc_attr( $this->field['class'] ) . '"';
102
+                echo 'type="text" value="' . esc_attr( $this->value['background-color'] ) . '"';
103
+                echo 'data-default-color="' . esc_attr( $def_bg_color ) . '"';
104
+
105
+                $data = array(
106
+                    'field' => $this->field,
107
+                    'index' => 'color',
108
+                );
109
+
110
+                echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput
111
+
112
+                echo '>';
113
+
114
+                echo '<input type="hidden" class="redux-saved-color" id="' . esc_attr( $this->field['id'] ) . '-saved-color" value="">';
115
+
116
+                if ( ! isset( $this->field['transparent'] ) || false !== $this->field['transparent'] ) {
117
+                    $is_checked = '';
118
+                    if ( 'transparent' === $this->value['background-color'] ) {
119
+                        $is_checked = ' checked="checked"';
120
+                    }
121
+                    echo '<label for="' . esc_attr( $this->field['id'] ) . '-transparency" class="color-transparency-check"><input type="checkbox" class="checkbox color-transparency redux-background-input ' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $this->field['id'] ) . '-transparency" data-id="' . esc_attr( $this->field['id'] ) . '-color" value="1" ' . esc_html( $is_checked ) . '> ' . esc_html__( 'Transparent', 'redux-framework' ) . '</label>';
122
+                }
123
+
124
+                if ( true === $this->field['background-repeat'] || true === $this->field['background-position'] || true === $this->field['background-attachment'] ) {
125
+                    echo '<br />';
126
+                }
127
+            }
128
+
129
+            if ( true === $this->field['background-repeat'] ) {
130
+                $array = array(
131
+                    'no-repeat' => esc_html__( 'No Repeat', 'redux-framework' ),
132
+                    'repeat'    => esc_html__( 'Repeat All', 'redux-framework' ),
133
+                    'repeat-x'  => esc_html__( 'Repeat Horizontally', 'redux-framework' ),
134
+                    'repeat-y'  => esc_html__( 'Repeat Vertically', 'redux-framework' ),
135
+                    'inherit'   => esc_html__( 'Inherit', 'redux-framework' ),
136
+                );
137
+
138
+                echo '<select id="' . esc_attr( $this->field['id'] ) . '-repeat-select" data-placeholder="' . esc_html__( 'Background Repeat', 'redux-framework' ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-repeat]" class="redux-select-item redux-background-input redux-background-repeat ' . esc_attr( $this->field['class'] ) . '"' . esc_attr( $select2_data ) . '>';
139
+                echo '<option></option>';
140
+
141
+                foreach ( $array as $k => $v ) {
142
+                    echo '<option value="' . esc_attr( $k ) . '" ' . selected( $this->value['background-repeat'], $k, false ) . '>' . esc_html( $v ) . '</option>';
143
+                }
144
+
145
+                echo '</select>';
146
+            }
147
+
148
+            if ( true === $this->field['background-clip'] ) {
149
+                $array = array(
150
+                    'inherit'     => esc_html__( 'Inherit', 'redux-framework' ),
151
+                    'border-box'  => esc_html__( 'Border Box', 'redux-framework' ),
152
+                    'content-box' => esc_html__( 'Content Box', 'redux-framework' ),
153
+                    'padding-box' => esc_html__( 'Padding Box', 'redux-framework' ),
154
+                );
155
+
156
+                echo '<select id="' . esc_attr( $this->field['id'] ) . '-clip-select" data-placeholder="' . esc_html__( 'Background Clip', 'redux-framework' ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-clip]" class="redux-select-item redux-background-input redux-background-clip ' . esc_attr( $this->field['class'] ) . '"' . esc_attr( $select2_data ) . '>';
157
+                echo '<option></option>';
158
+
159
+                foreach ( $array as $k => $v ) {
160
+                    echo '<option value="' . esc_attr( $k ) . '" ' . selected( $this->value['background-clip'], $k, false ) . '>' . esc_html( $v ) . '</option>';
161
+                }
162
+
163
+                echo '</select>';
164
+            }
165
+
166
+            if ( true === $this->field['background-origin'] ) {
167
+                $array = array(
168
+                    'inherit'     => esc_html__( 'Inherit', 'redux-framework' ),
169
+                    'border-box'  => esc_html__( 'Border Box', 'redux-framework' ),
170
+                    'content-box' => esc_html__( 'Content Box', 'redux-framework' ),
171
+                    'padding-box' => esc_html__( 'Padding Box', 'redux-framework' ),
172
+                );
173
+
174
+                echo '<select id="' . esc_attr( $this->field['id'] ) . '-origin-select" data-placeholder="' . esc_html__( 'Background Origin', 'redux-framework' ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-origin]" class="redux-select-item redux-background-input redux-background-origin ' . esc_attr( $this->field['class'] ) . '"' . esc_attr( $select2_data ) . '>';
175
+                echo '<option></option>';
176
+
177
+                foreach ( $array as $k => $v ) {
178
+                    echo '<option value="' . esc_attr( $k ) . '" ' . selected( $this->value['background-origin'], $k, false ) . '>' . esc_html( $v ) . '</option>';
179
+                }
180
+
181
+                echo '</select>';
182
+            }
183
+
184
+            if ( true === $this->field['background-size'] ) {
185
+                $array = array(
186
+                    'inherit' => esc_html__( 'Inherit', 'redux-framework' ),
187
+                    'cover'   => esc_html__( 'Cover', 'redux-framework' ),
188
+                    'contain' => esc_html__( 'Contain', 'redux-framework' ),
189
+                );
190
+
191
+                echo '<select id="' . esc_attr( $this->field['id'] ) . '-size-select" data-placeholder="' . esc_html__( 'Background Size', 'redux-framework' ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-size]" class="redux-select-item redux-background-input redux-background-size ' . esc_attr( $this->field['class'] ) . '"' . esc_attr( $select2_data ) . '>';
192
+                echo '<option></option>';
193
+
194
+                foreach ( $array as $k => $v ) {
195
+                    echo '<option value="' . esc_attr( $k ) . '" ' . selected( $this->value['background-size'], $k, false ) . '>' . esc_html( $v ) . '</option>';
196
+                }
197
+
198
+                echo '</select>';
199
+            }
200
+
201
+            if ( true === $this->field['background-attachment'] ) {
202
+                $array = array(
203
+                    'fixed'   => esc_html__( 'Fixed', 'redux-framework' ),
204
+                    'scroll'  => esc_html__( 'Scroll', 'redux-framework' ),
205
+                    'inherit' => esc_html__( 'Inherit', 'redux-framework' ),
206
+                );
207
+
208
+                echo '<select id="' . esc_attr( $this->field['id'] ) . '-attachment-select" data-placeholder="' . esc_html__( 'Background Attachment', 'redux-framework' ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-attachment]" class="redux-select-item redux-background-input redux-background-attachment ' . esc_attr( $this->field['class'] ) . '"' . esc_attr( $select2_data ) . '>';
209
+                echo '<option></option>';
210
+
211
+                foreach ( $array as $k => $v ) {
212
+                    echo '<option value="' . esc_attr( $k ) . '" ' . selected( $this->value['background-attachment'], $k, false ) . '>' . esc_html( $v ) . '</option>';
213
+                }
214
+
215
+                echo '</select>';
216
+            }
217
+
218
+            if ( true === $this->field['background-position'] ) {
219
+                $array = array(
220
+                    'left top'      => esc_html__( 'Left Top', 'redux-framework' ),
221
+                    'left center'   => esc_html__( 'Left center', 'redux-framework' ),
222
+                    'left bottom'   => esc_html__( 'Left Bottom', 'redux-framework' ),
223
+                    'center top'    => esc_html__( 'Center Top', 'redux-framework' ),
224
+                    'center center' => esc_html__( 'Center Center', 'redux-framework' ),
225
+                    'center bottom' => esc_html__( 'Center Bottom', 'redux-framework' ),
226
+                    'right top'     => esc_html__( 'Right Top', 'redux-framework' ),
227
+                    'right center'  => esc_html__( 'Right center', 'redux-framework' ),
228
+                    'right bottom'  => esc_html__( 'Right Bottom', 'redux-framework' ),
229
+                );
230
+
231
+                echo '<select id="' . esc_attr( $this->field['id'] ) . '-position-select" data-placeholder="' . esc_html__( 'Background Position', 'redux-framework' ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-position]" class="redux-select-item redux-background-input redux-background-position ' . esc_attr( $this->field['class'] ) . '"' . esc_attr( $select2_data ) . '>';
232
+                echo '<option></option>';
233
+
234
+                foreach ( $array as $k => $v ) {
235
+                    echo '<option value="' . esc_attr( $k ) . '" ' . selected( $this->value['background-position'], $k, false ) . '>' . esc_html( $v ) . '</option>';
236
+                }
237
+
238
+                echo '</select>';
239
+            }
240
+
241
+            if ( $this->field['background-image'] ) {
242
+                echo '<br />';
243
+
244
+                if ( empty( $this->value ) && ! empty( $this->field['default'] ) ) {
245
+                    if ( is_array( $this->field['default'] ) ) {
246
+                        if ( ! empty( $this->field['default']['media']['id'] ) ) {
247
+                            $this->value['media']['id'] = $this->field['default']['media']['id'];
248
+                        } elseif ( ! empty( $this->field['default']['id'] ) ) {
249
+                            $this->value['media']['id'] = $this->field['default']['id'];
250
+                        }
251
+
252
+                        if ( ! empty( $this->field['default']['url'] ) ) {
253
+                            $this->value['background-image'] = $this->field['default']['url'];
254
+                        } elseif ( ! empty( $this->field['default']['media']['url'] ) ) {
255
+                            $this->value['background-image'] = $this->field['default']['media']['url'];
256
+                        } elseif ( ! empty( $this->field['default']['background-image'] ) ) {
257
+                            $this->value['background-image'] = $this->field['default']['background-image'];
258
+                        }
259
+                    } elseif ( is_numeric( $this->field['default'] ) ) {
260
+                        // Check if it's an attachment ID.
261
+                            $this->value['media']['id'] = $this->field['default'];
262
+                    } else { // Must be a URL.
263
+                        $this->value['background-image'] = $this->field['default'];
264
+                    }
265
+                }
266
+
267
+                if ( empty( $this->value['background-image'] ) && ! empty( $this->value['media']['id'] ) ) {
268
+                    $img                             = wp_get_attachment_image_src( $this->value['media']['id'], 'full' );
269
+                    $this->value['background-image'] = $img[0];
270
+                    $this->value['media']['width']   = $img[1];
271
+                    $this->value['media']['height']  = $img[2];
272
+                }
273
+
274
+                $hide = 'hide ';
275
+
276
+                if ( ( isset( $this->field['preview_media'] ) && false === $this->field['preview_media'] ) ) {
277
+                    $this->field['class'] .= ' noPreview';
278
+                }
279
+
280
+                if ( ( ! empty( $this->field['background-image'] ) && true === $this->field['background-image'] ) || ( isset( $this->field['preview'] ) && false === $this->field['preview'] ) ) {
281
+                    $hide = '';
282
+                }
283
+
284
+                $placeholder = $this->field['placeholder'] ?? esc_html__( 'No media selected', 'redux-framework' );
285
+
286
+                echo '<input placeholder="' . esc_html( $placeholder ) . '" type="text" class="redux-background-input ' . esc_attr( $hide ) . 'upload ' . esc_attr( $this->field['class'] ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-image]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][background-image]" value="' . esc_url( $this->value['background-image'] ) . '" />';
287
+                echo '<input type="hidden" class="upload-id ' . esc_attr( $this->field['class'] ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[media][id]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][media][id]" value="' . esc_attr( $this->value['media']['id'] ) . '" />';
288
+                echo '<input type="hidden" class="upload-height" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[media][height]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][media][height]" value="' . esc_attr( $this->value['media']['height'] ) . '" />';
289
+                echo '<input type="hidden" class="upload-width" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[media][width]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][media][width]" value="' . esc_attr( $this->value['media']['width'] ) . '" />';
290
+                echo '<input type="hidden" class="upload-thumbnail" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[media][thumbnail]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][media][thumbnail]" value="' . esc_url( $this->value['media']['thumbnail'] ) . '" />';
291
+
292
+                // Preview.
293
+                $hide = '';
294
+
295
+                if ( ( isset( $this->field['preview_media'] ) && false === $this->field['preview_media'] ) || empty( $this->value['background-image'] ) ) {
296
+                    $hide = 'hide ';
297
+                }
298
+
299
+                if ( empty( $this->value['media']['thumbnail'] ) && ! empty( $this->value['background-image'] ) ) { // Just in case.
300
+                    if ( ! empty( $this->value['media']['id'] ) ) {
301
+                        $image = wp_get_attachment_image_src(
302
+                            $this->value['media']['id'],
303
+                            array(
304
+                                150,
305
+                                150,
306
+                            )
307
+                        );
308
+
309
+                        $this->value['media']['thumbnail'] = $image[0];
310
+                    } else {
311
+                        $this->value['media']['thumbnail'] = $this->value['background-image'];
312
+                    }
313
+                }
314
+
315
+                echo '<div class="' . esc_attr( $hide ) . 'screenshot">';
316
+                echo '<a class="of-uploaded-image" href="' . esc_url( $this->value['background-image'] ) . '" target="_blank">';
317
+
318
+                $alt = wp_prepare_attachment_for_js( $this->value['media']['id'] );
319
+                $alt = $alt['alt'] ?? '';
320
+
321
+                echo '<img class="redux-option-image" id="image_' . esc_attr( $this->value['media']['id'] ) . '" src="' . esc_url( $this->value['media']['thumbnail'] ) . '" alt="' . esc_attr( $alt ) . '" target="_blank" rel="external" />';
322
+                echo '</a>';
323
+                echo '</div>';
324
+
325
+                // Upload controls DIV.
326
+                echo '<div class="upload_button_div">';
327
+
328
+                // If the user has WP3.5+ show upload/remove button.
329
+                echo '<span class="button redux-background-upload" id="' . esc_attr( $this->field['id'] ) . '-media">' . esc_html__( 'Upload', 'redux-framework' ) . '</span>';
330
+
331
+                $hide = '';
332
+                if ( empty( $this->value['background-image'] ) || '' === $this->value['background-image'] ) {
333
+                    $hide = ' hide';
334
+                }
335
+
336
+                echo '<span class="button removeCSS redux-remove-background' . esc_attr( $hide ) . '" id="reset_' . esc_attr( $this->field['id'] ) . '" rel="' . esc_attr( $this->field['id'] ) . '">' . esc_html__( 'Remove', 'redux-framework' ) . '</span>';
337
+
338
+                echo '</div>';
339
+            }
340
+
341
+            /**
342
+             * Preview
343
+             * */
344
+            if ( ! isset( $this->field['preview'] ) || false !== $this->field['preview'] ) {
345
+                $css = $this->css_style( $this->value );
346
+
347
+                $is_bg = strpos( $css, 'background-image' );
348
+
349
+                if ( empty( $css ) || ! $is_bg ) {
350
+                    $css = 'display:none;';
351
+                }
352
+
353
+                $css .= 'height: ' . esc_attr( $this->field['preview_height'] ) . ';';
354
+                echo '<p class="clear ' . esc_attr( $this->field['id'] ) . '_previewer background-preview" style="' . esc_attr( $css ) . '">&nbsp;</p>';
355
+            }
356
+        }
357
+
358
+        /**
359
+         * Enqueue Function.
360
+         * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
361
+         *
362
+         * @since       1.0.0
363
+         * @access      public
364
+         * @return      void
365
+         */
366
+        public function enqueue() {
367
+            if ( function_exists( 'wp_enqueue_media' ) ) {
368
+                wp_enqueue_media();
369
+            } elseif ( ! wp_script_is( 'media-upload' ) ) {
370
+                wp_enqueue_script( 'media-upload' );
371
+            }
372
+
373
+            if ( ! wp_style_is( 'select2-css' ) ) {
374
+                wp_enqueue_style( 'select2-css' );
375
+            }
376
+
377
+            if ( ! wp_style_is( 'wp-color-picker' ) ) {
378
+                wp_enqueue_style( 'wp-color-picker' );
379
+            }
380
+
381
+            $dep_array = array( 'jquery', 'wp-color-picker', 'select2-js', 'redux-js' );
382
+
383
+            wp_enqueue_script(
384
+                'redux-field-background',
385
+                Redux_Core::$url . 'inc/fields/background/redux-background' . Redux_Functions::is_min() . '.js',
386
+                $dep_array,
387
+                $this->timestamp,
388
+                true
389
+            );
390
+
391
+            if ( $this->parent->args['dev_mode'] ) {
392
+                wp_enqueue_style(
393
+                    'redux-field-background',
394
+                    Redux_Core::$url . 'inc/fields/background/redux-background.css',
395
+                    array(),
396
+                    $this->timestamp
397
+                );
398
+
399
+                wp_enqueue_style( 'redux-color-picker' );
400
+            }
401
+        }
402
+
403
+        /**
404
+         * Output CSS styling.
405
+         *
406
+         * @param array $data Value array.
407
+         *
408
+         * @return string
409
+         */
410
+        public function css_style( $data = array() ): string {
411
+            $css = '';
412
+
413
+            if ( ! empty( $data ) && is_array( $data ) ) {
414
+                foreach ( $data as $key => $val ) {
415
+                    if ( ! empty( $val ) && 'media' !== $key ) {
416
+                        if ( 'background-image' === $key ) {
417
+                            $css .= $key . ":url('" . esc_url( $val ) . "');";
418
+                        } else {
419
+                            $css .= $key . ':' . esc_attr( $val ) . ';';
420
+                        }
421
+                    }
422
+                }
423
+            }
424
+
425
+            return $css;
426
+        }
427
+
428
+        /**
429
+         * Enable output_variables to be generated.
430
+         *
431
+         * @since       4.0.3
432
+         * @return void
433
+         */
434
+        public function output_variables() {
435
+            // No code needed, just defining the method is enough.
436
+        }
437
+    }
438 438
 }
439 439
 
440 440
 class_alias( 'Redux_Background', 'ReduxFramework_Background' );
Please login to merge, or discard this patch.
color_scheme/color_scheme/inc/class-redux-color-scheme-functions.php 2 patches
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 		 *
43 43
 		 * @var array|null
44 44
 		 */
45
-		public static ?array $field;
45
+		public static ? array $field;
46 46
 
47 47
 		/**
48 48
 		 * WP Upload directory.
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 		 *
64 64
 		 * @var array|null
65 65
 		 */
66
-		public static ?array $select;
66
+		public static ? array $select;
67 67
 
68 68
 		/**
69 69
 		 * Class init.
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
 				$html .= '<select name="' . self::$parent->args['opt_name'] . '[' . self::$field_id . '][' . $id . ']" id="redux-color-scheme-opt-select-' . $id . '"' . $width . ' class="redux-color-scheme-opt-select">';
400 400
 
401 401
 				foreach ( $v['options'] as $opt_id => $opt_val ) {
402
-					$data[ $id ]['value'] = $data[ $id ]['value'] ?? '';
403
-					$html                .= '<option value="' . $opt_id . '" ' . selected( $opt_id, $data[ $id ]['value'], false ) . '>' . $opt_val . '</option>';
402
+					$data[$id]['value'] = $data[$id]['value'] ?? '';
403
+					$html                .= '<option value="' . $opt_id . '" ' . selected( $opt_id, $data[$id]['value'], false ) . '>' . $opt_val . '</option>';
404 404
 				}
405 405
 
406 406
 				$html .= '</select>';
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 						$val['rgba']  = $val['rgba'] ?? $res;
546 546
 						$val['group'] = $val['group'] ?? '';
547 547
 
548
-						$scheme[ $val['id'] ] = $val;
548
+						$scheme[$val['id']] = $val;
549 549
 					}
550 550
 				}
551 551
 
@@ -579,9 +579,9 @@  discard block
 block discarded – undo
579 579
 					foreach ( self::$select as $sel_arr ) {
580 580
 						$sel_grp = $sel_arr['group'];
581 581
 						if ( ! array_key_exists( $sel_grp, $sel_grps ) ) {
582
-							$sel_grps[ $sel_grp ] = array();
582
+							$sel_grps[$sel_grp] = array();
583 583
 						}
584
-						$sel_grps[ $sel_grp ][] = $sel_arr;
584
+						$sel_grps[$sel_grp][] = $sel_arr;
585 585
 					}
586 586
 				}
587 587
 
@@ -589,19 +589,19 @@  discard block
 block discarded – undo
589 589
 				$group_arr = self::get_group_names();
590 590
 
591 591
 				foreach ( $group_arr as $group_name => $description ) {
592
-					$groups[ $group_name ] = array();
592
+					$groups[$group_name] = array();
593 593
 
594 594
 					if ( is_array( $description ) ) {
595
-						$grp_desc[ $group_name ]           = $description['desc'] ?? '';
596
-						$grp_grpdesc[ $group_name ]        = $description['group_desc'] ?? '';
597
-						$grp_hidden[ $group_name ]         = $description['hidden'] ?? false;
598
-						$grp_accordion_open[ $group_name ] = $description['accordion_open'] ?? false;
595
+						$grp_desc[$group_name]           = $description['desc'] ?? '';
596
+						$grp_grpdesc[$group_name]        = $description['group_desc'] ?? '';
597
+						$grp_hidden[$group_name]         = $description['hidden'] ?? false;
598
+						$grp_accordion_open[$group_name] = $description['accordion_open'] ?? false;
599 599
 
600 600
 					} else {
601
-						$grp_desc[ $group_name ]           = $description;
602
-						$grp_hidden[ $group_name ]         = false;
603
-						$grp_accordion_open[ $group_name ] = false;
604
-						$grp_grpdesc[ $group_name ]        = false;
601
+						$grp_desc[$group_name]           = $description;
602
+						$grp_hidden[$group_name]         = false;
603
+						$grp_accordion_open[$group_name] = false;
604
+						$grp_grpdesc[$group_name]        = false;
605 605
 					}
606 606
 				}
607 607
 
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 					if ( is_array( $arr ) ) {
611 611
 						if ( ! empty( $arr['group'] ) ) {
612 612
 							if ( array_key_exists( $arr['group'], $group_arr ) ) {
613
-								$groups[ $arr['group'] ][] = $arr;
613
+								$groups[$arr['group']][] = $arr;
614 614
 							} else {
615 615
 								$groups[''][] = $arr;
616 616
 							}
@@ -656,10 +656,10 @@  discard block
 block discarded – undo
656 656
 					$class_hide = '';
657 657
 					$is_open    = '';
658 658
 
659
-					if ( isset( $grp_hidden[ $title ] ) && '' !== $grp_hidden[ $title ] ) {
660
-						$is_hidden  = $grp_hidden[ $title ];
659
+					if ( isset( $grp_hidden[$title] ) && '' !== $grp_hidden[$title] ) {
660
+						$is_hidden  = $grp_hidden[$title];
661 661
 						$class_hide = ( true === $is_hidden ) ? ' hidden ' : '';
662
-						$is_open    = $grp_accordion_open[ $title ];
662
+						$is_open    = $grp_accordion_open[$title];
663 663
 					}
664 664
 
665 665
 					$add_class = '';
@@ -689,8 +689,8 @@  discard block
 block discarded – undo
689 689
 						}
690 690
 
691 691
 						// apply group description, if any.
692
-						if ( isset( $grp_desc[ $title ] ) && '' !== $grp_desc[ $title ] ) {
693
-							$html  .= '<span class="redux-label redux-layout-group-desc-label' . $icon_class . '">' . esc_attr( $grp_desc[ $title ] ) . '</label>';
692
+						if ( isset( $grp_desc[$title] ) && '' !== $grp_desc[$title] ) {
693
+							$html  .= '<span class="redux-label redux-layout-group-desc-label' . $icon_class . '">' . esc_attr( $grp_desc[$title] ) . '</label>';
694 694
 							$add_hr = true;
695 695
 
696 696
 							if ( $is_accordion ) {
@@ -716,14 +716,14 @@  discard block
 block discarded – undo
716 716
 							$html .= '<div class="redux-color-scheme-accordion-section" data-state="' . esc_attr( $is_open ) . '">';
717 717
 							if ( false !== $grp_grpdesc ) {
718 718
 								$html .= '<div class="redux-color-scheme-group-desc">';
719
-								$html .= esc_attr( $grp_grpdesc[ $title ] );
719
+								$html .= esc_attr( $grp_grpdesc[$title] );
720 720
 								$html .= '</div>';
721 721
 							}
722 722
 						}
723 723
 
724 724
 						// Select box render.
725 725
 						if ( array_key_exists( $title, $sel_grps ) ) {
726
-							$html .= self::render_selects( $sel_grps[ $title ], $scheme );
726
+							$html .= self::render_selects( $sel_grps[$title], $scheme );
727 727
 						}
728 728
 					} elseif ( $is_accordion ) {
729 729
 						$html .= '<div class="redux-color-scheme-accordion-section">';
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
 								return '';
799 799
 							}
800 800
 
801
-							$picker_data = $scheme_data[ $v['id'] ];
801
+							$picker_data = $scheme_data[$v['id']];
802 802
 
803 803
 							// Hidden input for data string.
804 804
 							$html .= '<input
@@ -962,7 +962,7 @@  discard block
 block discarded – undo
962 962
 				return false;
963 963
 			}
964 964
 
965
-			return $data[ $scheme_name ];
965
+			return $data[$scheme_name];
966 966
 		}
967 967
 
968 968
 		/**
@@ -989,7 +989,7 @@  discard block
 block discarded – undo
989 989
 				// Enum through values and assign them to new array.
990 990
 				foreach ( $arr as $val ) {
991 991
 					if ( isset( $val['id'] ) ) {
992
-						$new_scheme[ $val['id'] ] = $val;
992
+						$new_scheme[$val['id']] = $val;
993 993
 					}
994 994
 				}
995 995
 
@@ -1001,12 +1001,12 @@  discard block
 block discarded – undo
1001 1001
 					$schemes = array();
1002 1002
 				}
1003 1003
 
1004
-				$scheme_data = $schemes[ $name ] ?? '';
1004
+				$scheme_data = $schemes[$name] ?? '';
1005 1005
 
1006 1006
 				if ( $scheme_data !== $new_scheme ) {
1007 1007
 
1008 1008
 					// Add new scheme to array that will be saved.
1009
-					$schemes[ $name ] = $new_scheme;
1009
+					$schemes[$name] = $new_scheme;
1010 1010
 
1011 1011
 					// Write the data to the JSON file.
1012 1012
 					return self::write_scheme_file( $schemes );
@@ -1076,9 +1076,9 @@  discard block
 block discarded – undo
1076 1076
 					if ( isset( $v['type'] ) ) {
1077 1077
 						$val = $v['value'];
1078 1078
 
1079
-						unset( $data[ $k ] );
1079
+						unset( $data[$k] );
1080 1080
 
1081
-						$data[ $k ] = $val;
1081
+						$data[$k] = $val;
1082 1082
 					}
1083 1083
 				}
1084 1084
 			}
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
 			}
1112 1112
 
1113 1113
 			// Append ID to variable that holds the current scheme ID data.
1114
-			$redux_options[ self::$field_id ] = $data;
1114
+			$redux_options[self::$field_id] = $data;
1115 1115
 
1116 1116
 			// Save the modified settings.
1117 1117
 			update_option( $opt_name, $redux_options );
Please login to merge, or discard this patch.
Indentation   +1082 added lines, -1082 removed lines patch added patch discarded remove patch
@@ -11,773 +11,773 @@  discard block
 block discarded – undo
11 11
 defined( 'ABSPATH' ) || exit;
12 12
 
13 13
 if ( ! class_exists( 'Redux_Color_Scheme_Functions' ) ) {
14
-	/**
15
-	 * Class Redux_Color_Scheme_Functions
16
-	 */
17
-	class Redux_Color_Scheme_Functions {
18
-
19
-		/**
20
-		 * ReduxFramework object.
21
-		 *
22
-		 * @var null|ReduxFramework
23
-		 */
24
-		public static ?ReduxFramework $parent;
25
-
26
-		/**
27
-		 * Field ID
28
-		 *
29
-		 * @var string|null
30
-		 */
31
-		public static ?string $field_id;
32
-
33
-		/**
34
-		 * Field class.
35
-		 *
36
-		 * @var string|null
37
-		 */
38
-		public static ?string $field_class;
39
-
40
-		/**
41
-		 * Field array.
42
-		 *
43
-		 * @var array|null
44
-		 */
45
-		public static ?array $field;
46
-
47
-		/**
48
-		 * WP Upload directory.
49
-		 *
50
-		 * @var string|null
51
-		 */
52
-		public static ?string $upload_dir = '';
53
-
54
-		/**
55
-		 * WP Upload URI
56
-		 *
57
-		 * @var string|null
58
-		 */
59
-		public static ?string $upload_url = '';
60
-
61
-		/**
62
-		 * Select fields.
63
-		 *
64
-		 * @var array|null
65
-		 */
66
-		public static ?array $select;
67
-
68
-		/**
69
-		 * Class init.
70
-		 *
71
-		 * @param ReduxFramework $redux ReduxFramework object.
72
-		 */
73
-		public static function init( ReduxFramework $redux ) {
74
-			self::$parent = $redux;
75
-
76
-			if ( empty( self::$field_id ) ) {
77
-				self::$field = self::get_field( $redux );
78
-
79
-				if ( ! is_array( self::$field ) ) {
80
-					return;
81
-				}
82
-
83
-				self::$field_id = self::$field['id'];
84
-			}
85
-
86
-			// Make sanitized upload dir DIR.
87
-			self::$upload_dir = Redux_Functions_Ex::wp_normalize_path( ReduxFramework::$_upload_dir . 'color-schemes/' );
88
-
89
-			// Make sanitized upload dir URL.
90
-			self::$upload_url = Redux_Functions_Ex::wp_normalize_path( ReduxFramework::$_upload_url . 'color-schemes/' );
91
-
92
-			Redux_Functions::init_wp_filesystem();
93
-		}
94
-
95
-		/**
96
-		 * Checks if tooltips are in use.
97
-		 *
98
-		 * @param array $field Field array.
99
-		 *
100
-		 * @return bool
101
-		 */
102
-		public static function tooltips_in_use( array $field ): bool {
103
-			$blocks = $field['default'];
104
-
105
-			foreach ( $blocks as $arr ) {
106
-				if ( isset( $arr['tooltip'] ) ) {
107
-					return true;
108
-				}
109
-			}
110
-
111
-			return false;
112
-		}
113
-
114
-		/**
115
-		 * Convert DB values.
116
-		 */
117
-		public static function convert_to_db() {
118
-			$upload_dir = Redux_Functions_Ex::wp_normalize_path( ReduxFramework::$_upload_dir . 'color-schemes/' );
119
-
120
-			$cur_scheme_file = Redux_Functions_Ex::wp_normalize_path( $upload_dir . '/' . self::$parent->args['opt_name'] . '_' . self::$field_id . '.json' );
121
-
122
-			if ( is_dir( $upload_dir ) ) {
123
-				if ( file_exists( $cur_scheme_file ) ) {
124
-					$data = Redux_Core::$filesystem->execute( 'get_contents', $cur_scheme_file );
125
-					if ( ! empty( $data ) ) {
126
-						$data = json_decode( $data, true );
127
-
128
-						update_option( self::get_scheme_key(), $data );
129
-
130
-						Redux_Core::$filesystem->execute( 'delete', $cur_scheme_file );
131
-					}
132
-				}
133
-			}
134
-		}
135
-
136
-		/**
137
-		 * Get scheme key.
138
-		 *
139
-		 * @return string
140
-		 */
141
-		public static function get_scheme_key(): string {
142
-			return 'redux_cs_' . self::$parent->args['opt_name'] . '_' . self::$field_id;
143
-		}
144
-
145
-		/**
146
-		 * Get the list of groups names for the color scheme table.
147
-		 *
148
-		 * @since       2.0.0
149
-		 * @access      public static
150
-		 * @return      array Array of group names.
151
-		 */
152
-		public static function get_group_names(): array {
153
-			if ( empty( self::$field ) ) {
154
-				self::$field = self::get_field();
155
-			}
156
-
157
-			if ( isset( self::$field['groups'] ) ) {
158
-				if ( is_array( self::$field['groups'] ) && ! empty( self::$field['groups'] ) ) {
159
-					return self::$field['groups'];
160
-				}
161
-			}
162
-
163
-			return array();
164
-		}
165
-
166
-		/**
167
-		 * Get output transparent value.
168
-		 *
169
-		 * @return mixed
170
-		 */
171
-		public static function get_output_transparent_val() {
172
-			if ( empty( self::$field ) ) {
173
-				self::$field = self::get_field();
174
-			}
175
-
176
-			if ( isset( self::$field['output_transparent'] ) ) {
177
-				if ( ! empty( self::$field['output_transparent'] ) ) {
178
-					return self::$field['output_transparent'];
179
-				}
180
-			}
181
-
182
-			return false;
183
-		}
184
-
185
-		/**
186
-		 * Get select field name.
187
-		 *
188
-		 * @return array
189
-		 */
190
-		private static function get_select_names(): array {
191
-			if ( empty( self::$field ) ) {
192
-				self::$field = self::get_field();
193
-			}
194
-
195
-			if ( isset( self::$field['select'] ) ) {
196
-				if ( is_array( self::$field['select'] ) && ! empty( self::$field['select'] ) ) {
197
-					return self::$field['select'];
198
-				}
199
-			}
200
-
201
-			return array();
202
-		}
203
-
204
-		/**
205
-		 * Get color scheme field.
206
-		 *
207
-		 * @param ReduxFramework|null $redux pointer.
208
-		 *
209
-		 * @return mixed
210
-		 */
211
-		public static function get_field( ?ReduxFramework $redux = null ) {
212
-			if ( ! is_null( $redux ) ) {
213
-				self::$parent = $redux;
214
-			}
215
-
216
-			if ( isset( $redux->field_sections['color_scheme'] ) ) {
217
-				return reset( $redux->field_sections['color_scheme'] );
218
-			}
219
-
220
-			$arr = self::$parent;
221
-
222
-			foreach ( $arr as $part => $bla ) {
223
-				if ( 'sections' === $part ) {
224
-					foreach ( $bla as $field ) {
225
-						foreach ( $field as $arg => $val ) {
226
-							if ( 'fields' === $arg ) {
227
-								foreach ( $val as $v ) {
228
-									if ( ! empty( $v ) ) {
229
-										foreach ( $v as $id => $x ) {
230
-											if ( 'type' === $id ) {
231
-												if ( 'color_scheme' === $x ) {
232
-													return $v;
233
-												}
234
-											}
235
-										}
236
-									}
237
-								}
238
-							}
239
-						}
240
-					}
241
-				}
242
-			}
243
-
244
-			return null;
245
-		}
246
-
247
-		/**
248
-		 * Output scheme dropdown selector.
249
-		 *
250
-		 * @param       string $selected Selected scheme name.
251
-		 *
252
-		 * @return      string HTML of dropdown selector.
253
-		 * @since       1.0.0
254
-		 * @access      public static
255
-		 */
256
-		public static function get_scheme_select_html( string $selected ): string {
257
-
258
-			$html  = '<select name="' . esc_attr( self::$parent->args['opt_name'] ) . '[redux-scheme-select]" id="redux-scheme-select-' . esc_attr( self::$field_id ) . '" class="redux-scheme-select">';
259
-			$html .= self::get_scheme_list_html( $selected );
260
-			$html .= '</select>';
261
-
262
-			return $html;
263
-		}
264
-
265
-		/**
266
-		 * Set current scheme ID, if one isn't specified.
267
-		 *
268
-		 * @param       string $id Scheme name to set.
269
-		 *
270
-		 * @return      void
271
-		 * @since       1.0.0
272
-		 * @access      public static
273
-		 */
274
-		public static function set_current_scheme_id( string $id ) {
275
-
276
-			// Get opt name, for database.
277
-			$opt_name = self::$parent->args['opt_name'];
278
-
279
-			// Get all options from database.
280
-			$redux_options = get_option( $opt_name, array() );
281
-			if ( ! is_array( $redux_options ) ) {
282
-				$redux_options = array();
283
-			}
284
-			// Append ID to variable that holds the current scheme ID data.
285
-			$redux_options['redux-scheme-select'] = $id;
286
-
287
-			// Save the modified settings.
288
-			update_option( $opt_name, $redux_options );
289
-		}
290
-
291
-		/**
292
-		 * Get tooltip toggle state.
293
-		 *
294
-		 * @return bool
295
-		 */
296
-		public static function get_tooltip_toggle_state(): bool {
297
-
298
-			// Retrieve the opt_name, needed for database.
299
-			$opt_name = self::$parent->args['opt_name'];
300
-
301
-			// Get the entire options array.
302
-			$redux_options = get_option( $opt_name );
303
-
304
-			return $redux_options['redux-color-scheme-tooltip-toggle'] ?? true;
305
-		}
306
-
307
-		/**
308
-		 * Gets the current schem ID from the database.
309
-		 *
310
-		 * @since       1.0.0
311
-		 * @access      public static
312
-		 *
313
-		 * @return      string Current scheme ID.
314
-		 */
315
-		public static function get_current_scheme_id(): string {
316
-
317
-			// Retrieve the opt_name, needed for databasae.
318
-			$opt_name = self::$parent->args['opt_name'];
319
-
320
-			// Get the entire options array.
321
-			$redux_options = get_option( $opt_name );
322
-
323
-			// If the current scheme key exists...
324
-			return $redux_options['redux-scheme-select'] ?? 'Default';
325
-		}
326
-
327
-		/**
328
-		 * Get the list of schemes for the selector.
329
-		 *
330
-		 * @param       string $sel Scheme name to select.
331
-		 *
332
-		 * @return      string HTML option values.
333
-		 * @since       1.0.0
334
-		 * @access      static private
335
-		 */
336
-		private static function get_scheme_list_html( string $sel = '' ): string {
337
-			// no errors, please.
338
-			$html = '';
339
-
340
-			// Retrieves the list of saved schemes into an array variable.
341
-			$dropdown_values = self::get_scheme_names();
342
-
343
-			// If the dropdown array has items...
344
-			if ( ! empty( $dropdown_values ) ) {
345
-
346
-				// Sort them alphbetically.
347
-				asort( $dropdown_values );
348
-			}
349
-
350
-			// trim the selected item.
351
-			$sel = trim( $sel );
352
-
353
-			// If it's empty.
354
-			if ( '' === $sel ) {
355
-
356
-				// Make the current scheme id the selected value.
357
-				$selected = self::get_current_scheme_id();
358
-			} else {
359
-
360
-				// Otherwise, set it to the value passed to this function.
361
-				$selected = $sel;
362
-			}
363
-
364
-			// Enum through the dropdown array and append the necessary HTML for the selector.
365
-			foreach ( $dropdown_values as $k ) {
366
-				$html .= '<option value="' . $k . '" ' . selected( $k, $selected, false ) . '>' . $k . '</option>';
367
-			}
368
-
369
-			// Send it all packin'.
370
-			return $html;
371
-		}
372
-
373
-		/**
374
-		 * Returns select HTML.
375
-		 *
376
-		 * @param array $arr  Array of select fields to render.
377
-		 * @param array $data Array of scheme data.
378
-		 *
379
-		 * @return      string HTML of select fields.
380
-		 * @since       1.0.4
381
-		 * @access      static private
382
-		 */
383
-		private static function render_selects( array $arr, array $data ): string {
384
-
385
-			$html = '';
386
-			foreach ( $arr as $v ) {
387
-				$id = $v['id'];
388
-
389
-				if ( isset( $v['width'] ) && ! empty( $v['width'] ) ) {
390
-					$size = $v['width'];
391
-				} else {
392
-					$size = '40%';
393
-				}
394
-
395
-				$width = ' style="width: ' . $size . ';"';
396
-
397
-				$html .= '<span class="redux-label redux-color-scheme-opt-select-title">' . $v['title'] . '</span>';
398
-
399
-				$html .= '<select name="' . self::$parent->args['opt_name'] . '[' . self::$field_id . '][' . $id . ']" id="redux-color-scheme-opt-select-' . $id . '"' . $width . ' class="redux-color-scheme-opt-select">';
400
-
401
-				foreach ( $v['options'] as $opt_id => $opt_val ) {
402
-					$data[ $id ]['value'] = $data[ $id ]['value'] ?? '';
403
-					$html                .= '<option value="' . $opt_id . '" ' . selected( $opt_id, $data[ $id ]['value'], false ) . '>' . $opt_val . '</option>';
404
-				}
405
-
406
-				$html .= '</select>';
407
-				$html .= '<span class="redux-label redux-color-scheme-opt-select-desc">' . $v['desc'] . '</span>';
408
-				$html .= '<hr class="redux-color-scheme-select-close-hr">';
409
-				$html .= '<br/>';
410
-			}
411
-
412
-			return $html;
413
-		}
414
-
415
-		/**
416
-		 * Do diff.
417
-		 *
418
-		 * @param array $first_array  Array one.
419
-		 * @param array $second_array Array two.
420
-		 *
421
-		 * @return array
422
-		 */
423
-		private static function do_diff( array $first_array, array $second_array ): array {
424
-
425
-			/**
426
-			 * Serialize callback.
427
-			 *
428
-			 * @param array $arr Array.
429
-			 */
430
-			function my_serialize( array &$arr ) {
431
-				$arr = maybe_serialize( $arr );
432
-			}
433
-
434
-			/**
435
-			 * Unserialize callback.
436
-			 *
437
-			 * @param array $arr Array.
438
-			 */
439
-			function my_unserialize( &$arr ) {
440
-				$arr = maybe_unserialize( $arr );
441
-			}
442
-
443
-			// make a copy.
444
-			$first_array_s  = $first_array;
445
-			$second_array_s = $second_array;
446
-
447
-			// serialize all sub-arrays.
448
-			array_walk( $first_array_s, 'my_serialize' );
449
-			array_walk( $second_array_s, 'my_serialize' );
450
-
451
-			// array_diff the serialized versions.
452
-			$diff = array_diff( $first_array_s, $second_array_s );
453
-
454
-			// unserialize the result.
455
-			array_walk( $diff, 'my_unserialize' );
456
-
457
-			// you've got it!
458
-			return $diff;
459
-		}
460
-
461
-		/**
462
-		 * Returns colour pickers HTML table.
463
-		 *
464
-		 * @since       1.0.0
465
-		 * @access      public static
466
-		 *
467
-		 * @param       string $scheme_id Scheme name of HTML to return.
468
-		 *
469
-		 * @return      string HTML of colour picker table.
470
-		 */
471
-		public static function get_current_color_scheme_html( $scheme_id = false ): string {
472
-
473
-			// If scheme_id is false.
474
-			if ( ! $scheme_id ) {
475
-
476
-				// Attempt to get the current scheme.
477
-				$scheme_id = self::get_current_scheme_id();
478
-
479
-				// dummy check, because this shit happens!
480
-				$arr_schemes = self::get_scheme_names();
481
-
482
-				if ( ! in_array( $scheme_id, $arr_schemes, true ) ) {
483
-					$scheme_id = 'Default';
484
-					self::set_current_scheme_id( 'Default' );
485
-				}
486
-			}
487
-
488
-			// Set oft used variables.
489
-			$opt_name    = esc_attr( self::$parent->args['opt_name'] );
490
-			$field_id    = esc_attr( self::$field_id );
491
-			$field_class = esc_attr( self::$field_class );
492
-
493
-			// Get the default options.
494
-			$field = self::get_field();
495
-
496
-			$field['output_transparent'] = $field['output_transparent'] ?? '';
497
-			$is_accordion                = $field['accordion'] ?? true;
498
-
499
-			$def_opts = $field['default'];
500
-
501
-			// Create array of element ids from default options.
502
-			if ( ! empty( $def_opts ) ) {
503
-				$id_arr = array();
504
-
505
-				foreach ( $def_opts as $vv ) {
506
-					$id_arr[] = $vv['id'];
507
-				}
508
-			}
509
-
510
-			// Get last saved default.
511
-			$saved_def = get_option( 'redux_' . $opt_name . '_' . $field_id . '_color_scheme' );
512
-
513
-			// Compare key counts between saved and current defaults to check
514
-			// for changes in color scheme.
515
-			if ( false !== $saved_def && is_array( $saved_def ) ) {
516
-
517
-				// Get the new color inputs.
518
-				$arr_diff = self::do_diff( $def_opts, $saved_def );
519
-
520
-				if ( ! empty( $arr_diff ) ) {
521
-					update_option( 'redux_' . $opt_name . '_' . $field_id . '_color_scheme', $def_opts );
522
-				}                //}
523
-			} else {
524
-				update_option( 'redux_' . $opt_name . '_' . $field_id . '_color_scheme', $def_opts );
525
-			}
526
-
527
-			// get current scheme data.
528
-			$scheme = self::get_scheme_data( $scheme_id );
529
-
530
-			if ( false === $scheme ) {
531
-				return '';
532
-			}
533
-
534
-			// If new color inputs exist...
535
-			if ( ! empty( $arr_diff ) ) {
536
-				foreach ( $arr_diff as $val ) {
537
-					if ( ! empty( $val ) && isset( $val['id'] ) ) {
538
-
539
-						$val['title'] = $val['title'] ?? $val['id'];
540
-						$val['color'] = $val['color'] ?? '';
541
-						$val['alpha'] = $val['alpha'] ?? 1;
542
-
543
-						$trans        = $field['output_transparent'];
544
-						$res          = ( '' === $val['color'] || 'transparent' === $val['color'] ) ? $trans : Redux_Helpers::hex2rgba( $val['color'], $val['alpha'] );
545
-						$val['rgba']  = $val['rgba'] ?? $res;
546
-						$val['group'] = $val['group'] ?? '';
547
-
548
-						$scheme[ $val['id'] ] = $val;
549
-					}
550
-				}
551
-
552
-				// Get list of scheme names.
553
-				$scheme_names = self::get_scheme_names();
554
-
555
-				// Update is saved scheme with new picker data.
556
-				foreach ( $scheme_names as $name ) {
557
-					self::set_scheme_data( $name, $scheme );
558
-				}
559
-
560
-				// update the database.
561
-				self::set_database_data( $scheme_id );
562
-			}
563
-
564
-			// If it's not empty then...
565
-			if ( ! empty( $scheme ) ) {
566
-
567
-				// init arrays.
568
-				$groups     = array();
569
-				$grp_desc   = array();
570
-				$groups[''] = array();
571
-				$sel_grps   = array();
572
-
573
-				if ( ! isset( self::$select ) ) {
574
-					self::$select = self::get_select_names();
575
-				}
576
-
577
-				// Enum select fields into groups array for later render.
578
-				if ( isset( self::$select ) ) {
579
-					foreach ( self::$select as $sel_arr ) {
580
-						$sel_grp = $sel_arr['group'];
581
-						if ( ! array_key_exists( $sel_grp, $sel_grps ) ) {
582
-							$sel_grps[ $sel_grp ] = array();
583
-						}
584
-						$sel_grps[ $sel_grp ][] = $sel_arr;
585
-					}
586
-				}
587
-
588
-				// Enum groups names.
589
-				$group_arr = self::get_group_names();
590
-
591
-				foreach ( $group_arr as $group_name => $description ) {
592
-					$groups[ $group_name ] = array();
593
-
594
-					if ( is_array( $description ) ) {
595
-						$grp_desc[ $group_name ]           = $description['desc'] ?? '';
596
-						$grp_grpdesc[ $group_name ]        = $description['group_desc'] ?? '';
597
-						$grp_hidden[ $group_name ]         = $description['hidden'] ?? false;
598
-						$grp_accordion_open[ $group_name ] = $description['accordion_open'] ?? false;
599
-
600
-					} else {
601
-						$grp_desc[ $group_name ]           = $description;
602
-						$grp_hidden[ $group_name ]         = false;
603
-						$grp_accordion_open[ $group_name ] = false;
604
-						$grp_grpdesc[ $group_name ]        = false;
605
-					}
606
-				}
607
-
608
-				// Assign color pickers to their specified group.
609
-				foreach ( $scheme as $arr ) {
610
-					if ( is_array( $arr ) ) {
611
-						if ( ! empty( $arr['group'] ) ) {
612
-							if ( array_key_exists( $arr['group'], $group_arr ) ) {
613
-								$groups[ $arr['group'] ][] = $arr;
614
-							} else {
615
-								$groups[''][] = $arr;
616
-							}
617
-						} else {
618
-							$groups[''][] = $arr;
619
-						}
620
-					}
621
-				}
622
-
623
-				$open_icon  = '';
624
-				$close_icon = '';
625
-
626
-				if ( $is_accordion ) {
627
-					$open_icon  = apply_filters( 'redux/extension/color_scheme/' . self::$parent->args['opt_name'] . '/icon/open', 'dashicons dashicons-arrow-down' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName
628
-					$close_icon = apply_filters( 'redux/extension/color_scheme/' . self::$parent->args['opt_name'] . '/icon/close', 'dashicons dashicons-arrow-up' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName
629
-				}
630
-
631
-				// open the list.
632
-				$html = '<ul class="redux-scheme-layout" data-open-icon="' . $open_icon . '" data-close-icon="' . $close_icon . '">';
633
-
634
-				// Enumerate groups.
635
-				foreach ( $groups as $title => $scheme_arr ) {
636
-
637
-					if ( '' === $title ) {
638
-						if ( empty( $scheme_arr ) ) {
639
-							continue;
640
-						}
641
-
642
-						$kill_me = false;
643
-						foreach ( $scheme_arr as $data ) {
644
-							if ( ! array_key_exists( 'color', $data ) ) {
645
-								$kill_me = true;
646
-								break;
647
-							}
648
-						}
649
-						if ( $kill_me ) {
650
-							continue;
651
-						}
652
-					}
653
-
654
-					$add_hr     = false;
655
-					$is_hidden  = false;
656
-					$class_hide = '';
657
-					$is_open    = '';
658
-
659
-					if ( isset( $grp_hidden[ $title ] ) && '' !== $grp_hidden[ $title ] ) {
660
-						$is_hidden  = $grp_hidden[ $title ];
661
-						$class_hide = ( true === $is_hidden ) ? ' hidden ' : '';
662
-						$is_open    = $grp_accordion_open[ $title ];
663
-					}
664
-
665
-					$add_class = '';
666
-					if ( $is_accordion ) {
667
-						$add_class = ' accordion ';
668
-					}
669
-
670
-					$html .= '<div class="redux-color-scheme-group' . $add_class . $class_hide . '">';
671
-
672
-					if ( ! $is_hidden ) {
673
-
674
-						if ( $is_accordion ) {
675
-							$html .= '<div class="redux-color-scheme-accordion">';
676
-						}
677
-						$icon_class = '';
678
-
679
-						// apply group title, if any.
680
-						if ( '' !== $title ) {
681
-							$html .= '<br><span class="redux-label redux-layout-group-label">' . esc_attr( $title ) . '</span>';
682
-
683
-							if ( $is_accordion ) {
684
-								$icon_class = ' titled';
685
-							}
686
-							$add_hr = true;
687
-						} elseif ( $is_accordion ) {
688
-							$icon_class = ' not-titled';
689
-						}
690
-
691
-						// apply group description, if any.
692
-						if ( isset( $grp_desc[ $title ] ) && '' !== $grp_desc[ $title ] ) {
693
-							$html  .= '<span class="redux-label redux-layout-group-desc-label' . $icon_class . '">' . esc_attr( $grp_desc[ $title ] ) . '</label>';
694
-							$add_hr = true;
695
-
696
-							if ( $is_accordion ) {
697
-								$icon_class .= ' subtitled';
698
-							}
699
-						} else {
700
-							$icon_class .= ' not-subtitled';
701
-						}
702
-
703
-						if ( $is_accordion ) {
704
-							$html .= '<span class="' . esc_attr( $open_icon ) . $icon_class . '"></span>';
705
-						}
706
-
707
-						// Add HR, if needed.
708
-						if ( true === $add_hr ) {
709
-							if ( ! $is_accordion ) {
710
-								$html .= '<hr>';
711
-							}
712
-						}
713
-
714
-						if ( $is_accordion ) {
715
-							$html .= '</div>';
716
-							$html .= '<div class="redux-color-scheme-accordion-section" data-state="' . esc_attr( $is_open ) . '">';
717
-							if ( false !== $grp_grpdesc ) {
718
-								$html .= '<div class="redux-color-scheme-group-desc">';
719
-								$html .= esc_attr( $grp_grpdesc[ $title ] );
720
-								$html .= '</div>';
721
-							}
722
-						}
723
-
724
-						// Select box render.
725
-						if ( array_key_exists( $title, $sel_grps ) ) {
726
-							$html .= self::render_selects( $sel_grps[ $title ], $scheme );
727
-						}
728
-					} elseif ( $is_accordion ) {
729
-						$html .= '<div class="redux-color-scheme-accordion-section">';
730
-					}
731
-
732
-					$html .= "<ul class='redux-scheme-layout'>";
733
-
734
-					// Enum through each element/id.
735
-					foreach ( $scheme_arr as $v ) {
736
-						if ( in_array( $v['id'], $id_arr, true ) ) {
737
-
738
-							// If no title, use ID.
739
-							$v['title'] = $v['title'] ?? $v['id'];
740
-
741
-							// If no alpha, use 1 (solid).
742
-							$v['alpha'] = $v['alpha'] ?? 1;
743
-
744
-							// Fuck forbid no colour, set to white.
745
-							$v['color'] = $v['color'] ?? '';
746
-
747
-							// RGBA..
748
-							$trans     = $field['output_transparent'];
749
-							$res       = ( '' === $v['color'] || 'transparent' === $v['color'] ) ? $trans : Redux_Helpers::hex2rgba( $v['color'], $v['alpha'] );
750
-							$v['rgba'] = $v['rgba'] ?? $res;
751
-
752
-							// group name.
753
-							$v['group'] = $v['group'] ?? '';
754
-
755
-							$v['class'] = self::get_color_block_class( $field, $v['id'] );
756
-
757
-							$block_hide = self::get_block_hidden( $field, $v['id'] ) ? 'hidden' : '';
758
-
759
-							// tooltips.
760
-							$tip_title = '';
761
-							$tip_text  = '';
762
-
763
-							$tooltip_data = self::get_tooltip_data( $field, $v['id'] );
764
-							if ( false !== $tooltip_data ) {
765
-								$tip_title = $tooltip_data['title'] ?? '';
766
-								$tip_text  = $tooltip_data['text'] ?? '';
767
-							}
768
-
769
-							// Begin the layout.
770
-							$html .= '<li class="redux-scheme-layout ' . $class_hide . ' redux-cs-qtip ' . $block_hide . '" qtip-title="' . esc_attr( $tip_title ) . '" qtip-content="' . esc_attr( $tip_text ) . '">';
771
-							$html .= '<div class="redux-scheme-layout-container" data-id="' . $field_id . '-' . $v['id'] . '">';
772
-
773
-							if ( '' === $v['color'] || 'transparent' === $v['color'] ) {
774
-								$color = '';
775
-							} else {
776
-								$color = 'rgba(' . $v['rgba'] . ')';
777
-							}
778
-
779
-							// colour picker dropdown.
780
-							$html .= '<input
14
+    /**
15
+     * Class Redux_Color_Scheme_Functions
16
+     */
17
+    class Redux_Color_Scheme_Functions {
18
+
19
+        /**
20
+         * ReduxFramework object.
21
+         *
22
+         * @var null|ReduxFramework
23
+         */
24
+        public static ?ReduxFramework $parent;
25
+
26
+        /**
27
+         * Field ID
28
+         *
29
+         * @var string|null
30
+         */
31
+        public static ?string $field_id;
32
+
33
+        /**
34
+         * Field class.
35
+         *
36
+         * @var string|null
37
+         */
38
+        public static ?string $field_class;
39
+
40
+        /**
41
+         * Field array.
42
+         *
43
+         * @var array|null
44
+         */
45
+        public static ?array $field;
46
+
47
+        /**
48
+         * WP Upload directory.
49
+         *
50
+         * @var string|null
51
+         */
52
+        public static ?string $upload_dir = '';
53
+
54
+        /**
55
+         * WP Upload URI
56
+         *
57
+         * @var string|null
58
+         */
59
+        public static ?string $upload_url = '';
60
+
61
+        /**
62
+         * Select fields.
63
+         *
64
+         * @var array|null
65
+         */
66
+        public static ?array $select;
67
+
68
+        /**
69
+         * Class init.
70
+         *
71
+         * @param ReduxFramework $redux ReduxFramework object.
72
+         */
73
+        public static function init( ReduxFramework $redux ) {
74
+            self::$parent = $redux;
75
+
76
+            if ( empty( self::$field_id ) ) {
77
+                self::$field = self::get_field( $redux );
78
+
79
+                if ( ! is_array( self::$field ) ) {
80
+                    return;
81
+                }
82
+
83
+                self::$field_id = self::$field['id'];
84
+            }
85
+
86
+            // Make sanitized upload dir DIR.
87
+            self::$upload_dir = Redux_Functions_Ex::wp_normalize_path( ReduxFramework::$_upload_dir . 'color-schemes/' );
88
+
89
+            // Make sanitized upload dir URL.
90
+            self::$upload_url = Redux_Functions_Ex::wp_normalize_path( ReduxFramework::$_upload_url . 'color-schemes/' );
91
+
92
+            Redux_Functions::init_wp_filesystem();
93
+        }
94
+
95
+        /**
96
+         * Checks if tooltips are in use.
97
+         *
98
+         * @param array $field Field array.
99
+         *
100
+         * @return bool
101
+         */
102
+        public static function tooltips_in_use( array $field ): bool {
103
+            $blocks = $field['default'];
104
+
105
+            foreach ( $blocks as $arr ) {
106
+                if ( isset( $arr['tooltip'] ) ) {
107
+                    return true;
108
+                }
109
+            }
110
+
111
+            return false;
112
+        }
113
+
114
+        /**
115
+         * Convert DB values.
116
+         */
117
+        public static function convert_to_db() {
118
+            $upload_dir = Redux_Functions_Ex::wp_normalize_path( ReduxFramework::$_upload_dir . 'color-schemes/' );
119
+
120
+            $cur_scheme_file = Redux_Functions_Ex::wp_normalize_path( $upload_dir . '/' . self::$parent->args['opt_name'] . '_' . self::$field_id . '.json' );
121
+
122
+            if ( is_dir( $upload_dir ) ) {
123
+                if ( file_exists( $cur_scheme_file ) ) {
124
+                    $data = Redux_Core::$filesystem->execute( 'get_contents', $cur_scheme_file );
125
+                    if ( ! empty( $data ) ) {
126
+                        $data = json_decode( $data, true );
127
+
128
+                        update_option( self::get_scheme_key(), $data );
129
+
130
+                        Redux_Core::$filesystem->execute( 'delete', $cur_scheme_file );
131
+                    }
132
+                }
133
+            }
134
+        }
135
+
136
+        /**
137
+         * Get scheme key.
138
+         *
139
+         * @return string
140
+         */
141
+        public static function get_scheme_key(): string {
142
+            return 'redux_cs_' . self::$parent->args['opt_name'] . '_' . self::$field_id;
143
+        }
144
+
145
+        /**
146
+         * Get the list of groups names for the color scheme table.
147
+         *
148
+         * @since       2.0.0
149
+         * @access      public static
150
+         * @return      array Array of group names.
151
+         */
152
+        public static function get_group_names(): array {
153
+            if ( empty( self::$field ) ) {
154
+                self::$field = self::get_field();
155
+            }
156
+
157
+            if ( isset( self::$field['groups'] ) ) {
158
+                if ( is_array( self::$field['groups'] ) && ! empty( self::$field['groups'] ) ) {
159
+                    return self::$field['groups'];
160
+                }
161
+            }
162
+
163
+            return array();
164
+        }
165
+
166
+        /**
167
+         * Get output transparent value.
168
+         *
169
+         * @return mixed
170
+         */
171
+        public static function get_output_transparent_val() {
172
+            if ( empty( self::$field ) ) {
173
+                self::$field = self::get_field();
174
+            }
175
+
176
+            if ( isset( self::$field['output_transparent'] ) ) {
177
+                if ( ! empty( self::$field['output_transparent'] ) ) {
178
+                    return self::$field['output_transparent'];
179
+                }
180
+            }
181
+
182
+            return false;
183
+        }
184
+
185
+        /**
186
+         * Get select field name.
187
+         *
188
+         * @return array
189
+         */
190
+        private static function get_select_names(): array {
191
+            if ( empty( self::$field ) ) {
192
+                self::$field = self::get_field();
193
+            }
194
+
195
+            if ( isset( self::$field['select'] ) ) {
196
+                if ( is_array( self::$field['select'] ) && ! empty( self::$field['select'] ) ) {
197
+                    return self::$field['select'];
198
+                }
199
+            }
200
+
201
+            return array();
202
+        }
203
+
204
+        /**
205
+         * Get color scheme field.
206
+         *
207
+         * @param ReduxFramework|null $redux pointer.
208
+         *
209
+         * @return mixed
210
+         */
211
+        public static function get_field( ?ReduxFramework $redux = null ) {
212
+            if ( ! is_null( $redux ) ) {
213
+                self::$parent = $redux;
214
+            }
215
+
216
+            if ( isset( $redux->field_sections['color_scheme'] ) ) {
217
+                return reset( $redux->field_sections['color_scheme'] );
218
+            }
219
+
220
+            $arr = self::$parent;
221
+
222
+            foreach ( $arr as $part => $bla ) {
223
+                if ( 'sections' === $part ) {
224
+                    foreach ( $bla as $field ) {
225
+                        foreach ( $field as $arg => $val ) {
226
+                            if ( 'fields' === $arg ) {
227
+                                foreach ( $val as $v ) {
228
+                                    if ( ! empty( $v ) ) {
229
+                                        foreach ( $v as $id => $x ) {
230
+                                            if ( 'type' === $id ) {
231
+                                                if ( 'color_scheme' === $x ) {
232
+                                                    return $v;
233
+                                                }
234
+                                            }
235
+                                        }
236
+                                    }
237
+                                }
238
+                            }
239
+                        }
240
+                    }
241
+                }
242
+            }
243
+
244
+            return null;
245
+        }
246
+
247
+        /**
248
+         * Output scheme dropdown selector.
249
+         *
250
+         * @param       string $selected Selected scheme name.
251
+         *
252
+         * @return      string HTML of dropdown selector.
253
+         * @since       1.0.0
254
+         * @access      public static
255
+         */
256
+        public static function get_scheme_select_html( string $selected ): string {
257
+
258
+            $html  = '<select name="' . esc_attr( self::$parent->args['opt_name'] ) . '[redux-scheme-select]" id="redux-scheme-select-' . esc_attr( self::$field_id ) . '" class="redux-scheme-select">';
259
+            $html .= self::get_scheme_list_html( $selected );
260
+            $html .= '</select>';
261
+
262
+            return $html;
263
+        }
264
+
265
+        /**
266
+         * Set current scheme ID, if one isn't specified.
267
+         *
268
+         * @param       string $id Scheme name to set.
269
+         *
270
+         * @return      void
271
+         * @since       1.0.0
272
+         * @access      public static
273
+         */
274
+        public static function set_current_scheme_id( string $id ) {
275
+
276
+            // Get opt name, for database.
277
+            $opt_name = self::$parent->args['opt_name'];
278
+
279
+            // Get all options from database.
280
+            $redux_options = get_option( $opt_name, array() );
281
+            if ( ! is_array( $redux_options ) ) {
282
+                $redux_options = array();
283
+            }
284
+            // Append ID to variable that holds the current scheme ID data.
285
+            $redux_options['redux-scheme-select'] = $id;
286
+
287
+            // Save the modified settings.
288
+            update_option( $opt_name, $redux_options );
289
+        }
290
+
291
+        /**
292
+         * Get tooltip toggle state.
293
+         *
294
+         * @return bool
295
+         */
296
+        public static function get_tooltip_toggle_state(): bool {
297
+
298
+            // Retrieve the opt_name, needed for database.
299
+            $opt_name = self::$parent->args['opt_name'];
300
+
301
+            // Get the entire options array.
302
+            $redux_options = get_option( $opt_name );
303
+
304
+            return $redux_options['redux-color-scheme-tooltip-toggle'] ?? true;
305
+        }
306
+
307
+        /**
308
+         * Gets the current schem ID from the database.
309
+         *
310
+         * @since       1.0.0
311
+         * @access      public static
312
+         *
313
+         * @return      string Current scheme ID.
314
+         */
315
+        public static function get_current_scheme_id(): string {
316
+
317
+            // Retrieve the opt_name, needed for databasae.
318
+            $opt_name = self::$parent->args['opt_name'];
319
+
320
+            // Get the entire options array.
321
+            $redux_options = get_option( $opt_name );
322
+
323
+            // If the current scheme key exists...
324
+            return $redux_options['redux-scheme-select'] ?? 'Default';
325
+        }
326
+
327
+        /**
328
+         * Get the list of schemes for the selector.
329
+         *
330
+         * @param       string $sel Scheme name to select.
331
+         *
332
+         * @return      string HTML option values.
333
+         * @since       1.0.0
334
+         * @access      static private
335
+         */
336
+        private static function get_scheme_list_html( string $sel = '' ): string {
337
+            // no errors, please.
338
+            $html = '';
339
+
340
+            // Retrieves the list of saved schemes into an array variable.
341
+            $dropdown_values = self::get_scheme_names();
342
+
343
+            // If the dropdown array has items...
344
+            if ( ! empty( $dropdown_values ) ) {
345
+
346
+                // Sort them alphbetically.
347
+                asort( $dropdown_values );
348
+            }
349
+
350
+            // trim the selected item.
351
+            $sel = trim( $sel );
352
+
353
+            // If it's empty.
354
+            if ( '' === $sel ) {
355
+
356
+                // Make the current scheme id the selected value.
357
+                $selected = self::get_current_scheme_id();
358
+            } else {
359
+
360
+                // Otherwise, set it to the value passed to this function.
361
+                $selected = $sel;
362
+            }
363
+
364
+            // Enum through the dropdown array and append the necessary HTML for the selector.
365
+            foreach ( $dropdown_values as $k ) {
366
+                $html .= '<option value="' . $k . '" ' . selected( $k, $selected, false ) . '>' . $k . '</option>';
367
+            }
368
+
369
+            // Send it all packin'.
370
+            return $html;
371
+        }
372
+
373
+        /**
374
+         * Returns select HTML.
375
+         *
376
+         * @param array $arr  Array of select fields to render.
377
+         * @param array $data Array of scheme data.
378
+         *
379
+         * @return      string HTML of select fields.
380
+         * @since       1.0.4
381
+         * @access      static private
382
+         */
383
+        private static function render_selects( array $arr, array $data ): string {
384
+
385
+            $html = '';
386
+            foreach ( $arr as $v ) {
387
+                $id = $v['id'];
388
+
389
+                if ( isset( $v['width'] ) && ! empty( $v['width'] ) ) {
390
+                    $size = $v['width'];
391
+                } else {
392
+                    $size = '40%';
393
+                }
394
+
395
+                $width = ' style="width: ' . $size . ';"';
396
+
397
+                $html .= '<span class="redux-label redux-color-scheme-opt-select-title">' . $v['title'] . '</span>';
398
+
399
+                $html .= '<select name="' . self::$parent->args['opt_name'] . '[' . self::$field_id . '][' . $id . ']" id="redux-color-scheme-opt-select-' . $id . '"' . $width . ' class="redux-color-scheme-opt-select">';
400
+
401
+                foreach ( $v['options'] as $opt_id => $opt_val ) {
402
+                    $data[ $id ]['value'] = $data[ $id ]['value'] ?? '';
403
+                    $html                .= '<option value="' . $opt_id . '" ' . selected( $opt_id, $data[ $id ]['value'], false ) . '>' . $opt_val . '</option>';
404
+                }
405
+
406
+                $html .= '</select>';
407
+                $html .= '<span class="redux-label redux-color-scheme-opt-select-desc">' . $v['desc'] . '</span>';
408
+                $html .= '<hr class="redux-color-scheme-select-close-hr">';
409
+                $html .= '<br/>';
410
+            }
411
+
412
+            return $html;
413
+        }
414
+
415
+        /**
416
+         * Do diff.
417
+         *
418
+         * @param array $first_array  Array one.
419
+         * @param array $second_array Array two.
420
+         *
421
+         * @return array
422
+         */
423
+        private static function do_diff( array $first_array, array $second_array ): array {
424
+
425
+            /**
426
+             * Serialize callback.
427
+             *
428
+             * @param array $arr Array.
429
+             */
430
+            function my_serialize( array &$arr ) {
431
+                $arr = maybe_serialize( $arr );
432
+            }
433
+
434
+            /**
435
+             * Unserialize callback.
436
+             *
437
+             * @param array $arr Array.
438
+             */
439
+            function my_unserialize( &$arr ) {
440
+                $arr = maybe_unserialize( $arr );
441
+            }
442
+
443
+            // make a copy.
444
+            $first_array_s  = $first_array;
445
+            $second_array_s = $second_array;
446
+
447
+            // serialize all sub-arrays.
448
+            array_walk( $first_array_s, 'my_serialize' );
449
+            array_walk( $second_array_s, 'my_serialize' );
450
+
451
+            // array_diff the serialized versions.
452
+            $diff = array_diff( $first_array_s, $second_array_s );
453
+
454
+            // unserialize the result.
455
+            array_walk( $diff, 'my_unserialize' );
456
+
457
+            // you've got it!
458
+            return $diff;
459
+        }
460
+
461
+        /**
462
+         * Returns colour pickers HTML table.
463
+         *
464
+         * @since       1.0.0
465
+         * @access      public static
466
+         *
467
+         * @param       string $scheme_id Scheme name of HTML to return.
468
+         *
469
+         * @return      string HTML of colour picker table.
470
+         */
471
+        public static function get_current_color_scheme_html( $scheme_id = false ): string {
472
+
473
+            // If scheme_id is false.
474
+            if ( ! $scheme_id ) {
475
+
476
+                // Attempt to get the current scheme.
477
+                $scheme_id = self::get_current_scheme_id();
478
+
479
+                // dummy check, because this shit happens!
480
+                $arr_schemes = self::get_scheme_names();
481
+
482
+                if ( ! in_array( $scheme_id, $arr_schemes, true ) ) {
483
+                    $scheme_id = 'Default';
484
+                    self::set_current_scheme_id( 'Default' );
485
+                }
486
+            }
487
+
488
+            // Set oft used variables.
489
+            $opt_name    = esc_attr( self::$parent->args['opt_name'] );
490
+            $field_id    = esc_attr( self::$field_id );
491
+            $field_class = esc_attr( self::$field_class );
492
+
493
+            // Get the default options.
494
+            $field = self::get_field();
495
+
496
+            $field['output_transparent'] = $field['output_transparent'] ?? '';
497
+            $is_accordion                = $field['accordion'] ?? true;
498
+
499
+            $def_opts = $field['default'];
500
+
501
+            // Create array of element ids from default options.
502
+            if ( ! empty( $def_opts ) ) {
503
+                $id_arr = array();
504
+
505
+                foreach ( $def_opts as $vv ) {
506
+                    $id_arr[] = $vv['id'];
507
+                }
508
+            }
509
+
510
+            // Get last saved default.
511
+            $saved_def = get_option( 'redux_' . $opt_name . '_' . $field_id . '_color_scheme' );
512
+
513
+            // Compare key counts between saved and current defaults to check
514
+            // for changes in color scheme.
515
+            if ( false !== $saved_def && is_array( $saved_def ) ) {
516
+
517
+                // Get the new color inputs.
518
+                $arr_diff = self::do_diff( $def_opts, $saved_def );
519
+
520
+                if ( ! empty( $arr_diff ) ) {
521
+                    update_option( 'redux_' . $opt_name . '_' . $field_id . '_color_scheme', $def_opts );
522
+                }                //}
523
+            } else {
524
+                update_option( 'redux_' . $opt_name . '_' . $field_id . '_color_scheme', $def_opts );
525
+            }
526
+
527
+            // get current scheme data.
528
+            $scheme = self::get_scheme_data( $scheme_id );
529
+
530
+            if ( false === $scheme ) {
531
+                return '';
532
+            }
533
+
534
+            // If new color inputs exist...
535
+            if ( ! empty( $arr_diff ) ) {
536
+                foreach ( $arr_diff as $val ) {
537
+                    if ( ! empty( $val ) && isset( $val['id'] ) ) {
538
+
539
+                        $val['title'] = $val['title'] ?? $val['id'];
540
+                        $val['color'] = $val['color'] ?? '';
541
+                        $val['alpha'] = $val['alpha'] ?? 1;
542
+
543
+                        $trans        = $field['output_transparent'];
544
+                        $res          = ( '' === $val['color'] || 'transparent' === $val['color'] ) ? $trans : Redux_Helpers::hex2rgba( $val['color'], $val['alpha'] );
545
+                        $val['rgba']  = $val['rgba'] ?? $res;
546
+                        $val['group'] = $val['group'] ?? '';
547
+
548
+                        $scheme[ $val['id'] ] = $val;
549
+                    }
550
+                }
551
+
552
+                // Get list of scheme names.
553
+                $scheme_names = self::get_scheme_names();
554
+
555
+                // Update is saved scheme with new picker data.
556
+                foreach ( $scheme_names as $name ) {
557
+                    self::set_scheme_data( $name, $scheme );
558
+                }
559
+
560
+                // update the database.
561
+                self::set_database_data( $scheme_id );
562
+            }
563
+
564
+            // If it's not empty then...
565
+            if ( ! empty( $scheme ) ) {
566
+
567
+                // init arrays.
568
+                $groups     = array();
569
+                $grp_desc   = array();
570
+                $groups[''] = array();
571
+                $sel_grps   = array();
572
+
573
+                if ( ! isset( self::$select ) ) {
574
+                    self::$select = self::get_select_names();
575
+                }
576
+
577
+                // Enum select fields into groups array for later render.
578
+                if ( isset( self::$select ) ) {
579
+                    foreach ( self::$select as $sel_arr ) {
580
+                        $sel_grp = $sel_arr['group'];
581
+                        if ( ! array_key_exists( $sel_grp, $sel_grps ) ) {
582
+                            $sel_grps[ $sel_grp ] = array();
583
+                        }
584
+                        $sel_grps[ $sel_grp ][] = $sel_arr;
585
+                    }
586
+                }
587
+
588
+                // Enum groups names.
589
+                $group_arr = self::get_group_names();
590
+
591
+                foreach ( $group_arr as $group_name => $description ) {
592
+                    $groups[ $group_name ] = array();
593
+
594
+                    if ( is_array( $description ) ) {
595
+                        $grp_desc[ $group_name ]           = $description['desc'] ?? '';
596
+                        $grp_grpdesc[ $group_name ]        = $description['group_desc'] ?? '';
597
+                        $grp_hidden[ $group_name ]         = $description['hidden'] ?? false;
598
+                        $grp_accordion_open[ $group_name ] = $description['accordion_open'] ?? false;
599
+
600
+                    } else {
601
+                        $grp_desc[ $group_name ]           = $description;
602
+                        $grp_hidden[ $group_name ]         = false;
603
+                        $grp_accordion_open[ $group_name ] = false;
604
+                        $grp_grpdesc[ $group_name ]        = false;
605
+                    }
606
+                }
607
+
608
+                // Assign color pickers to their specified group.
609
+                foreach ( $scheme as $arr ) {
610
+                    if ( is_array( $arr ) ) {
611
+                        if ( ! empty( $arr['group'] ) ) {
612
+                            if ( array_key_exists( $arr['group'], $group_arr ) ) {
613
+                                $groups[ $arr['group'] ][] = $arr;
614
+                            } else {
615
+                                $groups[''][] = $arr;
616
+                            }
617
+                        } else {
618
+                            $groups[''][] = $arr;
619
+                        }
620
+                    }
621
+                }
622
+
623
+                $open_icon  = '';
624
+                $close_icon = '';
625
+
626
+                if ( $is_accordion ) {
627
+                    $open_icon  = apply_filters( 'redux/extension/color_scheme/' . self::$parent->args['opt_name'] . '/icon/open', 'dashicons dashicons-arrow-down' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName
628
+                    $close_icon = apply_filters( 'redux/extension/color_scheme/' . self::$parent->args['opt_name'] . '/icon/close', 'dashicons dashicons-arrow-up' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName
629
+                }
630
+
631
+                // open the list.
632
+                $html = '<ul class="redux-scheme-layout" data-open-icon="' . $open_icon . '" data-close-icon="' . $close_icon . '">';
633
+
634
+                // Enumerate groups.
635
+                foreach ( $groups as $title => $scheme_arr ) {
636
+
637
+                    if ( '' === $title ) {
638
+                        if ( empty( $scheme_arr ) ) {
639
+                            continue;
640
+                        }
641
+
642
+                        $kill_me = false;
643
+                        foreach ( $scheme_arr as $data ) {
644
+                            if ( ! array_key_exists( 'color', $data ) ) {
645
+                                $kill_me = true;
646
+                                break;
647
+                            }
648
+                        }
649
+                        if ( $kill_me ) {
650
+                            continue;
651
+                        }
652
+                    }
653
+
654
+                    $add_hr     = false;
655
+                    $is_hidden  = false;
656
+                    $class_hide = '';
657
+                    $is_open    = '';
658
+
659
+                    if ( isset( $grp_hidden[ $title ] ) && '' !== $grp_hidden[ $title ] ) {
660
+                        $is_hidden  = $grp_hidden[ $title ];
661
+                        $class_hide = ( true === $is_hidden ) ? ' hidden ' : '';
662
+                        $is_open    = $grp_accordion_open[ $title ];
663
+                    }
664
+
665
+                    $add_class = '';
666
+                    if ( $is_accordion ) {
667
+                        $add_class = ' accordion ';
668
+                    }
669
+
670
+                    $html .= '<div class="redux-color-scheme-group' . $add_class . $class_hide . '">';
671
+
672
+                    if ( ! $is_hidden ) {
673
+
674
+                        if ( $is_accordion ) {
675
+                            $html .= '<div class="redux-color-scheme-accordion">';
676
+                        }
677
+                        $icon_class = '';
678
+
679
+                        // apply group title, if any.
680
+                        if ( '' !== $title ) {
681
+                            $html .= '<br><span class="redux-label redux-layout-group-label">' . esc_attr( $title ) . '</span>';
682
+
683
+                            if ( $is_accordion ) {
684
+                                $icon_class = ' titled';
685
+                            }
686
+                            $add_hr = true;
687
+                        } elseif ( $is_accordion ) {
688
+                            $icon_class = ' not-titled';
689
+                        }
690
+
691
+                        // apply group description, if any.
692
+                        if ( isset( $grp_desc[ $title ] ) && '' !== $grp_desc[ $title ] ) {
693
+                            $html  .= '<span class="redux-label redux-layout-group-desc-label' . $icon_class . '">' . esc_attr( $grp_desc[ $title ] ) . '</label>';
694
+                            $add_hr = true;
695
+
696
+                            if ( $is_accordion ) {
697
+                                $icon_class .= ' subtitled';
698
+                            }
699
+                        } else {
700
+                            $icon_class .= ' not-subtitled';
701
+                        }
702
+
703
+                        if ( $is_accordion ) {
704
+                            $html .= '<span class="' . esc_attr( $open_icon ) . $icon_class . '"></span>';
705
+                        }
706
+
707
+                        // Add HR, if needed.
708
+                        if ( true === $add_hr ) {
709
+                            if ( ! $is_accordion ) {
710
+                                $html .= '<hr>';
711
+                            }
712
+                        }
713
+
714
+                        if ( $is_accordion ) {
715
+                            $html .= '</div>';
716
+                            $html .= '<div class="redux-color-scheme-accordion-section" data-state="' . esc_attr( $is_open ) . '">';
717
+                            if ( false !== $grp_grpdesc ) {
718
+                                $html .= '<div class="redux-color-scheme-group-desc">';
719
+                                $html .= esc_attr( $grp_grpdesc[ $title ] );
720
+                                $html .= '</div>';
721
+                            }
722
+                        }
723
+
724
+                        // Select box render.
725
+                        if ( array_key_exists( $title, $sel_grps ) ) {
726
+                            $html .= self::render_selects( $sel_grps[ $title ], $scheme );
727
+                        }
728
+                    } elseif ( $is_accordion ) {
729
+                        $html .= '<div class="redux-color-scheme-accordion-section">';
730
+                    }
731
+
732
+                    $html .= "<ul class='redux-scheme-layout'>";
733
+
734
+                    // Enum through each element/id.
735
+                    foreach ( $scheme_arr as $v ) {
736
+                        if ( in_array( $v['id'], $id_arr, true ) ) {
737
+
738
+                            // If no title, use ID.
739
+                            $v['title'] = $v['title'] ?? $v['id'];
740
+
741
+                            // If no alpha, use 1 (solid).
742
+                            $v['alpha'] = $v['alpha'] ?? 1;
743
+
744
+                            // Fuck forbid no colour, set to white.
745
+                            $v['color'] = $v['color'] ?? '';
746
+
747
+                            // RGBA..
748
+                            $trans     = $field['output_transparent'];
749
+                            $res       = ( '' === $v['color'] || 'transparent' === $v['color'] ) ? $trans : Redux_Helpers::hex2rgba( $v['color'], $v['alpha'] );
750
+                            $v['rgba'] = $v['rgba'] ?? $res;
751
+
752
+                            // group name.
753
+                            $v['group'] = $v['group'] ?? '';
754
+
755
+                            $v['class'] = self::get_color_block_class( $field, $v['id'] );
756
+
757
+                            $block_hide = self::get_block_hidden( $field, $v['id'] ) ? 'hidden' : '';
758
+
759
+                            // tooltips.
760
+                            $tip_title = '';
761
+                            $tip_text  = '';
762
+
763
+                            $tooltip_data = self::get_tooltip_data( $field, $v['id'] );
764
+                            if ( false !== $tooltip_data ) {
765
+                                $tip_title = $tooltip_data['title'] ?? '';
766
+                                $tip_text  = $tooltip_data['text'] ?? '';
767
+                            }
768
+
769
+                            // Begin the layout.
770
+                            $html .= '<li class="redux-scheme-layout ' . $class_hide . ' redux-cs-qtip ' . $block_hide . '" qtip-title="' . esc_attr( $tip_title ) . '" qtip-content="' . esc_attr( $tip_text ) . '">';
771
+                            $html .= '<div class="redux-scheme-layout-container" data-id="' . $field_id . '-' . $v['id'] . '">';
772
+
773
+                            if ( '' === $v['color'] || 'transparent' === $v['color'] ) {
774
+                                $color = '';
775
+                            } else {
776
+                                $color = 'rgba(' . $v['rgba'] . ')';
777
+                            }
778
+
779
+                            // colour picker dropdown.
780
+                            $html .= '<input
781 781
                                         id="' . $field_id . '-' . esc_attr( $v['id'] ) . '-color"
782 782
                                         class="' . $field_class . ' ' . esc_attr( $v['class'] ) . '"
783 783
                                         type="text"
@@ -793,15 +793,15 @@  discard block
 block discarded – undo
793 793
                                         data-output-transparent="' . esc_attr( $field['output_transparent'] ) . '"
794 794
                                       />';
795 795
 
796
-							$scheme_data = self::get_scheme_data( $scheme_id );
797
-							if ( false === $scheme_data ) {
798
-								return '';
799
-							}
796
+                            $scheme_data = self::get_scheme_data( $scheme_id );
797
+                            if ( false === $scheme_data ) {
798
+                                return '';
799
+                            }
800 800
 
801
-							$picker_data = $scheme_data[ $v['id'] ];
801
+                            $picker_data = $scheme_data[ $v['id'] ];
802 802
 
803
-							// Hidden input for data string.
804
-							$html .= '<input
803
+                            // Hidden input for data string.
804
+                            $html .= '<input
805 805
                                         type="hidden"
806 806
                                         class="redux-hidden-data"
807 807
                                         name="' . esc_attr( $opt_name ) . '[' . esc_attr( $field_id ) . '][' . esc_attr( $v['id'] ) . '][data]"
@@ -809,312 +809,312 @@  discard block
 block discarded – undo
809 809
                                         value="' . rawurlencode( wp_json_encode( $picker_data ) ) . '"
810 810
                                       />';
811 811
 
812
-							// closing html tags.
813
-							$html .= '</div>';
814
-							$html .= '<span class="redux-label redux-layout-label">' . esc_attr( $v['title'] ) . '</span>';
815
-							$html .= '</li>';
816
-						}
817
-					}
818
-					$html .= '</ul>';
819
-
820
-					$html .= '<hr class="redux-color-scheme-blank-hr">';
821
-
822
-					if ( $is_accordion ) {
823
-						$html .= '</div>';
824
-					}
825
-
826
-					$html .= '</div>';
827
-				}
828
-
829
-				// Close list.
830
-				$html .= '</ul>';
831
-			}
832
-
833
-			// html var not empty, return it.
834
-			if ( ! empty( $html ) ) {
835
-				return $html;
836
-			}
837
-
838
-			return '';
839
-		}
840
-
841
-		/**
842
-		 * Get color block class.
843
-		 *
844
-		 * @param array  $field Field array.
845
-		 * @param string $id    Field ID.
846
-		 *
847
-		 * @return string
848
-		 */
849
-		private static function get_color_block_class( array $field, string $id ): string {
850
-			$def = $field['default'];
851
-
852
-			if ( ! empty( $def ) ) {
853
-				foreach ( $def as $arr ) {
854
-					if ( $arr['id'] === $id ) {
855
-						if ( isset( $arr['class'] ) ) {
856
-							return $arr['class'];
857
-						}
858
-					}
859
-				}
860
-			}
861
-
862
-			return '';
863
-		}
864
-
865
-		/**
866
-		 * Get tooltip data.
867
-		 *
868
-		 * @param array  $field Field array.
869
-		 * @param string $id    Field ID.
870
-		 *
871
-		 * @return mixed
872
-		 */
873
-		private static function get_tooltip_data( array $field, string $id ) {
874
-			$def = $field['default'];
875
-
876
-			if ( ! empty( $def ) ) {
877
-				foreach ( $def as $arr ) {
878
-					if ( $arr['id'] === $id ) {
879
-						if ( isset( $arr['tooltip'] ) ) {
880
-							return $arr['tooltip'];
881
-						}
882
-					}
883
-				}
884
-			}
885
-
886
-			return false;
887
-		}
888
-
889
-		/**
890
-		 * Get hidden blocks.
891
-		 *
892
-		 * @param array  $field Field ID.
893
-		 * @param string $id    Field ID.
894
-		 *
895
-		 * @return bool
896
-		 */
897
-		private static function get_block_hidden( array $field, string $id ): bool {
898
-			$def = $field['default'];
899
-
900
-			if ( ! empty( $def ) ) {
901
-				foreach ( $def as $arr ) {
902
-					if ( $arr['id'] === $id ) {
903
-						if ( isset( $arr['hidden'] ) ) {
904
-							return $arr['hidden'];
905
-						}
906
-					}
907
-				}
908
-			}
909
-
910
-			return false;
911
-		}
912
-
913
-		/**
914
-		 * Returns scheme file contents.
915
-		 *
916
-		 * @since       1.0.0
917
-		 * @access      public static
918
-		 *
919
-		 * @return      array Array of scheme data.
920
-		 */
921
-		public static function read_scheme_file() {
922
-			$key  = self::get_scheme_key();
923
-			$data = get_option( $key );
924
-
925
-			if ( empty( $data ) ) {
926
-				$arr_data = false;
927
-			} else {
928
-				$arr_data = $data;
929
-			}
930
-
931
-			return $arr_data;
932
-		}
933
-
934
-		/**
935
-		 * Sets scheme file contents.
936
-		 *
937
-		 * @param       array $arr_data PHP array of data to encode.
938
-		 *
939
-		 * @return      bool Result of write function.
940
-		 * @since       1.0.0
941
-		 * @access      public static
942
-		 */
943
-		public static function write_scheme_file( array $arr_data ): bool {
944
-			$key = self::get_scheme_key();
945
-
946
-			return update_option( $key, $arr_data );
947
-		}
948
-
949
-		/**
950
-		 * Gets individual scheme data from scheme JSON file.
951
-		 *
952
-		 * @param       string $scheme_name Name of scheme.
953
-		 *
954
-		 * @return      mixed PHP array of scheme data.
955
-		 * @since       1.0.0
956
-		 * @access      public static
957
-		 */
958
-		public static function get_scheme_data( string $scheme_name ) {
959
-			$data = self::read_scheme_file();
960
-
961
-			if ( false === $data ) {
962
-				return false;
963
-			}
964
-
965
-			return $data[ $scheme_name ];
966
-		}
967
-
968
-		/**
969
-		 * Sets individual scheme data to scheme JSON file.
970
-		 *
971
-		 * @param string $name  Name of a scheme to save.
972
-		 * @param array  $arr   Scheme data to encode.
973
-		 *
974
-		 * @return      bool Result of file written.
975
-		 * @since       1.0.0
976
-		 * @access      public static
977
-		 */
978
-		public static function set_scheme_data( string $name, array $arr ): bool {
979
-
980
-			// Create blank array.
981
-			$new_scheme = array();
982
-
983
-			// If name is present.
984
-			if ( $name ) {
985
-
986
-				// then add the name at the new array's key.
987
-				$new_scheme['color_scheme_name'] = $name;
988
-
989
-				// Enum through values and assign them to new array.
990
-				foreach ( $arr as $val ) {
991
-					if ( isset( $val['id'] ) ) {
992
-						$new_scheme[ $val['id'] ] = $val;
993
-					}
994
-				}
995
-
996
-				// read the contents of the current scheme file.
997
-				$schemes = self::read_scheme_file();
998
-
999
-				// If returned false (not there) then create a new array.
1000
-				if ( false === $schemes ) {
1001
-					$schemes = array();
1002
-				}
1003
-
1004
-				$scheme_data = $schemes[ $name ] ?? '';
1005
-
1006
-				if ( $scheme_data !== $new_scheme ) {
1007
-
1008
-					// Add new scheme to array that will be saved.
1009
-					$schemes[ $name ] = $new_scheme;
1010
-
1011
-					// Write the data to the JSON file.
1012
-					return self::write_scheme_file( $schemes );
1013
-				}
1014
-			}
1015
-
1016
-			// !success
1017
-			return false;
1018
-		}
1019
-
1020
-		/**
1021
-		 * Enumerate the scheme names from the JSON store file.
1022
-		 *
1023
-		 * @since       1.0.0
1024
-		 * @access      public static
1025
-		 * @return      array Array of stored scheme names.
1026
-		 */
1027
-		public static function get_scheme_names(): array {
1028
-
1029
-			// Read the JSON file, which returns a PHP array.
1030
-			$schemes = self::read_scheme_file();
1031
-
1032
-			// Create a new array.
1033
-			$output = array();
1034
-
1035
-			if ( false !== $schemes ) {
1036
-
1037
-				// If the schemes array IS an array (versus false), then...
1038
-				if ( is_array( $schemes ) ) {
1039
-
1040
-					// Enum them.
1041
-					foreach ( $schemes as $scheme ) {
1042
-
1043
-						// If the color_scheme_name key is set...
1044
-						if ( isset( $scheme['color_scheme_name'] ) ) {
1045
-
1046
-							// Push it onto the array stack.
1047
-							$output[] = $scheme['color_scheme_name'];
1048
-						}
1049
-					}
1050
-				}
1051
-			}
1052
-
1053
-			// Kick the full array out the door.
1054
-			return $output;
1055
-		}
1056
-
1057
-		/**
1058
-		 * Get data array from scheme.
1059
-		 *
1060
-		 * @param string $scheme Scheme name.
1061
-		 *
1062
-		 * @return array
1063
-		 */
1064
-		public static function data_array_from_scheme( string $scheme ): array {
1065
-
1066
-			// Get scheme data from JSON file.
1067
-			$data = self::get_scheme_data( $scheme );
1068
-			if ( false === $data ) {
1069
-				return array();
1070
-			}
1071
-
1072
-			// Don't need to save select arrays to database,
1073
-			// just the id => value.
1074
-			if ( ! empty( $data ) ) {
1075
-				foreach ( $data as $k => $v ) {
1076
-					if ( isset( $v['type'] ) ) {
1077
-						$val = $v['value'];
1078
-
1079
-						unset( $data[ $k ] );
1080
-
1081
-						$data[ $k ] = $val;
1082
-					}
1083
-				}
1084
-			}
1085
-
1086
-			return $data;
1087
-		}
1088
-
1089
-		/**
1090
-		 * Sets current scheme to database.
1091
-		 *
1092
-		 * @param       string $scheme Current scheme name.
1093
-		 *
1094
-		 * @return      void
1095
-		 * @since       1.0.0
1096
-		 * @access      private
1097
-		 */
1098
-		public static function set_database_data( string $scheme = 'Default' ) {
1099
-
1100
-			$data = self::data_array_from_scheme( $scheme );
1101
-
1102
-			// Get opt name, for database.
1103
-			$opt_name = self::$parent->args['opt_name'];
1104
-
1105
-			// Get all options from database.
1106
-			$redux_options = get_option( $opt_name );
1107
-
1108
-			if ( empty( self::$field_id ) ) {
1109
-				self::$field    = self::get_field();
1110
-				self::$field_id = self::$field['id'];
1111
-			}
1112
-
1113
-			// Append ID to variable that holds the current scheme ID data.
1114
-			$redux_options[ self::$field_id ] = $data;
1115
-
1116
-			// Save the modified settings.
1117
-			update_option( $opt_name, $redux_options );
1118
-		}
1119
-	}
812
+                            // closing html tags.
813
+                            $html .= '</div>';
814
+                            $html .= '<span class="redux-label redux-layout-label">' . esc_attr( $v['title'] ) . '</span>';
815
+                            $html .= '</li>';
816
+                        }
817
+                    }
818
+                    $html .= '</ul>';
819
+
820
+                    $html .= '<hr class="redux-color-scheme-blank-hr">';
821
+
822
+                    if ( $is_accordion ) {
823
+                        $html .= '</div>';
824
+                    }
825
+
826
+                    $html .= '</div>';
827
+                }
828
+
829
+                // Close list.
830
+                $html .= '</ul>';
831
+            }
832
+
833
+            // html var not empty, return it.
834
+            if ( ! empty( $html ) ) {
835
+                return $html;
836
+            }
837
+
838
+            return '';
839
+        }
840
+
841
+        /**
842
+         * Get color block class.
843
+         *
844
+         * @param array  $field Field array.
845
+         * @param string $id    Field ID.
846
+         *
847
+         * @return string
848
+         */
849
+        private static function get_color_block_class( array $field, string $id ): string {
850
+            $def = $field['default'];
851
+
852
+            if ( ! empty( $def ) ) {
853
+                foreach ( $def as $arr ) {
854
+                    if ( $arr['id'] === $id ) {
855
+                        if ( isset( $arr['class'] ) ) {
856
+                            return $arr['class'];
857
+                        }
858
+                    }
859
+                }
860
+            }
861
+
862
+            return '';
863
+        }
864
+
865
+        /**
866
+         * Get tooltip data.
867
+         *
868
+         * @param array  $field Field array.
869
+         * @param string $id    Field ID.
870
+         *
871
+         * @return mixed
872
+         */
873
+        private static function get_tooltip_data( array $field, string $id ) {
874
+            $def = $field['default'];
875
+
876
+            if ( ! empty( $def ) ) {
877
+                foreach ( $def as $arr ) {
878
+                    if ( $arr['id'] === $id ) {
879
+                        if ( isset( $arr['tooltip'] ) ) {
880
+                            return $arr['tooltip'];
881
+                        }
882
+                    }
883
+                }
884
+            }
885
+
886
+            return false;
887
+        }
888
+
889
+        /**
890
+         * Get hidden blocks.
891
+         *
892
+         * @param array  $field Field ID.
893
+         * @param string $id    Field ID.
894
+         *
895
+         * @return bool
896
+         */
897
+        private static function get_block_hidden( array $field, string $id ): bool {
898
+            $def = $field['default'];
899
+
900
+            if ( ! empty( $def ) ) {
901
+                foreach ( $def as $arr ) {
902
+                    if ( $arr['id'] === $id ) {
903
+                        if ( isset( $arr['hidden'] ) ) {
904
+                            return $arr['hidden'];
905
+                        }
906
+                    }
907
+                }
908
+            }
909
+
910
+            return false;
911
+        }
912
+
913
+        /**
914
+         * Returns scheme file contents.
915
+         *
916
+         * @since       1.0.0
917
+         * @access      public static
918
+         *
919
+         * @return      array Array of scheme data.
920
+         */
921
+        public static function read_scheme_file() {
922
+            $key  = self::get_scheme_key();
923
+            $data = get_option( $key );
924
+
925
+            if ( empty( $data ) ) {
926
+                $arr_data = false;
927
+            } else {
928
+                $arr_data = $data;
929
+            }
930
+
931
+            return $arr_data;
932
+        }
933
+
934
+        /**
935
+         * Sets scheme file contents.
936
+         *
937
+         * @param       array $arr_data PHP array of data to encode.
938
+         *
939
+         * @return      bool Result of write function.
940
+         * @since       1.0.0
941
+         * @access      public static
942
+         */
943
+        public static function write_scheme_file( array $arr_data ): bool {
944
+            $key = self::get_scheme_key();
945
+
946
+            return update_option( $key, $arr_data );
947
+        }
948
+
949
+        /**
950
+         * Gets individual scheme data from scheme JSON file.
951
+         *
952
+         * @param       string $scheme_name Name of scheme.
953
+         *
954
+         * @return      mixed PHP array of scheme data.
955
+         * @since       1.0.0
956
+         * @access      public static
957
+         */
958
+        public static function get_scheme_data( string $scheme_name ) {
959
+            $data = self::read_scheme_file();
960
+
961
+            if ( false === $data ) {
962
+                return false;
963
+            }
964
+
965
+            return $data[ $scheme_name ];
966
+        }
967
+
968
+        /**
969
+         * Sets individual scheme data to scheme JSON file.
970
+         *
971
+         * @param string $name  Name of a scheme to save.
972
+         * @param array  $arr   Scheme data to encode.
973
+         *
974
+         * @return      bool Result of file written.
975
+         * @since       1.0.0
976
+         * @access      public static
977
+         */
978
+        public static function set_scheme_data( string $name, array $arr ): bool {
979
+
980
+            // Create blank array.
981
+            $new_scheme = array();
982
+
983
+            // If name is present.
984
+            if ( $name ) {
985
+
986
+                // then add the name at the new array's key.
987
+                $new_scheme['color_scheme_name'] = $name;
988
+
989
+                // Enum through values and assign them to new array.
990
+                foreach ( $arr as $val ) {
991
+                    if ( isset( $val['id'] ) ) {
992
+                        $new_scheme[ $val['id'] ] = $val;
993
+                    }
994
+                }
995
+
996
+                // read the contents of the current scheme file.
997
+                $schemes = self::read_scheme_file();
998
+
999
+                // If returned false (not there) then create a new array.
1000
+                if ( false === $schemes ) {
1001
+                    $schemes = array();
1002
+                }
1003
+
1004
+                $scheme_data = $schemes[ $name ] ?? '';
1005
+
1006
+                if ( $scheme_data !== $new_scheme ) {
1007
+
1008
+                    // Add new scheme to array that will be saved.
1009
+                    $schemes[ $name ] = $new_scheme;
1010
+
1011
+                    // Write the data to the JSON file.
1012
+                    return self::write_scheme_file( $schemes );
1013
+                }
1014
+            }
1015
+
1016
+            // !success
1017
+            return false;
1018
+        }
1019
+
1020
+        /**
1021
+         * Enumerate the scheme names from the JSON store file.
1022
+         *
1023
+         * @since       1.0.0
1024
+         * @access      public static
1025
+         * @return      array Array of stored scheme names.
1026
+         */
1027
+        public static function get_scheme_names(): array {
1028
+
1029
+            // Read the JSON file, which returns a PHP array.
1030
+            $schemes = self::read_scheme_file();
1031
+
1032
+            // Create a new array.
1033
+            $output = array();
1034
+
1035
+            if ( false !== $schemes ) {
1036
+
1037
+                // If the schemes array IS an array (versus false), then...
1038
+                if ( is_array( $schemes ) ) {
1039
+
1040
+                    // Enum them.
1041
+                    foreach ( $schemes as $scheme ) {
1042
+
1043
+                        // If the color_scheme_name key is set...
1044
+                        if ( isset( $scheme['color_scheme_name'] ) ) {
1045
+
1046
+                            // Push it onto the array stack.
1047
+                            $output[] = $scheme['color_scheme_name'];
1048
+                        }
1049
+                    }
1050
+                }
1051
+            }
1052
+
1053
+            // Kick the full array out the door.
1054
+            return $output;
1055
+        }
1056
+
1057
+        /**
1058
+         * Get data array from scheme.
1059
+         *
1060
+         * @param string $scheme Scheme name.
1061
+         *
1062
+         * @return array
1063
+         */
1064
+        public static function data_array_from_scheme( string $scheme ): array {
1065
+
1066
+            // Get scheme data from JSON file.
1067
+            $data = self::get_scheme_data( $scheme );
1068
+            if ( false === $data ) {
1069
+                return array();
1070
+            }
1071
+
1072
+            // Don't need to save select arrays to database,
1073
+            // just the id => value.
1074
+            if ( ! empty( $data ) ) {
1075
+                foreach ( $data as $k => $v ) {
1076
+                    if ( isset( $v['type'] ) ) {
1077
+                        $val = $v['value'];
1078
+
1079
+                        unset( $data[ $k ] );
1080
+
1081
+                        $data[ $k ] = $val;
1082
+                    }
1083
+                }
1084
+            }
1085
+
1086
+            return $data;
1087
+        }
1088
+
1089
+        /**
1090
+         * Sets current scheme to database.
1091
+         *
1092
+         * @param       string $scheme Current scheme name.
1093
+         *
1094
+         * @return      void
1095
+         * @since       1.0.0
1096
+         * @access      private
1097
+         */
1098
+        public static function set_database_data( string $scheme = 'Default' ) {
1099
+
1100
+            $data = self::data_array_from_scheme( $scheme );
1101
+
1102
+            // Get opt name, for database.
1103
+            $opt_name = self::$parent->args['opt_name'];
1104
+
1105
+            // Get all options from database.
1106
+            $redux_options = get_option( $opt_name );
1107
+
1108
+            if ( empty( self::$field_id ) ) {
1109
+                self::$field    = self::get_field();
1110
+                self::$field_id = self::$field['id'];
1111
+            }
1112
+
1113
+            // Append ID to variable that holds the current scheme ID data.
1114
+            $redux_options[ self::$field_id ] = $data;
1115
+
1116
+            // Save the modified settings.
1117
+            update_option( $opt_name, $redux_options );
1118
+        }
1119
+    }
1120 1120
 }
Please login to merge, or discard this patch.
redux-core/inc/classes/class-redux-thirdparty-fixes.php 1 patch
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -11,117 +11,117 @@
 block discarded – undo
11 11
 
12 12
 if ( ! class_exists( 'Redux_ThirdParty_Fixes', false ) ) {
13 13
 
14
-	/**
15
-	 * Class Redux_ThirdParty_Fixes
16
-	 */
17
-	class Redux_ThirdParty_Fixes extends Redux_Class {
18
-
19
-		/**
20
-		 * Redux_ThirdParty_Fixes constructor.
21
-		 *
22
-		 * @param object $redux ReduxFramework pointer.
23
-		 */
24
-		public function __construct( $redux ) {
25
-			parent::__construct( $redux );
26
-
27
-			$this->gt3_page_builder();
28
-
29
-			// These are necessary to override an outdated extension embedded in themes
30
-			// that are loaded via the antiquated 'loader.php' method.
31
-			add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/repeater', array( $this, 'repeater_extension_override' ) );
32
-			add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/metaboxes', array( $this, 'metaboxes_extension_override' ) );
33
-			add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/social_profiles', array( $this, 'social_profiles_extension_override' ) );
34
-			add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/widget_areas', array( $this, 'widget_areas_extension_override' ) );
35
-			add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/custom_fonts', array( $this, 'custom_fonts_extension_override' ) );
36
-			add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/icon_select', array( $this, 'icon_select_extension_override' ) );
37
-			add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/color_scheme', array( $this, 'color_scheme_extension_override' ) );
38
-			add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/accordion', array( $this, 'accordion_extension_override' ) );
39
-		}
40
-
41
-		/**
42
-		 * Search extension override.
43
-		 *
44
-		 * @return string
45
-		 */
46
-		public function accordion_extension_override(): string {
47
-			return Redux_Core::$dir . 'inc/extensions/accordion/class-redux-extension-accordion.php';
48
-		}
49
-
50
-		/**
51
-		 * Color Scheme extension override.
52
-		 *
53
-		 * @return string
54
-		 */
55
-		public function color_scheme_extension_override(): string {
56
-			return Redux_core::$dir . 'inc/extensions/color_scheme/class-redux-extension-color-scheme.php';
57
-		}
58
-
59
-		/**
60
-		 * Icon Select extension override.
61
-		 *
62
-		 * @return string
63
-		 */
64
-		public function icon_select_extension_override(): string {
65
-			return Redux_core::$dir . 'inc/extensions/icon_select/class-redux-extension-icon-select.php';
66
-		}
67
-
68
-		/**
69
-		 * Widget Area extension override.
70
-		 *
71
-		 * @return string
72
-		 */
73
-		public function custom_fonts_extension_override(): string {
74
-			return Redux_core::$dir . 'inc/extensions/custom_fonts/class-redux-extension-custom-fonts.php';
75
-		}
76
-
77
-		/**
78
-		 * Widget Area extension override.
79
-		 *
80
-		 * @return string
81
-		 */
82
-		public function widget_areas_extension_override(): string {
83
-			return Redux_core::$dir . 'inc/extensions/widget_areas/class-redux-extension-widget-areas.php';
84
-		}
85
-
86
-		/**
87
-		 * Repeater extension override.
88
-		 *
89
-		 * @return string
90
-		 */
91
-		public function repeater_extension_override(): string {
92
-			return Redux_core::$dir . 'inc/extensions/repeater/class-redux-extension-repeater.php';
93
-		}
94
-
95
-		/**
96
-		 * Metaboxes extension override.
97
-		 *
98
-		 * @return string
99
-		 */
100
-		public function metaboxes_extension_override(): string {
101
-			return Redux_core::$dir . 'inc/extensions/metaboxes/class-redux-extension-metaboxes.php';
102
-		}
103
-
104
-		/**
105
-		 * Social Profiles extension override.
106
-		 *
107
-		 * @return string
108
-		 */
109
-		public function social_profiles_extension_override(): string {
110
-			return Redux_core::$dir . 'inc/extensions/social_profiles/class-redux-extension-social-profiles.php';
111
-		}
112
-
113
-		/**
114
-		 * GT3 Page Builder fix.
115
-		 */
116
-		private function gt3_page_builder() {
117
-			// Fix for the GT3 page builder: http://www.gt3themes.com/wordpress-gt3-page-builder-plugin/.
118
-			if ( has_action( 'ecpt_field_options_' ) ) {
119
-				global $pagenow;
120
-
121
-				if ( 'admin.php' === $pagenow ) {
122
-					remove_action( 'admin_init', 'pb_admin_init' );
123
-				}
124
-			}
125
-		}
126
-	}
14
+    /**
15
+     * Class Redux_ThirdParty_Fixes
16
+     */
17
+    class Redux_ThirdParty_Fixes extends Redux_Class {
18
+
19
+        /**
20
+         * Redux_ThirdParty_Fixes constructor.
21
+         *
22
+         * @param object $redux ReduxFramework pointer.
23
+         */
24
+        public function __construct( $redux ) {
25
+            parent::__construct( $redux );
26
+
27
+            $this->gt3_page_builder();
28
+
29
+            // These are necessary to override an outdated extension embedded in themes
30
+            // that are loaded via the antiquated 'loader.php' method.
31
+            add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/repeater', array( $this, 'repeater_extension_override' ) );
32
+            add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/metaboxes', array( $this, 'metaboxes_extension_override' ) );
33
+            add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/social_profiles', array( $this, 'social_profiles_extension_override' ) );
34
+            add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/widget_areas', array( $this, 'widget_areas_extension_override' ) );
35
+            add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/custom_fonts', array( $this, 'custom_fonts_extension_override' ) );
36
+            add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/icon_select', array( $this, 'icon_select_extension_override' ) );
37
+            add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/color_scheme', array( $this, 'color_scheme_extension_override' ) );
38
+            add_filter( 'redux/extension/' . $this->parent->args['opt_name'] . '/accordion', array( $this, 'accordion_extension_override' ) );
39
+        }
40
+
41
+        /**
42
+         * Search extension override.
43
+         *
44
+         * @return string
45
+         */
46
+        public function accordion_extension_override(): string {
47
+            return Redux_Core::$dir . 'inc/extensions/accordion/class-redux-extension-accordion.php';
48
+        }
49
+
50
+        /**
51
+         * Color Scheme extension override.
52
+         *
53
+         * @return string
54
+         */
55
+        public function color_scheme_extension_override(): string {
56
+            return Redux_core::$dir . 'inc/extensions/color_scheme/class-redux-extension-color-scheme.php';
57
+        }
58
+
59
+        /**
60
+         * Icon Select extension override.
61
+         *
62
+         * @return string
63
+         */
64
+        public function icon_select_extension_override(): string {
65
+            return Redux_core::$dir . 'inc/extensions/icon_select/class-redux-extension-icon-select.php';
66
+        }
67
+
68
+        /**
69
+         * Widget Area extension override.
70
+         *
71
+         * @return string
72
+         */
73
+        public function custom_fonts_extension_override(): string {
74
+            return Redux_core::$dir . 'inc/extensions/custom_fonts/class-redux-extension-custom-fonts.php';
75
+        }
76
+
77
+        /**
78
+         * Widget Area extension override.
79
+         *
80
+         * @return string
81
+         */
82
+        public function widget_areas_extension_override(): string {
83
+            return Redux_core::$dir . 'inc/extensions/widget_areas/class-redux-extension-widget-areas.php';
84
+        }
85
+
86
+        /**
87
+         * Repeater extension override.
88
+         *
89
+         * @return string
90
+         */
91
+        public function repeater_extension_override(): string {
92
+            return Redux_core::$dir . 'inc/extensions/repeater/class-redux-extension-repeater.php';
93
+        }
94
+
95
+        /**
96
+         * Metaboxes extension override.
97
+         *
98
+         * @return string
99
+         */
100
+        public function metaboxes_extension_override(): string {
101
+            return Redux_core::$dir . 'inc/extensions/metaboxes/class-redux-extension-metaboxes.php';
102
+        }
103
+
104
+        /**
105
+         * Social Profiles extension override.
106
+         *
107
+         * @return string
108
+         */
109
+        public function social_profiles_extension_override(): string {
110
+            return Redux_core::$dir . 'inc/extensions/social_profiles/class-redux-extension-social-profiles.php';
111
+        }
112
+
113
+        /**
114
+         * GT3 Page Builder fix.
115
+         */
116
+        private function gt3_page_builder() {
117
+            // Fix for the GT3 page builder: http://www.gt3themes.com/wordpress-gt3-page-builder-plugin/.
118
+            if ( has_action( 'ecpt_field_options_' ) ) {
119
+                global $pagenow;
120
+
121
+                if ( 'admin.php' === $pagenow ) {
122
+                    remove_action( 'admin_init', 'pb_admin_init' );
123
+                }
124
+            }
125
+        }
126
+    }
127 127
 }
Please login to merge, or discard this patch.
redux-core/inc/extensions/search/class-redux-extension-search.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -15,29 +15,29 @@
 block discarded – undo
15 15
 // Don't duplicate me!
16 16
 if ( ! class_exists( 'Redux_Extension_Search' ) ) {
17 17
 
18
-	/**
19
-	 * Class Redux_Extension_Search
20
-	 */
21
-	class Redux_Extension_Search extends Redux_Extension_Abstract {
18
+    /**
19
+     * Class Redux_Extension_Search
20
+     */
21
+    class Redux_Extension_Search extends Redux_Extension_Abstract {
22 22
 
23
-		/**
24
-		 * Extension Friendly Name.
25
-		 *
26
-		 * @var string
27
-		 */
28
-		public string $extension_name = 'Search (Inactive Placeholder)';
23
+        /**
24
+         * Extension Friendly Name.
25
+         *
26
+         * @var string
27
+         */
28
+        public string $extension_name = 'Search (Inactive Placeholder)';
29 29
 
30
-		/**
31
-		 * Redux_Extension_Search constructor.
32
-		 *
33
-		 * @param object $redux ReduxFramework Object pointer.
34
-		 */
35
-		public function __construct( $redux ) {
36
-			parent::__construct( $redux, __FILE__ );
30
+        /**
31
+         * Redux_Extension_Search constructor.
32
+         *
33
+         * @param object $redux ReduxFramework Object pointer.
34
+         */
35
+        public function __construct( $redux ) {
36
+            parent::__construct( $redux, __FILE__ );
37 37
 
38
-			// Nothing here.
39
-		}
40
-	}
38
+            // Nothing here.
39
+        }
40
+    }
41 41
 
42
-	class_alias( Redux_Extension_Search::class, 'ReduxFramework_Extension_search' );
42
+    class_alias( Redux_Extension_Search::class, 'ReduxFramework_Extension_search' );
43 43
 }
Please login to merge, or discard this patch.
redux-core/inc/extensions/datetime/class-redux-extension-datetime.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -17,34 +17,34 @@
 block discarded – undo
17 17
 // Don't duplicate me!
18 18
 if ( ! class_exists( 'Redux_Extension_Datetime', false ) ) {
19 19
 
20
-	/**
21
-	 * Class Redux_Extension_Datetime
22
-	 */
23
-	class Redux_Extension_Datetime extends Redux_Extension_Abstract {
20
+    /**
21
+     * Class Redux_Extension_Datetime
22
+     */
23
+    class Redux_Extension_Datetime extends Redux_Extension_Abstract {
24 24
 
25
-		/**
26
-		 * Extension version.
27
-		 *
28
-		 * @var string
29
-		 */
30
-		public static $version = '4.3.15';
25
+        /**
26
+         * Extension version.
27
+         *
28
+         * @var string
29
+         */
30
+        public static $version = '4.3.15';
31 31
 
32
-		/**
33
-		 * Extension friendly name.
34
-		 *
35
-		 * @var string
36
-		 */
37
-		public string $extension_name = 'Date/Time';
32
+        /**
33
+         * Extension friendly name.
34
+         *
35
+         * @var string
36
+         */
37
+        public string $extension_name = 'Date/Time';
38 38
 
39
-		/**
40
-		 * Redux_Extension_Datetime constructor.
41
-		 *
42
-		 * @param ReduxFramework $redux ReduxFramework pointer.
43
-		 */
44
-		public function __construct( $redux ) {
45
-			parent::__construct( $redux, __FILE__ );
39
+        /**
40
+         * Redux_Extension_Datetime constructor.
41
+         *
42
+         * @param ReduxFramework $redux ReduxFramework pointer.
43
+         */
44
+        public function __construct( $redux ) {
45
+            parent::__construct( $redux, __FILE__ );
46 46
 
47
-			$this->add_field( 'datetime' );
48
-		}
49
-	}
47
+            $this->add_field( 'datetime' );
48
+        }
49
+    }
50 50
 }
Please login to merge, or discard this patch.
redux-core/inc/extensions/accordion/class-redux-extension-accordion.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -16,43 +16,43 @@
 block discarded – undo
16 16
 // Don't duplicate me!
17 17
 if ( ! class_exists( 'Redux_Extension_Accordion' ) ) {
18 18
 
19
-	/**
20
-	 * Main ReduxFramework_Extension_Accordion extension class
21
-	 *
22
-	 * @since       1.0.0
23
-	 */
24
-	class Redux_Extension_Accordion extends Redux_Extension_Abstract {
25
-
26
-		/**
27
-		 * Extension version.
28
-		 *
29
-		 * @var string
30
-		 */
31
-		public static $version = '4.3.16';
32
-
33
-		/**
34
-		 * Extension friendly name.
35
-		 *
36
-		 * @var string
37
-		 */
38
-		public string $extension_name = 'Accordion';
39
-
40
-		/**
41
-		 * Class Constructor. Defines the args for the extension class
42
-		 *
43
-		 * @since       1.0.0
44
-		 * @access      public
45
-		 *
46
-		 * @param       ReduxFramework $redux Parent settings.
47
-		 *
48
-		 * @return      void
49
-		 */
50
-		public function __construct( $redux ) {
51
-			parent::__construct( $redux, __FILE__ );
52
-
53
-			$this->add_field( 'accordion' );
54
-		}
55
-	}
56
-
57
-	class_alias( Redux_Extension_Accordion::class, 'ReduxFramework_Extension_Accordion' );
19
+    /**
20
+     * Main ReduxFramework_Extension_Accordion extension class
21
+     *
22
+     * @since       1.0.0
23
+     */
24
+    class Redux_Extension_Accordion extends Redux_Extension_Abstract {
25
+
26
+        /**
27
+         * Extension version.
28
+         *
29
+         * @var string
30
+         */
31
+        public static $version = '4.3.16';
32
+
33
+        /**
34
+         * Extension friendly name.
35
+         *
36
+         * @var string
37
+         */
38
+        public string $extension_name = 'Accordion';
39
+
40
+        /**
41
+         * Class Constructor. Defines the args for the extension class
42
+         *
43
+         * @since       1.0.0
44
+         * @access      public
45
+         *
46
+         * @param       ReduxFramework $redux Parent settings.
47
+         *
48
+         * @return      void
49
+         */
50
+        public function __construct( $redux ) {
51
+            parent::__construct( $redux, __FILE__ );
52
+
53
+            $this->add_field( 'accordion' );
54
+        }
55
+    }
56
+
57
+    class_alias( Redux_Extension_Accordion::class, 'ReduxFramework_Extension_Accordion' );
58 58
 }
Please login to merge, or discard this patch.