Completed
Push — master ( 316c10...cbdcdc )
by Devin
19:15
created
includes/admin/settings/class-settings-cmb2-backward-compatibility.php 1 patch
Spacing   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @since       1.8
10 10
  */
11 11
 
12
-if ( ! class_exists( 'Give_CMB2_Settings_Loader' ) ) :
12
+if ( ! class_exists('Give_CMB2_Settings_Loader')) :
13 13
 
14 14
 	/**
15 15
 	 * This class loads the cmb2 settings.
@@ -52,30 +52,30 @@  discard block
 block discarded – undo
52 52
 
53 53
 			// Get current tab.
54 54
 			$this->current_tab     = give_get_current_setting_tab();
55
-			$this->current_section = empty( $_REQUEST['section'] ) ? ( current( array_keys( $this->get_sections() ) ) ) : sanitize_title( $_REQUEST['section'] );
55
+			$this->current_section = empty($_REQUEST['section']) ? (current(array_keys($this->get_sections()))) : sanitize_title($_REQUEST['section']);
56 56
 
57 57
 			// Tab ID.
58 58
 			$this->id = $this->current_tab;
59 59
 
60 60
 			// Add addon tabs.
61
-			add_filter( 'give-settings_tabs_array', array( $this, 'add_addon_settings_page' ), 999999 );
61
+			add_filter('give-settings_tabs_array', array($this, 'add_addon_settings_page'), 999999);
62 62
 
63 63
 			// Add save hook to addons.
64
-			add_action( 'give-settings_get_settings_pages', array( $this, 'setup_addon_save_hook' ), 999999 );
64
+			add_action('give-settings_get_settings_pages', array($this, 'setup_addon_save_hook'), 999999);
65 65
 
66 66
 			// Add backward compatibility filters plugin settings.
67
-			$setting_tabs = array( 'general', 'gateways', 'display', 'emails', 'addons', 'licenses' );
67
+			$setting_tabs = array('general', 'gateways', 'display', 'emails', 'addons', 'licenses');
68 68
 
69 69
 			// Filter Payment Gateways settings.
70
-			if ( in_array( $this->current_tab, $setting_tabs ) ) {
71
-				add_filter( "give_get_settings_{$this->current_tab}", array(
70
+			if (in_array($this->current_tab, $setting_tabs)) {
71
+				add_filter("give_get_settings_{$this->current_tab}", array(
72 72
 					$this,
73 73
 					'get_filtered_addon_settings',
74
-				), 999999, 1 );
75
-				add_filter( "give_get_sections_{$this->current_tab}", array(
74
+				), 999999, 1);
75
+				add_filter("give_get_sections_{$this->current_tab}", array(
76 76
 					$this,
77 77
 					'get_filtered_addon_sections',
78
-				), 999999, 1 );
78
+				), 999999, 1);
79 79
 			}
80 80
 		}
81 81
 
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
 		 *
89 89
 		 * @return string
90 90
 		 */
