Completed
Push — master ( 3c99ea...a5a7ca )
by
unknown
18s
created
extensions/social_profiles/social_profiles/class-redux-social-profiles.php 2 patches
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -11,358 +11,358 @@
 block discarded – undo
11 11
 
12 12
 if ( ! class_exists( 'Redux_Social_Profiles' ) ) {
13 13
 
14
-	/**
15
-	 * Main Redux_Social_Profiles class
16
-	 *
17
-	 * @since       1.0.0
18
-	 */
19
-	class Redux_Social_Profiles extends Redux_Field {
20
-
21
-		/**
22
-		 * Field ID.
23
-		 *
24
-		 * @var null|string
25
-		 */
26
-		public ?string $field_id;
27
-
28
-		/**
29
-		 * Panel opt_name.
30
-		 *
31
-		 * @var null|string
32
-		 */
33
-		public ?string $opt_name;
34
-
35
-		/**
36
-		 * Defaults array.
37
-		 *
38
-		 * @var null|array
39
-		 */
40
-
41
-		private ?array $defaults = array();
42
-
43
-		/**
44
-		 * Set defaults.
45
-		 */
46
-		public function set_defaults() {
47
-			$this->opt_name = $this->parent->args['opt_name'];
48
-			$this->field_id = $this->field['id'];
49
-
50
-			$this->defaults = Redux_Social_Profiles_Functions::get_default_data();
51
-		}
52
-
53
-		/**
54
-		 * Rebuild Settings.
55
-		 *
56
-		 * @param array $settings Settings array.
57
-		 *
58
-		 * @return array
59
-		 */
60
-		private function rebuild_setttings( array $settings ): array {
61
-			$fixed_arr = array();
62
-			$stock     = '';
63
-
64
-			foreach ( $this->defaults as $key => $arr ) {
65
-				$search_default = true;
66
-
67
-				$default_id = $arr['id'];
68
-
69
-				foreach ( $settings as $a ) {
70
-					if ( isset( $a['data'] ) ) {
71
-						$a['data'] = rawurldecode( $a['data'] );
72
-						$a         = (array) json_decode( $a['data'] );
73
-					}
74
-
75
-					if ( $default_id === $a['id'] ) {
76
-						$search_default    = false;
77
-						$fixed_arr[ $key ] = $a;
78
-						break;
79
-					}
80
-				}
81
-
82
-				if ( $search_default ) {
83
-					if ( '' === $stock ) {
84
-						$stock = Redux_Social_Profiles_Defaults::get_social_media_defaults();
85
-						$stock = Redux_Social_Profiles_Functions::add_extra_icons( $stock );
86
-					}
87
-
88
-					foreach ( $stock as $def_arr ) {
89
-						if ( $default_id === $def_arr['id'] ) {
90
-							$fixed_arr[ $key ] = $def_arr;
91
-							break;
92
-						}
93
-					}
94
-				}
95
-			}
96
-
97
-			return $fixed_arr;
98
-		}
99
-
100
-		/**
101
-		 * Field Render Function.
102
-		 * Takes the vars and outputs the HTML for the field in the settings
103
-		 *
104
-		 * @since       1.0.0
105
-		 * @access      public
106
-		 * @return      void
107
-		 */
108
-		public function render() {
109
-			if ( empty( $this->field ) ) {
110
-				return;
111
-			}
112
-
113
-			global $pagenow, $post;
114
-
115
-			$redux_settings = get_option( $this->opt_name );
116
-			$settings       = $redux_settings[ $this->field_id ] ?? array();
117
-
118
-			if ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) {
119
-				$post_settings = get_post_meta( $post->ID, $this->field_id, true );
120
-
121
-				if ( ! empty( $post_settings ) ) {
122
-					$settings = $post_settings;
123
-				}
124
-			}
125
-
126
-			$color_pickers = $this->field['color_pickers'] ?? true;
127
-
128
-			// Icon container.
129
-			echo '<div
14
+    /**
15
+     * Main Redux_Social_Profiles class
16
+     *
17
+     * @since       1.0.0
18
+     */
19
+    class Redux_Social_Profiles extends Redux_Field {
20
+
21
+        /**
22
+         * Field ID.
23
+         *
24
+         * @var null|string
25
+         */
26
+        public ?string $field_id;
27
+
28
+        /**
29
+         * Panel opt_name.
30
+         *
31
+         * @var null|string
32
+         */
33
+        public ?string $opt_name;
34
+
35
+        /**
36
+         * Defaults array.
37
+         *
38
+         * @var null|array
39
+         */
40
+
41
+        private ?array $defaults = array();
42
+
43
+        /**
44
+         * Set defaults.
45
+         */
46
+        public function set_defaults() {
47
+            $this->opt_name = $this->parent->args['opt_name'];
48
+            $this->field_id = $this->field['id'];
49
+
50
+            $this->defaults = Redux_Social_Profiles_Functions::get_default_data();
51
+        }
52
+
53
+        /**
54
+         * Rebuild Settings.
55
+         *
56
+         * @param array $settings Settings array.
57
+         *
58
+         * @return array
59
+         */
60
+        private function rebuild_setttings( array $settings ): array {
61
+            $fixed_arr = array();
62
+            $stock     = '';
63
+
64
+            foreach ( $this->defaults as $key => $arr ) {
65
+                $search_default = true;
66
+
67
+                $default_id = $arr['id'];
68
+
69
+                foreach ( $settings as $a ) {
70
+                    if ( isset( $a['data'] ) ) {
71
+                        $a['data'] = rawurldecode( $a['data'] );
72
+                        $a         = (array) json_decode( $a['data'] );
73
+                    }
74
+
75
+                    if ( $default_id === $a['id'] ) {
76
+                        $search_default    = false;
77
+                        $fixed_arr[ $key ] = $a;
78
+                        break;
79
+                    }
80
+                }
81
+
82
+                if ( $search_default ) {
83
+                    if ( '' === $stock ) {
84
+                        $stock = Redux_Social_Profiles_Defaults::get_social_media_defaults();
85
+                        $stock = Redux_Social_Profiles_Functions::add_extra_icons( $stock );
86
+                    }
87
+
88
+                    foreach ( $stock as $def_arr ) {
89
+                        if ( $default_id === $def_arr['id'] ) {
90
+                            $fixed_arr[ $key ] = $def_arr;
91
+                            break;
92
+                        }
93
+                    }
94
+                }
95
+            }
96
+
97
+            return $fixed_arr;
98
+        }
99
+
100
+        /**
101
+         * Field Render Function.
102
+         * Takes the vars and outputs the HTML for the field in the settings
103
+         *
104
+         * @since       1.0.0
105
+         * @access      public
106
+         * @return      void
107
+         */
108
+        public function render() {
109
+            if ( empty( $this->field ) ) {
110
+                return;
111
+            }
112
+
113
+            global $pagenow, $post;
114
+
115
+            $redux_settings = get_option( $this->opt_name );
116
+            $settings       = $redux_settings[ $this->field_id ] ?? array();
117
+
118
+            if ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) {
119
+                $post_settings = get_post_meta( $post->ID, $this->field_id, true );
120
+
121
+                if ( ! empty( $post_settings ) ) {
122
+                    $settings = $post_settings;
123
+                }
124
+            }
125
+
126
+            $color_pickers = $this->field['color_pickers'] ?? true;
127
+
128
+            // Icon container.
129
+            echo '<div
130 130
                     class="redux-social-profiles-container ' . esc_attr( $this->field['class'] ) . '"
131 131
                     data-opt-name="' . esc_attr( $this->opt_name ) . '"
132 132
                     data-id="' . esc_attr( $this->field_id ) . '"
133 133
                   >';
134 134
 
135
-			$show_msg = $this->field['hide_widget_msg'] ?? true;
135
+            $show_msg = $this->field['hide_widget_msg'] ?? true;
136 136
 
137
-			// translators: %1$s: Widget page HTML/URL. %s: widget admin URL.
138
-			$def_msg = sprintf( esc_html__( 'Go to the %1$s page to add the Redux Social Widget to any active widget area.', 'redux-framework' ), sprintf( '<a href="%s">' . esc_html__( 'Widgets', 'redux-framework' ) . '</a> ', admin_url( 'widgets.php' ) ) );
137
+            // translators: %1$s: Widget page HTML/URL. %s: widget admin URL.
138
+            $def_msg = sprintf( esc_html__( 'Go to the %1$s page to add the Redux Social Widget to any active widget area.', 'redux-framework' ), sprintf( '<a href="%s">' . esc_html__( 'Widgets', 'redux-framework' ) . '</a> ', admin_url( 'widgets.php' ) ) );
139 139
 
140
-			$msg = $this->field['widget_msg'] ?? $def_msg;
140
+            $msg = $this->field['widget_msg'] ?? $def_msg;
141 141
 
142
-			if ( ! $show_msg ) {
143
-				echo '<div class="redux-social-profiles-header">';
144
-				echo $msg; // phpcs:ignore WordPress.Security.EscapeOutput
145
-				echo '</div>';
146
-			}
142
+            if ( ! $show_msg ) {
143
+                echo '<div class="redux-social-profiles-header">';
144
+                echo $msg; // phpcs:ignore WordPress.Security.EscapeOutput
145
+                echo '</div>';
146
+            }
147 147
 
148
-			echo '<div class="redux-social-profiles-selector-container">';
149
-			echo '<ul id="redux-social-profiles-selector-list">';
148
+            echo '<div class="redux-social-profiles-selector-container">';
149
+            echo '<ul id="redux-social-profiles-selector-list">';
150 150
 
151
-			$settings = $this->rebuild_setttings( $settings );
151
+            $settings = $this->rebuild_setttings( $settings );
152 152
 
153
-			foreach ( $this->defaults as $key => $social_provider_default ) {
154
-				$social_provider_option = ( $settings && is_array( $settings ) && array_key_exists( $key, $settings ) ) ? $settings[ $key ] : null;
153
+            foreach ( $this->defaults as $key => $social_provider_default ) {
154
+                $social_provider_option = ( $settings && is_array( $settings ) && array_key_exists( $key, $settings ) ) ? $settings[ $key ] : null;
155 155
 
156
-				$icon    = ( $social_provider_option && array_key_exists( 'icon', $social_provider_option ) && $social_provider_option['icon'] ) ? $social_provider_option['icon'] : $social_provider_default['icon'];
157
-				$name    = ( $social_provider_option && array_key_exists( 'name', $social_provider_option ) && $social_provider_option['name'] ) ? $social_provider_option['name'] : $social_provider_default['name'];
158
-				$class   = ( $social_provider_option && array_key_exists( 'class', $social_provider_option ) && $social_provider_option['class'] ) ? $social_provider_option['class'] : $social_provider_default['class'];
159
-				$order   = ( $social_provider_option && array_key_exists( 'order', $social_provider_option ) ) ? $social_provider_option['order'] : $key;
160
-				$order   = intval( $order );
161
-				$enabled = ( $social_provider_option && array_key_exists( 'enabled', $social_provider_option ) && $social_provider_option['enabled'] ) ? $social_provider_option['enabled'] : $social_provider_default['enabled'];
162
-				$display = ( $enabled ) ? 'enabled' : '';
156
+                $icon    = ( $social_provider_option && array_key_exists( 'icon', $social_provider_option ) && $social_provider_option['icon'] ) ? $social_provider_option['icon'] : $social_provider_default['icon'];
157
+                $name    = ( $social_provider_option && array_key_exists( 'name', $social_provider_option ) && $social_provider_option['name'] ) ? $social_provider_option['name'] : $social_provider_default['name'];
158
+                $class   = ( $social_provider_option && array_key_exists( 'class', $social_provider_option ) && $social_provider_option['class'] ) ? $social_provider_option['class'] : $social_provider_default['class'];
159
+                $order   = ( $social_provider_option && array_key_exists( 'order', $social_provider_option ) ) ? $social_provider_option['order'] : $key;
160
+                $order   = intval( $order );
161
+                $enabled = ( $social_provider_option && array_key_exists( 'enabled', $social_provider_option ) && $social_provider_option['enabled'] ) ? $social_provider_option['enabled'] : $social_provider_default['enabled'];
162
+                $display = ( $enabled ) ? 'enabled' : '';
163 163
 
164
-				echo '<li class="redux-social-profiles-item-enable ' . esc_attr( $display ) . '" id="redux-social-profiles-item-enable-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" data-order="' . esc_attr( $order ) . '">';
165
-				Redux_Social_Profiles_Functions::render_icon( $class, $icon, '', '', $name );
166
-				echo '</li>';
167
-			}
164
+                echo '<li class="redux-social-profiles-item-enable ' . esc_attr( $display ) . '" id="redux-social-profiles-item-enable-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" data-order="' . esc_attr( $order ) . '">';
165
+                Redux_Social_Profiles_Functions::render_icon( $class, $icon, '', '', $name );
166
+                echo '</li>';
167
+            }
168 168
 
169
-			echo '</ul>';
170
-			echo '</div>';
169
+            echo '</ul>';
170
+            echo '</div>';
171 171
 
172
-			echo '<ul id="redux-social-profiles-list">';
172
+            echo '<ul id="redux-social-profiles-list">';
173 173
 
174
-			foreach ( $this->defaults as $key => $social_provider_default ) {
175
-				echo '<li id="redux-social-item-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" style="display: none;">';
176
-				echo '<div class="redux-social-item-container">';
174
+            foreach ( $this->defaults as $key => $social_provider_default ) {
175
+                echo '<li id="redux-social-item-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" style="display: none;">';
176
+                echo '<div class="redux-social-item-container">';
177 177
 
178
-				$social_provider_option = ( $settings && is_array( $settings ) && array_key_exists( $key, $settings ) ) ? $settings[ $key ] : null;
179
-				$icon                   = ( $social_provider_option && array_key_exists( 'icon', $social_provider_option ) && $social_provider_option['icon'] ) ? $social_provider_option['icon'] : $social_provider_default['icon'];
180
-				$id                     = ( $social_provider_option && array_key_exists( 'id', $social_provider_option ) && $social_provider_option['id'] ) ? $social_provider_option['id'] : $social_provider_default['id'];
181
-				$class                  = ( $social_provider_option && array_key_exists( 'class', $social_provider_option ) && $social_provider_option['class'] ) ? $social_provider_option['class'] : $social_provider_default['class'];
182
-				$enabled                = ( $social_provider_option && array_key_exists( 'enabled', $social_provider_option ) && $social_provider_option['enabled'] ) ? $social_provider_option['enabled'] : $social_provider_default['enabled'];
183
-				$name                   = ( $social_provider_option && array_key_exists( 'name', $social_provider_option ) && $social_provider_option['name'] ) ? $social_provider_option['name'] : $social_provider_default['name'];
178
+                $social_provider_option = ( $settings && is_array( $settings ) && array_key_exists( $key, $settings ) ) ? $settings[ $key ] : null;
179
+                $icon                   = ( $social_provider_option && array_key_exists( 'icon', $social_provider_option ) && $social_provider_option['icon'] ) ? $social_provider_option['icon'] : $social_provider_default['icon'];
180
+                $id                     = ( $social_provider_option && array_key_exists( 'id', $social_provider_option ) && $social_provider_option['id'] ) ? $social_provider_option['id'] : $social_provider_default['id'];
181
+                $class                  = ( $social_provider_option && array_key_exists( 'class', $social_provider_option ) && $social_provider_option['class'] ) ? $social_provider_option['class'] : $social_provider_default['class'];
182
+                $enabled                = ( $social_provider_option && array_key_exists( 'enabled', $social_provider_option ) && $social_provider_option['enabled'] ) ? $social_provider_option['enabled'] : $social_provider_default['enabled'];
183
+                $name                   = ( $social_provider_option && array_key_exists( 'name', $social_provider_option ) && $social_provider_option['name'] ) ? $social_provider_option['name'] : $social_provider_default['name'];
184 184
 
185
-				$label = ( $social_provider_option && array_key_exists( 'label', $social_provider_option ) && $social_provider_option['label'] ) ? $social_provider_option['label'] : __( 'Link URL', 'redux-framework' );
185
+                $label = ( $social_provider_option && array_key_exists( 'label', $social_provider_option ) && $social_provider_option['label'] ) ? $social_provider_option['label'] : __( 'Link URL', 'redux-framework' );
186 186
 
187
-				$color = ( $social_provider_option && array_key_exists( 'color', $social_provider_option ) ) ? $social_provider_option['color'] : $social_provider_default['color'];
188
-				$color = esc_attr( $color );
187
+                $color = ( $social_provider_option && array_key_exists( 'color', $social_provider_option ) ) ? $social_provider_option['color'] : $social_provider_default['color'];
188
+                $color = esc_attr( $color );
189 189
 
190
-				$background = ( $social_provider_option && array_key_exists( 'background', $social_provider_option ) ) ? $social_provider_option['background'] : $social_provider_default['background'];
191
-				$background = esc_attr( $background );
190
+                $background = ( $social_provider_option && array_key_exists( 'background', $social_provider_option ) ) ? $social_provider_option['background'] : $social_provider_default['background'];
191
+                $background = esc_attr( $background );
192 192
 
193
-				$order = ( $social_provider_option && array_key_exists( 'order', $social_provider_option ) ) ? $social_provider_option['order'] : $key;
194
-				$order = intval( $order );
193
+                $order = ( $social_provider_option && array_key_exists( 'order', $social_provider_option ) ) ? $social_provider_option['order'] : $key;
194
+                $order = intval( $order );
195 195
 
196
-				$url = ( $social_provider_option && array_key_exists( 'url', $social_provider_option ) ) ? $social_provider_option['url'] : $social_provider_default['url'];
197
-				$url = esc_attr( $url );
196
+                $url = ( $social_provider_option && array_key_exists( 'url', $social_provider_option ) ) ? $social_provider_option['url'] : $social_provider_default['url'];
197
+                $url = esc_attr( $url );
198 198
 
199
-				$profile_data = array(
200
-					'id'         => $id,
201
-					'class'      => $class,
202
-					'icon'       => $icon,
203
-					'enabled'    => $enabled,
204
-					'url'        => $url,
205
-					'color'      => $color,
206
-					'background' => $background,
207
-					'order'      => $order,
208
-					'name'       => $name,
209
-					'label'      => $label,
210
-				);
199
+                $profile_data = array(
200
+                    'id'         => $id,
201
+                    'class'      => $class,
202
+                    'icon'       => $icon,
203
+                    'enabled'    => $enabled,
204
+                    'url'        => $url,
205
+                    'color'      => $color,
206
+                    'background' => $background,
207
+                    'order'      => $order,
208
+                    'name'       => $name,
209
+                    'label'      => $label,
210
+                );
211 211
 
212
-				$profile_data = rawurlencode( wp_json_encode( $profile_data ) );
212
+                $profile_data = rawurlencode( wp_json_encode( $profile_data ) );
213 213
 
214
-				echo '<input
214
+                echo '<input
215 215
 	                    type="hidden"
216 216
 	                    class="redux-social-profiles-hidden-data-' . esc_attr( $key ) . '"
217 217
 	                    id="' . esc_attr( $this->field_id ) . '-' . esc_attr( $id ) . '-data"
218 218
 	                    name="' . esc_attr( $this->field['name'] ) . esc_attr( $this->field['name_suffix'] ) . '[' . esc_attr( $key ) . '][data]"
219 219
 	                    value="' . $profile_data . '" />'; // phpcs:ignore WordPress.Security.EscapeOutput
220 220
 
221
-				echo '<div class="redux-icon-preview">';
222
-				Redux_Social_Profiles_Functions::render_icon( $class, $icon, $color, $background, $name );
223
-				echo '&nbsp;</div>';
221
+                echo '<div class="redux-icon-preview">';
222
+                Redux_Social_Profiles_Functions::render_icon( $class, $icon, $color, $background, $name );
223
+                echo '&nbsp;</div>';
224 224
 
225
-				echo '<div class="redux-social-profiles-item-name">';
226
-				echo esc_html( $name );
227
-				echo '</div>';
225
+                echo '<div class="redux-social-profiles-item-name">';
226
+                echo esc_html( $name );
227
+                echo '</div>';
228 228
 
229
-				echo '<div class="redux-social-profiles-item-enabled">';
230
-				$checked = ( $enabled ) ? 'checked' : '';
231
-				echo '<input type="checkbox" id="' . esc_attr( $this->field['id'] ) . '-checkbox-' . esc_attr( $key ) . '" class="checkbox-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" value="1" ' . esc_attr( $checked ) . '/>';
232
-				esc_html_e( 'Enabled', 'redux-framework' );
233
-				echo '</div>';
229
+                echo '<div class="redux-social-profiles-item-enabled">';
230
+                $checked = ( $enabled ) ? 'checked' : '';
231
+                echo '<input type="checkbox" id="' . esc_attr( $this->field['id'] ) . '-checkbox-' . esc_attr( $key ) . '" class="checkbox-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" value="1" ' . esc_attr( $checked ) . '/>';
232
+                esc_html_e( 'Enabled', 'redux-framework' );
233
+                echo '</div>';
234 234
 
235
-				$color_class = $color_pickers ? '' : ' no-color-pickers';
235
+                $color_class = $color_pickers ? '' : ' no-color-pickers';
236 236
 
237
-				echo '<div class="redux-social-profiles-link-url input_wrapper' . esc_attr( $color_class ) . '">';
238
-				echo '<label for="redux-social-profiles-url-' . esc_attr( $key ) . '-text" class="redux-text-url-label">' . esc_html( $label ) . '</label>';
239
-				echo '<input id="redux-social-profiles-url-' . esc_attr( $key ) . '-text" class="redux-social-profiles-url-text" data-key="' . esc_attr( $key ) . '" type="text" value="' . esc_url( $url ) . '" />';
240
-				echo '</div>';
237
+                echo '<div class="redux-social-profiles-link-url input_wrapper' . esc_attr( $color_class ) . '">';
238
+                echo '<label for="redux-social-profiles-url-' . esc_attr( $key ) . '-text" class="redux-text-url-label">' . esc_html( $label ) . '</label>';
239
+                echo '<input id="redux-social-profiles-url-' . esc_attr( $key ) . '-text" class="redux-social-profiles-url-text" data-key="' . esc_attr( $key ) . '" type="text" value="' . esc_url( $url ) . '" />';
240
+                echo '</div>';
241 241
 
242
-				$reset_text = __( 'Reset', 'redux-framework' );
243
-				echo '<div class="redux-social-profiles-item-reset">';
244
-				echo '<a class="button" data-value="' . esc_attr( $key ) . '" value="' . esc_attr( $reset_text ) . '" />' . esc_html( $reset_text ) . '</a>';
245
-				echo '</div>';
242
+                $reset_text = __( 'Reset', 'redux-framework' );
243
+                echo '<div class="redux-social-profiles-item-reset">';
244
+                echo '<a class="button" data-value="' . esc_attr( $key ) . '" value="' . esc_attr( $reset_text ) . '" />' . esc_html( $reset_text ) . '</a>';
245
+                echo '</div>';
246 246
 
247
-				if ( $color_pickers ) {
248
-					// phpcs:ignore WordPress.NamingConventions.ValidHookName
249
-					$label = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/color_picker/text', esc_html__( 'Text', 'redux-framework' ) );
247
+                if ( $color_pickers ) {
248
+                    // phpcs:ignore WordPress.NamingConventions.ValidHookName
249
+                    $label = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/color_picker/text', esc_html__( 'Text', 'redux-framework' ) );
250 250
 
251
-					echo '<div class="redux-social-profiles-text-color picker_wrapper" >';
252
-					echo '<label for="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' text" class="redux-text-color-label">' . esc_html( $label ) . '</label>';
253
-					echo '<input
251
+                    echo '<div class="redux-social-profiles-text-color picker_wrapper" >';
252
+                    echo '<label for="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' text" class="redux-text-color-label">' . esc_html( $label ) . '</label>';
253
+                    echo '<input
254 254
                             class="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' text"
255 255
                             id="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' text"
256 256
                             type="text"
257 257
                             value="' . esc_attr( $color ) . '"
258 258
                             data-key="' . esc_attr( $key ) . '"
259 259
                         />';
260
-					echo '</div>';
260
+                    echo '</div>';
261 261
 
262
-					// phpcs:ignore WordPress.NamingConventions.ValidHookName
263
-					$label = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/color_picker/background', esc_html__( 'Background', 'redux-framework' ) );
262
+                    // phpcs:ignore WordPress.NamingConventions.ValidHookName
263
+                    $label = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/color_picker/background', esc_html__( 'Background', 'redux-framework' ) );
264 264
 
265
-					echo '<div class="redux-social-profiles-background-color picker_wrapper">';
266
-					echo '<label for="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' background" class="redux-background-color-label" for="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' background">' . esc_html( $label ) . '</label>';
267
-					echo '<input
265
+                    echo '<div class="redux-social-profiles-background-color picker_wrapper">';
266
+                    echo '<label for="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' background" class="redux-background-color-label" for="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' background">' . esc_html( $label ) . '</label>';
267
+                    echo '<input
268 268
                             class="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' background"
269 269
                             id="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' background"
270 270
                             type="text"
271 271
                             value="' . esc_attr( $background ) . '"
272 272
                             data-key="' . esc_attr( $key ) . '"
273 273
                         />';
274
-					echo '</div>';
275
-				}
274
+                    echo '</div>';
275
+                }
276 276
 
277
-				echo '<div class="redux-social-profiles-item-order">';
278
-				echo '<input
277
+                echo '<div class="redux-social-profiles-item-order">';
278
+                echo '<input
279 279
 				        id="' . esc_attr( $this->field['id'] ) . '-item-order-' . esc_attr( $key ) . '"
280 280
                         type="hidden"
281 281
                         value="' . esc_attr( $order ) . '"
282 282
                     />';
283
-				echo '</div>';
284
-
285
-				echo '</div>';
286
-				echo '</li>';
287
-			}
288
-
289
-			echo '</ul>';
290
-			echo '</div>';
291
-		}
292
-
293
-		/**
294
-		 * This function is unused, but necessary to trigger output.
295
-		 *
296
-		 * @param mixed $data CSS data.
297
-		 *
298
-		 * @return mixed|string|void
299
-		 */
300
-		public function css_style( $data ) {
301
-			return $data;
302
-		}
303
-
304
-		/**
305
-		 * Used to enqueue to the front-end
306
-		 *
307
-		 * @param string|null|array $style Style.
308
-		 */
309
-		public function output( $style = '' ) {
310
-			if ( ! empty( $this->value ) ) {
311
-				foreach ( $this->value as $arr ) {
312
-
313
-					// For customizer.
314
-					if ( isset( $arr['data'] ) ) {
315
-						$arr = rawurldecode( $arr['data'] );
316
-						$arr = (array) json_decode( $arr );
317
-					}
318
-
319
-					if ( $arr['enabled'] ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement
320
-						Redux_Functions_Ex::enqueue_font_awesome();
321
-					}
322
-				}
323
-			}
324
-		}
325
-
326
-		/**
327
-		 * Enqueue Function.
328
-		 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
329
-		 *
330
-		 * @since       1.0.0
331
-		 * @access      public
332
-		 * @return      void
333
-		 */
334
-		public function enqueue() {
335
-			if ( empty( $this->field ) ) {
336
-				return;
337
-			}
338
-
339
-			$min = Redux_Functions::isMin();
340
-
341
-			Redux_Functions_Ex::enqueue_font_awesome();
342
-
343
-			// Field dependent JS.
344
-			wp_enqueue_script(
345
-				'redux-field-social-profiles',
346
-				$this->url . 'redux-social-profiles' . $min . '.js',
347
-				array( 'jquery', 'jquery-ui-sortable', 'redux-spectrum-js', 'redux-js' ),
348
-				Redux_Extension_Social_Profiles::$version,
349
-				true
350
-			);
351
-
352
-			wp_localize_script(
353
-				'redux-field-social-profiles',
354
-				'reduxSocialDefaults',
355
-				$this->defaults
356
-			);
357
-
358
-			if ( $this->parent->args['dev_mode'] ) {
359
-				wp_enqueue_style(
360
-					'redux-field-social-profiles',
361
-					$this->url . 'redux-social-profiles.css',
362
-					array( 'redux-spectrum-css' ),
363
-					Redux_Extension_Social_Profiles::$version
364
-				);
365
-			}
366
-		}
367
-	}
283
+                echo '</div>';
284
+
285
+                echo '</div>';
286
+                echo '</li>';
287
+            }
288
+
289
+            echo '</ul>';
290
+            echo '</div>';
291
+        }
292
+
293
+        /**
294
+         * This function is unused, but necessary to trigger output.
295
+         *
296
+         * @param mixed $data CSS data.
297
+         *
298
+         * @return mixed|string|void
299
+         */
300
+        public function css_style( $data ) {
301
+            return $data;
302
+        }
303
+
304
+        /**
305
+         * Used to enqueue to the front-end
306
+         *
307
+         * @param string|null|array $style Style.
308
+         */
309
+        public function output( $style = '' ) {
310
+            if ( ! empty( $this->value ) ) {
311
+                foreach ( $this->value as $arr ) {
312
+
313
+                    // For customizer.
314
+                    if ( isset( $arr['data'] ) ) {
315
+                        $arr = rawurldecode( $arr['data'] );
316
+                        $arr = (array) json_decode( $arr );
317
+                    }
318
+
319
+                    if ( $arr['enabled'] ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement
320
+                        Redux_Functions_Ex::enqueue_font_awesome();
321
+                    }
322
+                }
323
+            }
324
+        }
325
+
326
+        /**
327
+         * Enqueue Function.
328
+         * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
329
+         *
330
+         * @since       1.0.0
331
+         * @access      public
332
+         * @return      void
333
+         */
334
+        public function enqueue() {
335
+            if ( empty( $this->field ) ) {
336
+                return;
337
+            }
338
+
339
+            $min = Redux_Functions::isMin();
340
+
341
+            Redux_Functions_Ex::enqueue_font_awesome();
342
+
343
+            // Field dependent JS.
344
+            wp_enqueue_script(
345
+                'redux-field-social-profiles',
346
+                $this->url . 'redux-social-profiles' . $min . '.js',
347
+                array( 'jquery', 'jquery-ui-sortable', 'redux-spectrum-js', 'redux-js' ),
348
+                Redux_Extension_Social_Profiles::$version,
349
+                true
350
+            );
351
+
352
+            wp_localize_script(
353
+                'redux-field-social-profiles',
354
+                'reduxSocialDefaults',
355
+                $this->defaults
356
+            );
357
+
358
+            if ( $this->parent->args['dev_mode'] ) {
359
+                wp_enqueue_style(
360
+                    'redux-field-social-profiles',
361
+                    $this->url . 'redux-social-profiles.css',
362
+                    array( 'redux-spectrum-css' ),
363
+                    Redux_Extension_Social_Profiles::$version
364
+                );
365
+            }
366
+        }
367
+    }
368 368
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
 				foreach ( $settings as $a ) {
70 70
 					if ( isset( $a['data'] ) ) {
71 71
 						$a['data'] = rawurldecode( $a['data'] );
72
-						$a         = (array) json_decode( $a['data'] );
72
+						$a         = ( array ) json_decode( $a['data'] );
73 73
 					}
74 74
 
75 75
 					if ( $default_id === $a['id'] ) {
76 76
 						$search_default    = false;
77
-						$fixed_arr[ $key ] = $a;
77
+						$fixed_arr[$key] = $a;
78 78
 						break;
79 79
 					}
80 80
 				}
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 
88 88
 					foreach ( $stock as $def_arr ) {
89 89
 						if ( $default_id === $def_arr['id'] ) {
90
-							$fixed_arr[ $key ] = $def_arr;
90
+							$fixed_arr[$key] = $def_arr;
91 91
 							break;
92 92
 						}
93 93
 					}
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 			global $pagenow, $post;
114 114
 
