GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — feature/gallery-template-clien... ( 9f6bad...85df04 )
by Brad
02:37
created

perform_gallery_settings_upgrade()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class used to upgrade internal gallery settings when needed
4
 * Date: 19/07/2017
5
 */
6
if ( ! class_exists( 'FooGallery_Upgrade' ) ) {
7
8
	class FooGallery_Upgrade {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
10
		function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
11
			add_action( 'foogallery_admin_new_version_detected', array( $this, 'upgrade_all_galleries' ) );
12
13
			add_filter( 'foogallery_admin_settings_override', array( $this, 'add_force_upgrade_setting' ) );
14
			add_action( 'foogallery_admin_settings_custom_type_render_setting', array( $this, 'render_force_upgrades_settings' ) );
15
			add_action( 'wp_ajax_foogallery_force_upgrade', array( $this, 'ajax_force_upgrade' ) );
16
17
			add_action( 'add_meta_boxes_' . FOOGALLERY_CPT_GALLERY, array( $this, 'add_meta_boxes_to_gallery' ) );
18
		}
19
20
		public function add_meta_boxes_to_gallery( $post ) {
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
22
			if ( foogallery_get_setting( 'enable_debugging' ) ) {
23
				add_meta_box(
24
					'foogallery_upgrade_debug',
25
					__( 'Settings Upgrade Debugging', 'foogallery' ),
26
					array( $this, 'render_upgrade_debug_metabox' ),
27
					FOOGALLERY_CPT_GALLERY,
28
					'normal',
29
					'low'
30
				);
31
			}
32
		}
33
34
		public function render_upgrade_debug_metabox( $post ) {
35
			$gallery = FooGallery::get( $post );
36
37
			if ( $gallery->is_new() ) {
38
				return;
39
			}
40
41
			$old_settings = get_post_meta( $gallery->ID, FOOGALLERY_META_SETTINGS_OLD, true );
42
			$new_settings = get_post_meta( $gallery->ID, FOOGALLERY_META_SETTINGS, true );
43
			$upgrade_helper = new FooGallery_Upgrade_Helper();
44
			$upgrade_settings = $upgrade_helper->build_new_settings( $gallery );
45
46
			ksort( $old_settings );
47
			ksort( $new_settings );
48
			ksort( $upgrade_settings );
49
			?>
50
			<style>
51
				#foogallery_upgrade_debug .inside { overflow: scroll; }
52
				#foogallery_upgrade_debug table { font-size: 0.8em; }
53
				#foogallery_upgrade_debug td { vertical-align: top; }
54
			</style>
55
			<table>
56
				<tr>
57
					<td><h3>Old Settings</h3></td>
58
					<td><h3>New Settings</h3></td>
59
					<td><h3>Upgrade Settings</h3></td>
60
				</tr>
61
				<tr>
62
					<td><?php var_dump( $old_settings ); ?></td>
1 ignored issue
show
Security Debugging Code introduced by
var_dump($old_settings); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
63
					<td><?php var_dump( $new_settings ); ?></td>
64
					<td><?php var_dump( $upgrade_settings ); ?></td>
65
				</tr>
66
			</table>
67
			<?php
68
		}
69
70
		function ajax_force_upgrade() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
71
			if ( check_admin_referer( 'foogallery_force_upgrade' ) && current_user_can( 'install_plugins' ) ) {
72
73
				//clear any and all previous upgrades!
74
				delete_post_meta_by_key( '_foogallery_settings' );
75
				$this->upgrade_all_galleries();
76
77
				_e('The BETA upgrade process has been run!', 'foogallery' );
78
				die();
79
			}
80
		}
81
82
		function add_force_upgrade_setting( $settings ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
83
			$settings['settings'][] = array(
84
				'id'      => 'force_upgrade',
85
				'title'   => __( 'Force Upgrade', 'foogallery' ),
86
				'desc'    => sprintf( __( 'Force the BETA upgrade process to run. This may sometimes be needed if the upgrade did not run automatically. Any changes you have made to galleries after updating will be lost. THERE IS NO UNDO.', 'foogallery' ), foogallery_plugin_name() ),
87
				'type'    => 'force_upgrade',
88
				'tab'     => 'advanced'
89
			);
90
91
			return $settings;
92
		}