91
-		function set_default_setting_tab( $setting_tab ) {
91
+		function set_default_setting_tab($setting_tab) {
92 92
 			$default_tab = '';
93 93
 
94 94
 			// Set default tab to first setting tab.
95
-			if ( $sections = array_keys( $this->get_sections() ) ) {
96
-				$default_tab = current( $sections );
95
+			if ($sections = array_keys($this->get_sections())) {
96
+				$default_tab = current($sections);
97 97
 			}
98 98
 
99 99
 			return $default_tab;
@@ -108,29 +108,29 @@  discard block
 block discarded – undo
108 108
 		 *
109 109
 		 * @return mixed
110 110
 		 */
111
-		function add_addon_settings_page( $pages ) {
111
+		function add_addon_settings_page($pages) {
112 112
 			// Previous setting page.
113 113
 			$previous_pages = $this->prev_settings->give_get_settings_tabs();
114 114
 
115 115
 			// API and System Info setting tab merge to Tools setting tab, so remove them from tabs.
116
-			unset( $previous_pages['api'] );
117
-			unset( $previous_pages['system_info'] );
116
+			unset($previous_pages['api']);
117
+			unset($previous_pages['system_info']);
118 118
 
119 119
 			// Tab is not register.
120
-			$pages_diff = array_keys( array_diff( $previous_pages, $pages ) );
120
+			$pages_diff = array_keys(array_diff($previous_pages, $pages));
121 121
 
122 122
 			// Merge old settings with new settings.
123
-			$pages = array_merge( $pages, $previous_pages );
123
+			$pages = array_merge($pages, $previous_pages);
124 124
 
125
-			if ( in_array( $this->current_tab, $pages_diff ) ) {
125
+			if (in_array($this->current_tab, $pages_diff)) {
126 126
 				// Filter & actions.
127
-				add_filter( "give_default_setting_tab_section_{$this->current_tab}", array(
127
+				add_filter("give_default_setting_tab_section_{$this->current_tab}", array(
128 128
 					$this,
129 129
 					'set_default_setting_tab',
130
-				), 10 );
131
-				add_action( "give-settings_sections_{$this->current_tab}_page", array( $this, 'output_sections' ) );
132
-				add_action( "give-settings_settings_{$this->current_tab}_page", array( $this, 'output' ), 10 );
133
-				add_action( "give-settings_save_{$this->current_tab}", array( $this, 'save' ) );
130
+				), 10);
131
+				add_action("give-settings_sections_{$this->current_tab}_page", array($this, 'output_sections'));
132
+				add_action("give-settings_settings_{$this->current_tab}_page", array($this, 'output'), 10);
133
+				add_action("give-settings_save_{$this->current_tab}", array($this, 'save'));
134 134
 			}
135 135
 
136 136
 			return $pages;
@@ -146,29 +146,29 @@  discard block
 block discarded – undo
146 146
 		 *
147 147
 		 * @return mixed
148 148
 		 */
149
-		function setup_addon_save_hook( $pages ) {
149
+		function setup_addon_save_hook($pages) {
150 150
 			$page_ids = array();
151 151
 
152
-			foreach ( $pages as $page ) {
153
-				$page_ids = $page->add_settings_page( $page_ids );
152
+			foreach ($pages as $page) {
153
+				$page_ids = $page->add_settings_page($page_ids);
154 154
 			}
155 155
 
156 156
 			// Previous setting page.
157 157
 			$previous_pages = $this->prev_settings->give_get_settings_tabs();
158 158
 
159 159
 			// API and System Info setting tab merge to Tools setting tab, so remove them from tabs.
160
-			unset( $previous_pages['api'] );
161
-			unset( $previous_pages['system_info'] );
160
+			unset($previous_pages['api']);
161
+			unset($previous_pages['system_info']);
162 162
 
163 163
 			// Tab is not register.
164
-			$pages_diff = array_keys( array_diff( $previous_pages, $page_ids ) );
164
+			$pages_diff = array_keys(array_diff($previous_pages, $page_ids));
165 165
 
166 166
 			// Merge old settings with new settings.
167
-			$pages = array_merge( $page_ids, $previous_pages );
167
+			$pages = array_merge($page_ids, $previous_pages);
168 168
 
169
-			if ( in_array( $this->current_tab, $pages_diff ) ) {
169
+			if (in_array($this->current_tab, $pages_diff)) {
170 170
 				// Filter & actions.
171
-				add_action( "give-settings_save_{$this->current_tab}", array( $this, 'save' ) );
171
+				add_action("give-settings_save_{$this->current_tab}", array($this, 'save'));
172 172
 			}
173 173
 
174 174
 			return $pages;
@@ -183,16 +183,16 @@  discard block
 block discarded – undo
183 183
 		 *
184 184
 		 * @return string
185 185
 		 */
186
-		function get_section_name( $field_name ) {
186
+		function get_section_name($field_name) {
187 187
 			// Bailout.
188
-			if ( empty( $field_name ) ) {
188
+			if (empty($field_name)) {
189 189
 				return $field_name;
190 190
 			}
191 191
 
192
-			$section_name = explode( ' ', $field_name );
192
+			$section_name = explode(' ', $field_name);
193 193
 
194 194
 			// Output.
195
-			return strip_tags( implode( ' ', $section_name ) );
195
+			return strip_tags(implode(' ', $section_name));
196 196
 		}
197 197
 
198 198
 
@@ -205,39 +205,39 @@  discard block
 block discarded – undo
205 205
 		 *
206 206
 		 * @return mixed
207 207
 		 */
208
-		function get_filtered_addon_sections( $sections = array() ) {
208
+		function get_filtered_addon_sections($sections = array()) {
209 209
 			// New sections.
210 210
 			$new_sections = array();
211
-			$sections_ID  = array_keys( $sections );
211
+			$sections_ID  = array_keys($sections);
212 212
 
213
-			if ( ( $setting_fields = $this->prev_settings->give_settings( $this->current_tab ) ) && ! empty( $setting_fields['fields'] ) ) {
213
+			if (($setting_fields = $this->prev_settings->give_settings($this->current_tab)) && ! empty($setting_fields['fields'])) {
214 214
 
215
-				foreach ( $setting_fields['fields'] as $field ) {
215
+				foreach ($setting_fields['fields'] as $field) {
216 216
 					// Section name.
217
-					$field['name'] = isset( $field['name'] ) ? $field['name'] : '';
218
-					$section_name  = $this->get_section_name( $field['name'] );
217
+					$field['name'] = isset($field['name']) ? $field['name'] : '';
218
+					$section_name  = $this->get_section_name($field['name']);
219 219
 
220 220
 					// Check if section name exit and section title array is not empty.
221
-					if ( ! empty( $sections ) && ! empty( $field['name'] ) ) {
221
+					if ( ! empty($sections) && ! empty($field['name'])) {
222 222
 
223 223
 						// Bailout: Do not load section if it is already exist.
224 224
 						if (
225
-							in_array( sanitize_title( $field['name'] ), $sections_ID ) // Check section id.
226
-							|| in_array( $section_name, $sections )                    // Check section name.
225
+							in_array(sanitize_title($field['name']), $sections_ID) // Check section id.
226
+							|| in_array($section_name, $sections)                    // Check section name.
227 227
 						) {
228 228
 							continue;
229 229
 						}
230 230
 					}
231 231
 
232 232
 					// Collect new sections from addons.
233
-					if ( 'give_title' == $field['type'] ) {
234
-						$new_sections[ sanitize_title( $field['name'] ) ] = $section_name;
233
+					if ('give_title' == $field['type']) {
234
+						$new_sections[sanitize_title($field['name'])] = $section_name;
235 235
 					}
236 236
 				}
237 237
 			}
238 238
 
239 239
 			// Add new section.
240
-			$sections = array_merge( $sections, $new_sections );
240
+			$sections = array_merge($sections, $new_sections);
241 241
 
242 242
 			// Output.
243 243
 			return $sections;
@@ -254,19 +254,19 @@  discard block
 block discarded – undo
254 254
 		 *
255 255
 		 * @return array
256 256
 		 */
257
-		function get_filtered_addon_settings( $settings, $setting_fields = array() ) {
257
+		function get_filtered_addon_settings($settings, $setting_fields = array()) {
258 258
 			global $wp_filter;
259 259
 
260 260
 			$new_setting_fields = array();
261 261
 
262
-			if ( ! empty( $settings ) ) {
262
+			if ( ! empty($settings)) {
263 263
 				// Bailout: If setting array contain first element of type title then it means it is already created with new setting api (skip this section ).
264
-				if ( isset( $settings[0]['type'] ) && 'title' == $settings[0]['type'] ) {
265
-					foreach ( $settings as $setting ) {
264
+				if (isset($settings[0]['type']) && 'title' == $settings[0]['type']) {
265
+					foreach ($settings as $setting) {
266 266
 						$new_setting_fields[] = $setting;
267 267
 
268 268
 						// We need setting only till first section end.
269
-						if ( 'sectionend' === $setting['type'] ) {
269
+						if ('sectionend' === $setting['type']) {
270 270
 							break;
271 271
 						}
272 272
 					}
@@ -278,24 +278,24 @@  discard block
 block discarded – undo
278 278
 				$prev_title_field_id = '';
279 279
 
280 280
 				// Create new setting fields.
281
-				foreach ( $settings as $index => $field ) {
281
+				foreach ($settings as $index => $field) {
282 282
 
283 283
 					// Bailout: Must need field type to process.
284
-					if ( ! isset( $field['type'] ) ) {
284
+					if ( ! isset($field['type'])) {
285 285
 						continue;
286 286
 					}
287 287
 
288 288
 					// Set wrapper class if any.
289
-					if ( ! empty( $field['row_classes'] ) ) {
289
+					if ( ! empty($field['row_classes'])) {
290 290
 						$field['wrapper_class'] = $field['row_classes'];
291
-						unset( $field['row_classes'] );
291
+						unset($field['row_classes']);
292 292
 					}
293 293
 
294
-					$field['name'] = ! isset( $field['name'] ) ? '' : $field['name'];
295
-					$field['desc'] = ! isset( $field['desc'] ) ? '' : $field['desc'];
294
+					$field['name'] = ! isset($field['name']) ? '' : $field['name'];
295
+					$field['desc'] = ! isset($field['desc']) ? '' : $field['desc'];
296 296
 
297 297
 					// Modify cmb2 setting fields.
298
-					switch ( $field['type'] ) {
298
+					switch ($field['type']) {
299 299
 						case 'text' :
300 300
 						case 'file' :
301 301
 							$field['css'] = 'width:25em;';
@@ -319,18 +319,18 @@  discard block
 block discarded – undo
319 319
 							$field['type'] = 'title';
320 320
 
321 321
 							// Since we are showing sections, so there now ned to show horizontal rules.
322
-							if ( '<hr>' === $field['desc'] ) {
322
+							if ('<hr>' === $field['desc']) {
323 323
 								$field['desc'] = '';
324 324
 							}
325 325
 
326 326
 							break;
327 327
 					}
328 328
 
329
-					if ( 'title' === $field['type'] ) {
329
+					if ('title' === $field['type']) {
330 330
 
331 331
 						// If we do not have first element as title then these field will be skip from frontend
332 332
 						// because there are not belong to any section, so put all abandon fields under first section.
333
-						if ( $index && empty( $prev_title_field_id ) ) {
333
+						if ($index && empty($prev_title_field_id)) {
334 334
 							array_unshift(
335 335
 								$new_setting_fields,
336 336
 								array(
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 							$prev_title_field_id = $field['id'];
345 345
 
346 346
 							continue;
347
-						} elseif ( $index ) {
347
+						} elseif ($index) {
348 348
 							// Section end.
349 349
 							$new_setting_fields[] = array(
350 350
 								'type' => 'sectionend',
@@ -376,52 +376,52 @@  discard block
 block discarded – undo
376 376
 
377 377
 				// Check if setting page has title section or not.
378 378
 				// If setting page does not have title section  then add title section to it and fix section end array id.
379
-				if ( 'title' !== $new_setting_fields[0]['type'] ) {
379
+				if ('title' !== $new_setting_fields[0]['type']) {
380 380
 					array_unshift(
381 381
 						$new_setting_fields,
382 382
 						array(
383
-							'title' => ( isset( $settings['give_title'] ) ? $settings['give_title'] : '' ),
383
+							'title' => (isset($settings['give_title']) ? $settings['give_title'] : ''),
384 384
 							'type'  => 'title',
385
-							'desc'  => ! empty( $setting_fields['desc'] ) ? $setting_fields['desc'] : '',
386
-							'id'    => ( isset( $settings['id'] ) ? $settings['id'] : '' ),
385
+							'desc'  => ! empty($setting_fields['desc']) ? $setting_fields['desc'] : '',
386
+							'id'    => (isset($settings['id']) ? $settings['id'] : ''),
387 387
 						)
388 388
 					);
389 389
 
390 390
 					// Update id in section end array if does not contain.
391
-					if ( empty( $new_setting_fields[ count( $new_setting_fields ) - 1 ]['id'] ) ) {
392
-						$new_setting_fields[ count( $new_setting_fields ) - 1 ]['id'] = ( isset( $settings['id'] ) ? $settings['id'] : '' );
391
+					if (empty($new_setting_fields[count($new_setting_fields) - 1]['id'])) {
392
+						$new_setting_fields[count($new_setting_fields) - 1]['id'] = (isset($settings['id']) ? $settings['id'] : '');
393 393
 					}
394 394
 				}
395 395
 
396 396
 				// Return only section related settings.
397
-				if ( $sections = $this->get_filtered_addon_sections() ) {
398
-					$new_setting_fields = $this->get_section_settings( $new_setting_fields );
397
+				if ($sections = $this->get_filtered_addon_sections()) {
398
+					$new_setting_fields = $this->get_section_settings($new_setting_fields);
399 399
 				}
400 400
 
401 401
 				// Third party plugin backward compatibility.
402
-				$wp_filter_keys = array_keys( $wp_filter );
403
-				foreach ( $new_setting_fields as $index => $field ) {
404
-					if ( ! isset( $field['type'] ) || in_array( $field['type'], array( 'title', 'sectionend' ) ) ) {
402
+				$wp_filter_keys = array_keys($wp_filter);
403
+				foreach ($new_setting_fields as $index => $field) {
404
+					if ( ! isset($field['type']) || in_array($field['type'], array('title', 'sectionend'))) {
405 405
 						continue;
406 406
 					}
407 407
 
408 408
 					$cmb2_filter_name = "cmb2_render_{$field['type']}";
409 409
 
410
-					if ( in_array( $cmb2_filter_name, $wp_filter_keys ) ) {
410
+					if (in_array($cmb2_filter_name, $wp_filter_keys)) {
411 411
 
412
-						if ( 0 >= version_compare( 4.7, get_bloginfo( 'version' ) ) && ! empty( $wp_filter[ $cmb2_filter_name ]->callbacks ) ) {
413
-							$cmb2_filter_arr = current( $wp_filter[ $cmb2_filter_name ]->callbacks );
412
+						if (0 >= version_compare(4.7, get_bloginfo('version')) && ! empty($wp_filter[$cmb2_filter_name]->callbacks)) {
413
+							$cmb2_filter_arr = current($wp_filter[$cmb2_filter_name]->callbacks);
414 414
 						} else {
415
-							$cmb2_filter_arr = current( $wp_filter[ $cmb2_filter_name ] );
415
+							$cmb2_filter_arr = current($wp_filter[$cmb2_filter_name]);
416 416
 						}
417 417
 
418
-						if ( ! empty( $cmb2_filter_arr ) ) {
418
+						if ( ! empty($cmb2_filter_arr)) {
419 419
 							// Note: function can be called either globally or with class object, it depends on how developer invoke it.
420
-							$new_setting_fields[ $index ]['func'] = current( $cmb2_filter_arr );
421
-							add_action( "give_admin_field_{$field['type']}", array(
420
+							$new_setting_fields[$index]['func'] = current($cmb2_filter_arr);
421
+							add_action("give_admin_field_{$field['type']}", array(
422 422
 								$this,
423 423
 								'addon_setting_field',
424
-							), 10, 2 );
424
+							), 10, 2);
425 425
 						}
426 426
 					}
427 427
 				}
@@ -442,31 +442,31 @@  discard block
 block discarded – undo
442 442
 		 *
443 443
 		 * @return array
444 444
 		 */
445
-		function get_section_settings( $tab_settings ) {
445
+		function get_section_settings($tab_settings) {
446 446
 			$current_section = give_get_current_setting_section();
447 447
 
448 448
 			// Note: If we are opening default tabe for addon setting then it is possible that we will get empty string as current section
449 449
 			// because default section filter added after save hook fire, so we will always get problem to save first section [default] or if there are only on section
450 450
 			// This is hack to fix this.
451
-			if ( empty( $current_section ) ) {
452
-				$current_section = $this->set_default_setting_tab( $current_section );
451
+			if (empty($current_section)) {
452
+				$current_section = $this->set_default_setting_tab($current_section);
453 453
 			}
454 454
 
455 455
 			$section_start               = false;
456 456
 			$section_end                 = false;
457 457
 			$section_only_setting_fields = array();
458 458
 
459
-			foreach ( $tab_settings as $field ) {
460
-				if ( 'title' == $field['type'] && $current_section == sanitize_title( $field['title'] ) ) {
459
+			foreach ($tab_settings as $field) {
460
+				if ('title' == $field['type'] && $current_section == sanitize_title($field['title'])) {
461 461
 					$section_start = true;
462 462
 				}
463 463
 
464
-				if ( ! $section_start || $section_end ) {
464
+				if ( ! $section_start || $section_end) {
465 465
 					continue;
466 466
 				}
467 467
 
468
-				if ( $section_start && ! $section_end ) {
469
-					if ( 'sectionend' == $field['type'] ) {
468
+				if ($section_start && ! $section_end) {
469
+					if ('sectionend' == $field['type']) {
470 470
 						$section_end = true;
471 471
 					}
472 472
 					$section_only_setting_fields[] = $field;
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 			// Remove title from setting, pevent it from render in setting tab.
477 477
 			$section_only_setting_fields[0]['title'] = '';
478 478
 
479
-			return apply_filters( "give_get_settings_{$this->current_tab}_{$current_section}", $section_only_setting_fields, $tab_settings );
479
+			return apply_filters("give_get_settings_{$this->current_tab}_{$current_section}", $section_only_setting_fields, $tab_settings);
480 480
 		}
481 481
 
482 482
 
@@ -490,17 +490,17 @@  discard block
 block discarded – undo
490 490
 		 *
491 491
 		 * @return void
492 492
 		 */
493
-		function addon_setting_field( $field, $saved_value ) {
493
+		function addon_setting_field($field, $saved_value) {
494 494
 			// Create object for cmb2  function callback backward compatibility.
495 495
 			// Note: Do not call any cmb2 function on these objects
496
-			$field_obj      = (object) array( 'args' => $field );
497
-			$field_type_obj = (object) array( 'field' => $field_obj );
496
+			$field_obj      = (object) array('args' => $field);
497
+			$field_type_obj = (object) array('field' => $field_obj);
498 498
 
499
-			switch ( $this->current_tab ) :
499
+			switch ($this->current_tab) :
500 500
 				case 'licenses':
501 501
 					?>
502 502
 					<div class="give-settings-wrap give-settings-wrap-<?php echo $this->current_tab; ?>">
503
-						<?php $field['func']['function']( $field_obj, $saved_value, '', '', $field_type_obj ); ?>
503
+						<?php $field['func']['function']($field_obj, $saved_value, '', '', $field_type_obj); ?>
504 504
 					</div>
505 505
 					<?php break;
506 506
 
@@ -508,21 +508,21 @@  discard block
 block discarded – undo
508 508
 					$colspan = 'colspan="2"';
509 509
 					?>
510 510
 					<tr valign="top">
511
-						<?php if ( ! empty( $field['name'] ) && ! in_array( $field['name'], array( '&nbsp;' ) ) ) : ?>
511
+						<?php if ( ! empty($field['name']) && ! in_array($field['name'], array('&nbsp;'))) : ?>
512 512
 							<th scope="row" class="titledesc">
513 513
 								<label
514
-										for="<?php echo esc_attr( $field['name'] ); ?>"><?php echo $field['title']; ?></label>
514
+										for="<?php echo esc_attr($field['name']); ?>"><?php echo $field['title']; ?></label>
515 515
 							</th>
516 516
 							<?php $colspan = ''; ?>
517 517
 						<?php endif; ?>
518 518
 						<td class="give-forminp" <?php echo $colspan; ?>>
519 519
 							<?php
520
-							if ( is_array( $field['func']['function'] ) ) {
520
+							if (is_array($field['func']['function'])) {
521 521
 								$classname = $field['func']['function'][0];
522 522
 								$function_name = $field['func']['function'][1];
523
-								$classname->$function_name( $field_obj, $saved_value, '', '', $field_type_obj );
523
+								$classname->$function_name($field_obj, $saved_value, '', '', $field_type_obj);
524 524
 							} else {
525
-								$field['func']['function']( $field_obj, $saved_value, '', '', $field_type_obj );
525
+								$field['func']['function']($field_obj, $saved_value, '', '', $field_type_obj);
526 526
 							}
527 527
 							?>
528 528
 						</td>
@@ -540,10 +540,10 @@  discard block
 block discarded – undo
540 540
 		public function get_sections() {
541 541
 			$sections = array();
542 542
 
543
-			if ( ( $setting_fields = $this->prev_settings->give_settings( $this->current_tab ) ) && ! empty( $setting_fields['fields'] ) ) {
544
-				foreach ( $setting_fields['fields'] as $field ) {
545
-					if ( 'give_title' == $field['type'] ) {
546
-						$sections[ sanitize_title( $field['name'] ) ] = $this->get_section_name( $field['name'] );
543
+			if (($setting_fields = $this->prev_settings->give_settings($this->current_tab)) && ! empty($setting_fields['fields'])) {
544
+				foreach ($setting_fields['fields'] as $field) {
545
+					if ('give_title' == $field['type']) {
546
+						$sections[sanitize_title($field['name'])] = $this->get_section_name($field['name']);
547 547
 					}
548 548
 				}
549 549
 			}
@@ -563,16 +563,16 @@  discard block
 block discarded – undo
563 563
 
564 564
 			$new_setting_fields = array();
565 565
 
566
-			if ( $setting_fields = $this->prev_settings->give_settings( $this->current_tab ) ) {
567
-				if ( isset( $setting_fields['fields'] ) ) {
566
+			if ($setting_fields = $this->prev_settings->give_settings($this->current_tab)) {
567
+				if (isset($setting_fields['fields'])) {
568 568
 
569 569
 					$tab_data = array(
570 570
 						'id'         => $setting_fields['id'],
571 571
 						'give_title' => $setting_fields['give_title'],
572
-						'desc'       => ( isset( $setting_fields['desc'] ) ? $setting_fields['desc'] : '' ),
572
+						'desc'       => (isset($setting_fields['desc']) ? $setting_fields['desc'] : ''),
573 573
 					);
574 574
 
575
-					$new_setting_fields = $this->get_filtered_addon_settings( $setting_fields['fields'], $tab_data );
575
+					$new_setting_fields = $this->get_filtered_addon_settings($setting_fields['fields'], $tab_data);
576 576
 				}
577 577
 			}
578 578
 
@@ -589,24 +589,24 @@  discard block
 block discarded – undo
589 589
 			$sections = $this->get_sections();
590 590
 
591 591
 			// Show section settings only if setting section exist.
592
-			if ( $this->current_section && ! in_array( $this->current_section, array_keys( $sections ) ) ) {
593
-				echo '<div class="error"><p>' . __( 'Oops, this settings page does not exist.', 'give' ) . '</p></div>';
592
+			if ($this->current_section && ! in_array($this->current_section, array_keys($sections))) {
593
+				echo '<div class="error"><p>'.__('Oops, this settings page does not exist.', 'give').'</p></div>';
594 594
 				$GLOBALS['give_hide_save_button'] = true;
595 595
 
596 596
 				return;
597 597
 			}
598 598
 
599 599
 			// Bailout.
600
-			if ( empty( $sections ) ) {
600
+			if (empty($sections)) {
601 601
 				return;
602 602
 			}
603 603
 
604 604
 			echo '<ul class="subsubsub">';
605 605
 
606
-			$array_keys = array_keys( $sections );
606
+			$array_keys = array_keys($sections);
607 607
 
608
-			foreach ( $sections as $id => $label ) {
609
-				echo '<li><a href="' . admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=' . $this->current_tab . '&section=' . sanitize_title( $id ) ) . '" class="' . ( $this->current_section == $id ? 'current' : '' ) . '">' . strip_tags( $label ) . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>';
608
+			foreach ($sections as $id => $label) {
609
+				echo '<li><a href="'.admin_url('edit.php?post_type=give_forms&page=give-settings&tab='.$this->current_tab.'&section='.sanitize_title($id)).'" class="'.($this->current_section == $id ? 'current' : '').'">'.strip_tags($label).'</a> '.(end($array_keys) == $id ? '' : '|').' </li>';
610 610
 			}
611 611
 
612 612
 			echo '</ul><br class="clear" /><hr>';
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
 		public function output() {
622 622
 			$settings = $this->get_settings();
623 623
 
624
-			Give_Admin_Settings::output_fields( $settings, 'give_settings' );
624
+			Give_Admin_Settings::output_fields($settings, 'give_settings');
625 625
 		}
626 626
 
627 627
 		/**
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
 		public function save() {
634 634
 			$settings = $this->get_settings();
635 635
 
636
-			Give_Admin_Settings::save_fields( $settings, 'give_settings' );
636
+			Give_Admin_Settings::save_fields($settings, 'give_settings');
637 637
 		}
638 638
 	}
639 639
 endif;
Please login to merge, or discard this patch.