Completed
Push — master ( c4cd1f...963c86 )
by
unknown
36s
created
redux-core/inc/extensions/repeater/repeater/class-redux-repeater.php 1 patch
Indentation   +429 added lines, -429 removed lines patch added patch discarded remove patch
@@ -12,440 +12,440 @@
 block discarded – undo
12 12
 // Don't duplicate me!
13 13
 if ( ! class_exists( 'Redux_Repeater' ) ) {
14 14
 
15
-	/**
16
-	 * Class Redux_Repeater
17
-	 */
18
-	class Redux_Repeater extends Redux_Field {
19
-
20
-		/**
21
-		 * Repeater values.
22
-		 *
23
-		 * @var string
24
-		 */
25
-		private string $repeater_values;
26
-
27
-		/**
28
-		 * Set defaults.
29
-		 */
30
-		public function set_defaults() {
31
-			$this->repeater_values = '';
32
-
33
-			if ( ! isset( $this->field['bind_title'] ) && ! empty( $this->field['fields'] ) ) {
34
-				$this->field['bind_title'] = $this->field['fields'][0]['id'];
35
-			}
36
-
37
-			$default = array(
38
-				'group_values'  => false,
39
-				'item_name'     => '',
40
-				'bind_title'    => true,
41
-				'sortable'      => true,
42
-				'limit'         => 10,
43
-				'init_empty'    => false,
44
-				'panels_closed' => false,
45
-			);
46
-
47
-			$this->field = wp_parse_args( $this->field, $default );
48
-		}
49
-
50
-		/**
51
-		 * Field Render Function.
52
-		 * Takes the vars and outputs the HTML for the field in the settings
53
-		 *
54
-		 * @since       1.0.0
55
-		 * @access      public
56
-		 * @return      void
57
-		 */
58
-		public function render() {
59
-			$unallowed = array( 'tabbed', 'social_profiles', 'color_scheme', 'repeater' );
60
-
61
-			if ( isset( $this->field['group_values'] ) && $this->field['group_values'] ) {
62
-				$this->repeater_values = '[' . $this->field['id'] . ']';
63
-			}
64
-
65
-			if ( false === $this->field['init_empty'] ) {
66
-				$title = '';
67
-
68
-				if ( empty( $this->value ) || ! is_array( $this->value ) ) {
69
-					$this->value = array(
70
-						'redux_repeater_data' => array(
71
-							array(
72
-								'title' => $title,
73
-							),
74
-						),
75
-					);
76
-				}
77
-			}
78
-
79
-			if ( isset( $this->field['subfields'] ) && empty( $this->field['fields'] ) ) {
80
-				$this->field['fields'] = $this->field['subfields'];
81
-				unset( $this->field['subfields'] );
82
-			}
83
-
84
-			echo '<div class="redux-repeater-accordion" data-id="' . esc_attr( $this->field['id'] ) . '" data-panels-closed="' . esc_attr( $this->field['panels_closed'] ) . '">';
85
-
86
-			$x = 0;
87
-
88
-			if ( isset( $this->value['redux_repeater_data'] ) && is_array( $this->value['redux_repeater_data'] ) && ! empty( $this->value['redux_repeater_data'] ) ) {
89
-				$repeaters = $this->value['redux_repeater_data'];
90
-
91
-				if ( '' === $this->field['bind_title'] ) {
92
-					$keys                      = array_keys( min( $repeaters ) );
93
-					$this->field['bind_title'] = $keys[0];
94
-				}
95
-				foreach ( $repeaters as $repeater ) {
96
-					if ( empty( $repeater ) ) {
97
-						continue;
98
-					}
99
-
100
-					echo '<div class="redux-repeater-accordion-repeater" data-sortid="' . esc_attr( $x ) . '">';
101
-					echo '<table style="margin-top: 0;" class="redux-repeater-accordion redux-repeater form-table no-border">';
102
-					echo '<fieldset class="redux-field " data-id="' . esc_attr( $this->field['id'] ) . '">';
103
-
104
-					echo '<input type="hidden" name="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][redux_repeater_data][' . esc_attr( $x ) . '][title]" value="' . esc_attr( $repeater['title'] ) . '" class="regular-text slide-title" data-key="' . esc_attr( $x ) . '" />';
105
-
106
-					if ( isset( $this->field['bind_title'] ) ) {
107
-						foreach ( $this->field['fields'] as $field ) {
108
-							if ( $field['id'] === $this->field['bind_title'] ) {
109
-								if ( isset( $field['options'] ) ) {
110
-
111
-									// Sorter data filter.
112
-									if ( 'sorter' === $field['type'] && ! empty( $field['data'] ) && is_array( $field['data'] ) ) {
113
-										if ( ! isset( $field['args'] ) ) {
114
-											$field['args'] = array();
115
-										}
116
-
117
-										foreach ( $field['data'] as $key => $data ) {
118
-											if ( ! isset( $field['args'][ $key ] ) ) {
119
-												$field['args'][ $key ] = array();
120
-											}
121
-
122
-											$field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] );
123
-										}
124
-									}
125
-								}
126
-
127
-								$default = $field['default'] ?? '';
128
-
129
-								if ( ! empty( $this->repeater_values ) ) {
130
-									$repeater['title'] = ! isset( $this->parent->options[ $this->field['id'] ][ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $this->field['id'] ][ $field['id'] ][ $x ];
131
-								} else {
132
-									$repeater['title'] = ! isset( $this->parent->options[ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $field['id'] ][ $x ];
133
-								}
134
-
135
-								if ( isset( $field['options'] ) && is_array( $field['options'] ) ) {
136
-									if ( isset( $field['options'][ $repeater['title'] ] ) ) {
137
-										$repeater['title'] = $field['options'][ $repeater['title'] ];
138
-									}
139
-								}
140
-							}
141
-						}
142
-					}
143
-
144
-					if ( is_array( $repeater['title'] ) ) {
145
-						$repeater['title'] = esc_html__( 'Title', 'redux-framework' );
146
-					}
147
-
148
-					echo '<h3><span class="redux-repeater-header">' . esc_html( $repeater['title'] ) . ' </span></h3>';
149
-
150
-					echo '<div>';
151
-
152
-					foreach ( $this->field['fields'] as $field ) {
153
-						if ( ! isset( $field['class'] ) ) {
154
-							$field['class'] = '';
155
-						}
156
-
157
-						if ( isset( $this->field['bind_title'] ) && $field['id'] === $this->field['bind_title'] ) {
158
-							$field['class'] .= ' bind_title';
159
-						}
160
-
161
-						if ( in_array( $field['type'], $unallowed, true ) ) {
162
-							echo esc_html__( 'The', 'redux-framework' ) . ' <code>' . esc_html( $field['type'] ) . '</code> ' . esc_html__( 'field is not supported within the Repeater field.', 'redux-framework' );
163
-						} else {
164
-							$this->output_field( $field, $x );
165
-						}
166
-					}
167
-
168
-					if ( ! isset( $this->field['static'] ) && empty( $this->field['static'] ) ) {
169
-						echo '<a href="javascript:void(0);" class="button deletion redux-warning-primary redux-repeaters-remove">' . esc_html__( 'Delete', 'redux-framework' ) . ' ' . esc_html( $this->field['item_name'] ) . '</a>';
170
-					}
171
-
172
-					echo '</div>';
173
-					echo '</fieldset>';
174
-					echo '</table>';
175
-					echo '</div>';
176
-
177
-					++$x;
178
-				}
179
-			}
180
-
181
-			if ( 0 === $x || ( isset( $this->field['static'] ) && ( $x - 1 ) < $this->field['static'] ) ) {
182
-				if ( isset( $this->field['static'] ) && $x < $this->field['static'] ) {
183
-					$loop = $this->field['static'] - $x;
184
-				} else {
185
-					$loop = 1;
186
-				}
187
-
188
-				$class = '';
189
-
190
-				if ( 0 === $x && true === $this->field['init_empty'] ) {
191
-					$class = 'close-me';
192
-				}
193
-
194
-				while ( $loop > 0 ) {
195
-					echo '<div class="redux-repeater-accordion-repeater ' . esc_attr( $class ) . '">';
196
-					echo '<table style="margin-top: 0;" class="redux-repeater-accordion redux-repeater form-table no-border">';
197
-					echo '<fieldset class="redux-field" data-id="' . esc_attr( $this->field['id'] ) . '">';
198
-
199
-					if ( ! isset( $this->value['redux_repeater_data'][ $x ]['title'] ) && is_array( $this->value ) && isset( $this->value['redux_repeater_data'] ) && is_array( $this->value['redux_repeater_data'] ) ) {
200
-						$this->value['redux_repeater_data'][ $x ]['title'] = null;
201
-					}
202
-
203
-					echo '<input type="hidden" name="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][redux_repeater_data][' . intval( $x ) . '][title]" value="" class="regular-text slide-title" />';
204
-
205
-					echo '<h3><span class="redux-repeater-header"> </span></h3>';
206
-					echo '<div>';
207
-
208
-					foreach ( $this->field['fields'] as $field ) {
209
-						if ( isset( $this->field['bind_title'] ) && $field['id'] === $this->field['bind_title'] ) {
210
-							if ( ! isset( $field['class'] ) || ( isset( $field['title'] ) && empty( $field['title'] ) ) ) {
211
-								$field['class'] = 'bind_title';
212
-							} else {
213
-								$field['class'] .= ' bind_title';
214
-							}
215
-						}
216
-
217
-						$this->output_field( $field, $x );
218
-					}
219
-
220
-					if ( ! isset( $this->field['static'] ) && empty( $this->field['static'] ) ) {
221
-						echo '<a href="javascript:void(0);" class="button deletion redux-repeaters-remove">' . esc_html__( 'Delete', 'redux-framework' ) . ' ' . esc_html( $this->field['item_name'] ) . '</a>';
222
-					}
223
-
224
-					echo '</div>';
225
-					echo '</fieldset>';
226
-					echo '</table>';
227
-					echo '</div>';
228
-
229
-					++$x;
230
-					--$loop;
231
-				}
232
-			}
233
-
234
-			echo '</div>';
235
-			if ( ! isset( $this->field['static'] ) && empty( $this->field['static'] ) ) {
236
-				$disabled = '';
237
-
238
-				if ( isset( $this->field['limit'] ) && is_integer( $this->field['limit'] ) ) {
239
-					if ( $x >= $this->field['limit'] ) {
240
-						$disabled = ' button-disabled';
241
-					}
242
-				}
243
-
244
-				echo '<a href="javascript:void(0);" class="button redux-repeaters-add button-primary' . esc_attr( $disabled ) . '" data-name="' . esc_attr( $this->parent->args['opt_name'] . $this->repeater_values ) . '[title][]">' . esc_html__( 'Add', 'redux-framework' ) . ' ' . esc_html( $this->field['item_name'] ) . '</a><br/>';
245
-			}
246
-		}
247
-
248
-		/**
249
-		 * Enqueue Function.
250
-		 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
251
-		 *
252
-		 * @since       1.0.0
253
-		 * @access      public
254
-		 * @return      void
255
-		 */
256
-		public function enqueue() {
257
-			wp_print_styles( 'editor-buttons' );
258
-
259
-			// Set up min files for dev_mode = false.
260
-			$min = Redux_Functions::is_min();
261
-
262
-			wp_enqueue_script(
263
-				'redux-field-repeater',
264
-				// phpcs:ignore WordPress.NamingConventions.ValidHookName
265
-				$this->url . 'redux-repeater' . $min . '.js',
266
-				array( 'jquery', 'jquery-ui-core', 'jquery-ui-accordion', 'jquery-ui-sortable', 'wp-color-picker', 'redux-js' ),
267
-				Redux_Extension_Repeater::$version,
268
-				true
269
-			);
270
-
271
-			if ( $this->parent->args['dev_mode'] ) {
272
-				wp_enqueue_style(
273
-					'redux-field-repeater',
274
-					// phpcs:ignore WordPress.NamingConventions.ValidHookName
275
-					$this->url . 'redux-repeater.css',
276
-					array(),
277
-					Redux_Extension_Repeater::$version
278
-				);
279
-			}
280
-		}
281
-
282
-		/**
283
-		 * Output field.
284
-		 *
285
-		 * @param array $field Field array.
286
-		 * @param int   $x     Index.
287
-		 */
288
-		public function output_field( array $field, int $x ) {
289
-			$this->enqueue_dependencies( $field );
290
-
291
-			if ( ! isset( $field['class'] ) ) {
292
-				$field['class'] = '';
293
-			}
294
-
295
-			$field['class'] .= ' repeater';
296
-
297
-			if ( ! empty( $field['title'] ) ) {
298
-				echo '<h4>' . wp_kses_post( $field['title'] ) . '</h4>';
299
-			}
300
-
301
-			if ( ! empty( $field['subtitle'] ) ) {
302
-				echo '<span class="description">' . wp_kses_post( $field['subtitle'] ) . '</span>';
303
-			}
304
-
305
-			$orig_field_id = $field['id'];
306
-
307
-			$field['id']          = $field['id'] . '-' . $x;
308
-			$field['name']        = $this->parent->args['opt_name'] . $this->repeater_values . '[' . $orig_field_id . ']';
309
-			$field['name_suffix'] = '[' . $x . ']';
310
-			$field['class']      .= ' in-repeater';
311
-			$field['repeater_id'] = $orig_field_id;
312
-
313
-			if ( isset( $field['options'] ) ) {
314
-
315
-				// Sorter data filter.
316
-				if ( 'sorter' === $field['type'] && ! empty( $field['data'] ) && is_array( $field['data'] ) ) {
317
-					if ( ! isset( $field['args'] ) ) {
318
-						$field['args'] = array();
319
-					}
320
-
321
-					foreach ( $field['data'] as $key => $data ) {
322
-						if ( ! isset( $field['args'][ $key ] ) ) {
323
-							$field['args'][ $key ] = array();
324
-						}
325
-						$field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] );
326
-					}
327
-				}
328
-			}
329
-
330
-			$default = $field['default'] ?? '';
331
-
332
-			if ( ! empty( $this->repeater_values ) ) {
333
-				$value = empty( $this->parent->options[ $this->field['id'] ][ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $this->field['id'] ][ $orig_field_id ][ $x ];
334
-			} else {
335
-				$value = empty( $this->parent->options[ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $orig_field_id ][ $x ];
336
-			}
337
-
338
-			ob_start();
339
-
340
-			$this->parent->render_class->field_input( $field, $value );
341
-
342
-			$content = ob_get_contents();
343
-
344
-			// phpcs:ignore WordPress.NamingConventions.ValidHookName
345
-			$_field = apply_filters( 'redux-support-repeater', $content, $field, 0 );
346
-
347
-			ob_end_clean();
348
-
349
-			echo $_field; // phpcs:ignore WordPress.Security.EscapeOutput
350
-		}
351
-
352
-
353
-		/**
354
-		 * Localize.
355
-		 *
356
-		 * @param array  $field Field array.
357
-		 * @param string $value Value.
358
-		 *
359
-		 * @return array|string
360
-		 */
361
-		public function localize( array $field, string $value = '' ) {
362
-			if ( isset( $field['subfields'] ) && empty( $field['fields'] ) ) {
363
-				$field['fields'] = $field['subfields'];
364
-				unset( $field['subfields'] );
365
-			}
366
-
367
-			if ( isset( $field['group_values'] ) && $field['group_values'] ) {
368
-				$this->repeater_values = '[' . $field['id'] . ']';
369
-			}
370
-
371
-			$var = '';
372
-
373
-			if ( '' === $value ) {
374
-				$value = array();
375
-			}
376
-
377
-			if ( ! empty( $field['fields'] ) ) {
378
-				ob_start();
379
-
380
-				foreach ( $field['fields'] as $f ) {
381
-					if ( isset( $this->field['bind_title'] ) && $f['id'] === $this->field['bind_title'] ) {
382
-						if ( ! isset( $f['class'] ) || ( isset( $f['title'] ) && empty( $f['title'] ) ) ) {
383
-							$f['class'] = 'bind_title';
384
-						} else {
385
-							$f['class'] .= ' bind_title';
386
-						}
387
-					}
15
+    /**
16
+     * Class Redux_Repeater
17
+     */
18
+    class Redux_Repeater extends Redux_Field {
19
+
20
+        /**
21
+         * Repeater values.
22
+         *
23
+         * @var string
24
+         */
25
+        private string $repeater_values;
26
+
27
+        /**
28
+         * Set defaults.
29
+         */
30
+        public function set_defaults() {
31
+            $this->repeater_values = '';
32
+
33
+            if ( ! isset( $this->field['bind_title'] ) && ! empty( $this->field['fields'] ) ) {
34
+                $this->field['bind_title'] = $this->field['fields'][0]['id'];
35
+            }
36
+
37
+            $default = array(
38
+                'group_values'  => false,
39
+                'item_name'     => '',
40
+                'bind_title'    => true,
41
+                'sortable'      => true,
42
+                'limit'         => 10,
43
+                'init_empty'    => false,
44
+                'panels_closed' => false,
45
+            );
46
+
47
+            $this->field = wp_parse_args( $this->field, $default );
48
+        }
49
+
50
+        /**
51
+         * Field Render Function.
52
+         * Takes the vars and outputs the HTML for the field in the settings
53
+         *
54
+         * @since       1.0.0
55
+         * @access      public
56
+         * @return      void
57
+         */
58
+        public function render() {
59
+            $unallowed = array( 'tabbed', 'social_profiles', 'color_scheme', 'repeater' );
60
+
61
+            if ( isset( $this->field['group_values'] ) && $this->field['group_values'] ) {
62
+                $this->repeater_values = '[' . $this->field['id'] . ']';
63
+            }
64
+
65
+            if ( false === $this->field['init_empty'] ) {
66
+                $title = '';
67
+
68
+                if ( empty( $this->value ) || ! is_array( $this->value ) ) {
69
+                    $this->value = array(
70
+                        'redux_repeater_data' => array(
71
+                            array(
72
+                                'title' => $title,
73
+                            ),
74
+                        ),
75
+                    );
76
+                }
77
+            }
78
+
79
+            if ( isset( $this->field['subfields'] ) && empty( $this->field['fields'] ) ) {
80
+                $this->field['fields'] = $this->field['subfields'];
81
+                unset( $this->field['subfields'] );
82
+            }
83
+
84
+            echo '<div class="redux-repeater-accordion" data-id="' . esc_attr( $this->field['id'] ) . '" data-panels-closed="' . esc_attr( $this->field['panels_closed'] ) . '">';
85
+
86
+            $x = 0;
87
+
88
+            if ( isset( $this->value['redux_repeater_data'] ) && is_array( $this->value['redux_repeater_data'] ) && ! empty( $this->value['redux_repeater_data'] ) ) {
89
+                $repeaters = $this->value['redux_repeater_data'];
90
+
91
+                if ( '' === $this->field['bind_title'] ) {
92
+                    $keys                      = array_keys( min( $repeaters ) );
93
+                    $this->field['bind_title'] = $keys[0];
94
+                }
95
+                foreach ( $repeaters as $repeater ) {
96
+                    if ( empty( $repeater ) ) {
97
+                        continue;
98
+                    }
99
+
100
+                    echo '<div class="redux-repeater-accordion-repeater" data-sortid="' . esc_attr( $x ) . '">';
101
+                    echo '<table style="margin-top: 0;" class="redux-repeater-accordion redux-repeater form-table no-border">';
102
+                    echo '<fieldset class="redux-field " data-id="' . esc_attr( $this->field['id'] ) . '">';
103
+
104
+                    echo '<input type="hidden" name="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][redux_repeater_data][' . esc_attr( $x ) . '][title]" value="' . esc_attr( $repeater['title'] ) . '" class="regular-text slide-title" data-key="' . esc_attr( $x ) . '" />';
105
+
106
+                    if ( isset( $this->field['bind_title'] ) ) {
107
+                        foreach ( $this->field['fields'] as $field ) {
108
+                            if ( $field['id'] === $this->field['bind_title'] ) {
109
+                                if ( isset( $field['options'] ) ) {
110
+
111
+                                    // Sorter data filter.
112
+                                    if ( 'sorter' === $field['type'] && ! empty( $field['data'] ) && is_array( $field['data'] ) ) {
113
+                                        if ( ! isset( $field['args'] ) ) {
114
+                                            $field['args'] = array();
115
+                                        }
116
+
117
+                                        foreach ( $field['data'] as $key => $data ) {
118
+                                            if ( ! isset( $field['args'][ $key ] ) ) {
119
+                                                $field['args'][ $key ] = array();
120
+                                            }
121
+
122
+                                            $field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] );
123
+                                        }
124
+                                    }
125
+                                }
126
+
127
+                                $default = $field['default'] ?? '';
128
+
129
+                                if ( ! empty( $this->repeater_values ) ) {
130
+                                    $repeater['title'] = ! isset( $this->parent->options[ $this->field['id'] ][ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $this->field['id'] ][ $field['id'] ][ $x ];
131
+                                } else {
132
+                                    $repeater['title'] = ! isset( $this->parent->options[ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $field['id'] ][ $x ];
133
+                                }
134
+
135
+                                if ( isset( $field['options'] ) && is_array( $field['options'] ) ) {
136
+                                    if ( isset( $field['options'][ $repeater['title'] ] ) ) {
137
+                                        $repeater['title'] = $field['options'][ $repeater['title'] ];
138
+                                    }
139
+                                }
140
+                            }
141
+                        }
142
+                    }
143
+
144
+                    if ( is_array( $repeater['title'] ) ) {
145
+                        $repeater['title'] = esc_html__( 'Title', 'redux-framework' );
146
+                    }
147
+
148
+                    echo '<h3><span class="redux-repeater-header">' . esc_html( $repeater['title'] ) . ' </span></h3>';
149
+
150
+                    echo '<div>';
151
+
152
+                    foreach ( $this->field['fields'] as $field ) {
153
+                        if ( ! isset( $field['class'] ) ) {
154
+                            $field['class'] = '';
155
+                        }
156
+
157
+                        if ( isset( $this->field['bind_title'] ) && $field['id'] === $this->field['bind_title'] ) {
158
+                            $field['class'] .= ' bind_title';
159
+                        }
160
+
161
+                        if ( in_array( $field['type'], $unallowed, true ) ) {
162
+                            echo esc_html__( 'The', 'redux-framework' ) . ' <code>' . esc_html( $field['type'] ) . '</code> ' . esc_html__( 'field is not supported within the Repeater field.', 'redux-framework' );
163
+                        } else {
164
+                            $this->output_field( $field, $x );
165
+                        }
166
+                    }
167
+
168
+                    if ( ! isset( $this->field['static'] ) && empty( $this->field['static'] ) ) {
169
+                        echo '<a href="javascript:void(0);" class="button deletion redux-warning-primary redux-repeaters-remove">' . esc_html__( 'Delete', 'redux-framework' ) . ' ' . esc_html( $this->field['item_name'] ) . '</a>';
170
+                    }
171
+
172
+                    echo '</div>';
173
+                    echo '</fieldset>';
174
+                    echo '</table>';
175
+                    echo '</div>';
176
+
177
+                    ++$x;
178
+                }
179
+            }
180
+
181
+            if ( 0 === $x || ( isset( $this->field['static'] ) && ( $x - 1 ) < $this->field['static'] ) ) {
182
+                if ( isset( $this->field['static'] ) && $x < $this->field['static'] ) {
183
+                    $loop = $this->field['static'] - $x;
184
+                } else {
185
+                    $loop = 1;
186
+                }
187
+
188
+                $class = '';
189
+
190
+                if ( 0 === $x && true === $this->field['init_empty'] ) {
191
+                    $class = 'close-me';
192
+                }
193
+
194
+                while ( $loop > 0 ) {
195
+                    echo '<div class="redux-repeater-accordion-repeater ' . esc_attr( $class ) . '">';
196
+                    echo '<table style="margin-top: 0;" class="redux-repeater-accordion redux-repeater form-table no-border">';
197
+                    echo '<fieldset class="redux-field" data-id="' . esc_attr( $this->field['id'] ) . '">';
198
+
199
+                    if ( ! isset( $this->value['redux_repeater_data'][ $x ]['title'] ) && is_array( $this->value ) && isset( $this->value['redux_repeater_data'] ) && is_array( $this->value['redux_repeater_data'] ) ) {
200
+                        $this->value['redux_repeater_data'][ $x ]['title'] = null;
201
+                    }
202
+
203
+                    echo '<input type="hidden" name="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][redux_repeater_data][' . intval( $x ) . '][title]" value="" class="regular-text slide-title" />';
204
+
205
+                    echo '<h3><span class="redux-repeater-header"> </span></h3>';
206
+                    echo '<div>';
207
+
208
+                    foreach ( $this->field['fields'] as $field ) {
209
+                        if ( isset( $this->field['bind_title'] ) && $field['id'] === $this->field['bind_title'] ) {
210
+                            if ( ! isset( $field['class'] ) || ( isset( $field['title'] ) && empty( $field['title'] ) ) ) {
211
+                                $field['class'] = 'bind_title';
212
+                            } else {
213
+                                $field['class'] .= ' bind_title';
214
+                            }
215
+                        }
216
+
217
+                        $this->output_field( $field, $x );
218
+                    }
219
+
220
+                    if ( ! isset( $this->field['static'] ) && empty( $this->field['static'] ) ) {
221
+                        echo '<a href="javascript:void(0);" class="button deletion redux-repeaters-remove">' . esc_html__( 'Delete', 'redux-framework' ) . ' ' . esc_html( $this->field['item_name'] ) . '</a>';
222
+                    }
223
+
224
+                    echo '</div>';
225
+                    echo '</fieldset>';
226
+                    echo '</table>';
227
+                    echo '</div>';
228
+
229
+                    ++$x;
230
+                    --$loop;
231
+                }
232
+            }
233
+
234
+            echo '</div>';
235
+            if ( ! isset( $this->field['static'] ) && empty( $this->field['static'] ) ) {
236
+                $disabled = '';
237
+
238
+                if ( isset( $this->field['limit'] ) && is_integer( $this->field['limit'] ) ) {
239
+                    if ( $x >= $this->field['limit'] ) {
240
+                        $disabled = ' button-disabled';
241
+                    }
242
+                }
243
+
244
+                echo '<a href="javascript:void(0);" class="button redux-repeaters-add button-primary' . esc_attr( $disabled ) . '" data-name="' . esc_attr( $this->parent->args['opt_name'] . $this->repeater_values ) . '[title][]">' . esc_html__( 'Add', 'redux-framework' ) . ' ' . esc_html( $this->field['item_name'] ) . '</a><br/>';
245
+            }
246
+        }
247
+
248
+        /**
249
+         * Enqueue Function.
250
+         * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
251
+         *
252
+         * @since       1.0.0
253
+         * @access      public
254
+         * @return      void
255
+         */
256
+        public function enqueue() {
257
+            wp_print_styles( 'editor-buttons' );
258
+
259
+            // Set up min files for dev_mode = false.
260
+            $min = Redux_Functions::is_min();
261
+
262
+            wp_enqueue_script(
263
+                'redux-field-repeater',
264
+                // phpcs:ignore WordPress.NamingConventions.ValidHookName
265
+                $this->url . 'redux-repeater' . $min . '.js',
266
+                array( 'jquery', 'jquery-ui-core', 'jquery-ui-accordion', 'jquery-ui-sortable', 'wp-color-picker', 'redux-js' ),
267
+                Redux_Extension_Repeater::$version,
268
+                true
269
+            );
270
+
271
+            if ( $this->parent->args['dev_mode'] ) {
272
+                wp_enqueue_style(
273
+                    'redux-field-repeater',
274
+                    // phpcs:ignore WordPress.NamingConventions.ValidHookName
275
+                    $this->url . 'redux-repeater.css',
276
+                    array(),
277
+                    Redux_Extension_Repeater::$version
278
+                );
279
+            }
280
+        }
281
+
282
+        /**
283
+         * Output field.
284
+         *
285
+         * @param array $field Field array.
286
+         * @param int   $x     Index.
287
+         */
288
+        public function output_field( array $field, int $x ) {
289
+            $this->enqueue_dependencies( $field );
290
+
291
+            if ( ! isset( $field['class'] ) ) {
292
+                $field['class'] = '';
293
+            }
294
+
295
+            $field['class'] .= ' repeater';
296
+
297
+            if ( ! empty( $field['title'] ) ) {
298
+                echo '<h4>' . wp_kses_post( $field['title'] ) . '</h4>';
299
+            }
300
+
301
+            if ( ! empty( $field['subtitle'] ) ) {
302
+                echo '<span class="description">' . wp_kses_post( $field['subtitle'] ) . '</span>';
303
+            }
304
+
305
+            $orig_field_id = $field['id'];
306
+
307
+            $field['id']          = $field['id'] . '-' . $x;
308
+            $field['name']        = $this->parent->args['opt_name'] . $this->repeater_values . '[' . $orig_field_id . ']';
309
+            $field['name_suffix'] = '[' . $x . ']';
310
+            $field['class']      .= ' in-repeater';
311
+            $field['repeater_id'] = $orig_field_id;
312
+
313
+            if ( isset( $field['options'] ) ) {
314
+
315
+                // Sorter data filter.
316
+                if ( 'sorter' === $field['type'] && ! empty( $field['data'] ) && is_array( $field['data'] ) ) {
317
+                    if ( ! isset( $field['args'] ) ) {
318
+                        $field['args'] = array();
319
+                    }
320
+
321
+                    foreach ( $field['data'] as $key => $data ) {
322
+                        if ( ! isset( $field['args'][ $key ] ) ) {
323
+                            $field['args'][ $key ] = array();
324
+                        }
325
+                        $field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] );
326
+                    }
327
+                }
328
+            }
329
+
330
+            $default = $field['default'] ?? '';
331
+
332
+            if ( ! empty( $this->repeater_values ) ) {
333
+                $value = empty( $this->parent->options[ $this->field['id'] ][ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $this->field['id'] ][ $orig_field_id ][ $x ];
334
+            } else {
335
+                $value = empty( $this->parent->options[ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $orig_field_id ][ $x ];
336
+            }
337
+
338
+            ob_start();
339
+
340
+            $this->parent->render_class->field_input( $field, $value );
341
+
342
+            $content = ob_get_contents();
343
+
344
+            // phpcs:ignore WordPress.NamingConventions.ValidHookName
345
+            $_field = apply_filters( 'redux-support-repeater', $content, $field, 0 );
346
+
347
+            ob_end_clean();
348
+
349
+            echo $_field; // phpcs:ignore WordPress.Security.EscapeOutput
350
+        }
351
+
352
+
353
+        /**
354
+         * Localize.
355
+         *
356
+         * @param array  $field Field array.
357
+         * @param string $value Value.
358
+         *
359
+         * @return array|string
360
+         */
361
+        public function localize( array $field, string $value = '' ) {
362
+            if ( isset( $field['subfields'] ) && empty( $field['fields'] ) ) {
363
+                $field['fields'] = $field['subfields'];
364
+                unset( $field['subfields'] );
365
+            }
366
+
367
+            if ( isset( $field['group_values'] ) && $field['group_values'] ) {
368
+                $this->repeater_values = '[' . $field['id'] . ']';
369
+            }
370
+
371
+            $var = '';
372
+
373
+            if ( '' === $value ) {
374
+                $value = array();
375
+            }
376
+
377
+            if ( ! empty( $field['fields'] ) ) {
378
+                ob_start();
379
+
380
+                foreach ( $field['fields'] as $f ) {
381
+                    if ( isset( $this->field['bind_title'] ) && $f['id'] === $this->field['bind_title'] ) {
382
+                        if ( ! isset( $f['class'] ) || ( isset( $f['title'] ) && empty( $f['title'] ) ) ) {
383
+                            $f['class'] = 'bind_title';
384
+                        } else {
385
+                            $f['class'] .= ' bind_title';
386
+                        }
387
+                    }
388 388
 
389
-					$this->output_field( $f, 99999 );
390
-				}
391
-
392
-				$var = ob_get_contents();
389
+                    $this->output_field( $f, 99999 );
390
+                }
391
+
392
+                $var = ob_get_contents();
393 393
 
394
-				$var = array(
395
-					'html'     => $var . '<a href="javascript:void(0);" class="button deletion redux-repeaters-remove">' . esc_html__( 'Delete', 'redux-framework' ) . '</a>',
396
-					'count'    => count( $value ),
397
-					'sortable' => true,
398
-					'limit'    => '',
399
-					'name'     => $this->parent->args['opt_name'] . '[' . $field['id'] . '][0]',
400
-				);
401
-
402
-				if ( isset( $field['sortable'] ) && is_bool( $this->field['sortable'] ) ) {
403
-					$var['sortable'] = $field['sortable'];
404
-				}
405
-				if ( isset( $field['limit'] ) && is_integer( $field['limit'] ) ) {
406
-					$var['limit'] = $field['limit'];
407
-				}
408
-
409
-				ob_end_clean();
410
-			}
411
-
412
-			return $var;
413
-		}
414
-
415
-		/**
416
-		 * Enqueue Deps.
417
-		 *
418
-		 * @param array $field Field.
419
-		 */
420
-		private function enqueue_dependencies( array $field ) {
421
-			$field_type = $field['type'];
422
-
423
-			$field_class = 'Redux_' . $field_type;
394
+                $var = array(
395
+                    'html'     => $var . '<a href="javascript:void(0);" class="button deletion redux-repeaters-remove">' . esc_html__( 'Delete', 'redux-framework' ) . '</a>',
396
+                    'count'    => count( $value ),
397
+                    'sortable' => true,
398
+                    'limit'    => '',
399
+                    'name'     => $this->parent->args['opt_name'] . '[' . $field['id'] . '][0]',
400
+                );
401
+
402
+                if ( isset( $field['sortable'] ) && is_bool( $this->field['sortable'] ) ) {
403
+                    $var['sortable'] = $field['sortable'];
404
+                }
405
+                if ( isset( $field['limit'] ) && is_integer( $field['limit'] ) ) {
406
+                    $var['limit'] = $field['limit'];
407
+                }
408
+
409
+                ob_end_clean();
410
+            }
411
+
412
+            return $var;
413
+        }
414
+
415
+        /**
416
+         * Enqueue Deps.
417
+         *
418
+         * @param array $field Field.
419
+         */
420
+        private function enqueue_dependencies( array $field ) {
421
+            $field_type = $field['type'];
422
+
423
+            $field_class = 'Redux_' . $field_type;
424 424
 
425
-			if ( ! class_exists( $field_class ) ) {
426
-				$field_type = str_replace( '_', '-', $field_type );
425
+            if ( ! class_exists( $field_class ) ) {
426
+                $field_type = str_replace( '_', '-', $field_type );
427 427
 
428
-				// phpcs:ignore WordPress.NamingConventions.ValidHookName
429
-				$class_file = apply_filters( 'redux-typeclass-load', ReduxFramework::$_dir . 'inc/fields/' . $field_type . '/class-redux-' . $field_type . '.php', $field_class );
428
+                // phpcs:ignore WordPress.NamingConventions.ValidHookName
429
+                $class_file = apply_filters( 'redux-typeclass-load', ReduxFramework::$_dir . 'inc/fields/' . $field_type . '/class-redux-' . $field_type . '.php', $field_class );
430 430
 
431
-				if ( file_exists( $class_file ) ) {
432
-					require_once $class_file;
433
-				}
434
-			}
431
+                if ( file_exists( $class_file ) ) {
432
+                    require_once $class_file;
433
+                }
434
+            }
435 435
 
436
-			if ( class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) {
437
-				$enqueue = new $field_class( '', '', $this->parent );
438
-				$enqueue->enqueue();
439
-			}
436
+            if ( class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) {
437
+                $enqueue = new $field_class( '', '', $this->parent );
438
+                $enqueue->enqueue();
439
+            }
440 440
 
441
-			if ( class_exists( $field_class ) && method_exists( $field_class, 'localize' ) ) {
442
-
443
-				$enqueue = new $field_class( '', '', $this->parent );
444
-
445
-				$data = $enqueue->localize( $field );
446
-
447
-				$this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data;
448
-			}
449
-		}
450
-	}
441
+            if ( class_exists( $field_class ) && method_exists( $field_class, 'localize' ) ) {
442
+
443
+                $enqueue = new $field_class( '', '', $this->parent );
444
+
445
+                $data = $enqueue->localize( $field );
446
+
447
+                $this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data;
448
+            }
449
+        }
450
+    }
451 451
 }