115 115
 			$redux_settings = get_option( $this->opt_name );
116
-			$settings       = $redux_settings[ $this->field_id ] ?? array();
116
+			$settings       = $redux_settings[$this->field_id] ?? array();
117 117
 
118 118
 			if ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) {
119 119
 				$post_settings = get_post_meta( $post->ID, $this->field_id, true );
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 			$settings = $this->rebuild_setttings( $settings );
152 152
 
153 153
 			foreach ( $this->defaults as $key => $social_provider_default ) {
154
-				$social_provider_option = ( $settings && is_array( $settings ) && array_key_exists( $key, $settings ) ) ? $settings[ $key ] : null;
154
+				$social_provider_option = ( $settings && is_array( $settings ) && array_key_exists( $key, $settings ) ) ? $settings[$key] : null;
155 155
 
156 156
 				$icon    = ( $social_provider_option && array_key_exists( 'icon', $social_provider_option ) && $social_provider_option['icon'] ) ? $social_provider_option['icon'] : $social_provider_default['icon'];
157 157
 				$name    = ( $social_provider_option && array_key_exists( 'name', $social_provider_option ) && $social_provider_option['name'] ) ? $social_provider_option['name'] : $social_provider_default['name'];
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 				echo '<li id="redux-social-item-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" style="display: none;">';
176 176
 				echo '<div class="redux-social-item-container">';
177 177
 
178
-				$social_provider_option = ( $settings && is_array( $settings ) && array_key_exists( $key, $settings ) ) ? $settings[ $key ] : null;
178
+				$social_provider_option = ( $settings && is_array( $settings ) && array_key_exists( $key, $settings ) ) ? $settings[$key] : null;
179 179
 				$icon                   = ( $social_provider_option && array_key_exists( 'icon', $social_provider_option ) && $social_provider_option['icon'] ) ? $social_provider_option['icon'] : $social_provider_default['icon'];
180 180
 				$id                     = ( $social_provider_option && array_key_exists( 'id', $social_provider_option ) && $social_provider_option['id'] ) ? $social_provider_option['id'] : $social_provider_default['id'];
181 181
 				$class                  = ( $social_provider_option && array_key_exists( 'class', $social_provider_option ) && $social_provider_option['class'] ) ? $social_provider_option['class'] : $social_provider_default['class'];
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 					// For customizer.
314 314
 					if ( isset( $arr['data'] ) ) {
315 315
 						$arr = rawurldecode( $arr['data'] );
316
-						$arr = (array) json_decode( $arr );
316
+						$arr = ( array ) json_decode( $arr );
317 317
 					}
318 318
 
319 319
 					if ( $arr['enabled'] ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement
Please login to merge, or discard this patch.
sample/sections/extensions/icon-select.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -16,82 +16,82 @@
 block discarded – undo
16 16
 require_once Redux_Core::$dir . 'inc/extensions/icon_select/font-awesome-5-free.php';
17 17
 
18 18
 Redux::set_section(
19
-	$opt_name,
20
-	array(
21
-		'title'      => esc_html__( 'Icon Select', 'your-textdomain-here' ),
22
-		'desc'       => esc_html__( 'For full documentation on this field, visit: ', 'your-textdomain-here' ) . '<a href="https://devs.redux.io/core-extensions/icon-select.html" target="_blank">https://devs.redux.io/core-extensions/icon-select.html</a>',
23
-		'subsection' => true,
24
-		'fields'     => array(
19
+    $opt_name,
20
+    array(
21
+        'title'      => esc_html__( 'Icon Select', 'your-textdomain-here' ),
22
+        'desc'       => esc_html__( 'For full documentation on this field, visit: ', 'your-textdomain-here' ) . '<a href="https://devs.redux.io/core-extensions/icon-select.html" target="_blank">https://devs.redux.io/core-extensions/icon-select.html</a>',
23
+        'subsection' => true,
24
+        'fields'     => array(
25 25
 
26
-			/**
27
-			 * This field was left in the sample config to display that every effort to maintain backward compatibility with older
28
-			 * versions of Icon Select has been implemented.
29
-			 * Please do NOT use argument in this field in your projects.
30
-			 * They are considered deprecated.
31
-			 */
32
-			array(
33
-				'id'               => 'icon-select-legacy',
34
-				'type'             => 'icon_select',
35
-				'title'            => esc_html__( 'Legacy Icon Select', 'your-textdomain-here' ),
36
-				'subtitle'         => esc_html__( 'Original Icon Select field that maintains backward compatibility with the original extension.', 'your-textdomain-here' ),
37
-				'default'          => '',
38
-				'options'          => redux_icon_select_fa_5_free(),
26
+            /**
27
+             * This field was left in the sample config to display that every effort to maintain backward compatibility with older
28
+             * versions of Icon Select has been implemented.
29
+             * Please do NOT use argument in this field in your projects.
30
+             * They are considered deprecated.
31
+             */
32
+            array(
33
+                'id'               => 'icon-select-legacy',
34
+                'type'             => 'icon_select',
35
+                'title'            => esc_html__( 'Legacy Icon Select', 'your-textdomain-here' ),
36
+                'subtitle'         => esc_html__( 'Original Icon Select field that maintains backward compatibility with the original extension.', 'your-textdomain-here' ),
37
+                'default'          => '',
38
+                'options'          => redux_icon_select_fa_5_free(),
39 39
 
40
-				// Disable auto-enqueue of stylesheet if present in the panel.
41
-				'enqueue'          => true,
40
+                // Disable auto-enqueue of stylesheet if present in the panel.
41
+                'enqueue'          => true,
42 42
 
43
-				// Disable auto-enqueue of stylesheet on the front-end.
44
-				'enqueue_frontend' => true,
43
+                // Disable auto-enqueue of stylesheet on the front-end.
44
+                'enqueue_frontend' => true,
45 45
 
46
-				// Stylesheet URL.
47
-				//'stylesheet'       => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css',
46
+                // Stylesheet URL.
47
+                //'stylesheet'       => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css',
48 48
 
49
-				// (Optional) Specify a class prefix if one is needed to initialize the icon.
50
-				'prefix'           => 'fa',
51
-			),
49
+                // (Optional) Specify a class prefix if one is needed to initialize the icon.
50
+                'prefix'           => 'fa',
51
+            ),
52 52
 
53
-			/**
54
-			 * When creating fields for Icon Select, use this as a template instead.
55
-			 * For detailed documentation, see: https://devs.redux.io/core-extensions/icon-select.html
56
-			 */
57
-			array(
58
-				'id'               => 'icon-select',
59
-				'type'             => 'icon_select',
60
-				'title'            => esc_html__( 'Icon Select', 'your-textdomain-here' ),
61
-				'subtitle'         => esc_html__( 'Select an icon.', 'your-textdomain-here' ),
62
-				'default'          => 'fas fa-1',
53
+            /**
54
+             * When creating fields for Icon Select, use this as a template instead.
55
+             * For detailed documentation, see: https://devs.redux.io/core-extensions/icon-select.html
56
+             */
57
+            array(
58
+                'id'               => 'icon-select',
59
+                'type'             => 'icon_select',
60
+                'title'            => esc_html__( 'Icon Select', 'your-textdomain-here' ),
61
+                'subtitle'         => esc_html__( 'Select an icon.', 'your-textdomain-here' ),
62
+                'default'          => 'fas fa-1',
63 63
 
64
-				// Disable auto-enqueue of stylesheet if present in the panel.
65
-				'enqueue'          => true,
64
+                // Disable auto-enqueue of stylesheet if present in the panel.
65
+                'enqueue'          => true,
66 66
 
67
-				// Disable auto-enqueue of stylesheet on the front-end.
68
-				'enqueue_frontend' => true,
67
+                // Disable auto-enqueue of stylesheet on the front-end.
68
+                'enqueue_frontend' => true,
69 69
 
70
-				// Stylesheet data.
71
-				'stylesheet'       => array(
72
-					array(
73
-						'url'    => 'https://cdnjs.cloudflare.com/ajax/libs/MaterialDesign-Webfont/7.2.96/css/materialdesignicons.css',
74
-						'title'  => 'Material Icons',
75
-						'prefix' => 'mdi-set',
76
-					),
77
-					array(
78
-						'url'    => 'https://icons.getbootstrap.com/assets/font/bootstrap-icons.min.css',
79
-						'title'  => 'Bootstrap',
80
-						'prefix' => 'bi',
81
-					),
82
-					array(
83
-						'url'    => 'https://cdn.lineicons.com/4.0/lineicons.css',
84
-						'title'  => 'Line Icons',
85
-						'prefix' => 'lni',
86
-					),
87
-					array(
88
-						'url'    => 'https://cdn.jsdelivr.net/gh/devicons/[email protected]/devicon.min.css',
89
-						'title'  => 'Dev Icons',
90
-						'prefix' => '',
91
-					),
92
-				),
93
-			),
94
-		),
95
-	)
70
+                // Stylesheet data.
71
+                'stylesheet'       => array(
72
+                    array(
73
+                        'url'    => 'https://cdnjs.cloudflare.com/ajax/libs/MaterialDesign-Webfont/7.2.96/css/materialdesignicons.css',
74
+                        'title'  => 'Material Icons',
75
+                        'prefix' => 'mdi-set',
76
+                    ),
77
+                    array(
78
+                        'url'    => 'https://icons.getbootstrap.com/assets/font/bootstrap-icons.min.css',
79
+                        'title'  => 'Bootstrap',
80
+                        'prefix' => 'bi',
81
+                    ),
82
+                    array(
83
+                        'url'    => 'https://cdn.lineicons.com/4.0/lineicons.css',
84
+                        'title'  => 'Line Icons',
85
+                        'prefix' => 'lni',
86
+                    ),
87
+                    array(
88
+                        'url'    => 'https://cdn.jsdelivr.net/gh/devicons/[email protected]/devicon.min.css',
89
+                        'title'  => 'Dev Icons',
90
+                        'prefix' => '',
91
+                    ),
92
+                ),
93
+            ),
94
+        ),
95
+    )
96 96
 );
97 97
 // phpcs:enable
Please login to merge, or discard this patch.
redux-core/inc/classes/class-redux-validation.php 2 patches
Indentation   +237 added lines, -237 removed lines patch added patch discarded remove patch
@@ -11,241 +11,241 @@
 block discarded – undo
11 11
 
12 12
 if ( ! class_exists( 'Redux_Validation', false ) ) {
13 13
 
14
-	/**
15
-	 * Class Redux_Validation
16
-	 */
17
-	class Redux_Validation extends Redux_Class {
18
-
19
-		/**
20
-		 * Validate values from options form (used in settings api validate function)
21
-		 * calls the custom validation class for the field so authors can override with custom classes
22
-		 *
23
-		 * @since       1.0.0
24
-		 * @access      public
25
-		 *
26
-		 * @param       array $plugin_options Plugin Options.
27
-		 * @param       array $options        Options.
28
-		 * @param       array $sections       Sections array.
29
-		 *
30
-		 * @return      array $plugin_options
31
-		 */
32
-		public function validate( array $plugin_options, array $options, array $sections ): array {
33
-			$core = $this->core();
34
-
35
-			if (null === $core) {
36
-				return $plugin_options;
37
-			}
38
-
39
-			foreach ( $sections as $k => $section ) {
40
-				if ( isset( $section['fields'] ) ) {
41
-					foreach ( $section['fields'] as $fkey => $field ) {
42
-						if ( is_array( $field ) ) {
43
-							$field['section_id'] = $k;
44
-						}
45
-
46
-						if ( isset( $field['type'] ) && ( 'checkbox' === $field['type'] || 'checkbox_hide_below' === $field['type'] || 'checkbox_hide_all' === $field['type'] ) ) {
47
-							if ( ! isset( $plugin_options[ $field['id'] ] ) ) {
48
-								$plugin_options[ $field['id'] ] = 0;
49
-							}
50
-						}
51
-
52
-						// Part of Dovy's serialize typography effort.  Preserved here in case it becomes a thing. - kp.
53
-						/**
54
-						 * If ( isset ( $field['type'] ) && $field['type'] == 'typography' ) {
55
-						 *      if ( ! is_array( $plugin_options[ $field['id'] ] ) && ! empty( $plugin_options[ $field['id'] ] ) ) {
56
-						 *          $plugin_options[ $field['id'] ] = json_decode( $plugin_options[ $field['id'] ], true );
57
-						 *      }
58
-						 * }
59
-						 */
60
-
61
-						if ( isset( $core->extensions[ $field['type'] ] ) && method_exists( $core->extensions[ $field['type'] ], '_validate_values' ) ) {
62
-							$plugin_options = $core->extensions[ $field['type'] ]->_validate_values( $plugin_options, $field, $sections );
63
-						}
64
-
65
-						// Make sure 'validate' field is set.
66
-						if ( isset( $field['validate'] ) ) {
67
-
68
-							// Can we make this an array of validations?
69
-							$val_arr = array();
70
-
71
-							if ( is_array( $field['validate'] ) ) {
72
-								$val_arr = $field['validate'];
73
-							} else {
74
-								$val_arr[] = $field['validate'];
75
-							}
76
-
77
-							foreach ( $val_arr as $idx => $val ) {
78
-								// shim for old *_not_empty validations.
79
-								if ( 'email_not_empty' === $val || 'numeric_not_empty' === $val ) {
80
-									$val = 'not_empty';
81
-								}
82
-
83
-								// Make sure 'validate field' is set to 'not_empty'.
84
-								$is_not_empty = false;
85
-
86
-								if ( 'not_empty' === $val ) {
87
-									// Set the flag.
88
-									$is_not_empty = true;
89
-								}
90
-
91
-								// Check for empty id value.
92
-								if ( ! isset( $field['id'] ) || ! isset( $plugin_options[ $field['id'] ] ) || ( '' === $plugin_options[ $field['id'] ] ) ) {
93
-
94
-									// If we are looking for an empty value, in the case of 'not_empty'
95
-									// then we need to keep processing.
96
-									if ( ! $is_not_empty ) {
97
-
98
-										// Empty id and not checking for 'not_empty'.  Bail out...
99
-										if ( ! isset( $field['validate_callback'] ) ) {
100
-											continue;
101
-										}
102
-									}
103
-								}
104
-
105
-								// Force validate of custom field types.
106
-								if ( isset( $field['type'] ) && ! isset( $val ) && ! isset( $field['validate_callback'] ) ) {
107
-									if ( 'color' === $field['type'] || 'color_gradient' === $field['type'] ) {
108
-										$val = 'color';
109
-									} elseif ( 'date' === $field['type'] ) {
110
-										$val = 'date';
111
-									}
112
-								}
113
-
114
-								// No need.  Spectrum self validates.
115
-								if ( 'color_rgba' === $field['type'] ) {
116
-									continue;
117
-								}
118
-
119
-								// Shim out old color rgba validators.
120
-								if ( 'color_rgba' === $val || 'colorrgba' === $val ) {
121
-									$val = 'color';
122
-								}
123
-
124
-								$validate = 'Redux_Validation_' . $val;
125
-
126
-								if ( ! class_exists( $validate ) ) {
127
-									$file = str_replace( '_', '-', $val );
128
-
129
-									/**
130
-									 * Filter 'redux/validate/{opt_name}/class/{field.validate}'
131
-									 *
132
-									 * @param string $validate   validation class file path
133
-									 */
134
-
135
-									// phpcs:ignore WordPress.NamingConventions.ValidHookName
136
-									$class_file = apply_filters( "redux/validate/{$core->args['opt_name']}/class/$val", Redux_Core::$dir . "inc/validation/$val/class-redux-validation-$file.php", $validate );
137
-
138
-									if ( $class_file ) {
139
-										if ( file_exists( $class_file ) ) {
140
-											require_once $class_file;
141
-										}
142
-									}
143
-								}
144
-
145
-								if ( class_exists( $validate ) ) {
146
-									if ( empty( $options[ $field['id'] ] ) ) {
147
-										$options[ $field['id'] ] = '';
148
-									}
149
-
150
-									if ( isset( $plugin_options[ $field['id'] ] ) && is_array( $plugin_options[ $field['id'] ] ) && ! empty( $plugin_options[ $field['id'] ] ) ) {
151
-										foreach ( $plugin_options[ $field['id'] ] as $key => $value ) {
152
-											$before = null;
153
-											$after  = null;
154
-
155
-											if ( isset( $plugin_options[ $field['id'] ][ $key ] ) && ( ! empty( $plugin_options[ $field['id'] ][ $key ] ) || '0' === $plugin_options[ $field['id'] ][ $key ] ) ) {
156
-												if ( is_array( $plugin_options[ $field['id'] ][ $key ] ) ) {
157
-													$before = $plugin_options[ $field['id'] ][ $key ];
158
-												} else {
159
-													$before = trim( $plugin_options[ $field['id'] ][ $key ] );
160
-												}
161
-											}
162
-
163
-											if ( isset( $options[ $field['id'] ][ $key ] ) && ( ! empty( $plugin_options[ $field['id'] ][ $key ] ) || '0' === $plugin_options[ $field['id'] ][ $key ] ) ) {
164
-												$after = $options[ $field['id'] ][ $key ];
165
-											}
166
-
167
-											$validation = new $validate( $core, $field, $before, $after );
168
-
169
-											if ( ! empty( $validation->value ) || '0' === $validation->value ) {
170
-												$plugin_options[ $field['id'] ][ $key ] = $validation->value;
171
-											} else {
172
-												unset( $plugin_options[ $field['id'] ][ $key ] );
173
-											}
174
-
175
-											if ( ! empty( $validation->error ) ) {
176
-												$core->errors[] = $validation->error;
177
-											}
178
-
179
-											if ( ! empty( $validation->warning ) ) {
180
-												$core->warnings[] = $validation->warning;
181
-											}
182
-
183
-											if ( ! empty( $validation->sanitize ) ) {
184
-												$core->sanitize[] = $validation->sanitize;
185
-											}
186
-										}
187
-									} else {
188
-										if ( isset( $plugin_options[ $field['id'] ] ) ) {
189
-											if ( is_array( $plugin_options[ $field['id'] ] ) ) {
190
-												$pofi = $plugin_options[ $field['id'] ];
191
-											} else {
192
-												$pofi = trim( $plugin_options[ $field['id'] ] );
193
-											}
194
-										} else {
195
-											$pofi = null;
196
-										}
197
-
198
-										$validation                     = new $validate( $core, $field, $pofi, $options[ $field['id'] ] );
199
-										$plugin_options[ $field['id'] ] = $validation->value;
200
-
201
-										if ( ! empty( $validation->error ) ) {
202
-											$core->errors[] = $validation->error;
203
-										}
204
-
205
-										if ( ! empty( $validation->warning ) ) {
206
-											$core->warnings[] = $validation->warning;
207
-										}
208
-
209
-										if ( ! empty( $validation->sanitize ) ) {
210
-											$core->sanitize[] = $validation->sanitize;
211
-										}
212
-									}
213
-
214
-									break;
215
-								}
216
-							}
217
-						}
218
-
219
-						if ( isset( $field['validate_callback'] ) && ( is_callable( $field['validate_callback'] ) || ( is_string( $field['validate_callback'] ) && function_exists( $field['validate_callback'] ) ) ) ) {
220
-							$callback = $field['validate_callback'];
221
-							unset( $field['validate_callback'] );
222
-
223
-							$plugin_option = $plugin_options[ $field['id'] ] ?? null;
224
-							$option        = $options[ $field['id'] ] ?? null;
225
-
226
-							if ( null !== $plugin_option ) {
227
-								$callbackvalues = call_user_func( $callback, $field, $plugin_option, $option );
228
-
229
-								$plugin_options[ $field['id'] ] = $callbackvalues['value'];
230
-
231
-								if ( isset( $callbackvalues['error'] ) ) {
232
-									$core->errors[] = $callbackvalues['error'];
233
-								}
234
-
235
-								if ( isset( $callbackvalues['warning'] ) ) {
236
-									$core->warnings[] = $callbackvalues['warning'];
237
-								}
238
-
239
-								if ( isset( $callbackvalues['sanitize'] ) ) {
240
-									$core->sanitize[] = $callbackvalues['sanitize'];
241
-								}
242
-							}
243
-						}
244
-					}
245
-				}
246
-			}
247
-
248
-			return $plugin_options;
249
-		}
250
-	}
14
+    /**
15
+     * Class Redux_Validation
16
+     */
17
+    class Redux_Validation extends Redux_Class {
18
+
19
+        /**
20
+         * Validate values from options form (used in settings api validate function)
21
+         * calls the custom validation class for the field so authors can override with custom classes
22
+         *
23
+         * @since       1.0.0
24
+         * @access      public
25
+         *
26
+         * @param       array $plugin_options Plugin Options.
27
+         * @param       array $options        Options.
28
+         * @param       array $sections       Sections array.
29
+         *
30
+         * @return      array $plugin_options
31
+         */
32
+        public function validate( array $plugin_options, array $options, array $sections ): array {
33
+            $core = $this->core();
34
+
35
+            if (null === $core) {
36
+                return $plugin_options;
37
+            }
38
+
39
+            foreach ( $sections as $k => $section ) {
40
+                if ( isset( $section['fields'] ) ) {
41
+                    foreach ( $section['fields'] as $fkey => $field ) {
42
+                        if ( is_array( $field ) ) {
43
+                            $field['section_id'] = $k;
44
+                        }
45
+
46
+                        if ( isset( $field['type'] ) && ( 'checkbox' === $field['type'] || 'checkbox_hide_below' === $field['type'] || 'checkbox_hide_all' === $field['type'] ) ) {
47
+                            if ( ! isset( $plugin_options[ $field['id'] ] ) ) {
48
+                                $plugin_options[ $field['id'] ] = 0;
49
+                            }
50
+                        }
51
+
52
+                        // Part of Dovy's serialize typography effort.  Preserved here in case it becomes a thing. - kp.
53
+                        /**
54
+                         * If ( isset ( $field['type'] ) && $field['type'] == 'typography' ) {
55
+                         *      if ( ! is_array( $plugin_options[ $field['id'] ] ) && ! empty( $plugin_options[ $field['id'] ] ) ) {
56
+                         *          $plugin_options[ $field['id'] ] = json_decode( $plugin_options[ $field['id'] ], true );
57
+                         *      }
58
+                         * }
59
+                         */
60
+
61
+                        if ( isset( $core->extensions[ $field['type'] ] ) && method_exists( $core->extensions[ $field['type'] ], '_validate_values' ) ) {
62
+                            $plugin_options = $core->extensions[ $field['type'] ]->_validate_values( $plugin_options, $field, $sections );
63
+                        }
64
+
65
+                        // Make sure 'validate' field is set.
66
+                        if ( isset( $field['validate'] ) ) {
67
+
68
+                            // Can we make this an array of validations?
69
+                            $val_arr = array();
70
+
71
+                            if ( is_array( $field['validate'] ) ) {
72
+                                $val_arr = $field['validate'];
73
+                            } else {
74
+                                $val_arr[] = $field['validate'];
75
+                            }
76
+
77
+                            foreach ( $val_arr as $idx => $val ) {
78
+                                // shim for old *_not_empty validations.
79
+                                if ( 'email_not_empty' === $val || 'numeric_not_empty' === $val ) {
80
+                                    $val = 'not_empty';
81
+                                }
82
+
83
+                                // Make sure 'validate field' is set to 'not_empty'.
84
+                                $is_not_empty = false;
85
+
86
+                                if ( 'not_empty' === $val ) {
87
+                                    // Set the flag.
88
+                                    $is_not_empty = true;
89
+                                }
90
+
91
+                                // Check for empty id value.
92
+                                if ( ! isset( $field['id'] ) || ! isset( $plugin_options[ $field['id'] ] ) || ( '' === $plugin_options[ $field['id'] ] ) ) {
93
+
94
+                                    // If we are looking for an empty value, in the case of 'not_empty'
95
+                                    // then we need to keep processing.
96
+                                    if ( ! $is_not_empty ) {
97
+
98
+                                        // Empty id and not checking for 'not_empty'.  Bail out...
99
+                                        if ( ! isset( $field['validate_callback'] ) ) {
100
+                                            continue;
101
+                                        }
102
+                                    }
103
+                                }
104
+
105
+                                // Force validate of custom field types.
106
+                                if ( isset( $field['type'] ) && ! isset( $val ) && ! isset( $field['validate_callback'] ) ) {
107
+                                    if ( 'color' === $field['type'] || 'color_gradient' === $field['type'] ) {
108
+                                        $val = 'color';
109
+                                    } elseif ( 'date' === $field['type'] ) {
110
+                                        $val = 'date';
111
+                                    }
112
+                                }
113
+
114
+                                // No need.  Spectrum self validates.
115
+                                if ( 'color_rgba' === $field['type'] ) {
116
+                                    continue;
117
+                                }
118
+
119
+                                // Shim out old color rgba validators.
120
+                                if ( 'color_rgba' === $val || 'colorrgba' === $val ) {
121
+                                    $val = 'color';
122
+                                }
123
+
124
+                                $validate = 'Redux_Validation_' . $val;
125
+
126
+                                if ( ! class_exists( $validate ) ) {
127
+                                    $file = str_replace( '_', '-', $val );
128
+
129
+                                    /**
130
+                                     * Filter 'redux/validate/{opt_name}/class/{field.validate}'
131
+                                     *
132
+                                     * @param string $validate   validation class file path
133
+                                     */
134
+
135
+                                    // phpcs:ignore WordPress.NamingConventions.ValidHookName
136
+                                    $class_file = apply_filters( "redux/validate/{$core->args['opt_name']}/class/$val", Redux_Core::$dir . "inc/validation/$val/class-redux-validation-$file.php", $validate );
137
+
138
+                                    if ( $class_file ) {
139
+                                        if ( file_exists( $class_file ) ) {
140
+                                            require_once $class_file;
141
+                                        }
142
+                                    }
143
+                                }
144
+
145
+                                if ( class_exists( $validate ) ) {
146
+                                    if ( empty( $options[ $field['id'] ] ) ) {
147
+                                        $options[ $field['id'] ] = '';
148
+                                    }
149
+
150
+                                    if ( isset( $plugin_options[ $field['id'] ] ) && is_array( $plugin_options[ $field['id'] ] ) && ! empty( $plugin_options[ $field['id'] ] ) ) {
151
+                                        foreach ( $plugin_options[ $field['id'] ] as $key => $value ) {
152
+                                            $before = null;
153
+                                            $after  = null;
154
+
155
+                                            if ( isset( $plugin_options[ $field['id'] ][ $key ] ) && ( ! empty( $plugin_options[ $field['id'] ][ $key ] ) || '0' === $plugin_options[ $field['id'] ][ $key ] ) ) {
156
+                                                if ( is_array( $plugin_options[ $field['id'] ][ $key ] ) ) {
157
+                                                    $before = $plugin_options[ $field['id'] ][ $key ];
158
+                                                } else {
159
+                                                    $before = trim( $plugin_options[ $field['id'] ][ $key ] );
160
+                                                }
161
+                                            }
162
+
163
+                                            if ( isset( $options[ $field['id'] ][ $key ] ) && ( ! empty( $plugin_options[ $field['id'] ][ $key ] ) || '0' === $plugin_options[ $field['id'] ][ $key ] ) ) {
164
+                                                $after = $options[ $field['id'] ][ $key ];
165
+                                            }
166
+
167
+                                            $validation = new $validate( $core, $field, $before, $after );
168
+
169
+                                            if ( ! empty( $validation->value ) || '0' === $validation->value ) {
170
+                                                $plugin_options[ $field['id'] ][ $key ] = $validation->value;
171
+                                            } else {
172
+                                                unset( $plugin_options[ $field['id'] ][ $key ] );
173
+                                            }
174
+
175
+                                            if ( ! empty( $validation->error ) ) {
176
+                                                $core->errors[] = $validation->error;
177
+                                            }
178
+
179
+                                            if ( ! empty( $validation->warning ) ) {
180
+                                                $core->warnings[] = $validation->warning;
181
+                                            }
182
+
183
+                                            if ( ! empty( $validation->sanitize ) ) {
184
+                                                $core->sanitize[] = $validation->sanitize;
185
+                                            }
186
+                                        }
187
+                                    } else {
188
+                                        if ( isset( $plugin_options[ $field['id'] ] ) ) {
189
+                                            if ( is_array( $plugin_options[ $field['id'] ] ) ) {
190
+                                                $pofi = $plugin_options[ $field['id'] ];
191
+                                            } else {
192
+                                                $pofi = trim( $plugin_options[ $field['id'] ] );
193
+                                            }
194
+                                        } else {
195
+                                            $pofi = null;
196
+                                        }
197
+
198
+                                        $validation                     = new $validate( $core, $field, $pofi, $options[ $field['id'] ] );
199
+                                        $plugin_options[ $field['id'] ] = $validation->value;
200
+
201
+                                        if ( ! empty( $validation->error ) ) {
202
+                                            $core->errors[] = $validation->error;
203
+                                        }
204
+
205
+                                        if ( ! empty( $validation->warning ) ) {
206
+                                            $core->warnings[] = $validation->warning;
207
+                                        }
208
+
209
+                                        if ( ! empty( $validation->sanitize ) ) {
210
+                                            $core->sanitize[] = $validation->sanitize;
211
+                                        }
212
+                                    }
213
+
214
+                                    break;
215
+                                }
216
+                            }
217
+                        }
218
+
219
+                        if ( isset( $field['validate_callback'] ) && ( is_callable( $field['validate_callback'] ) || ( is_string( $field['validate_callback'] ) && function_exists( $field['validate_callback'] ) ) ) ) {
220
+                            $callback = $field['validate_callback'];
221
+                            unset( $field['validate_callback'] );
222
+
223
+                            $plugin_option = $plugin_options[ $field['id'] ] ?? null;
224
+                            $option        = $options[ $field['id'] ] ?? null;
225
+
226
+                            if ( null !== $plugin_option ) {
227
+                                $callbackvalues = call_user_func( $callback, $field, $plugin_option, $option );
228
+
229
+                                $plugin_options[ $field['id'] ] = $callbackvalues['value'];
230
+
231
+                                if ( isset( $callbackvalues['error'] ) ) {
232
+                                    $core->errors[] = $callbackvalues['error'];
233
+                                }
234
+
235
+                                if ( isset( $callbackvalues['warning'] ) ) {
236
+                                    $core->warnings[] = $callbackvalues['warning'];
237
+                                }
238
+
239
+                                if ( isset( $callbackvalues['sanitize'] ) ) {
240
+                                    $core->sanitize[] = $callbackvalues['sanitize'];
241
+                                }
242
+                            }
243
+                        }
244
+                    }
245
+                }
246
+            }
247
+
248
+            return $plugin_options;
249
+        }
250
+    }
251 251
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 		public function validate( array $plugin_options, array $options, array $sections ): array {
33 33
 			$core = $this->core();
34 34
 
35
-			if (null === $core) {
35
+			if ( null === $core ) {
36 36
 				return $plugin_options;
37 37
 			}
38 38
 
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 						}
45 45
 
46 46
 						if ( isset( $field['type'] ) && ( 'checkbox' === $field['type'] || 'checkbox_hide_below' === $field['type'] || 'checkbox_hide_all' === $field['type'] ) ) {
47
-							if ( ! isset( $plugin_options[ $field['id'] ] ) ) {
48
-								$plugin_options[ $field['id'] ] = 0;
47
+							if ( ! isset( $plugin_options[$field['id']] ) ) {
48
+								$plugin_options[$field['id']] = 0;
49 49
 							}
50 50
 						}
51 51
 
@@ -58,8 +58,8 @@  discard block
 block discarded – undo
58 58
 						 * }
59 59
 						 */
60 60
 
61
-						if ( isset( $core->extensions[ $field['type'] ] ) && method_exists( $core->extensions[ $field['type'] ], '_validate_values' ) ) {
62
-							$plugin_options = $core->extensions[ $field['type'] ]->_validate_values( $plugin_options, $field, $sections );
61
+						if ( isset( $core->extensions[$field['type']] ) && method_exists( $core->extensions[$field['type']], '_validate_values' ) ) {
62
+							$plugin_options = $core->extensions[$field['type']]->_validate_values( $plugin_options, $field, $sections );
63 63
 						}
64 64
 
65 65
 						// Make sure 'validate' field is set.
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 								}
90 90
 
91 91
 								// Check for empty id value.
92
-								if ( ! isset( $field['id'] ) || ! isset( $plugin_options[ $field['id'] ] ) || ( '' === $plugin_options[ $field['id'] ] ) ) {
92
+								if ( ! isset( $field['id'] ) || ! isset( $plugin_options[$field['id']] ) || ( '' === $plugin_options[$field['id']] ) ) {
93 93
 
94 94
 									// If we are looking for an empty value, in the case of 'not_empty'
95 95
 									// then we need to keep processing.
@@ -143,33 +143,33 @@  discard block
 block discarded – undo
143 143
 								}
144 144
 
145 145
 								if ( class_exists( $validate ) ) {
146
-									if ( empty( $options[ $field['id'] ] ) ) {
147
-										$options[ $field['id'] ] = '';
146
+									if ( empty( $options[$field['id']] ) ) {
147
+										$options[$field['id']] = '';
148 148
 									}
149 149
 
150
-									if ( isset( $plugin_options[ $field['id'] ] ) && is_array( $plugin_options[ $field['id'] ] ) && ! empty( $plugin_options[ $field['id'] ] ) ) {
151
-										foreach ( $plugin_options[ $field['id'] ] as $key => $value ) {
150
+									if ( isset( $plugin_options[$field['id']] ) && is_array( $plugin_options[$field['id']] ) && ! empty( $plugin_options[$field['id']] ) ) {
151
+										foreach ( $plugin_options[$field['id']] as $key => $value ) {
152 152
 											$before = null;
153 153
 											$after  = null;
154 154
 
155
-											if ( isset( $plugin_options[ $field['id'] ][ $key ] ) && ( ! empty( $plugin_options[ $field['id'] ][ $key ] ) || '0' === $plugin_options[ $field['id'] ][ $key ] ) ) {
156
-												if ( is_array( $plugin_options[ $field['id'] ][ $key ] ) ) {
157
-													$before = $plugin_options[ $field['id'] ][ $key ];
155
+											if ( isset( $plugin_options[$field['id']][$key] ) && ( ! empty( $plugin_options[$field['id']][$key] ) || '0' === $plugin_options[$field['id']][$key] ) ) {
156
+												if ( is_array( $plugin_options[$field['id']][$key] ) ) {
157
+													$before = $plugin_options[$field['id']][$key];
158 158
 												} else {
159
-													$before = trim( $plugin_options[ $field['id'] ][ $key ] );
159
+													$before = trim( $plugin_options[$field['id']][$key] );
160 160
 												}
161 161
 											}
162 162
 
163
-											if ( isset( $options[ $field['id'] ][ $key ] ) && ( ! empty( $plugin_options[ $field['id'] ][ $key ] ) || '0' === $plugin_options[ $field['id'] ][ $key ] ) ) {
164
-												$after = $options[ $field['id'] ][ $key ];
163
+											if ( isset( $options[$field['id']][$key] ) && ( ! empty( $plugin_options[$field['id']][$key] ) || '0' === $plugin_options[$field['id']][$key] ) ) {
164
+												$after = $options[$field['id']][$key];
165 165
 											}
166 166
 
167 167
 											$validation = new $validate( $core, $field, $before, $after );
168 168
 
169 169
 											if ( ! empty( $validation->value ) || '0' === $validation->value ) {
170
-												$plugin_options[ $field['id'] ][ $key ] = $validation->value;
170
+												$plugin_options[$field['id']][$key] = $validation->value;
171 171
 											} else {
172
-												unset( $plugin_options[ $field['id'] ][ $key ] );
172
+												unset( $plugin_options[$field['id']][$key] );
173 173
 											}
174 174
 
175 175
 											if ( ! empty( $validation->error ) ) {
@@ -185,18 +185,18 @@  discard block
 block discarded – undo
185 185
 											}
186 186
 										}
187 187
 									} else {
188
-										if ( isset( $plugin_options[ $field['id'] ] ) ) {
189
-											if ( is_array( $plugin_options[ $field['id'] ] ) ) {
190
-												$pofi = $plugin_options[ $field['id'] ];
188
+										if ( isset( $plugin_options[$field['id']] ) ) {
189
+											if ( is_array( $plugin_options[$field['id']] ) ) {
190
+												$pofi = $plugin_options[$field['id']];
191 191
 											} else {
192
-												$pofi = trim( $plugin_options[ $field['id'] ] );
192
+												$pofi = trim( $plugin_options[$field['id']] );
193 193
 											}
194 194
 										} else {
195 195
 											$pofi = null;
196 196
 										}
197 197
 
198
-										$validation                     = new $validate( $core, $field, $pofi, $options[ $field['id'] ] );
199
-										$plugin_options[ $field['id'] ] = $validation->value;
198
+										$validation                     = new $validate( $core, $field, $pofi, $options[$field['id']] );
199
+										$plugin_options[$field['id']] = $validation->value;
200 200
 
201 201
 										if ( ! empty( $validation->error ) ) {
202 202
 											$core->errors[] = $validation->error;
@@ -220,13 +220,13 @@  discard block
 block discarded – undo
220 220
 							$callback = $field['validate_callback'];
221 221
 							unset( $field['validate_callback'] );
222 222
 
223
-							$plugin_option = $plugin_options[ $field['id'] ] ?? null;
224
-							$option        = $options[ $field['id'] ] ?? null;
223
+							$plugin_option = $plugin_options[$field['id']] ?? null;
224
+							$option        = $options[$field['id']] ?? null;
225 225
 
226 226
 							if ( null !== $plugin_option ) {
227 227
 								$callbackvalues = call_user_func( $callback, $field, $plugin_option, $option );
228 228
 
229
-								$plugin_options[ $field['id'] ] = $callbackvalues['value'];
229
+								$plugin_options[$field['id']] = $callbackvalues['value'];
230 230
 
231 231
 								if ( isset( $callbackvalues['error'] ) ) {
232 232
 									$core->errors[] = $callbackvalues['error'];
Please login to merge, or discard this patch.
redux-core/inc/fields/gallery/class-redux-gallery.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -12,73 +12,73 @@
 block discarded – undo
12 12
 // Don't duplicate me!
13 13
 if ( ! class_exists( 'Redux_Gallery', false ) ) {
14 14
 
15
-	/**
16
-	 * Main Redux_gallery class
17
-	 *
18
-	 * @since       3.0.0
19
-	 */
20
-	class Redux_Gallery extends Redux_Field {
15
+    /**
16
+     * Main Redux_gallery class
17
+     *
18
+     * @since       3.0.0
19
+     */
20
+    class Redux_Gallery extends Redux_Field {
21 21
 
22
-		/**
23
-		 * Field Render Function.
24
-		 * Takes the vars and outputs the HTML for the field in the settings
25
-		 *
26
-		 * @since       1.0.0
27
-		 * @access      public
28
-		 * @return      void
29
-		 */
30
-		public function render() {
31
-			echo '<div class="screenshot">';
22
+        /**
23
+         * Field Render Function.
24
+         * Takes the vars and outputs the HTML for the field in the settings
25
+         *
26
+         * @since       1.0.0
27
+         * @access      public
28
+         * @return      void
29
+         */
30
+        public function render() {
31
+            echo '<div class="screenshot">';
32 32
 
33
-			if ( ! empty( $this->value ) ) {
34
-				$ids = explode( ',', $this->value );
33
+            if ( ! empty( $this->value ) ) {
34
+                $ids = explode( ',', $this->value );
35 35
 
36
-				foreach ( $ids as $attachment_id ) {
37
-					$img = wp_get_attachment_image_src( $attachment_id );
38
-					if ( false !== $img ) {
39
-						$alt = wp_prepare_attachment_for_js( $attachment_id );
40
-						$alt = $alt['alt'] ?? '';
36
+                foreach ( $ids as $attachment_id ) {
37
+                    $img = wp_get_attachment_image_src( $attachment_id );
38
+                    if ( false !== $img ) {
39
+                        $alt = wp_prepare_attachment_for_js( $attachment_id );
40
+                        $alt = $alt['alt'] ?? '';
41 41
 
42
-						echo '<a class="of-uploaded-image" href="' . esc_url( $img[0] ) . '">';
43
-						echo '<img class="redux-option-image" id="image_' . esc_attr( $this->field['id'] ) . '_' . esc_attr( $attachment_id ) . '" src="' . esc_url( $img[0] ) . '" alt="' . esc_attr( $alt ) . '" target="_blank" rel="external" />';
44
-						echo '</a>';
45
-					}
46
-				}
47
-			}
42
+                        echo '<a class="of-uploaded-image" href="' . esc_url( $img[0] ) . '">';
43
+                        echo '<img class="redux-option-image" id="image_' . esc_attr( $this->field['id'] ) . '_' . esc_attr( $attachment_id ) . '" src="' . esc_url( $img[0] ) . '" alt="' . esc_attr( $alt ) . '" target="_blank" rel="external" />';
44
+                        echo '</a>';
45
+                    }
46
+                }
47
+            }
48 48
 
49
-			echo '</div>';
50
-			echo '<a href="#" onclick="return false;" id="edit-gallery" class="gallery-attachments button button-primary">' . esc_html__( 'Add/Edit Gallery', 'redux-framework' ) . '</a> ';
51
-			echo '<a href="#" onclick="return false;" id="clear-gallery" class="gallery-attachments button">' . esc_html__( 'Clear Gallery', 'redux-framework' ) . '</a>';
52
-			echo '<input type="hidden" class="gallery_values ' . esc_attr( $this->field['class'] ) . '" value="' . esc_attr( $this->value ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '" />';
53
-		}
49
+            echo '</div>';
50
+            echo '<a href="#" onclick="return false;" id="edit-gallery" class="gallery-attachments button button-primary">' . esc_html__( 'Add/Edit Gallery', 'redux-framework' ) . '</a> ';
51
+            echo '<a href="#" onclick="return false;" id="clear-gallery" class="gallery-attachments button">' . esc_html__( 'Clear Gallery', 'redux-framework' ) . '</a>';
52
+            echo '<input type="hidden" class="gallery_values ' . esc_attr( $this->field['class'] ) . '" value="' . esc_attr( $this->value ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '" />';
53
+        }
54 54
 
55
-		/**
56
-		 * Enqueue Function.
57
-		 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
58
-		 *
59
-		 * @since       1.0.0
60
-		 * @access      public
61
-		 * @return      void
62
-		 */
63
-		public function enqueue() {
55
+        /**
56
+         * Enqueue Function.
57
+         * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
58
+         *
59
+         * @since       1.0.0
60
+         * @access      public
61
+         * @return      void
62
+         */
63
+        public function enqueue() {
64 64
 
65
-			if ( function_exists( 'wp_enqueue_media' ) ) {
66
-				wp_enqueue_media();
67
-			} else {
68
-				wp_enqueue_script( 'media-upload' );
69
-				wp_enqueue_script( 'thickbox' );
70
-				wp_enqueue_style( 'thickbox' );
71
-			}
65
+            if ( function_exists( 'wp_enqueue_media' ) ) {
66
+                wp_enqueue_media();
67
+            } else {
68
+                wp_enqueue_script( 'media-upload' );
69
+                wp_enqueue_script( 'thickbox' );
70
+                wp_enqueue_style( 'thickbox' );
71
+            }
72 72
 
73
-			wp_enqueue_script(
74
-				'redux-field-gallery',
75
-				Redux_Core::$url . 'inc/fields/gallery/redux-gallery' . Redux_Functions::is_min() . '.js',
76
-				array( 'jquery', 'redux-js' ),
77
-				$this->timestamp,
78
-				true
79
-			);
80
-		}
81
-	}
73
+            wp_enqueue_script(
74
+                'redux-field-gallery',
75
+                Redux_Core::$url . 'inc/fields/gallery/redux-gallery' . Redux_Functions::is_min() . '.js',
76
+                array( 'jquery', 'redux-js' ),
77
+                $this->timestamp,
78
+                true
79
+            );
80
+        }
81
+    }
82 82
 }
83 83
 
84 84
 class_alias( 'Redux_Gallery', 'ReduxFramework_Gallery' );
Please login to merge, or discard this patch.
redux-core/inc/extensions/shortcodes/class-redux-shortcodes.php 2 patches
Indentation   +295 added lines, -295 removed lines patch added patch discarded remove patch
@@ -11,299 +11,299 @@
 block discarded – undo
11 11
 
12 12
 if ( ! class_exists( 'Redux_Shortcodes' ) ) {
13 13
 
14
-	/**
15
-	 * Redux Framework shortcode extension class. Takes the common WordPress functions `wp_get_theme()` and `bloginfo()` and a few other functions and makes them accessible via shortcodes. Below you will find a table for the possible shortcodes and their values.
16
-	 * | shortcode | Function | Description |
17
-	 * |-----------|----------|-------------|
18
-	 * | blog-name | bloginfo("name") | Displays the "Site Title" set in Settings > General. This data is retrieved from the "blogname" record in the wp_options table. |
19
-	 * | blog-description | bloginfo("description") |  Displays the "Tagline" set in Settings > General. This data is retrieved from the "blogdescription" record in the wp_options table.|
20
-	 * | blog-wpurl | bloginfo("wpurl") |  Displays the "WordPress address (URL)" set in Settings > General. This data is retrieved from the "siteurl" record in the wp_options table. Consider using **blog-root_url** instead, especially for multi-site configurations using paths instead of subdomains (it will return the root site not the current sub-site). |
21
-	 * | blog-root_url | site_url() |  Return the root site, not the current sub-site. |
22
-	 * | blog-url | home_url() |  Displays the "Site address (URL)" set in Settings > General. This data is retrieved from the "home" record in the wp_options table. |
23
-	 * | blog-admin_email | bloginfo("admin_email") |  Displays the "E-mail address" set in Settings > General. This data is retrieved from the "admin_email" record in the wp_options table.|
24
-	 * | blog-charset | bloginfo("charset") |  Displays the "Encoding for pages and feeds" set in Settings > Reading. This data is retrieved from the "blog_charset" record in the wp_options table. Note: In Version 3.5.0 and later, character encoding is no longer configurable from the Administration Panel. Therefore, this parameter always echoes "UTF-8", which is the default encoding of WordPress.|
25
-	 * | blog-version | bloginfo("version") |  Displays the WordPress Version you use. This data is retrieved from the $wp_version variable set in wp-includes/version.php.|
26
-	 * | blog-html_type | bloginfo("html_type") |  Displays the Content-Type of WordPress HTML pages (default: "text/html"). This data is retrieved from the "html_type" record in the wp_options table. Themes and plugins can override the default value using the pre_option_html_type filter.|
27
-	 * | blog-text_direction | bloginfo("text_direction") |  Displays the Text Direction of WordPress HTML pages. Consider using **blog-text_direction_boolean** instead if you want a true/false response. |
28
-	 * | blog-text_direction_boolean | is_rtl() |  Displays true/false check if the Text Direction of WordPress HTML pages is left instead of right |
29
-	 * | blog-language | bloginfo("language") |  Displays the language of WordPress.|
30
-	 * | blog-stylesheet_url | get_stylesheet_uri() |  Displays the primary CSS (usually style.css) file URL of the active theme. |
31
-	 * | blog-stylesheet_directory | bloginfo("stylesheet_directory") |  Displays the stylesheet directory URL of the active theme. (Was a local path in earlier WordPress versions.) Consider echoing get_stylesheet_directory_uri() instead.|
32
-	 * | blog-template_url | get_template_directory_uri() |  Parent template uri. Consider using **blog-child_template_url** for the child template URI. |
33
-	 * | blog-child_template_url | get_stylesheet_directory_uri() | Child template URI. |
34
-	 * | blog-pingback_url | bloginfo("pingback_url") |  Displays the Pingback XML-RPC file URL (xmlrpc.php).|
35
-	 * | blog-atom_url | bloginfo("atom_url") |  Displays the Atom feed URL (/feed/atom).|
36
-	 * | blog-rdf_url | bloginfo("rdf_url") |  Displays the RDF/RSS 1.0 feed URL (/feed/rfd).|
37
-	 * | blog-rss_url | bloginfo("rss_url") |  Displays the RSS 0.92 feed URL (/feed/rss).|
38
-	 * | blog-rss2_url | bloginfo("rss2_url") |  Displays the RSS 2.0 feed URL (/feed).|
39
-	 * | blog-comments_atom_url | bloginfo("comments_atom_url") |  Displays the comments Atom feed URL (/comments/feed).|
40
-	 * | blog-comments_rss2_url | bloginfo("comments_rss2_url") |  Displays the comments RSS 2.0 feed URL (/comments/feed).|
41
-	 * | login-url | wp_login_url() | Returns the WordPress login URL. |
42
-	 * | login-url | wp_logout_url() | Returns the WordPress logout URL. |
43
-	 * | current_year | date("Y") | Returns the current year. |
44
-	 * | theme-name | $theme_info->get("Name") | Theme name as given in theme's style.css |
45
-	 * | theme-uri | $theme_info->get("ThemeURI") | The path to the theme's directory |
46
-	 * | theme-description | $theme_info->get("Description") | The description of the theme |
47
-	 * | theme-author | $theme_info->get("Author") | The theme's author |
48
-	 * | theme-author_uri | $theme_info->get("AuthorURI") | The website of the theme author |
49
-	 * | theme-version | $theme_info->get("Version") | The version of the theme |
50
-	 * | theme-template | $theme_info->get("Template") | The folder name of the current theme |
51
-	 * | theme-status | $theme_info->get("Status") | If the theme is published |
52
-	 * | theme-tags | $theme_info->get("Tags") | Tags used to describe the theme |
53
-	 * | theme-text_domain | $theme_info->get("TextDomain") | The text domain used in the theme for translation purposes |
54
-	 * | theme-domain_path | $theme_info->get("DomainPath") | Path to the theme translation files |
55
-	 *
56
-	 * @version 1.0.0
57
-	 */
58
-
59
-	/**
60
-	 * Class Redux_Shortcodes
61
-	 */
62
-	class Redux_Shortcodes {
63
-
64
-		/**
65
-		 * Redux_Shortcodes constructor.
66
-		 */
67
-		public function __construct() {
68
-			if ( ! shortcode_exists( 'bloginfo' ) ) {
69
-				add_shortcode( 'bloginfo', array( $this, 'blog_info' ) );
70
-			} else {
71
-				add_shortcode( 'redux_bloginfo', array( $this, 'blog_info' ) );
72
-			}
73
-
74
-			if ( ! shortcode_exists( 'themeinfo' ) ) {
75
-				add_shortcode( 'themeinfo', array( $this, 'theme_info' ) );
76
-			} else {
77
-				add_shortcode( 'redux_themeinfo', array( $this, 'theme_info' ) );
78
-			}
79
-
80
-			if ( ! shortcode_exists( 'date' ) ) {
81
-				add_shortcode( 'date', array( $this, 'date' ) );
82
-			} else {
83
-				add_shortcode( 'redux_date', array( $this, 'date' ) );
84
-			}
85
-		}
86
-
87
-		/**
88
-		 * Return site/blog info by a validated selector.
89
-		 * Assumes the return value is printed into HTML (text node).
90
-		 * If you need raw values for other contexts, remove the esc_* here
91
-		 * and escape at the final render point instead.
92
-		 *
93
-		 * @param array|string $atts    Attributes.
94
-		 * @param string|null  $content Content.
95
-		 *
96
-		 * @return string Escaped for HTML text (URLs are escaped with esc_url()).
97
-		 */
98
-		public function blog_info( $atts = array(), ?string $content = null ): string {
99
-
100
-			// Normalize and merge defaults.
101
-			$atts = is_array( $atts ) ? wp_unslash( $atts ) : array();
102
-			$atts = shortcode_atts(
103
-				array(
104
-					'data' => '',
105
-				),
106
-				$atts
107
-			);
108
-
109
-			// Allow content as fallback for the selector.
110
-			if ( null !== $content && '' === $atts['data'] ) {
111
-				$atts['data'] = $content;
112
-			}
113
-
114
-			// Validate selector as a key and clamp length.
115
-			$key = substr( sanitize_key( $atts['data'] ), 0, 64 );
116
-
117
-			// Map aliases -> handlers.
118
-			// Keep your original intent (filesystem paths vs URIs) but make it safe and explicit.
119
-			switch ( $key ) {
120
-				// Filesystem paths (escape as text).
121
-				case 'stylesheet_directory':
122
-				case 'child_template_directory':
123
-					return esc_html( get_stylesheet_directory() );
124
-
125
-				case 'template_directory':
126
-					return esc_html( get_template_directory() );
127
-
128
-				// Theme URIs.
129
-				case 'parent_template_url':
130
-					return esc_url( get_template_directory_uri() );
131
-
132
-				case 'child_template_url':
133
-				case 'template_url':
134
-					return esc_url( get_stylesheet_directory_uri() );
135
-
136
-				// URLs.
137
-				case 'url':
138
-					return esc_url( home_url() );
139
-
140
-				case 'root_url':
141
-					return esc_url( site_url() );
142
-
143
-				case 'stylesheet_url':
144
-					return esc_url( get_stylesheet_uri() );
145
-
146
-				case 'logout_url':
147
-					return esc_url( wp_logout_url() );
148
-
149
-				case 'login_url':
150
-					return esc_url( wp_login_url() );
151
-
152
-				case 'register_url':
153
-					return esc_url( wp_registration_url() );
154
-
155
-				case 'lostpassword_url':
156
-				case 'lost_password_url':
157
-					return esc_url( wp_lostpassword_url() );
158
-
159
-				// Booleans.
160
-				case 'text_direction_bool':
161
-				case 'text_direction_boolean':
162
-					return esc_html( is_rtl() ? '1' : '0' );
163
-
164
-				case 'is_multisite':
165
-					return esc_html( is_multisite() ? '1' : '0' );
166
-
167
-				// Text direction as string.
168
-				case 'text_direction':
169
-					return esc_html( is_rtl() ? 'rtl' : 'ltr' );
170
-
171
-				default:
172
-					// Safe fallback: pull raw blog info, then escape as text.
173
-					// (Avoid over-sanitizing: this is trusted core data).
174
-					$value = get_bloginfo( $key );
175
-					return esc_html( (string) $value );
176
-			}
177
-		}
178
-
179
-		/**
180
-		 * Get theme info.
181
-		 *
182
-		 * @param array|string $atts    Attributes.
183
-		 * @param string|null  $content Content.
184
-		 *
185
-		 * @return string
186
-		 */
187
-		public function theme_info( array $atts = array(), ?string $content = null ): string {
188
-			// Normalize input and merge defaults.
189
-			$atts = wp_unslash( $atts );
190
-			$atts = shortcode_atts(
191
-				array(
192
-					'data' => '',
193
-				),
194
-				$atts
195
-			);
196
-
197
-			// Allow content as a fallback selector.
198
-			if ( null !== $content && '' === $atts['data'] ) {
199
-				$atts['data'] = $content;
200
-			}
201
-
202
-			// Validate selector as a key.
203
-			$key = sanitize_key( $atts['data'] );
204
-
205
-			// Map aliases -> canonical WP_Theme header keys or special handlers.
206
-			$map = array(
207
-				'name'        => 'Name',
208
-				'themeuri'    => 'ThemeURI',
209
-				'theme_uri'   => 'ThemeURI',
210
-				'description' => 'Description',
211
-				'author'      => 'Author',
212
-				'authoruri'   => 'AuthorURI',
213
-				'author_uri'  => 'AuthorURI',
214
-				'version'     => 'Version',
215
-				'template'    => 'Template',
216
-				'status'      => 'Status',
217
-				'tags'        => 'Tags',
218
-				'textdomain'  => 'TextDomain',
219
-				'text_domain' => 'TextDomain',
220
-				'domainpath'  => 'DomainPath',
221
-				'domain_path' => 'DomainPath',
222
-				'is_child'    => 'is_child', // special case.
223
-			);
224
-
225
-			// Default to "name" when empty or unknown.
226
-			if ( '' === $key || ! isset( $map[ $key ] ) ) {
227
-				$key = 'name';
228
-			}
229
-
230
-			// Cache theme object.
231
-			if ( empty( $this->theme_info ) ) {
232
-				$this->theme_info = wp_get_theme();
233
-			}
234
-
235
-			$canonical = $map[ $key ];
236
-
237
-			// Special case: is_child — return "1" or "0" as string.
238
-			if ( 'is_child' === $canonical ) {
239
-				$bool = Redux_Helpers::is_child_theme( get_template_directory() );
240
-				return esc_html( $bool ? '1' : '0' );
241
-			}
242
-
243
-			$value = $this->theme_info->get( $canonical );
244
-
245
-			// WP_Theme::get('Tags') may be array; normalize to string.
246
-			if ( is_array( $value ) ) {
247
-				$value = implode( ', ', array_filter( array_map( 'trim', $value ) ) );
248
-			}
249
-
250
-			$value = (string) $value;
251
-
252
-			// Escape by context.
253
-			switch ( $canonical ) {
254
-				case 'ThemeURI':
255
-				case 'AuthorURI':
256
-					// If you ultimately print this inside an href, escape at that final context instead.
257
-					// Here we assume the plain text output of the URL.
258
-					return esc_url( $value );
259
-
260
-				default:
261
-					return esc_html( $value );
262
-			}
263
-		}
264
-
265
-		/**
266
-		 * Get date info.
267
-		 *
268
-		 * @param array|string $atts    Attributes.
269
-		 * @param string|null  $content Content.
270
-		 *
271
-		 * @return string
272
-		 */
273
-		public function date( $atts = array(), ?string $content = null ): string {
274
-
275
-			// 1) Normalize + unslash
276
-			$atts = is_array( $atts ) ? wp_unslash( $atts ) : array();
277
-
278
-			// 2) Default/merge (if this is a shortcode handler, pass the tag as the 3rd arg)
279
-			$atts = shortcode_atts(
280
-				array(
281
-					'data' => '',
282
-				),
283
-				$atts
284
-			);
285
-
286
-			// 3) Allow content as a fallback for the format
287
-			if ( null !== $content && '' === $atts['data'] ) {
288
-				// Keep content simple text; strip tags and control chars.
289
-				$atts['data'] = sanitize_text_field( wp_unslash( $content ) );
290
-			}
291
-
292
-			// 4) Validate and constrain the format string
293
-			$format = (string) $atts['data'];
294
-			$format = substr( $format, 0, 64 ); // avoid absurdly long inputs.
295
-
296
-			// Allow common date format tokens + typical literal punctuation and backslash for escaping.
297
-			// If invalid chars are present, fall back to a safe default.
298
-			if ( '' === $format || ! preg_match( '/^[A-Za-z0-9\s:\-.,\/\\\\T]+$/', $format ) ) {
299
-				$format = 'Y';
300
-			}
301
-
302
-			// 5) Use wp_date() to respect WP timezone and locale (date_i18n is deprecated).
303
-			$output = wp_date( $format );
304
-
305
-			// 6) Escape for HTML context before returning (safe default for shortcode/rendered output).
306
-			return esc_html( $output );
307
-		}
308
-	}
14
+    /**
15
+     * Redux Framework shortcode extension class. Takes the common WordPress functions `wp_get_theme()` and `bloginfo()` and a few other functions and makes them accessible via shortcodes. Below you will find a table for the possible shortcodes and their values.
16
+     * | shortcode | Function | Description |
17
+     * |-----------|----------|-------------|
18
+     * | blog-name | bloginfo("name") | Displays the "Site Title" set in Settings > General. This data is retrieved from the "blogname" record in the wp_options table. |
19
+     * | blog-description | bloginfo("description") |  Displays the "Tagline" set in Settings > General. This data is retrieved from the "blogdescription" record in the wp_options table.|
20
+     * | blog-wpurl | bloginfo("wpurl") |  Displays the "WordPress address (URL)" set in Settings > General. This data is retrieved from the "siteurl" record in the wp_options table. Consider using **blog-root_url** instead, especially for multi-site configurations using paths instead of subdomains (it will return the root site not the current sub-site). |
21
+     * | blog-root_url | site_url() |  Return the root site, not the current sub-site. |
22
+     * | blog-url | home_url() |  Displays the "Site address (URL)" set in Settings > General. This data is retrieved from the "home" record in the wp_options table. |
23
+     * | blog-admin_email | bloginfo("admin_email") |  Displays the "E-mail address" set in Settings > General. This data is retrieved from the "admin_email" record in the wp_options table.|
24
+     * | blog-charset | bloginfo("charset") |  Displays the "Encoding for pages and feeds" set in Settings > Reading. This data is retrieved from the "blog_charset" record in the wp_options table. Note: In Version 3.5.0 and later, character encoding is no longer configurable from the Administration Panel. Therefore, this parameter always echoes "UTF-8", which is the default encoding of WordPress.|
25
+     * | blog-version | bloginfo("version") |  Displays the WordPress Version you use. This data is retrieved from the $wp_version variable set in wp-includes/version.php.|
26
+     * | blog-html_type | bloginfo("html_type") |  Displays the Content-Type of WordPress HTML pages (default: "text/html"). This data is retrieved from the "html_type" record in the wp_options table. Themes and plugins can override the default value using the pre_option_html_type filter.|
27
+     * | blog-text_direction | bloginfo("text_direction") |  Displays the Text Direction of WordPress HTML pages. Consider using **blog-text_direction_boolean** instead if you want a true/false response. |
28
+     * | blog-text_direction_boolean | is_rtl() |  Displays true/false check if the Text Direction of WordPress HTML pages is left instead of right |
29
+     * | blog-language | bloginfo("language") |  Displays the language of WordPress.|
30
+     * | blog-stylesheet_url | get_stylesheet_uri() |  Displays the primary CSS (usually style.css) file URL of the active theme. |
31
+     * | blog-stylesheet_directory | bloginfo("stylesheet_directory") |  Displays the stylesheet directory URL of the active theme. (Was a local path in earlier WordPress versions.) Consider echoing get_stylesheet_directory_uri() instead.|
32
+     * | blog-template_url | get_template_directory_uri() |  Parent template uri. Consider using **blog-child_template_url** for the child template URI. |
33
+     * | blog-child_template_url | get_stylesheet_directory_uri() | Child template URI. |
34
+     * | blog-pingback_url | bloginfo("pingback_url") |  Displays the Pingback XML-RPC file URL (xmlrpc.php).|
35
+     * | blog-atom_url | bloginfo("atom_url") |  Displays the Atom feed URL (/feed/atom).|
36
+     * | blog-rdf_url | bloginfo("rdf_url") |  Displays the RDF/RSS 1.0 feed URL (/feed/rfd).|
37
+     * | blog-rss_url | bloginfo("rss_url") |  Displays the RSS 0.92 feed URL (/feed/rss).|
38
+     * | blog-rss2_url | bloginfo("rss2_url") |  Displays the RSS 2.0 feed URL (/feed).|
39
+     * | blog-comments_atom_url | bloginfo("comments_atom_url") |  Displays the comments Atom feed URL (/comments/feed).|
40
+     * | blog-comments_rss2_url | bloginfo("comments_rss2_url") |  Displays the comments RSS 2.0 feed URL (/comments/feed).|
41
+     * | login-url | wp_login_url() | Returns the WordPress login URL. |
42
+     * | login-url | wp_logout_url() | Returns the WordPress logout URL. |
43
+     * | current_year | date("Y") | Returns the current year. |
44
+     * | theme-name | $theme_info->get("Name") | Theme name as given in theme's style.css |
45
+     * | theme-uri | $theme_info->get("ThemeURI") | The path to the theme's directory |
46
+     * | theme-description | $theme_info->get("Description") | The description of the theme |
47
+     * | theme-author | $theme_info->get("Author") | The theme's author |
48
+     * | theme-author_uri | $theme_info->get("AuthorURI") | The website of the theme author |
49
+     * | theme-version | $theme_info->get("Version") | The version of the theme |
50
+     * | theme-template | $theme_info->get("Template") | The folder name of the current theme |
51
+     * | theme-status | $theme_info->get("Status") | If the theme is published |
52
+     * | theme-tags | $theme_info->get("Tags") | Tags used to describe the theme |
53
+     * | theme-text_domain | $theme_info->get("TextDomain") | The text domain used in the theme for translation purposes |
54
+     * | theme-domain_path | $theme_info->get("DomainPath") | Path to the theme translation files |
55
+     *
56
+     * @version 1.0.0
57
+     */
58
+
59
+    /**
60
+     * Class Redux_Shortcodes
61
+     */
62
+    class Redux_Shortcodes {
63
+
64
+        /**
65
+         * Redux_Shortcodes constructor.
66
+         */
67
+        public function __construct() {
68
+            if ( ! shortcode_exists( 'bloginfo' ) ) {
69
+                add_shortcode( 'bloginfo', array( $this, 'blog_info' ) );
70
+            } else {
71
+                add_shortcode( 'redux_bloginfo', array( $this, 'blog_info' ) );
72
+            }
73
+
74
+            if ( ! shortcode_exists( 'themeinfo' ) ) {
75
+                add_shortcode( 'themeinfo', array( $this, 'theme_info' ) );
76
+            } else {
77
+                add_shortcode( 'redux_themeinfo', array( $this, 'theme_info' ) );
78
+            }
79
+
80
+            if ( ! shortcode_exists( 'date' ) ) {
81
+                add_shortcode( 'date', array( $this, 'date' ) );
82
+            } else {
83
+                add_shortcode( 'redux_date', array( $this, 'date' ) );
84
+            }
85
+        }
86
+
87
+        /**
88
+         * Return site/blog info by a validated selector.
89
+         * Assumes the return value is printed into HTML (text node).
90
+         * If you need raw values for other contexts, remove the esc_* here
91
+         * and escape at the final render point instead.
92
+         *
93
+         * @param array|string $atts    Attributes.
94
+         * @param string|null  $content Content.
95
+         *
96
+         * @return string Escaped for HTML text (URLs are escaped with esc_url()).
97
+         */
98
+        public function blog_info( $atts = array(), ?string $content = null ): string {
99
+
100
+            // Normalize and merge defaults.
101
+            $atts = is_array( $atts ) ? wp_unslash( $atts ) : array();
102
+            $atts = shortcode_atts(
103
+                array(
104
+                    'data' => '',
105
+                ),
106
+                $atts
107
+            );
108
+
109
+            // Allow content as fallback for the selector.
110
+            if ( null !== $content && '' === $atts['data'] ) {
111
+                $atts['data'] = $content;
112
+            }
113
+
114
+            // Validate selector as a key and clamp length.
115
+            $key = substr( sanitize_key( $atts['data'] ), 0, 64 );
116
+
117
+            // Map aliases -> handlers.
118
+            // Keep your original intent (filesystem paths vs URIs) but make it safe and explicit.
119
+            switch ( $key ) {
120
+                // Filesystem paths (escape as text).
121
+                case 'stylesheet_directory':
122
+                case 'child_template_directory':
123
+                    return esc_html( get_stylesheet_directory() );
124
+
125
+                case 'template_directory':
126
+                    return esc_html( get_template_directory() );
127
+
128
+                // Theme URIs.
129
+                case 'parent_template_url':
130
+                    return esc_url( get_template_directory_uri() );
131
+
132
+                case 'child_template_url':
133
+                case 'template_url':
134
+                    return esc_url( get_stylesheet_directory_uri() );
135
+
136
+                // URLs.
137
+                case 'url':
138
+                    return esc_url( home_url() );
139
+
140
+                case 'root_url':
141
+                    return esc_url( site_url() );
142
+
143
+                case 'stylesheet_url':
144
+                    return esc_url( get_stylesheet_uri() );
145
+
146
+                case 'logout_url':
147
+                    return esc_url( wp_logout_url() );
148
+
149
+                case 'login_url':
150
+                    return esc_url( wp_login_url() );
151
+
152
+                case 'register_url':
153
+                    return esc_url( wp_registration_url() );
154
+
155
+                case 'lostpassword_url':
156
+                case 'lost_password_url':
157
+                    return esc_url( wp_lostpassword_url() );
158
+
159
+                // Booleans.
160
+                case 'text_direction_bool':
161
+                case 'text_direction_boolean':
162
+                    return esc_html( is_rtl() ? '1' : '0' );
163
+
164
+                case 'is_multisite':
165
+                    return esc_html( is_multisite() ? '1' : '0' );
166
+
167
+                // Text direction as string.
168
+                case 'text_direction':
169
+                    return esc_html( is_rtl() ? 'rtl' : 'ltr' );
170
+
171
+                default:
172
+                    // Safe fallback: pull raw blog info, then escape as text.
173
+                    // (Avoid over-sanitizing: this is trusted core data).
174
+                    $value = get_bloginfo( $key );
175
+                    return esc_html( (string) $value );
176
+            }
177
+        }
178
+
179
+        /**
180
+         * Get theme info.
181
+         *
182
+         * @param array|string $atts    Attributes.
183
+         * @param string|null  $content Content.
184
+         *
185
+         * @return string
186
+         */
187
+        public function theme_info( array $atts = array(), ?string $content = null ): string {
188
+            // Normalize input and merge defaults.
189
+            $atts = wp_unslash( $atts );
190
+            $atts = shortcode_atts(
191
+                array(
192
+                    'data' => '',
193
+                ),
194
+                $atts
195
+            );
196
+
197
+            // Allow content as a fallback selector.
198
+            if ( null !== $content && '' === $atts['data'] ) {
199
+                $atts['data'] = $content;
200
+            }
201
+
202
+            // Validate selector as a key.
203
+            $key = sanitize_key( $atts['data'] );
204
+
205
+            // Map aliases -> canonical WP_Theme header keys or special handlers.
206
+            $map = array(
207
+                'name'        => 'Name',
208
+                'themeuri'    => 'ThemeURI',
209
+                'theme_uri'   => 'ThemeURI',
210
+                'description' => 'Description',
211
+                'author'      => 'Author',
212
+                'authoruri'   => 'AuthorURI',
213
+                'author_uri'  => 'AuthorURI',
214
+                'version'     => 'Version',
215
+                'template'    => 'Template',
216
+                'status'      => 'Status',
217
+                'tags'        => 'Tags',
218
+                'textdomain'  => 'TextDomain',
219
+                'text_domain' => 'TextDomain',
220
+                'domainpath'  => 'DomainPath',
221
+                'domain_path' => 'DomainPath',
222
+                'is_child'    => 'is_child', // special case.
223
+            );
224
+
225
+            // Default to "name" when empty or unknown.
226
+            if ( '' === $key || ! isset( $map[ $key ] ) ) {
227
+                $key = 'name';
228
+            }
229
+
230
+            // Cache theme object.
231
+            if ( empty( $this->theme_info ) ) {
232
+                $this->theme_info = wp_get_theme();
233
+            }
234
+
235
+            $canonical = $map[ $key ];
236
+
237
+            // Special case: is_child — return "1" or "0" as string.
238
+            if ( 'is_child' === $canonical ) {
239
+                $bool = Redux_Helpers::is_child_theme( get_template_directory() );
240
+                return esc_html( $bool ? '1' : '0' );
241
+            }
242
+
243
+            $value = $this->theme_info->get( $canonical );
244
+
245
+            // WP_Theme::get('Tags') may be array; normalize to string.
246
+            if ( is_array( $value ) ) {
247
+                $value = implode( ', ', array_filter( array_map( 'trim', $value ) ) );
248
+            }
249
+
250
+            $value = (string) $value;
251
+
252
+            // Escape by context.
253
+            switch ( $canonical ) {
254
+                case 'ThemeURI':
255
+                case 'AuthorURI':
256
+                    // If you ultimately print this inside an href, escape at that final context instead.
257
+                    // Here we assume the plain text output of the URL.
258
+                    return esc_url( $value );
259
+
260
+                default:
261
+                    return esc_html( $value );
262
+            }
263
+        }
264
+
265
+        /**
266
+         * Get date info.
267
+         *
268
+         * @param array|string $atts    Attributes.
269
+         * @param string|null  $content Content.
270
+         *
271
+         * @return string
272
+         */
273
+        public function date( $atts = array(), ?string $content = null ): string {
274
+
275
+            // 1) Normalize + unslash
276
+            $atts = is_array( $atts ) ? wp_unslash( $atts ) : array();
277
+
278
+            // 2) Default/merge (if this is a shortcode handler, pass the tag as the 3rd arg)
279
+            $atts = shortcode_atts(
280
+                array(
281
+                    'data' => '',
282
+                ),
283
+                $atts
284
+            );
285
+
286
+            // 3) Allow content as a fallback for the format
287
+            if ( null !== $content && '' === $atts['data'] ) {
288
+                // Keep content simple text; strip tags and control chars.
289
+                $atts['data'] = sanitize_text_field( wp_unslash( $content ) );
290
+            }
291
+
292
+            // 4) Validate and constrain the format string
293
+            $format = (string) $atts['data'];
294
+            $format = substr( $format, 0, 64 ); // avoid absurdly long inputs.
295
+
296
+            // Allow common date format tokens + typical literal punctuation and backslash for escaping.
297
+            // If invalid chars are present, fall back to a safe default.
298
+            if ( '' === $format || ! preg_match( '/^[A-Za-z0-9\s:\-.,\/\\\\T]+$/', $format ) ) {
299
+                $format = 'Y';
300
+            }
301
+
302
+            // 5) Use wp_date() to respect WP timezone and locale (date_i18n is deprecated).
303
+            $output = wp_date( $format );
304
+
305
+            // 6) Escape for HTML context before returning (safe default for shortcode/rendered output).
306
+            return esc_html( $output );
307
+        }
308
+    }
309 309
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 					// Safe fallback: pull raw blog info, then escape as text.
173 173
 					// (Avoid over-sanitizing: this is trusted core data).
174 174
 					$value = get_bloginfo( $key );
175
-					return esc_html( (string) $value );
175
+					return esc_html( ( string ) $value );
176 176
 			}
177 177
 		}
178 178
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 			);
224 224
 
225 225
 			// Default to "name" when empty or unknown.
226
-			if ( '' === $key || ! isset( $map[ $key ] ) ) {
226
+			if ( '' === $key || ! isset( $map[$key] ) ) {
227 227
 				$key = 'name';
228 228
 			}
229 229
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 				$this->theme_info = wp_get_theme();
233 233
 			}
234 234
 
235
-			$canonical = $map[ $key ];
235
+			$canonical = $map[$key];
236 236
 
237 237
 			// Special case: is_child — return "1" or "0" as string.
238 238
 			if ( 'is_child' === $canonical ) {
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 				$value = implode( ', ', array_filter( array_map( 'trim', $value ) ) );
248 248
 			}
249 249
 
250
-			$value = (string) $value;
250
+			$value = ( string ) $value;
251 251
 
252 252
 			// Escape by context.
253 253
 			switch ( $canonical ) {
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 			}
291 291
 
292 292
 			// 4) Validate and constrain the format string
293
-			$format = (string) $atts['data'];
293
+			$format = ( string ) $atts['data'];
294 294
 			$format = substr( $format, 0, 64 ); // avoid absurdly long inputs.
295 295
 
296 296
 			// Allow common date format tokens + typical literal punctuation and backslash for escaping.
Please login to merge, or discard this patch.
redux-core/inc/extensions/repeater/repeater/class-redux-repeater.php 2 patches
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.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
 										}
116 116
 
117 117
 										foreach ( $field['data'] as $key => $data ) {
118
-											if ( ! isset( $field['args'][ $key ] ) ) {
119
-												$field['args'][ $key ] = array();
118
+											if ( ! isset( $field['args'][$key] ) ) {
119
+												$field['args'][$key] = array();
120 120
 											}
121 121
 
122
-											$field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] );
122
+											$field['options'][$key] = $this->parent->wordpress_data->get( $data, $field['args'][$key], $this->parent->args['opt_name'] );
123 123
 										}
124 124
 									}
125 125
 								}
@@ -127,14 +127,14 @@  discard block
 block discarded – undo
127 127
 								$default = $field['default'] ?? '';
128 128
 
129 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 ];
130
+									$repeater['title'] = ! isset( $this->parent->options[$this->field['id']][$field['id']][$x] ) ? $default : $this->parent->options[$this->field['id']][$field['id']][$x];
131 131
 								} else {
132
-									$repeater['title'] = ! isset( $this->parent->options[ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $field['id'] ][ $x ];
132
+									$repeater['title'] = ! isset( $this->parent->options[$field['id']][$x] ) ? $default : $this->parent->options[$field['id']][$x];
133 133
 								}
134 134
 
135 135
 								if ( isset( $field['options'] ) && is_array( $field['options'] ) ) {
136
-									if ( isset( $field['options'][ $repeater['title'] ] ) ) {
137
-										$repeater['title'] = $field['options'][ $repeater['title'] ];
136
+									if ( isset( $field['options'][$repeater['title']] ) ) {
137
+										$repeater['title'] = $field['options'][$repeater['title']];
138 138
 									}
139 139
 								}
140 140
 							}
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 					echo '<table style="margin-top: 0;" class="redux-repeater-accordion redux-repeater form-table no-border">';
197 197
 					echo '<fieldset class="redux-field" data-id="' . esc_attr( $this->field['id'] ) . '">';
198 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;
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 201
 					}
202 202
 
203 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" />';
@@ -319,10 +319,10 @@  discard block
 block discarded – undo
319 319
 					}
320 320
 
321 321
 					foreach ( $field['data'] as $key => $data ) {
322
-						if ( ! isset( $field['args'][ $key ] ) ) {
323
-							$field['args'][ $key ] = array();
322
+						if ( ! isset( $field['args'][$key] ) ) {
323
+							$field['args'][$key] = array();
324 324
 						}
325
-						$field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] );
325
+						$field['options'][$key] = $this->parent->wordpress_data->get( $data, $field['args'][$key], $this->parent->args['opt_name'] );
326 326
 					}
327 327
 				}
328 328
 			}
@@ -330,9 +330,9 @@  discard block
 block discarded – undo
330 330
 			$default = $field['default'] ?? '';
331 331
 
332 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 ];
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 334
 			} else {
335
-				$value = empty( $this->parent->options[ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $orig_field_id ][ $x ];
335
+				$value = empty( $this->parent->options[$orig_field_id][$x] ) ? $default : $this->parent->options[$orig_field_id][$x];
336 336
 			}
337 337
 
338 338
 			ob_start();
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 
445 445
 				$data = $enqueue->localize( $field );
446 446
 
447
-				$this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data;
447
+				$this->parent->enqueue_class->localize_data[$field['type']][$field['id']] = $data;
448 448
 			}
449 449
 		}
450 450
 	}
Please login to merge, or discard this patch.
redux-core/inc/extensions/tabbed/tabbed/class-redux-tabbed.php 2 patches
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.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -114,11 +114,11 @@  discard block
 block discarded – undo
114 114
 					}
115 115
 
116 116
 					foreach ( $field['data'] as $key => $data ) {
117
-						if ( ! isset( $field['args'][ $key ] ) ) {
118
-							$field['args'][ $key ] = array();
117
+						if ( ! isset( $field['args'][$key] ) ) {
118
+							$field['args'][$key] = array();
119 119
 						}
120 120
 
121
-						$field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] );
121
+						$field['options'][$key] = $this->parent->wordpress_data->get( $data, $field['args'][$key], $this->parent->args['opt_name'] );
122 122
 					}
123 123
 				}
124 124
 			}
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 
128 128
 			// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
129 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;
130
+			$value = $this->parent->options[$orig_field_id] ?? $default;
131 131
 
132 132
 			$this->parent->render_class->field_input( $field, $value );
133 133
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 
188 188
 				$data = $enqueue->localize( $field );
189 189
 
190
-				$this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data;
190
+				$this->parent->enqueue_class->localize_data[$field['type']][$field['id']] = $data;
191 191
 			}