93
94
		function render_force_upgrades_settings( $args ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
95
			if ( 'force_upgrade' === $args['type'] ) { ?>
96
				<div class="foogallery_settings_ajax_container">
97
					<input type="button" data-action="foogallery_force_upgrade" data-confirm="<?php _e('Are you sure? Any changes you have made since updating will be lost. There is no undo!', 'foogallery'); ?>" data-response="replace_container" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_force_upgrade' ) ); ?>" class="button-primary foogallery_settings_ajax foogallery_force_upgrade" value="<?php _e( 'Run Upgrade Process', 'foogallery' ); ?>">
98
					<span style="position: absolute" class="spinner"></span>
99
				</div>
100
			<?php }
101
		}
102
103
		function upgrade_all_galleries() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
104
			$galleries = foogallery_get_all_galleries();
105
106
			foreach ( $galleries as $gallery ) {
107
				$new_settings = get_post_meta( $gallery->ID, FOOGALLERY_META_SETTINGS, true );
108
				$old_settings = get_post_meta( $gallery->ID, FOOGALLERY_META_SETTINGS_OLD, true );
109
110
				//only upgrade galleries that need to be
111
				if ( !is_array($new_settings) && is_array($old_settings) ) {
112
					$upgrade_helper = new FooGallery_Upgrade_Helper();
113
					$upgrade_helper->perform_gallery_settings_upgrade( $gallery );
114
				}
115
			}
116
		}
117
	}