Please login to merge, or discard this patch.
redux-core/inc/extensions/tabbed/tabbed/class-redux-tabbed.php 1 patch
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -11,211 +11,211 @@
 block discarded – undo
11 11
 
12 12
 if ( ! class_exists( 'Redux_Tabbed', false ) ) {
13 13
 
14
-	/**
15
-	 * Class Redux_Tabbed
16
-	 */
17
-	class Redux_Tabbed extends Redux_Field {
14
+    /**
15
+     * Class Redux_Tabbed
16
+     */
17
+    class Redux_Tabbed extends Redux_Field {
18 18
 
19
-		/**
20
-		 * Set field defaults.
21
-		 */
22
-		public function set_defaults() {
23
-			$defaults = array(
24
-				'icon' => '',
25
-			);
19
+        /**
20
+         * Set field defaults.
21
+         */
22
+        public function set_defaults() {
23
+            $defaults = array(
24
+                'icon' => '',
25
+            );
26 26
 
27
-			$this->field = wp_parse_args( $this->field, $defaults );
28
-		}
27
+            $this->field = wp_parse_args( $this->field, $defaults );
28
+        }
29 29
 
30
-		/**
31
-		 * Field Render Function.
32
-		 * Takes the vars and outputs the HTML for the field in the settings
33
-		 *
34
-		 * @since ReduxFramework 0.0.4
35
-		 */
36
-		public function render() {
37
-			$unallowed = array( 'tabbed', 'social_profiles', 'color_schemes', 'repeater' );
30
+        /**
31
+         * Field Render Function.
32
+         * Takes the vars and outputs the HTML for the field in the settings
33
+         *
34
+         * @since ReduxFramework 0.0.4
35
+         */
36
+        public function render() {
37
+            $unallowed = array( 'tabbed', 'social_profiles', 'color_schemes', 'repeater' );
38 38
 
39
-			echo '<div id="' . esc_attr( $this->field['id'] ) . '-tabbed" class="redux-tabbed" rel="' . esc_attr( $this->field['id'] ) . '">';
40
-			echo '<div class="redux-tabbed-nav" data-id="' . esc_attr( $this->field['id'] ) . '">';
41
-			foreach ( $this->field['tabs'] as $key => $tab ) {
39
+            echo '<div id="' . esc_attr( $this->field['id'] ) . '-tabbed" class="redux-tabbed" rel="' . esc_attr( $this->field['id'] ) . '">';
40
+            echo '<div class="redux-tabbed-nav" data-id="' . esc_attr( $this->field['id'] ) . '">';
41
+            foreach ( $this->field['tabs'] as $key => $tab ) {
42 42
 
43
-				$tabbed_icon   = ( ! empty( $tab['icon'] ) ) ? '<i class="redux-tab-icon ' . esc_attr( $tab['icon'] ) . '"></i>' : '';
44
-				$tabbed_active = ( empty( $key ) ) ? 'redux-tabbed-active' : '';
45
-
46
-				// Output HTML escaped above.
47
-				// phpcs:ignore WordPress.Security.EscapeOutput
48
-				echo '<a href="#" class="' . esc_attr( $tabbed_active ) . '"">' . $tabbed_icon . esc_attr( $tab['title'] ) . '</a>';
49
-
50
-			}
51
-			echo '</div>';
52
-
53
-			echo '<div class="redux-tabbed-contents">';
54
-			foreach ( $this->field['tabs'] as $key => $tab ) {
55
-
56
-				$tabbed_hidden = ( ! empty( $key ) ) ? ' hidden' : '';
57
-
58
-				echo '<div class="redux-tabbed-content' . esc_attr( $tabbed_hidden ) . '">';
59
-
60
-				foreach ( $tab['fields'] as $field ) {
61
-
62
-					if ( in_array( $field['type'], $unallowed, true ) ) {
63
-						echo esc_html__( 'The', 'redux-framework' ) . ' <code>' . esc_html( $field['type'] ) . '</code> ' . esc_html__( 'field is not supported within the Tabbed field.', 'redux-framework' );
64
-					} else {
65
-						$this->output_field( $field );
66
-					}
67
-				}
68
-
69
-				echo '</div>';
70
-			}
71
-
72
-			echo '</div>';
73
-			echo '</div>';
74
-		}
75
-
76
-		/**
77
-		 * Output field.
78
-		 *
79
-		 * @param array $field Field array.
80
-		 */
81
-		public function output_field( array $field ) {
82
-			$this->enqueue_dependencies( $field );
83
-
84
-			if ( ! isset( $field['class'] ) ) {
85
-				$field['class'] = '';
86
-			}
43
+                $tabbed_icon   = ( ! empty( $tab['icon'] ) ) ? '<i class="redux-tab-icon ' . esc_attr( $tab['icon'] ) . '"></i>' : '';
44
+                $tabbed_active = ( empty( $key ) ) ? 'redux-tabbed-active' : '';
45
+
46
+                // Output HTML escaped above.
47
+                // phpcs:ignore WordPress.Security.EscapeOutput
48
+                echo '<a href="#" class="' . esc_attr( $tabbed_active ) . '"">' . $tabbed_icon . esc_attr( $tab['title'] ) . '</a>';
49
+
50
+            }
51
+            echo '</div>';
52
+
53
+            echo '<div class="redux-tabbed-contents">';
54
+            foreach ( $this->field['tabs'] as $key => $tab ) {
55
+
56
+                $tabbed_hidden = ( ! empty( $key ) ) ? ' hidden' : '';
57
+
58
+                echo '<div class="redux-tabbed-content' . esc_attr( $tabbed_hidden ) . '">';
59
+
60
+                foreach ( $tab['fields'] as $field ) {
61
+
62
+                    if ( in_array( $field['type'], $unallowed, true ) ) {
63
+                        echo esc_html__( 'The', 'redux-framework' ) . ' <code>' . esc_html( $field['type'] ) . '</code> ' . esc_html__( 'field is not supported within the Tabbed field.', 'redux-framework' );
64
+                    } else {
65
+                        $this->output_field( $field );
66
+                    }
67
+                }
68
+
69
+                echo '</div>';
70
+            }
71
+
72
+            echo '</div>';
73
+            echo '</div>';
74
+        }
75
+
76
+        /**
77
+         * Output field.
78
+         *
79
+         * @param array $field Field array.
80
+         */
81
+        public function output_field( array $field ) {
82
+            $this->enqueue_dependencies( $field );
83
+
84
+            if ( ! isset( $field['class'] ) ) {
85
+                $field['class'] = '';
86
+            }
87 87
 
88
-			$field['class'] .= ' tabbed';
88
+            $field['class'] .= ' tabbed';
89 89
 
90
-			echo '<div class="redux-tab-field">';
90
+            echo '<div class="redux-tab-field">';
91 91
 
92
-			if ( ! empty( $field['title'] ) ) {
93
-				echo '<div class="redux-field-title">';
94
-				echo '<h4>' . wp_kses_post( $field['title'] ) . '</h4>';
92
+            if ( ! empty( $field['title'] ) ) {
93
+                echo '<div class="redux-field-title">';
94
+                echo '<h4>' . wp_kses_post( $field['title'] ) . '</h4>';
95 95
 
96
-				if ( ! empty( $field['subtitle'] ) ) {
97
-					echo '<div class="redux-field-subtitle">' . wp_kses_post( $field['subtitle'] ) . '</div>';
98
-				}
99
-
100
-				echo '</div>';
101
-			}
102
-
103
-			$orig_field_id = $field['id'];
104
-
105
-			$field['name']   = $this->parent->args['opt_name'] . '[' . $orig_field_id . ']';
106
-			$field['class'] .= ' in-tabbed';
107
-
108
-			if ( isset( $field['options'] ) ) {
109
-
110
-				// Sorter data filter.
111
-				if ( 'sorter' === $field['type'] && ! empty( $field['data'] ) && is_array( $field['data'] ) ) {
112
-					if ( ! isset( $field['args'] ) ) {
113
-						$field['args'] = array();
114
-					}
115
-
116
-					foreach ( $field['data'] as $key => $data ) {
117
-						if ( ! isset( $field['args'][ $key ] ) ) {
118
-							$field['args'][ $key ] = array();
119
-						}
120
-
121
-						$field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] );
122
-					}
123
-				}
124
-			}
125
-
126
-			$default = $field['default'] ?? null;
127
-
128
-			// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
129
-			// $value = isset( $this->parent->options[ $orig_field_id ] ) && 0 !== (int) $this->parent->options[ $orig_field_id ] ? $this->parent->options[ $orig_field_id ] : $default;
130
-			$value = $this->parent->options[ $orig_field_id ] ?? $default;
131
-
132
-			$this->parent->render_class->field_input( $field, $value );
133
-
134
-			echo '<div class="clear"></div>';
135
-			echo '</div>';
136
-		}
137
-
138
-		/**
139
-		 * Localize.
140
-		 *
141
-		 * @param array  $field Field.
142
-		 * @param string $value Value.
143
-		 *
144
-		 * @return void
145
-		 */
146
-		public function localize( array $field, string $value = '' ) {
147
-			ob_start();
148
-
149
-			foreach ( $field['tabs'] as $f ) {
150
-				foreach ( $f['fields'] as $field ) {
151
-					$this->output_field( $field );
152
-				}
153
-			}
154
-
155
-			ob_end_clean();
156
-		}
157
-
158
-		/**
159
-		 * Enqueue Deps.
160
-		 *
161
-		 * @param array $field Field.
162
-		 */
163
-		private function enqueue_dependencies( array $field ) {
164
-			$field_type = $field['type'];
165
-
166
-			$field_class = 'Redux_' . $field_type;
167
-
168
-			if ( ! class_exists( $field_class ) ) {
169
-				$field_type = str_replace( '_', '-', $field_type );
170
-
171
-				// phpcs:ignore WordPress.NamingConventions.ValidHookName
172
-				$class_file = apply_filters( 'redux-typeclass-load', ReduxFramework::$_dir . 'inc/fields/' . $field_type . '/class-redux-' . $field_type . '.php', $field_class );
173
-
174
-				if ( file_exists( $class_file ) ) {
175
-					require_once $class_file;
176
-				}
177
-			}
178
-
179
-			if ( class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) {
180
-				$enqueue = new $field_class( '', '', $this->parent );
181
-				$enqueue->enqueue();
182
-			}
183
-
184
-			if ( class_exists( $field_class ) && method_exists( $field_class, 'localize' ) ) {
185
-
186
-				$enqueue = new $field_class( '', '', $this->parent );
187
-
188
-				$data = $enqueue->localize( $field );
189
-
190
-				$this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data;
191
-			}
192
-		}
193
-
194
-		/**
195
-		 * Enqueue Function.
196
-		 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
197
-		 *
198
-		 * @since ReduxFramework 0.0.4
199
-		 */
200
-		public function enqueue() {
201
-			wp_print_styles( 'editor-buttons' );
202
-
203
-			wp_enqueue_script(
204
-				'redux-field-tabbed',
205
-				Redux_Core::$url . 'inc/extensions/tabbed/tabbed/redux-tabbed' . Redux_Functions::is_min() . '.js',
206
-				array( 'jquery', 'redux-js' ),
207
-				Redux_Extension_Tabbed::$version,
208
-				true
209
-			);
210
-
211
-			if ( $this->parent->args['dev_mode'] ) {
212
-				wp_enqueue_style(
213
-					'redux-field-tabbed',
214
-					Redux_Core::$url . 'inc/extensions/tabbed/tabbed/redux-tabbed.css',
215
-					array(),
216
-					Redux_Extension_Tabbed::$version
217
-				);
218
-			}
219
-		}
220
-	}
96
+                if ( ! empty( $field['subtitle'] ) ) {
97
+                    echo '<div class="redux-field-subtitle">' . wp_kses_post( $field['subtitle'] ) . '</div>';
98
+                }
99
+
100
+                echo '</div>';
101
+            }
102
+
103
+            $orig_field_id = $field['id'];
104
+
105
+            $field['name']   = $this->parent->args['opt_name'] . '[' . $orig_field_id . ']';
106
+            $field['class'] .= ' in-tabbed';
107
+
108
+            if ( isset( $field['options'] ) ) {
109
+
110
+                // Sorter data filter.
111
+                if ( 'sorter' === $field['type'] && ! empty( $field['data'] ) && is_array( $field['data'] ) ) {
112
+                    if ( ! isset( $field['args'] ) ) {
113
+                        $field['args'] = array();
114
+                    }
115
+
116
+                    foreach ( $field['data'] as $key => $data ) {
117
+                        if ( ! isset( $field['args'][ $key ] ) ) {
118
+                            $field['args'][ $key ] = array();
119
+                        }
120
+
121
+                        $field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] );
122
+                    }
123
+                }
124
+            }
125
+
126
+            $default = $field['default'] ?? null;
127
+
128
+            // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
129
+            // $value = isset( $this->parent->options[ $orig_field_id ] ) && 0 !== (int) $this->parent->options[ $orig_field_id ] ? $this->parent->options[ $orig_field_id ] : $default;
130
+            $value = $this->parent->options[ $orig_field_id ] ?? $default;
131
+
132
+            $this->parent->render_class->field_input( $field, $value );
133
+
134
+            echo '<div class="clear"></div>';
135
+            echo '</div>';
136
+        }
137
+
138
+        /**
139
+         * Localize.
140
+         *
141
+         * @param array  $field Field.
142
+         * @param string $value Value.
143
+         *
144
+         * @return void
145
+         */
146
+        public function localize( array $field, string $value = '' ) {
147
+            ob_start();
148
+
149
+            foreach ( $field['tabs'] as $f ) {
150
+                foreach ( $f['fields'] as $field ) {
151
+                    $this->output_field( $field );
152
+                }
153
+            }
154
+
155
+            ob_end_clean();
156
+        }
157
+
158
+        /**
159
+         * Enqueue Deps.
160
+         *
161
+         * @param array $field Field.
162
+         */
163
+        private function enqueue_dependencies( array $field ) {
164
+            $field_type = $field['type'];
165
+
166
+            $field_class = 'Redux_' . $field_type;
167
+
168
+            if ( ! class_exists( $field_class ) ) {
169
+                $field_type = str_replace( '_', '-', $field_type );
170
+
171
+                // phpcs:ignore WordPress.NamingConventions.ValidHookName
172
+                $class_file = apply_filters( 'redux-typeclass-load', ReduxFramework::$_dir . 'inc/fields/' . $field_type . '/class-redux-' . $field_type . '.php', $field_class );
173
+
174
+                if ( file_exists( $class_file ) ) {
175
+                    require_once $class_file;
176
+                }
177
+            }
178
+
179
+            if ( class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) {
180
+                $enqueue = new $field_class( '', '', $this->parent );
181
+                $enqueue->enqueue();
182
+            }
183
+
184
+            if ( class_exists( $field_class ) && method_exists( $field_class, 'localize' ) ) {
185
+
186
+                $enqueue = new $field_class( '', '', $this->parent );
187
+
188
+                $data = $enqueue->localize( $field );
189
+
190
+                $this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data;
191
+            }
192
+        }
193
+
194
+        /**
195
+         * Enqueue Function.
196
+         * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
197
+         *
198
+         * @since ReduxFramework 0.0.4
199
+         */
200
+        public function enqueue() {
201
+            wp_print_styles( 'editor-buttons' );
202
+
203
+            wp_enqueue_script(
204
+                'redux-field-tabbed',
205
+                Redux_Core::$url . 'inc/extensions/tabbed/tabbed/redux-tabbed' . Redux_Functions::is_min() . '.js',
206
+                array( 'jquery', 'redux-js' ),
207
+                Redux_Extension_Tabbed::$version,
208
+                true
209
+            );
210
+
211
+            if ( $this->parent->args['dev_mode'] ) {
212
+                wp_enqueue_style(
213
+                    'redux-field-tabbed',
214
+                    Redux_Core::$url . 'inc/extensions/tabbed/tabbed/redux-tabbed.css',
215
+                    array(),
216
+                    Redux_Extension_Tabbed::$version
217
+                );
218
+            }
219
+        }
220
+    }
221 221
 }