192 192
 		}
193 193
 
Please login to merge, or discard this patch.
redux-core/inc/fields/ace_editor/class-redux-ace-editor.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -13,45 +13,45 @@  discard block
 block discarded – undo
13 13
 // Don't duplicate me!
14 14
 if ( ! class_exists( 'Redux_Ace_Editor', false ) ) {
15 15
 
16
-	/**
17
-	 * Class Redux_Ace_Editor
18
-	 */
19
-	class Redux_Ace_Editor extends Redux_Field {
16
+    /**
17
+     * Class Redux_Ace_Editor
18
+     */
19
+    class Redux_Ace_Editor extends Redux_Field {
20 20
 
21
-		/**
22
-		 * Field Render Function.
23
-		 * Takes the vars and outputs the HTML for the field in the settings
24
-		 *
25
-		 * @since ReduxFramework 1.0.0
26
-		 */
27
-		public function render() {
28
-			if ( is_array( $this->value ) ) {
29
-				$this->value = '';
30
-			} else {
31
-				$this->value = trim( $this->value );
32
-			}
21
+        /**
22
+         * Field Render Function.
23
+         * Takes the vars and outputs the HTML for the field in the settings
24
+         *
25
+         * @since ReduxFramework 1.0.0
26
+         */
27
+        public function render() {
28
+            if ( is_array( $this->value ) ) {
29
+                $this->value = '';
30
+            } else {
31
+                $this->value = trim( $this->value );
32
+            }
33 33
 
34
-			if ( ! empty( $this->field['options'] ) ) {
35
-				$this->field['args'] = $this->field['options'];
36
-				unset( $this->field['options'] );
37
-			}
34
+            if ( ! empty( $this->field['options'] ) ) {
35
+                $this->field['args'] = $this->field['options'];
36
+                unset( $this->field['options'] );
37
+            }
38 38
 
39
-			if ( ! isset( $this->field['mode'] ) ) {
40
-				$this->field['mode'] = 'javascript';
41
-			}
42
-			if ( ! isset( $this->field['theme'] ) ) {
43
-				$this->field['theme'] = 'monokai';
44
-			}
39
+            if ( ! isset( $this->field['mode'] ) ) {
40
+                $this->field['mode'] = 'javascript';
41
+            }
42
+            if ( ! isset( $this->field['theme'] ) ) {
43
+                $this->field['theme'] = 'monokai';
44
+            }
45 45
 
46
-			$params = array(
47
-				'minLines' => 10,
48
-				'maxLines' => 30,
49
-			);
46
+            $params = array(
47
+                'minLines' => 10,
48
+                'maxLines' => 30,
49
+            );
50 50
 
51
-			if ( isset( $this->field['args'] ) && ! empty( $this->field['args'] ) && is_array( $this->field['args'] ) ) {
52
-				$params = wp_parse_args( $this->field['args'], $params );
53
-			}
54
-			?>
51
+            if ( isset( $this->field['args'] ) && ! empty( $this->field['args'] ) && is_array( $this->field['args'] ) ) {
52
+                $params = wp_parse_args( $this->field['args'], $params );
53
+            }
54
+            ?>
55 55
 			<div class="ace-wrapper">
56 56
 				<input
57 57
 					type="hidden"
@@ -70,46 +70,46 @@  discard block
 block discarded – undo
70 70
 					class="ace-editor-area"><?php echo esc_html( $this->value ); ?></pre>
71 71
 			</div>
72 72
 			<?php
73
-		}
73
+        }
74 74
 
75
-		/**
76
-		 * Enqueue Function.
77
-		 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
78
-		 *
79
-		 * @since       1.0.0
80
-		 * @access      public
81
-		 * @return      void
82
-		 */
83
-		public function enqueue() {
84
-			if ( $this->parent->args['dev_mode'] ) {
85
-				wp_enqueue_style(
86
-					'redux-field-ace-editor',
87
-					Redux_Core::$url . 'inc/fields/ace_editor/redux-ace-editor.css',
88
-					array(),
89
-					$this->timestamp
90
-				);
91
-			}
75
+        /**
76
+         * Enqueue Function.
77
+         * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
78
+         *
79
+         * @since       1.0.0
80
+         * @access      public
81
+         * @return      void
82
+         */
83
+        public function enqueue() {
84
+            if ( $this->parent->args['dev_mode'] ) {
85
+                wp_enqueue_style(
86
+                    'redux-field-ace-editor',
87
+                    Redux_Core::$url . 'inc/fields/ace_editor/redux-ace-editor.css',
88
+                    array(),
89
+                    $this->timestamp
90
+                );
91
+            }
92 92
 
93
-			if ( ! wp_script_is( 'ace-editor-js' ) ) {
94
-				wp_enqueue_script(
95
-					'ace-editor-js',
96
-					// phpcs:ignore Generic.Strings.UnnecessaryStringConcat, WordPress.NamingConventions.ValidHookName
97
-					apply_filters( 'redux/' . $this->parent->args['opt_name'] . 'fields/ace/script', '//' . 'cdnjs' . '.cloudflare' . '.com/ajax/libs/ace/1.43.0/ace.min.js' ),
98
-					array( 'jquery' ),
99
-					'1.43.0',
100
-					true
101
-				);
102
-			}
93
+            if ( ! wp_script_is( 'ace-editor-js' ) ) {
94
+                wp_enqueue_script(
95
+                    'ace-editor-js',
96
+                    // phpcs:ignore Generic.Strings.UnnecessaryStringConcat, WordPress.NamingConventions.ValidHookName
97
+                    apply_filters( 'redux/' . $this->parent->args['opt_name'] . 'fields/ace/script', '//' . 'cdnjs' . '.cloudflare' . '.com/ajax/libs/ace/1.43.0/ace.min.js' ),
98
+                    array( 'jquery' ),
99
+                    '1.43.0',
100
+                    true
101
+                );
102
+            }
103 103
 
104
-			wp_enqueue_script(
105
-				'redux-field-ace-editor',
106
-				Redux_Core::$url . 'inc/fields/ace_editor/redux-ace-editor' . Redux_Functions::is_min() . '.js',
107
-				array( 'jquery', 'ace-editor-js', 'redux-js' ),
108
-				$this->timestamp,
109
-				true
110
-			);
111
-		}
112
-	}
104
+            wp_enqueue_script(
105
+                'redux-field-ace-editor',
106
+                Redux_Core::$url . 'inc/fields/ace_editor/redux-ace-editor' . Redux_Functions::is_min() . '.js',
107
+                array( 'jquery', 'ace-editor-js', 'redux-js' ),
108
+                $this->timestamp,
109
+                true
110
+            );
111
+        }
112
+    }
113 113
 }