118
}
119
120
if ( ! class_exists( 'FooGallery_Upgrade_Helper' ) ) {
121
122
	class FooGallery_Upgrade_Helper {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
123
124
		function perform_gallery_settings_upgrade( $foogallery ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
125
			//build up the new settings
126
			$new_settings = $this->build_new_settings( $foogallery );
127
128
			//save the new settings
129
			add_post_meta( $foogallery->ID, FOOGALLERY_META_SETTINGS, $new_settings, true );
130
131
			//clear any cache that may be saved for the gallery
132
			delete_post_meta( $foogallery->ID, FOOGALLERY_META_CACHE );
133
134
			//clear any previously calculated thumb dimensions
135
			delete_post_meta( $foogallery->ID, FOOGALLERY_META_THUMB_DIMENSIONS );
136
137
			//calculate new thumb dimensions if needed
138
			$thumb_dimensions = new FooGallery_Thumbnail_Dimensions();
139
			$thumb_dimensions->calculate_thumbnail_dimensions( $foogallery->ID );
140
		}
141
142
		function build_new_settings( $foogallery ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
143
			$mappings = array(
144
				array(
145
					'id' => 'border-style',
146
					'value' => 'border-style-square-white',
147
					'new' => array(
148
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
149
						array ( 'id' => 'border_size', 'value' => 'fg-border-thin' ),
150
						array ( 'id' => 'drop_shadow', 'value' => 'fg-shadow-small' ),
151
						array ( 'id' => 'rounded_corners', 'value' => '' ),
152
						array ( 'id' => 'inner_shadow', 'value' => '' ),
153
					)
154
				),
155
				array(
156
					'id' => 'border-style',
157
					'value' => 'border-style-circle-white',
158
					'new' => array(
159
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
160
						array ( 'id' => 'border_size', 'value' => 'fg-border-thin' ),
161
						array ( 'id' => 'drop_shadow', 'value' => 'fg-shadow-small' ),
162
						array ( 'id' => 'rounded_corners', 'value' => 'fg-round-full' ),
163
						array ( 'id' => 'inner_shadow', 'value' => '' ),
164
					)
165
				),
166
				array(
167
					'id' => 'border-style',
168
					'value' => 'border-style-square-black',
169
					'new' => array(
170
						array ( 'id' => 'theme', 'value' => 'fg-dark' ),
171
						array ( 'id' => 'border_size', 'value' => 'fg-border-thin' ),
172
						array ( 'id' => 'drop_shadow', 'value' => 'fg-shadow-small' ),
173
						array ( 'id' => 'rounded_corners', 'value' => '' ),
174
						array ( 'id' => 'inner_shadow', 'value' => '' ),
175
					)
176
				),
177
				array(
178
					'id' => 'border-style',
179
					'value' => 'border-style-circle-black',
180
					'new' => array(
181
						array ( 'id' => 'theme', 'value' => 'fg-dark' ),
182
						array ( 'id' => 'border_size', 'value' => 'fg-border-thin' ),
183
						array ( 'id' => 'drop_shadow', 'value' => 'fg-shadow-small' ),
184
						array ( 'id' => 'rounded_corners', 'value' => 'fg-round-full' ),
185
						array ( 'id' => 'inner_shadow', 'value' => '' ),
186
					)
187
				),
188
				array(
189
					'id' => 'border-style',
190
					'value' => 'border-style-inset',
191
					'new' => array(
192
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
193
						array ( 'id' => 'border_size', 'value' => '' ),
194
						array ( 'id' => 'drop_shadow', 'value' => 'fg-shadow-small' ),
195
						array ( 'id' => 'rounded_corners', 'value' => '' ),
196
						array ( 'id' => 'inner_shadow', 'value' => 'fg-shadow-inset-large' ),
197
					)
198
				),
199
				array(
200
					'id' => 'border-style',
201
					'value' => 'border-style-rounded',
202
					'new' => array(
203
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
204
						array ( 'id' => 'border_size', 'value' => '' ),
205
						array ( 'id' => 'drop_shadow', 'value' => '' ),
206
						array ( 'id' => 'rounded_corners', 'value' => 'fg-round-small' ),
207
						array ( 'id' => 'inner_shadow', 'value' => '' ),
208
					)
209
				),
210
				array(
211
					'id' => 'border-style',
212
					'value' => '',
213
					'new' => array(
214
						array ( 'id' => 'theme', 'value' => 'fg-light' ),
215
						array ( 'id' => 'border_size', 'value' => '' ),
216
						array ( 'id' => 'drop_shadow', 'value' => '' ),
217
						array ( 'id' => 'rounded_corners', 'value' => '' ),
218
						array ( 'id' => 'inner_shadow', 'value' => '' ),
219
					)
220
				),
221
222
				array(
223
					'id' => 'spacing',
224
					'value' => 'spacing-width-0',
225
					'new' => array(
226
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-0' )
227
					)
228
				),
229
				array(
230
					'id' => 'spacing',
231
					'value' => 'spacing-width-5',
232
					'new' => array(
233
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-5' )
234
					)
235
				),
236
				array(
237
					'id' => 'spacing',
238
					'value' => 'spacing-width-10',
239
					'new' => array(
240
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-10' )
241
					)
242
				),
243
				array(
244
					'id' => 'spacing',
245
					'value' => 'spacing-width-15',
246
					'new' => array(
247
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-15' )
248
					)
249
				),
250
				array(
251
					'id' => 'spacing',
252
					'value' => 'spacing-width-20',
253
					'new' => array(
254
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-20' )
255
					)
256
				),
257
				array(
258
					'id' => 'spacing',
259
					'value' => 'spacing-width-25',
260
					'new' => array(
261
						array ( 'id' => 'spacing', 'value' => 'fg-gutter-25' )
262
					)
263
				),
264
265
				array(
266
					'id' => 'alignment',
267
					'value' => 'alignment-left',
268
					'new' => array(
269
						array ( 'id' => 'alignment', 'value' => 'fg-left' )
270
					)
271
				),
272
				array(
273
					'id' => 'alignment',
274
					'value' => 'alignment-center',
275
					'new' => array(
276
						array ( 'id' => 'alignment', 'value' => 'fg-center' )
277
					)
278
				),
279
				array(
280
					'id' => 'alignment',
281
					'value' => 'alignment-right',
282
					'new' => array(
283
						array ( 'id' => 'alignment', 'value' => 'fg-right' )
284
					)
285
				),
286
287
				array(
288
					'id' => 'loading_animation',
289
					'value' => 'yes',
290
					'new' => array(
291
						array ( 'id' => 'loading_icon', 'value' => 'fg-loading-default' )
292
					)
293
				),
294
				array(
295
					'id' => 'loading_animation',
296
					'value' => 'no',
297
					'new' => array(
298
						array ( 'id' => 'loading_icon', 'value' => 'fg-loading-none' )
299
					)
300
				),
301
302
303
				array(
304
					'id' => 'hover-effect-type',
305
					'value' => '', //Icon
306
					'new' => array(
307
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
308
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
309
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
310
						array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-zoom' ),
311
						array ( 'id' => 'caption_title', 'value' => 'none' ),
312
						array ( 'id' => 'caption_desc', 'value' => 'none' )
313
					)
314
				),
315
316
				array(
317
					'id' => 'hover-effect-type',
318
					'value' => 'hover-effect-tint', //Dark Tint
319
					'new' => array(
320
						array ( 'id' => 'hover_effect_preset', 'value' => '' ),
321
						array ( 'id' => 'hover_effect', 'value' => 'fg-hover-tint' )
322
					)
323
				),
324
325
				array(
326
					'id' => 'hover-effect-type',
327
					'value' => 'hover-effect-color', //Colorize
328
					'new' => array(
329
						array ( 'id' => 'hover_effect_preset', 'value' => '' ),
330
						array ( 'id' => 'hover_effect_color', 'value' => 'fg-hover-colorize' )
331
					)
332
				),
333
334
				array(
335
					'id' => 'hover-effect-type',
336
					'value' => 'hover-effect-none', //None
337
					'new' => array(
338
						array ( 'id' => 'hover_effect_preset', 'value' => '' )
339
					)
340
				),
341
342
				array(
343
					'id' => 'hover-effect-type',
344
					'value' => 'hover-effect-caption', //Caption
345
					'new' => array(
346
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
347
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
348
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
349
					)
350
				),
351
352
				array(
353
					'id' => 'hover-effect',
354
					'value' => 'hover-effect-zoom',
355
					'new' => array(
356
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
357
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
358
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
359
						array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-zoom' )
360
					)
361
				),
362
363
				array(
364
					'id' => 'hover-effect',
365
					'value' => 'hover-effect-zoom2',
366
					'new' => array(
367
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
368
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
369
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
370
						array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-zoom2' )
371
					)
372
				),
373
374
				array(
375
					'id' => 'hover-effect',
376
					'value' => 'hover-effect-zoom3',
377
					'new' => array(
378
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
379
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
380
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
381
						array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-zoom3' )
382
					)
383
				),
384
385
				array(
386
					'id' => 'hover-effect',
387
					'value' => 'hover-effect-plus',
388
					'new' => array(
389
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
390
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
391
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
392
						array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-plus' )
393
					)
394
				),
395
396
				array(
397
					'id' => 'hover-effect',
398
					'value' => 'hover-effect-circle-plus',
399
					'new' => array(
400
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
401
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
402
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
403
						array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-circle-plus' )
404
					)
405
				),
406
407
				array(
408
					'id' => 'hover-effect',
409
					'value' => 'hover-effect-eye',
410
					'new' => array(
411
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
412
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
413
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
414
						array ( 'id' => 'hover_effect_icon', 'value' => 'fg-hover-eye' )
415
					)
416
				),
417
418
				array(
419
					'id' => 'caption-hover-effect',
420
					'value' => 'hover-caption-simple',
421
					'new' => array(
422
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
423
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
424
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
425
						array ( 'id' => 'hover_effect_icon', 'value' => '' )
426
					)
427
				),
428
				array(
429
					'id' => 'caption-hover-effect',
430
					'value' => 'hover-caption-full-drop',
431
					'new' => array(
432
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
433
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
434
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-slide-down' ),
435
						array ( 'id' => 'hover_effect_icon', 'value' => '' )
436
					)
437
				),
438
				array(
439
					'id' => 'caption-hover-effect',
440
					'value' => 'hover-caption-full-fade',
441
					'new' => array(
442
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
443
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
444
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
445
						array ( 'id' => 'hover_effect_icon', 'value' => '' )
446
					)
447
				),
448
				array(
449
					'id' => 'caption-hover-effect',
450
					'value' => 'hover-caption-push',
451
					'new' => array(
452
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
453
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
454
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-push' ),
455
						array ( 'id' => 'hover_effect_icon', 'value' => '' )
456
					)
457
				),
458
				array(
459
					'id' => 'caption-hover-effect',
460
					'value' => 'hover-caption-simple-always',
461
					'new' => array(
462
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
463
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-always' ),
464
						array ( 'id' => 'hover_effect_icon', 'value' => '' )
465
					)
466
				),
467
468
				array(
469
					'id' => 'caption-content',
470
					'value' => 'title',
471
					'new' => array(
472
						array ( 'id' => 'caption_title', 'value' => '' ),
473
						array ( 'id' => 'caption_desc', 'value' => 'none' )
474
					)
475
				),
476
				array(
477
					'id' => 'caption-content',
478
					'value' => 'desc',
479
					'new' => array(
480
						array ( 'id' => 'caption_title', 'value' => 'none' ),
481
						array ( 'id' => 'caption_desc', 'value' => '' )
482
					)
483
				),
484
				array(
485
					'id' => 'caption-content',
486
					'value' => 'both',
487
					'new' => array(
488
						array ( 'id' => 'caption_title', 'value' => '' ),
489
						array ( 'id' => 'caption_desc', 'value' => '' )
490
					)
491
				),
492
493
				//masonry layout mappings
494
				array(
495
					'id' => 'layout',
496
					'value' => '2col',
497
					'new' => array(
498
						array ( 'id' => 'layout', 'value' => 'col2' )
499
					)
500
				),
501
502
				array(
503
					'id' => 'layout',
504
					'value' => '3col',
505
					'new' => array(
506
						array ( 'id' => 'layout', 'value' => 'col3' )
507
					)
508
				),
509
510
				array(
511
					'id' => 'layout',
512
					'value' => '4col',
513
					'new' => array(
514
						array ( 'id' => 'layout', 'value' => 'col4' )
515
					)
516
				),
517
518
				array(
519
					'id' => 'layout',
520
					'value' => '5col',
521
					'new' => array(
522
						array ( 'id' => 'layout', 'value' => 'col5' )
523
					)
524
				),
525
526
				array(
527
					'id' => 'gutter_percent',
528
					'value' => 'no-gutter',
529
					'new' => array(
530
						array ( 'id' => 'gutter_percent', 'value' => 'fg-gutter-none' )
531
					)
532
				),
533
534
				array(
535
					'id' => 'gutter_percent',
536
					'value' => 'large-gutter',
537
					'new' => array(
538
						array ( 'id' => 'gutter_percent', 'value' => 'fg-gutter-large' )
539
					)
540
				),
541
542
				array(
543
					'id' => 'center_align',
544
					'value' => 'default',
545
					'new' => array(
546
						array ( 'id' => 'alignment', 'value' => '' )
547
					)
548
				),
549
550
				array(
551
					'id' => 'center_align',
552
					'value' => 'center',
553
					'new' => array(
554
						array ( 'id' => 'alignment', 'value' => 'fg-center' )
555
					)
556
				),
557
558
				array(
559
					'id' => 'hover_zoom',
560
					'value' => 'default',
561
					'new' => array(
562
						array ( 'id' => 'hover_effect_scale', 'value' => 'fg-hover-scale' )
563
					)
564
				),
565
566
				array(
567
					'id' => 'hover_zoom',
568
					'value' => 'none',
569
					'new' => array(
570
						array ( 'id' => 'hover_effect_scale', 'value' => '' )
571
					)
572
				),
573
574
575
				//image viewer upgrades
576
				array(
577
					'id' => 'theme',
578
					'value' => 'fiv-dark',
579
					'new' => array(
580
						array ( 'id' => 'theme', 'value' => 'fg-dark' )
581
					)
582
				),
583
				array(
584
					'id' => 'theme',
585
					'value' => '',
586
					'new' => array(
587
						array ( 'id' => 'theme', 'value' => 'fg-light' )
588
					)
589
				),
590
				array(
591
					'id' => 'theme',
592
					'value' => 'fiv-custom',
593
					'new' => array(
594
						array ( 'id' => 'theme', 'value' => 'fg-light' )
595
					)
596
				),
597
598
				array(
599
					'id' => 'alignment',
600
					'value' => 'alignment-left',
601
					'new' => array(
602
						array ( 'id' => 'alignment', 'value' => 'fg-left' )
603
					)
604
				),
605
				array(
606
					'id' => 'alignment',
607
					'value' => 'alignment-center',
608
					'new' => array(
609
						array ( 'id' => 'alignment', 'value' => 'fg-center' )
610
					)
611
				),
612
				array(
613
					'id' => 'alignment',
614
					'value' => 'alignment-right',
615
					'new' => array(
616
						array ( 'id' => 'alignment', 'value' => 'fg-right' )
617
					)
618
				),
619
620
				//simple portfolio
621
				array(
622
					'id' => 'caption_position',
623
					'value' => 'bf-captions-above',
624
					'new' => array(
625
						array ( 'id' => 'caption_position', 'value' => 'fg-captions-top' )
626
					)
627
				),
628
629
				//single thumbnail
630
				array(
631
					'id' => 'caption_style',
632
					'value' => 'caption-simple',
633
					'new' => array(
634
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
635
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-always' )
636
					)
637
				),
638
				array(
639
					'id' => 'caption_style',
640
					'value' => 'caption-slideup',
641
					'new' => array(
642
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
643
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
644
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-slide-up' ),
645
					)
646
				),
647
648
				array(
649
					'id' => 'caption_style',
650
					'value' => 'caption-fall',
651
					'new' => array(
652
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
653
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
654
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-slide-down' ),
655
					)
656
				),
657
				array(
658
					'id' => 'caption_style',
659
					'value' => 'caption-fade',
660
					'new' => array(
661
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
662
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
663
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-fade' ),
664
					)
665
				),
666
				array(
667
					'id' => 'caption_style',
668
					'value' => 'caption-push',
669
					'new' => array(
670
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
671
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
672
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-push' ),
673
					)
674
				),
675
				array(
676
					'id' => 'caption_style',
677
					'value' => 'caption-scale',
678
					'new' => array(
679
						array ( 'id' => 'hover_effect_preset', 'value' => 'fg-custom' ),
680
						array ( 'id' => 'hover_effect_caption_visibility', 'value' => 'fg-caption-hover' ),
681
						array ( 'id' => 'hover_effect_transition', 'value' => 'fg-hover-slide-left' ),
682
					)
683
				),
684
685
				//single thumbnail gallery
686
				array(
687
					'id' => 'position',
688
					'value' => 'position-block',
689
					'new' => array(
690
						array ( 'id' => 'position', 'value' => 'fg-center' ),
691
					)
692
				),
693
				array(
694
					'id' => 'position',
695
					'value' => 'position-float-left',
696
					'new' => array(
697
						array ( 'id' => 'position', 'value' => 'fg-left' ),
698
					)
699
				),
700
				array(
701
					'id' => 'position',
702
					'value' => 'position-float-right',
703
					'new' => array(
704
						array ( 'id' => 'position', 'value' => 'fg-right' ),
705
					)
706
				),
707
708
			);
709
710
			$old_settings = get_post_meta( $foogallery->ID, FOOGALLERY_META_SETTINGS_OLD, true );
711
712
			//start with the old settings
713
			$new_settings = $old_settings;
714
715
			//upgrade all template settings
716
			foreach ( foogallery_gallery_templates() as $template ) {
717
718
				foreach ( $mappings as $mapping ) {
719
720
					$settings_key = "{$template['slug']}_{$mapping['id']}";
721
722
					//check if the settings exists
723
					if ( array_key_exists( $settings_key, $old_settings ) ) {
724
725
						$old_settings_value = $old_settings[$settings_key];
726
727
						if ( $mapping['value'] === $old_settings_value ) {
728
							//we have found a match!
729
730
							foreach ( $mapping['new'] as $setting_to_create ) {
731
								$new_setting_key                = "{$template['slug']}_{$setting_to_create['id']}";
732
								$new_setting_value              = $setting_to_create['value'];
733
								$new_settings[$new_setting_key] = $new_setting_value;
734
							}
735
						}
736
					}
737
				}
738
			}
739
740
			//template specific settings overrides
741
			if ( 'image-viewer' === $foogallery->gallery_template ) {
742
				$new_settings['image-viewer_theme'] = 'fg-light';
743
				$new_settings['image-viewer_border_size'] = '';
744
				$new_settings['image-viewer_drop_shadow'] = '';
745
				$new_settings['image-viewer_rounded_corners'] = '';
746
				$new_settings['image-viewer_inner_shadow'] = '';
747
			}
748
749
			if ( 'justified' === $foogallery->gallery_template ) {
750
				$new_settings['image-viewer_theme'] = 'fg-light';
751
				$new_settings['image-viewer_border_size'] = '';
752
				$new_settings['image-viewer_drop_shadow'] = '';
753
				$new_settings['image-viewer_rounded_corners'] = '';
754
				$new_settings['image-viewer_inner_shadow'] = '';
755
			}
756
757
			if ( 'masonry' === $foogallery->gallery_template ) {
758
				$new_settings['image-viewer_theme'] = 'fg-light';
759
				$new_settings['image-viewer_border_size'] = '';
760
				$new_settings['image-viewer_drop_shadow'] = '';
761
				$new_settings['image-viewer_rounded_corners'] = '';
762
				$new_settings['image-viewer_inner_shadow'] = '';
763
			}
764
765
			return $new_settings;
766
		}
767
	}
768
}