Please login to merge, or discard this patch.
redux-core/inc/fields/button_set/class-redux-button-set.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -12,132 +12,132 @@
 block discarded – undo
12 12
 // Don't duplicate me!
13 13
 if ( ! class_exists( 'Redux_Button_Set', false ) ) {
14 14
 
15
-	/**
16
-	 * Main Redux_button_set class
17
-	 *
18
-	 * @since       1.0.0
19
-	 */
20
-	class Redux_Button_Set extends Redux_Field {
21
-
22
-		/**
23
-		 * Set field defaults.
24
-		 */
25
-		public function set_defaults() {
26
-			$defaults = array(
27
-				'options' => array(),
28
-				'multi'   => false,
29
-			);
30
-
31
-			$this->field = wp_parse_args( $this->field, $defaults );
32
-		}
33
-
34
-		/**
35
-		 * Field Render Function.
36
-		 * Takes the vars and outputs the HTML for the field in the settings
37
-		 *
38
-		 * @since       1.0.0
39
-		 * @access      public
40
-		 * @return      void
41
-		 */
42
-		public function render() {
43
-			if ( ! empty( $this->field['data'] ) && empty( $this->field['options'] ) ) {
44
-				if ( empty( $this->field['args'] ) ) {
45
-					$this->field['args'] = array();
46
-				}
47
-
48
-				$this->field['options'] = $this->parent->wordpress_data->get( $this->field['data'], $this->field['args'], $this->parent->args['opt_name'], $this->value );
49
-
50
-				if ( empty( $this->field['options'] ) ) {
51
-					return;
52
-				}
53
-			}
54
-
55
-			$is_multi = isset( $this->field['multi'] ) && true === (bool) $this->field['multi'];
56
-
57
-			$name = $this->field['name'] . $this->field['name_suffix'];
58
-
59
-			// multi => true renders the field multi-selectable (checkbox vs radio).
60
-			echo '<div class="buttonset ui-buttonset">';
61
-
62
-			if ( $is_multi ) {
63
-				$s = '';
64
-
65
-				if ( empty( $this->value ) ) {
66
-					$s = $name;
67
-				}
68
-
69
-				echo '<input type="hidden" data-name="' . esc_attr( $name ) . '" class="buttonset-empty" name="' . esc_attr( $s ) . '" value=""/>';
70
-
71
-				$name = $name . '[]';
72
-			}
73
-
74
-			foreach ( $this->field['options'] as $k => $v ) {
75
-				$selected = '';
76
-
77
-				if ( $is_multi ) {
78
-					$post_value = '';
79
-					$type       = 'checkbox';
80
-
81
-					if ( ! empty( $this->value ) && ! is_array( $this->value ) ) {
82
-						$this->value = array( $this->value );
83
-					}
84
-
85
-					if ( is_array( $this->value ) && in_array( (string) $k, $this->value, true ) ) {
86
-						$selected   = 'checked="checked"';
87
-						$post_value = $k;
88
-					}
89
-				} else {
90
-					$type = 'radio';
91
-
92
-					if ( is_scalar( $this->value ) ) {
93
-						$selected = checked( $this->value, $k, false );
94
-					}
95
-				}
96
-
97
-				$the_val     = $k;
98
-				$the_name    = $name;
99
-				$data_val    = '';
100
-				$multi_class = '';
101
-
102
-				if ( $is_multi ) {
103
-					$the_val     = '';
104
-					$the_name    = '';
105
-					$data_val    = ' data-val=' . $k;
106
-					$hidden_name = $name;
107
-					$multi_class = 'multi ';
108
-
109
-					if ( '' === $post_value ) {
110
-						$hidden_name = '';
111
-					}
112
-
113
-					echo '<input type="hidden" class="buttonset-check" id="' . esc_attr( $this->field['id'] ) . '-buttonset' . esc_attr( $k ) . '-hidden" name="' . esc_attr( $hidden_name ) . '" value="' . esc_attr( $post_value ) . '"/>';
114
-				}
115
-
116
-				echo '<input' . esc_attr( $data_val ) . ' data-id="' . esc_attr( $this->field['id'] ) . '" type="' . esc_attr( $type ) . '" id="' . esc_attr( $this->field['id'] ) . '-buttonset' . esc_attr( $k ) . '" name="' . esc_attr( $the_name ) . '" class="buttonset-item ' . esc_attr( $multi_class ) . esc_attr( $this->field['class'] ) . '" value="' . esc_attr( $the_val ) . '" ' . esc_html( $selected ) . '/>';
117
-				echo '<label for="' . esc_attr( $this->field['id'] ) . '-buttonset' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label>';
118
-			}
119
-
120
-			echo '</div>';
121
-		}
122
-
123
-		/**
124
-		 * Enqueue Function.
125
-		 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
126
-		 *
127
-		 * @since       1.0.0
128
-		 * @access      public
129
-		 * @return      void
130
-		 */
131
-		public function enqueue() {
132
-			wp_enqueue_script(
133
-				'redux-field-button-set',
134
-				Redux_Core::$url . 'inc/fields/button_set/redux-button-set' . Redux_Functions::is_min() . '.js',
135
-				array( 'jquery', 'jquery-ui-core', 'redux-js' ),
136
-				$this->timestamp,
137
-				true
138
-			);
139
-		}
140
-	}
15
+    /**
16
+     * Main Redux_button_set class
17
+     *
18
+     * @since       1.0.0
19
+     */
20
+    class Redux_Button_Set extends Redux_Field {
21
+
22
+        /**
23
+         * Set field defaults.
24
+         */
25
+        public function set_defaults() {
26
+            $defaults = array(
27
+                'options' => array(),
28
+                'multi'   => false,
29
+            );
30
+
31
+            $this->field = wp_parse_args( $this->field, $defaults );
32
+        }
33
+
34
+        /**
35
+         * Field Render Function.
36
+         * Takes the vars and outputs the HTML for the field in the settings
37
+         *
38
+         * @since       1.0.0
39
+         * @access      public
40
+         * @return      void
41
+         */
42
+        public function render() {
43
+            if ( ! empty( $this->field['data'] ) && empty( $this->field['options'] ) ) {
44
+                if ( empty( $this->field['args'] ) ) {
45
+                    $this->field['args'] = array();
46
+                }
47
+
48
+                $this->field['options'] = $this->parent->wordpress_data->get( $this->field['data'], $this->field['args'], $this->parent->args['opt_name'], $this->value );
49
+
50
+                if ( empty( $this->field['options'] ) ) {
51
+                    return;
52
+                }
53
+            }
54
+
55
+            $is_multi = isset( $this->field['multi'] ) && true === (bool) $this->field['multi'];
56
+
57
+            $name = $this->field['name'] . $this->field['name_suffix'];
58
+
59
+            // multi => true renders the field multi-selectable (checkbox vs radio).
60
+            echo '<div class="buttonset ui-buttonset">';
61
+
62
+            if ( $is_multi ) {
63
+                $s = '';
64
+
65
+                if ( empty( $this->value ) ) {
66
+                    $s = $name;
67
+                }
68
+
69
+                echo '<input type="hidden" data-name="' . esc_attr( $name ) . '" class="buttonset-empty" name="' . esc_attr( $s ) . '" value=""/>';
70
+
71
+                $name = $name . '[]';
72
+            }
73
+
74
+            foreach ( $this->field['options'] as $k => $v ) {
75
+                $selected = '';
76
+
77
+                if ( $is_multi ) {
78
+                    $post_value = '';
79
+                    $type       = 'checkbox';
80
+
81
+                    if ( ! empty( $this->value ) && ! is_array( $this->value ) ) {
82
+                        $this->value = array( $this->value );
83
+                    }
84
+
85
+                    if ( is_array( $this->value ) && in_array( (string) $k, $this->value, true ) ) {
86
+                        $selected   = 'checked="checked"';
87
+                        $post_value = $k;
88
+                    }
89
+                } else {
90
+                    $type = 'radio';
91
+
92
+                    if ( is_scalar( $this->value ) ) {
93
+                        $selected = checked( $this->value, $k, false );
94
+                    }
95
+                }
96
+
97
+                $the_val     = $k;
98
+                $the_name    = $name;
99
+                $data_val    = '';
100
+                $multi_class = '';
101
+
102
+                if ( $is_multi ) {
103
+                    $the_val     = '';
104
+                    $the_name    = '';
105
+                    $data_val    = ' data-val=' . $k;
106
+                    $hidden_name = $name;
107
+                    $multi_class = 'multi ';
108
+
109
+                    if ( '' === $post_value ) {
110
+                        $hidden_name = '';
111
+                    }
112
+
113
+                    echo '<input type="hidden" class="buttonset-check" id="' . esc_attr( $this->field['id'] ) . '-buttonset' . esc_attr( $k ) . '-hidden" name="' . esc_attr( $hidden_name ) . '" value="' . esc_attr( $post_value ) . '"/>';
114
+                }
115
+
116
+                echo '<input' . esc_attr( $data_val ) . ' data-id="' . esc_attr( $this->field['id'] ) . '" type="' . esc_attr( $type ) . '" id="' . esc_attr( $this->field['id'] ) . '-buttonset' . esc_attr( $k ) . '" name="' . esc_attr( $the_name ) . '" class="buttonset-item ' . esc_attr( $multi_class ) . esc_attr( $this->field['class'] ) . '" value="' . esc_attr( $the_val ) . '" ' . esc_html( $selected ) . '/>';
117
+                echo '<label for="' . esc_attr( $this->field['id'] ) . '-buttonset' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label>';
118
+            }
119
+
120
+            echo '</div>';
121
+        }
122
+
123
+        /**
124
+         * Enqueue Function.
125
+         * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
126
+         *
127
+         * @since       1.0.0
128
+         * @access      public
129
+         * @return      void
130
+         */
131
+        public function enqueue() {
132
+            wp_enqueue_script(
133
+                'redux-field-button-set',
134
+                Redux_Core::$url . 'inc/fields/button_set/redux-button-set' . Redux_Functions::is_min() . '.js',
135
+                array( 'jquery', 'jquery-ui-core', 'redux-js' ),
136
+                $this->timestamp,
137
+                true
138
+            );
139
+        }
140
+    }
141 141
 }
142 142
 
143 143
 class_alias( 'Redux_Button_Set', 'ReduxFramework_Button_Set' );
Please login to merge, or discard this patch.