114 114
 
115 115
 class_alias( 'Redux_Ace_Editor', 'ReduxFramework_Ace_Editor' );
Please login to merge, or discard this patch.
class-redux-framework-plugin.php 1 patch
Indentation   +435 added lines, -435 removed lines patch added patch discarded remove patch
@@ -11,439 +11,439 @@
 block discarded – undo
11 11
 
12 12
 if ( ! class_exists( 'Redux_Framework_Plugin', false ) ) {
13 13
 
14
-	/**
15
-	 * Main Redux_Framework_Plugin class
16
-	 *
17
-	 * @since       3.0.0
18
-	 */
19
-	class Redux_Framework_Plugin {
20
-
21
-		/**
22
-		 * Option array for demo mode.
23
-		 *
24
-		 * @access      protected
25
-		 * @var         array $options Array of config options, used to check for demo mode
26
-		 * @since       3.0.0
27
-		 */
28
-		protected array $options = array();
29
-
30
-		/**
31
-		 * Use this value as the text domain when translating strings from this plugin. It should match
32
-		 * the Text Domain field set in the plugin header, as well as the directory name of the plugin.
33
-		 * Additionally, text domains should only contain letters, number and hyphens, not underscores
34
-		 * or spaces.
35
-		 *
36
-		 * @access      protected
37
-		 * @var         string $plugin_slug The unique ID (slug) of this plugin
38
-		 * @since       3.0.0
39
-		 */
40
-		protected string $plugin_slug = 'redux-framework';
41
-
42
-		/**
43
-		 * Set on network activate.
44
-		 *
45
-		 * @access      protected
46
-		 * @var         null|string $plugin_network_activated Check for plugin network activation
47
-		 * @since       3.0.0
48
-		 */
49
-		protected ?string $plugin_network_activated = null;
50
-
51
-		/**
52
-		 * Class instance.
53
-		 *
54
-		 * @access      private
55
-		 * @var         ?Redux_Framework_Plugin $instance The one true Redux_Framework_Plugin
56
-		 * @since       3.0.0
57
-		 */
58
-		private static ?Redux_Framework_Plugin $instance = null;
59
-
60
-		/**
61
-		 * Crash flag.
62
-		 *
63
-		 * @access      private
64
-		 * @var         Redux_Framework_Plugin $crash Crash flag if inside a crash.
65
-		 * @since       4.1.15
66
-		 */
67
-		public static $crash = false;
68
-
69
-		/**
70
-		 * Get active instance
71
-		 *
72
-		 * @access      public
73
-		 * @since       3.1.3
74
-		 * @return      self::$instance The one true Redux_Framework_Plugin
75
-		 */
76
-		public static function instance(): ?Redux_Framework_Plugin {
77
-			$path = REDUX_PLUGIN_FILE;
78
-			$res  = false;
79
-
80
-			if ( function_exists( 'get_plugin_data' ) && file_exists( $path ) ) {
81
-				$data = get_plugin_data( $path, true, false );
82
-
83
-				if ( isset( $data['Version'] ) && '' !== $data['Version'] ) {
84
-					$res = version_compare( $data['Version'], '4', '<' );
85
-				}
86
-
87
-				// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals -- active_plugins is a WP hook.
88
-				if ( true === $res && ! in_array( 'redux-framework/redux-framework.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
89
-					echo '<div class="error"><p>' . esc_html__( 'Redux Framework version 4 is activated but not loaded. Redux Framework version 3 is still installed and activated.  Please deactivate Redux Framework version 3.', 'redux-framework' ) . '</p></div>'; // phpcs:ignore WordPress.Security.EscapeOutput
90
-					return null;
91
-				}
92
-			}
93
-
94
-			if ( ! self::$instance ) {
95
-				self::$instance = new self();
96
-				if ( class_exists( 'ReduxFramework' ) ) {
97
-					self::$instance->load_first();
98
-				} else {
99
-					self::$instance->get_redux_options();
100
-					self::$instance->includes();
101
-					self::$instance->hooks();
102
-				}
103
-			}
104
-
105
-			return self::$instance;
106
-		}
107
-
108
-		/**
109
-		 * Shim for getting instance
110
-		 *
111
-		 * @access      public
112
-		 * @since       4.0.1
113
-		 * @return      self::$instance The one true Redux_Framework_Plugin
114
-		 */
115
-		public static function get_instance(): ?Redux_Framework_Plugin {
116
-			return self::instance();
117
-		}
118
-
119
-		/**
120
-		 * Get Redux options
121
-		 *
122
-		 * @access      public
123
-		 * @since       3.1.3
124
-		 * @return      void
125
-		 */
126
-		public function get_redux_options() {
127
-
128
-			// Setup defaults.
129
-			$defaults = array(
130
-				'demo' => false,
131
-			);
132
-
133
-			// If multisite is enabled.
134
-			if ( is_multisite() ) {
135
-
136
-				// Get network activated plugins.
137
-				$plugins = get_site_option( 'active_sitewide_plugins' );
138
-
139
-				foreach ( $plugins as $file => $plugin ) {
140
-					if ( strpos( $file, 'redux-framework.php' ) !== false ) {
141
-						$this->plugin_network_activated = true;
142
-						$this->options                  = get_site_option( 'ReduxFrameworkPlugin', $defaults );
143
-					}
144
-				}
145
-			}
146
-
147
-			// If options aren't set, grab them now!
148
-			if ( empty( $this->options ) ) {
149
-				$this->options = get_option( 'ReduxFrameworkPlugin', $defaults );
150
-			}
151
-		}
152
-
153
-		/**
154
-		 * Include the necessary files
155
-		 *
156
-		 * @access      public
157
-		 * @since       3.1.3
158
-		 * @return      void
159
-		 */
160
-		public function includes() {
161
-
162
-			// Include Redux_Core.
163
-			if ( file_exists( __DIR__ . '/redux-core/framework.php' ) ) {
164
-				require_once __DIR__ . '/redux-core/framework.php';
165
-			}
166
-
167
-			if ( file_exists( __DIR__ . '/redux-templates/redux-templates.php' ) ) {
168
-				require_once __DIR__ . '/redux-templates/redux-templates.php';
169
-			}
170
-
171
-			if ( isset( Redux_Core::$as_plugin ) ) {
172
-				Redux_Core::$as_plugin = true;
173
-			}
174
-
175
-			add_action( 'setup_theme', array( $this, 'load_sample_config' ) );
176
-		}
177
-
178
-		/**
179
-		 * Loads the sample config after everything is loaded.
180
-		 *
181
-		 * @access      public
182
-		 * @since       4.0.2
183
-		 * @return      void
184
-		 */
185
-		public function load_sample_config() {
186
-			// Include demo config, if demo mode is active.
187
-			if ( $this->options['demo'] && file_exists( __DIR__ . '/sample/sample-config.php' ) ) {
188
-				require_once __DIR__ . '/sample/sample-config.php';
189
-			}
190
-		}
191
-
192
-		/**
193
-		 * Run action and filter hooks
194
-		 *
195
-		 * @access      private
196
-		 * @since       3.1.3
197
-		 * @return      void
198
-		 */
199
-		private function hooks() {
200
-			add_action( 'activated_plugin', array( $this, 'load_first' ) );
201
-			add_action( 'wp_loaded', array( $this, 'options_toggle_check' ) );
202
-
203
-			// Activate plugin when a new blog is added.
204
-			add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
205
-
206
-			// Display admin notices.
207
-			add_action( 'admin_notices', array( $this, 'admin_notices' ) );
208
-
209
-			// Edit plugin metalinks.
210
-			add_filter( 'plugin_row_meta', array( $this, 'plugin_metalinks' ), null, 2 );
211
-			add_filter( 'network_admin_plugin_action_links', array( $this, 'add_settings_link' ), 1, 2 );
212
-			add_filter( 'plugin_action_links', array( $this, 'add_settings_link' ), 1, 2 );
213
-
214
-			// phpcs:ignore WordPress.NamingConventions.ValidHookName
215
-			do_action( 'redux/plugin/hooks', $this );
216
-		}
217
-
218
-		/**
219
-		 * Pushes Redux to the top of plugin load list, so it initializes before any plugin that may use it.
220
-		 */
221
-		public function load_first() {
222
-			if ( ! class_exists( 'Redux_Functions_Ex' ) ) {
223
-				require_once __DIR__ . '/redux-core/inc/classes/class-redux-functions-ex.php';
224
-			}
225
-
226
-			$plugin_dir = Redux_Functions_Ex::wp_normalize_path( WP_PLUGIN_DIR ) . '/';
227
-			$self_file  = Redux_Functions_Ex::wp_normalize_path( __FILE__ );
228
-
229
-			$path = str_replace( $plugin_dir, '', $self_file );
230
-			$path = str_replace( 'class-redux-framework-plugin.php', 'redux-framework.php', $path );
231
-
232
-			$plugins = get_option( 'active_plugins' );
233
-
234
-			if ( $plugins ) {
235
-				$key = array_search( $path, $plugins, true );
236
-
237
-				if ( false !== $key ) {
238
-					array_splice( $plugins, $key, 1 );
239
-					array_unshift( $plugins, $path );
240
-					update_option( 'active_plugins', $plugins );
241
-				}
242
-			}
243
-		}
244
-
245
-		/**
246
-		 * Fired on plugin activation
247
-		 *
248
-		 * @access      public
249
-		 * @return      void
250
-		 * @since       3.0.0
251
-		 */
252
-		public static function activate() {
253
-			delete_site_transient( 'update_plugins' );
254
-		}
255
-
256
-		/**
257
-		 * Fired when plugin is deactivated
258
-		 *
259
-		 * @access      public
260
-		 * @since       3.0.0
261
-		 *
262
-		 * @param       boolean $network_wide True if plugin is network activated, false otherwise.
263
-		 *
264
-		 * @return      void
265
-		 */
266
-		public static function deactivate( ?bool $network_wide ) {
267
-			if ( function_exists( 'is_multisite' ) && is_multisite() ) {
268
-				if ( $network_wide ) {
269
-					// Get all blog IDs.
270
-					$blog_ids = self::get_blog_ids();
271
-
272
-					foreach ( $blog_ids as $blog_id ) {
273
-						switch_to_blog( $blog_id );
274
-						self::single_deactivate();
275
-					}
276
-					restore_current_blog();
277
-				} else {
278
-					self::single_deactivate();
279
-				}
280
-			} else {
281
-				self::single_deactivate();
282
-			}
283
-
284
-			delete_option( 'ReduxFrameworkPlugin' );
285
-		}
286
-
287
-		/**
288
-		 * Fired when a new WPMU site is activated
289
-		 *
290
-		 * @access      public
291
-		 *
292
-		 * @param       int $blog_id The ID of the new blog.
293
-		 *
294
-		 * @return      void
295
-		 * @since       3.0.0
296
-		 */
297
-		public function activate_new_site( int $blog_id ) {
298
-			if ( 1 !== did_action( 'wpmu_new_blog' ) ) {
299
-				return;
300
-			}
301
-
302
-			switch_to_blog( $blog_id );
303
-			self::single_activate();
304
-			restore_current_blog();
305
-		}
306
-
307
-		/**
308
-		 * Get all IDs of blogs that are not activated, not spam, and not deleted
309
-		 *
310
-		 * @access      private
311
-		 * @since       3.0.0
312
-		 * @global      object $wpdb
313
-		 * @return      array|false Array of IDs or false if none are found
314
-		 */
315
-		private static function get_blog_ids() {
316
-			global $wpdb;
317
-
318
-			$var = '0';
319
-
320
-			// Get an array of IDs (We have to do it this way because WordPress says so, however redundant).
321
-			$result = wp_cache_get( 'redux-blog-ids' );
322
-			if ( false === $result ) {
323
-
324
-				// WordPress says get_col is discouraged?  I found no alternative.  So...ignore! - kp.
325
-				// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
326
-				$result = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE archived = %s AND spam = %s AND deleted = %s", $var, $var, $var ) );
327
-
328
-				wp_cache_set( 'redux-blog-ids', $result );
329
-			}
330
-
331
-			return $result;
332
-		}
333
-
334
-		/**
335
-		 * Fired for each WPMS blog on plugin activation
336
-		 *
337
-		 * @access      private
338
-		 * @since       3.0.0
339
-		 * @return      void
340
-		 */
341
-		private static function single_activate() {
342
-			$nonce = wp_create_nonce( 'redux_framework_demo' );
343
-
344
-			$notices   = get_option( 'ReduxFrameworkPlugin_ACTIVATED_NOTICES', array() );
345
-			$notices[] = esc_html__( 'Redux Framework has an embedded demo.', 'redux-framework' ) . ' <a href="./plugins.php?redux-framework-plugin=demo&nonce=' . $nonce . '">' . esc_html__( 'Click here to activate the sample config file.', 'redux-framework' ) . '</a>';
346
-
347
-			update_option( 'ReduxFrameworkPlugin_ACTIVATED_NOTICES', $notices );
348
-		}
349
-
350
-		/**
351
-		 * Display admin notices
352
-		 *
353
-		 * @access      public
354
-		 * @since       3.0.0
355
-		 * @return      void
356
-		 */
357
-		public function admin_notices() {
358
-			do_action( 'redux_framework_plugin_admin_notice' );
359
-			$notices = get_option( 'ReduxFrameworkPlugin_ACTIVATED_NOTICES', '' );
360
-			if ( ! empty( $notices ) ) {
361
-				foreach ( $notices as $notice ) {
362
-					echo '<div class="updated notice is-dismissible"><p>' . $notice . '</p></div>'; // phpcs:ignore WordPress.Security.EscapeOutput
363
-				}
364
-
365
-				delete_option( 'ReduxFrameworkPlugin_ACTIVATED_NOTICES' );
366
-			}
367
-		}
368
-
369
-		/**
370
-		 * Fired for each blog when the plugin is deactivated
371
-		 *
372
-		 * @access      private
373
-		 * @since       3.0.0
374
-		 * @return      void
375
-		 */
376
-		private static function single_deactivate() {
377
-			delete_option( 'ReduxFrameworkPlugin_ACTIVATED_NOTICES' );
378
-		}
379
-
380
-		/**
381
-		 * Turn on or off
382
-		 *
383
-		 * @access      public
384
-		 * @since       3.0.0
385
-		 * @return      void
386
-		 */
387
-		public function options_toggle_check() {
388
-			if ( isset( $_GET['nonce'] ) && wp_verify_nonce( sanitize_key( $_GET['nonce'] ), 'redux_framework_demo' ) ) {
389
-				if ( isset( $_GET['redux-framework-plugin'] ) && 'demo' === $_GET['redux-framework-plugin'] ) {
390
-					$url = admin_url( add_query_arg( array( 'page' => 'redux-framework' ), 'options-general.php' ) );
391
-
392
-					if ( false === $this->options['demo'] ) {
393
-						$this->options['demo'] = true;
394
-						$url                   = admin_url( add_query_arg( array( 'page' => 'redux_demo' ), 'admin.php' ) );
395
-					} else {
396
-						$this->options['demo'] = false;
397
-					}
398
-
399
-					if ( is_multisite() && $this->plugin_network_activated ) {
400
-						update_site_option( 'ReduxFrameworkPlugin', $this->options );
401
-					} else {
402
-						update_option( 'ReduxFrameworkPlugin', $this->options );
403
-					}
404
-
405
-					wp_safe_redirect( esc_url( $url ) );
406
-
407
-					exit();
408
-				}
409
-			}
410
-		}
411
-
412
-
413
-		/**
414
-		 * Add a settings link to the Redux entry in the plugin overview screen
415
-		 *
416
-		 * @param array $links Links array.
417
-		 *
418
-		 * @return array
419
-		 * @see   filter:plugin_action_links
420
-		 * @since 1.0
421
-		 */
422
-		public function add_settings_link( array $links ): array {
423
-			return $links;
424
-		}
425
-
426
-		/**
427
-		 * Edit plugin metalinks
428
-		 *
429
-		 * @access      public
430
-		 *
431
-		 * @param array  $links The current array of links.
432
-		 * @param string $file  A specific plugin row.
433
-		 *
434
-		 * @return      array The modified array of links
435
-		 * @since       3.0.0
436
-		 */
437
-		public function plugin_metalinks( array $links, string $file ): array {
438
-			if ( strpos( $file, 'redux-framework.php' ) !== false && is_plugin_active( $file ) ) {
439
-				$links[] = '<a href="' . esc_url( admin_url( add_query_arg( array( 'page' => 'redux-framework' ), 'options-general.php' ) ) ) . '">' . esc_html__( 'What is this?', 'redux-framework' ) . '</a>';
440
-			}
441
-
442
-			return $links;
443
-		}
444
-	}
445
-
446
-	if ( ! class_exists( 'ReduxFrameworkPlugin' ) ) {
447
-		class_alias( 'Redux_Framework_Plugin', 'ReduxFrameworkPlugin' );
448
-	}
14
+    /**
15
+     * Main Redux_Framework_Plugin class
16
+     *
17
+     * @since       3.0.0
18
+     */
19
+    class Redux_Framework_Plugin {
20
+
21
+        /**
22
+         * Option array for demo mode.
23
+         *
24
+         * @access      protected
25
+         * @var         array $options Array of config options, used to check for demo mode
26
+         * @since       3.0.0
27
+         */
28
+        protected array $options = array();
29
+
30
+        /**
31
+         * Use this value as the text domain when translating strings from this plugin. It should match
32
+         * the Text Domain field set in the plugin header, as well as the directory name of the plugin.
33
+         * Additionally, text domains should only contain letters, number and hyphens, not underscores
34
+         * or spaces.
35
+         *
36
+         * @access      protected
37
+         * @var         string $plugin_slug The unique ID (slug) of this plugin
38
+         * @since       3.0.0
39
+         */
40
+        protected string $plugin_slug = 'redux-framework';
41
+
42
+        /**
43
+         * Set on network activate.
44
+         *
45
+         * @access      protected
46
+         * @var         null|string $plugin_network_activated Check for plugin network activation
47
+         * @since       3.0.0
48
+         */
49
+        protected ?string $plugin_network_activated = null;
50
+
51
+        /**
52
+         * Class instance.
53
+         *
54
+         * @access      private
55
+         * @var         ?Redux_Framework_Plugin $instance The one true Redux_Framework_Plugin
56
+         * @since       3.0.0
57
+         */
58
+        private static ?Redux_Framework_Plugin $instance = null;
59
+
60
+        /**
61
+         * Crash flag.
62
+         *
63
+         * @access      private
64
+         * @var         Redux_Framework_Plugin $crash Crash flag if inside a crash.
65
+         * @since       4.1.15
66
+         */
67
+        public static $crash = false;
68
+
69
+        /**
70
+         * Get active instance
71
+         *
72
+         * @access      public
73
+         * @since       3.1.3
74
+         * @return      self::$instance The one true Redux_Framework_Plugin
75
+         */
76
+        public static function instance(): ?Redux_Framework_Plugin {
77
+            $path = REDUX_PLUGIN_FILE;
78
+            $res  = false;
79
+
80
+            if ( function_exists( 'get_plugin_data' ) && file_exists( $path ) ) {
81
+                $data = get_plugin_data( $path, true, false );
82
+
83
+                if ( isset( $data['Version'] ) && '' !== $data['Version'] ) {
84
+                    $res = version_compare( $data['Version'], '4', '<' );
85
+                }
86
+
87
+                // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals -- active_plugins is a WP hook.
88
+                if ( true === $res && ! in_array( 'redux-framework/redux-framework.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
89
+                    echo '<div class="error"><p>' . esc_html__( 'Redux Framework version 4 is activated but not loaded. Redux Framework version 3 is still installed and activated.  Please deactivate Redux Framework version 3.', 'redux-framework' ) . '</p></div>'; // phpcs:ignore WordPress.Security.EscapeOutput
90
+                    return null;
91
+                }
92
+            }
93
+
94
+            if ( ! self::$instance ) {
95
+                self::$instance = new self();
96
+                if ( class_exists( 'ReduxFramework' ) ) {
97
+                    self::$instance->load_first();
98
+                } else {
99
+                    self::$instance->get_redux_options();
100
+                    self::$instance->includes();
101
+                    self::$instance->hooks();
102
+                }
103
+            }
104
+
105
+            return self::$instance;
106
+        }
107
+
108
+        /**
109
+         * Shim for getting instance
110
+         *
111
+         * @access      public
112
+         * @since       4.0.1
113
+         * @return      self::$instance The one true Redux_Framework_Plugin
114
+         */
115
+        public static function get_instance(): ?Redux_Framework_Plugin {
116
+            return self::instance();
117
+        }
118
+
119
+        /**
120
+         * Get Redux options
121
+         *
122
+         * @access      public
123
+         * @since       3.1.3
124
+         * @return      void
125
+         */
126
+        public function get_redux_options() {
127
+
128
+            // Setup defaults.
129
+            $defaults = array(
130
+                'demo' => false,
131
+            );
132
+
133
+            // If multisite is enabled.
134
+            if ( is_multisite() ) {
135
+
136
+                // Get network activated plugins.
137
+                $plugins = get_site_option( 'active_sitewide_plugins' );
138
+
139
+                foreach ( $plugins as $file => $plugin ) {
140
+                    if ( strpos( $file, 'redux-framework.php' ) !== false ) {
141
+                        $this->plugin_network_activated = true;
142
+                        $this->options                  = get_site_option( 'ReduxFrameworkPlugin', $defaults );
143
+                    }
144
+                }
145
+            }
146
+
147
+            // If options aren't set, grab them now!
148
+            if ( empty( $this->options ) ) {
149
+                $this->options = get_option( 'ReduxFrameworkPlugin', $defaults );
150
+            }
151
+        }
152
+
153
+        /**
154
+         * Include the necessary files
155
+         *
156
+         * @access      public
157
+         * @since       3.1.3
158
+         * @return      void
159
+         */
160
+        public function includes() {
161
+
162
+            // Include Redux_Core.
163
+            if ( file_exists( __DIR__ . '/redux-core/framework.php' ) ) {
164
+                require_once __DIR__ . '/redux-core/framework.php';
165
+            }
166
+
167
+            if ( file_exists( __DIR__ . '/redux-templates/redux-templates.php' ) ) {
168
+                require_once __DIR__ . '/redux-templates/redux-templates.php';
169
+            }
170
+
171
+            if ( isset( Redux_Core::$as_plugin ) ) {
172
+                Redux_Core::$as_plugin = true;
173
+            }
174
+
175
+            add_action( 'setup_theme', array( $this, 'load_sample_config' ) );
176
+        }
177
+
178
+        /**
179
+         * Loads the sample config after everything is loaded.
180
+         *
181
+         * @access      public
182
+         * @since       4.0.2
183
+         * @return      void
184
+         */
185
+        public function load_sample_config() {
186
+            // Include demo config, if demo mode is active.
187
+            if ( $this->options['demo'] && file_exists( __DIR__ . '/sample/sample-config.php' ) ) {
188
+                require_once __DIR__ . '/sample/sample-config.php';
189
+            }
190
+        }
191
+
192
+        /**
193
+         * Run action and filter hooks
194
+         *
195
+         * @access      private
196
+         * @since       3.1.3
197
+         * @return      void
198
+         */
199
+        private function hooks() {
200
+            add_action( 'activated_plugin', array( $this, 'load_first' ) );
201
+            add_action( 'wp_loaded', array( $this, 'options_toggle_check' ) );
202
+
203
+            // Activate plugin when a new blog is added.
204
+            add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
205
+
206
+            // Display admin notices.
207
+            add_action( 'admin_notices', array( $this, 'admin_notices' ) );
208
+
209
+            // Edit plugin metalinks.
210
+            add_filter( 'plugin_row_meta', array( $this, 'plugin_metalinks' ), null, 2 );
211
+            add_filter( 'network_admin_plugin_action_links', array( $this, 'add_settings_link' ), 1, 2 );
212
+            add_filter( 'plugin_action_links', array( $this, 'add_settings_link' ), 1, 2 );
213
+
214
+            // phpcs:ignore WordPress.NamingConventions.ValidHookName
215
+            do_action( 'redux/plugin/hooks', $this );
216
+        }
217
+
218
+        /**
219
+         * Pushes Redux to the top of plugin load list, so it initializes before any plugin that may use it.
220
+         */
221
+        public function load_first() {
222
+            if ( ! class_exists( 'Redux_Functions_Ex' ) ) {
223
+                require_once __DIR__ . '/redux-core/inc/classes/class-redux-functions-ex.php';
224
+            }
225
+
226
+            $plugin_dir = Redux_Functions_Ex::wp_normalize_path( WP_PLUGIN_DIR ) . '/';
227
+            $self_file  = Redux_Functions_Ex::wp_normalize_path( __FILE__ );
228
+
229
+            $path = str_replace( $plugin_dir, '', $self_file );
230
+            $path = str_replace( 'class-redux-framework-plugin.php', 'redux-framework.php', $path );
231
+
232
+            $plugins = get_option( 'active_plugins' );
233
+
234
+            if ( $plugins ) {
235
+                $key = array_search( $path, $plugins, true );
236
+
237
+                if ( false !== $key ) {
238
+                    array_splice( $plugins, $key, 1 );
239
+                    array_unshift( $plugins, $path );
240
+                    update_option( 'active_plugins', $plugins );
241
+                }
242
+            }
243
+        }
244
+
245
+        /**
246
+         * Fired on plugin activation
247
+         *
248
+         * @access      public
249
+         * @return      void
250
+         * @since       3.0.0
251
+         */
252
+        public static function activate() {
253
+            delete_site_transient( 'update_plugins' );
254
+        }
255
+
256
+        /**
257
+         * Fired when plugin is deactivated
258
+         *
259
+         * @access      public
260
+         * @since       3.0.0
261
+         *
262
+         * @param       boolean $network_wide True if plugin is network activated, false otherwise.
263
+         *
264
+         * @return      void
265
+         */
266
+        public static function deactivate( ?bool $network_wide ) {
267
+            if ( function_exists( 'is_multisite' ) && is_multisite() ) {
268
+                if ( $network_wide ) {
269
+                    // Get all blog IDs.
270
+                    $blog_ids = self::get_blog_ids();
271
+
272
+                    foreach ( $blog_ids as $blog_id ) {
273
+                        switch_to_blog( $blog_id );
274
+                        self::single_deactivate();
275
+                    }
276
+                    restore_current_blog();
277
+                } else {
278
+                    self::single_deactivate();
279
+                }
280
+            } else {
281
+                self::single_deactivate();
282
+            }
283
+
284
+            delete_option( 'ReduxFrameworkPlugin' );
285
+        }
286
+
287
+        /**
288
+         * Fired when a new WPMU site is activated
289
+         *
290
+         * @access      public
291
+         *
292
+         * @param       int $blog_id The ID of the new blog.
293
+         *
294
+         * @return      void
295
+         * @since       3.0.0
296
+         */
297
+        public function activate_new_site( int $blog_id ) {
298
+            if ( 1 !== did_action( 'wpmu_new_blog' ) ) {
299
+                return;
300
+            }
301
+
302
+            switch_to_blog( $blog_id );
303
+            self::single_activate();
304
+            restore_current_blog();
305
+        }
306
+
307
+        /**
308
+         * Get all IDs of blogs that are not activated, not spam, and not deleted
309
+         *
310
+         * @access      private
311
+         * @since       3.0.0
312
+         * @global      object $wpdb
313
+         * @return      array|false Array of IDs or false if none are found
314
+         */
315
+        private static function get_blog_ids() {
316
+            global $wpdb;
317
+
318
+            $var = '0';
319
+
320
+            // Get an array of IDs (We have to do it this way because WordPress says so, however redundant).
321
+            $result = wp_cache_get( 'redux-blog-ids' );
322
+            if ( false === $result ) {
323
+
324
+                // WordPress says get_col is discouraged?  I found no alternative.  So...ignore! - kp.
325
+                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
326
+                $result = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE archived = %s AND spam = %s AND deleted = %s", $var, $var, $var ) );
327
+
328
+                wp_cache_set( 'redux-blog-ids', $result );
329
+            }
330
+
331
+            return $result;
332
+        }
333
+
334
+        /**
335
+         * Fired for each WPMS blog on plugin activation
336
+         *
337
+         * @access      private
338
+         * @since       3.0.0
339
+         * @return      void
340
+         */
341
+        private static function single_activate() {
342
+            $nonce = wp_create_nonce( 'redux_framework_demo' );
343
+
344
+            $notices   = get_option( 'ReduxFrameworkPlugin_ACTIVATED_NOTICES', array() );
345
+            $notices[] = esc_html__( 'Redux Framework has an embedded demo.', 'redux-framework' ) . ' <a href="./plugins.php?redux-framework-plugin=demo&nonce=' . $nonce . '">' . esc_html__( 'Click here to activate the sample config file.', 'redux-framework' ) . '</a>';
346
+
347
+            update_option( 'ReduxFrameworkPlugin_ACTIVATED_NOTICES', $notices );
348
+        }
349
+
350
+        /**
351
+         * Display admin notices
352
+         *
353
+         * @access      public
354
+         * @since       3.0.0
355
+         * @return      void
356
+         */
357
+        public function admin_notices() {
358
+            do_action( 'redux_framework_plugin_admin_notice' );
359
+            $notices = get_option( 'ReduxFrameworkPlugin_ACTIVATED_NOTICES', '' );
360
+            if ( ! empty( $notices ) ) {
361
+                foreach ( $notices as $notice ) {
362
+                    echo '<div class="updated notice is-dismissible"><p>' . $notice . '</p></div>'; // phpcs:ignore WordPress.Security.EscapeOutput
363
+                }
364
+
365
+                delete_option( 'ReduxFrameworkPlugin_ACTIVATED_NOTICES' );
366
+            }
367
+        }
368
+
369
+        /**
370
+         * Fired for each blog when the plugin is deactivated
371
+         *
372
+         * @access      private
373
+         * @since       3.0.0
374
+         * @return      void
375
+         */
376
+        private static function single_deactivate() {
377
+            delete_option( 'ReduxFrameworkPlugin_ACTIVATED_NOTICES' );
378
+        }
379
+
380
+        /**
381
+         * Turn on or off
382
+         *
383
+         * @access      public
384
+         * @since       3.0.0
385
+         * @return      void
386
+         */
387
+        public function options_toggle_check() {
388
+            if ( isset( $_GET['nonce'] ) && wp_verify_nonce( sanitize_key( $_GET['nonce'] ), 'redux_framework_demo' ) ) {
389
+                if ( isset( $_GET['redux-framework-plugin'] ) && 'demo' === $_GET['redux-framework-plugin'] ) {
390
+                    $url = admin_url( add_query_arg( array( 'page' => 'redux-framework' ), 'options-general.php' ) );
391
+
392
+                    if ( false === $this->options['demo'] ) {
393
+                        $this->options['demo'] = true;
394
+                        $url                   = admin_url( add_query_arg( array( 'page' => 'redux_demo' ), 'admin.php' ) );
395
+                    } else {
396
+                        $this->options['demo'] = false;
397
+                    }
398
+
399
+                    if ( is_multisite() && $this->plugin_network_activated ) {
400
+                        update_site_option( 'ReduxFrameworkPlugin', $this->options );
401
+                    } else {
402
+                        update_option( 'ReduxFrameworkPlugin', $this->options );
403
+                    }
404
+
405
+                    wp_safe_redirect( esc_url( $url ) );
406
+
407
+                    exit();
408
+                }
409
+            }
410
+        }
411
+
412
+
413
+        /**
414
+         * Add a settings link to the Redux entry in the plugin overview screen
415
+         *
416
+         * @param array $links Links array.
417
+         *
418
+         * @return array
419
+         * @see   filter:plugin_action_links
420
+         * @since 1.0
421
+         */
422
+        public function add_settings_link( array $links ): array {
423
+            return $links;
424
+        }
425
+
426
+        /**
427
+         * Edit plugin metalinks
428
+         *
429
+         * @access      public
430
+         *
431
+         * @param array  $links The current array of links.
432
+         * @param string $file  A specific plugin row.
433
+         *
434
+         * @return      array The modified array of links
435
+         * @since       3.0.0
436
+         */
437
+        public function plugin_metalinks( array $links, string $file ): array {
438
+            if ( strpos( $file, 'redux-framework.php' ) !== false && is_plugin_active( $file ) ) {
439
+                $links[] = '<a href="' . esc_url( admin_url( add_query_arg( array( 'page' => 'redux-framework' ), 'options-general.php' ) ) ) . '">' . esc_html__( 'What is this?', 'redux-framework' ) . '</a>';
440
+            }
441
+
442
+            return $links;
443
+        }
444
+    }
445
+
446
+    if ( ! class_exists( 'ReduxFrameworkPlugin' ) ) {
447
+        class_alias( 'Redux_Framework_Plugin', 'ReduxFrameworkPlugin' );
448
+    }
449 449
 }
Please login to merge, or discard this patch.