1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
|
<?php
if ( ! class_exists( 'FooGallery_Admin_Settings' ) ) {
/** * Class FooGallery_Admin_Settings */ class FooGallery_Admin_Settings {
function __construct() { add_filter( 'foogallery_admin_settings', array( $this, 'create_settings' ), 10, 2 ); add_action( 'foogallery_admin_settings_custom_type_render_setting', array( $this, 'render_custom_setting_types' ) ); add_action( 'foogallery_admin_settings_after_render_setting', array( $this, 'after_render_setting' ) );
// Ajax calls add_action( 'wp_ajax_foogallery_clear_css_optimizations', array( $this, 'ajax_clear_css_optimizations' ) ); add_action( 'wp_ajax_foogallery_thumb_generation_test', array( $this, 'ajax_thumb_generation_test' ) ); add_action( 'wp_ajax_foogallery_apply_retina_defaults', array( $this, 'ajax_apply_retina_defaults' ) ); add_action( 'wp_ajax_foogallery_uninstall', array( $this, 'ajax_uninstall' ) ); }
/** * Create the settings for FooGallery * @return array */ function create_settings() {
//region General Tab $tabs['general'] = __( 'General', 'foogallery' );
$settings[] = array( 'id' => 'clear_css_optimizations', 'title' => __( 'Clear CSS Cache', 'foogallery' ), 'desc' => sprintf( __( '%s optimizes the way it loads gallery stylesheets to improve page performance. This can lead to the incorrect CSS being loaded in some cases. Use this button to clear all the CSS optimizations that have been cached across all galleries.', 'foogallery' ), foogallery_plugin_name() ), 'type' => 'clear_optimization_button', 'tab' => 'general', 'section' => __( 'Cache', 'foogallery' ) );
$gallery_templates = foogallery_gallery_templates(); $gallery_templates_choices = array(); foreach ( $gallery_templates as $template ) { $gallery_templates_choices[ $template['slug'] ] = $template['name']; }
$settings[] = array( 'id' => 'gallery_template', 'title' => __( 'Default Gallery Template', 'foogallery' ), 'desc' => __( 'The default gallery template to use for new galleries', 'foogallery' ), 'default' => foogallery_get_default( 'gallery_template' ) , 'type' => 'select', 'choices' => $gallery_templates_choices, 'tab' => 'general', 'section' => __( 'Gallery Defaults', 'foogallery' ) );
$settings[] = array( 'id' => 'gallery_sorting', 'title' => __( 'Default Gallery Sorting', 'foogallery' ), 'desc' => __( 'The default attachment sorting to use for new galleries', 'foogallery' ), 'default' => '', 'type' => 'select', 'choices' => foogallery_sorting_options(), 'tab' => 'general', 'section' => __( 'Gallery Defaults', 'foogallery' ) );
$gallery_posts = get_posts( array( 'post_type' => FOOGALLERY_CPT_GALLERY, 'post_status' => array( 'publish', 'draft' ), 'cache_results' => false, 'nopaging' => true, ) );
$galleries = array();
foreach ( $gallery_posts as $post ) { $galleries[] = array( 'ID' => $post->ID, 'name' => $post->post_title ); }
$gallery_choices = array(); $gallery_choices[] = __( 'No default', 'foogallery' ); foreach ( $galleries as $gallery ) { $gallery_choices[ $gallery['ID'] ] = $gallery['name']; }
$settings[] = array( 'id' => 'default_gallery_settings', 'title' => __( 'Default Gallery Settings', 'foogallery' ), 'desc' => __( 'When creating a new gallery, it can use the settings from an existing gallery as the default settings. This will save you time when creating many galleries that all have the same look and feel.', 'foogallery' ), 'type' => 'select', 'choices' => $gallery_choices, 'tab' => 'general', 'section' => __( 'Gallery Defaults', 'foogallery' ) );
$settings[] = array( 'id' => 'caption_title_source', 'title' => __( 'Caption Title Source', 'foogallery' ), 'desc' => __( 'By default, image caption titles are pulled from the attachment "Caption" field. Alternatively, you can choose to use other fields.', 'foogallery' ), 'type' => 'select', 'choices' => array( 'title' => foogallery_get_attachment_field_friendly_name( 'title' ), 'caption' => foogallery_get_attachment_field_friendly_name( 'caption' ), 'alt' => foogallery_get_attachment_field_friendly_name( 'alt' ), 'desc' => foogallery_get_attachment_field_friendly_name( 'desc' ) ), 'default' => 'caption', 'tab' => 'general', 'section' => __( 'Captions', 'foogallery' ), 'spacer' => '<span class="spacer"></span>' );
$settings[] = array( 'id' => 'caption_desc_source', 'title' => __( 'Caption Description Source', 'foogallery' ), 'desc' => __( 'By default, image caption descriptions are pulled from the attachment "Description" field. Alternatively, you can choose to use other fields.', 'foogallery' ), 'type' => 'select', 'choices' => array( 'title' => foogallery_get_attachment_field_friendly_name( 'title' ), 'caption' => foogallery_get_attachment_field_friendly_name( 'caption' ), 'alt' => foogallery_get_attachment_field_friendly_name( 'alt' ), 'desc' => foogallery_get_attachment_field_friendly_name( 'desc' ) ), 'default' => 'desc', 'tab' => 'general', 'section' => __( 'Captions', 'foogallery' ), 'spacer' => '<span class="spacer"></span>' );
$settings[] = array( 'id' => 'hide_gallery_template_help', 'title' => __( 'Hide Gallery Template Help', 'foogallery' ), 'desc' => __( 'Some gallery templates show helpful tips, which are useful for new users. You can choose to hide these tips.', 'foogallery' ), 'type' => 'checkbox', 'tab' => 'general', 'section' => __( 'Admin', 'foogallery' ) );
$settings[] = array( 'id' => 'hide_editor_button', 'title' => __( 'Hide WYSIWYG Editor Button', 'foogallery' ), 'desc' => sprintf( __( 'If enabled, this will hide the "Add %s" button in the WYSIWYG editor.', 'foogallery' ), foogallery_plugin_name() ), 'type' => 'checkbox', 'tab' => 'general', 'section' => __( 'Admin', 'foogallery' ) );
//endregion General
//region Images Tab $tabs['thumb'] = __( 'Images', 'foogallery' );
$settings[] = array( 'id' => 'thumb_jpeg_quality', 'title' => __( 'Thumbnail JPEG Quality', 'foogallery' ), 'desc' => __( 'The image quality to be used when resizing JPEG images.', 'foogallery' ), 'type' => 'text', 'default' => '80', 'tab' => 'thumb' );
$settings[] = array( 'id' => 'default_retina_support', 'title' => __( 'Default Retina Support', 'foogallery' ), 'desc' => __( 'Default retina support for all new galleries that are created. This can also be overridden for each gallery.', 'foogallery' ), 'type' => 'checkboxlist', 'choices' => foogallery_retina_options(), 'tab' => 'thumb' );
$settings[] = array( 'id' => 'use_original_thumbs', 'title' => __( 'Use Original Thumbnails', 'foogallery' ), 'desc' => __( 'Allow for the original thumbnails to be used when possible. This can be useful if your thumbs are animated gifs.<br/>PLEASE NOTE : this will only work if your gallery thumbnail sizes are identical to your thumbnail sizes under Settings -> Media.', 'foogallery' ), 'type' => 'checkbox', 'tab' => 'thumb' );
$settings[] = array( 'id' => 'thumb_resize_animations', 'title' => __( 'Resize Animated GIFs', 'foogallery' ), 'desc' => __( 'Should animated gifs be resized or not. If enabled, only the first frame is used in the resize.', 'foogallery' ), 'type' => 'checkbox', 'tab' => 'thumb' );
$settings[] = array( 'id' => 'animated_gif_use_original_image', 'title' => __( 'Show Animated Thumbnails', 'foogallery' ), 'desc' => __( 'If animated GIFs are used, then show the original GIF as the thumbnail.', 'foogallery' ), 'type' => 'checkbox', 'tab' => 'thumb' );
$settings[] = array( 'id' => 'thumb_generation_test', 'title' => __( 'Thumbnail Generation Test', 'foogallery' ), 'desc' => sprintf( __( 'Test to see if %s can generate the thumbnails it needs.', 'foogallery' ), foogallery_plugin_name() ), 'type' => 'thumb_generation_test', 'tab' => 'thumb' );
//endregion Thumbnail Tab
// //region Advanced Tab // $tabs['advanced'] = __( 'Advanced', 'foogallery' ); // // $example_url = '<code>' . trailingslashit( site_url() ) . foogallery_permalink() . '/my-cool-gallery</code>'; // // $settings[] = array( // 'id' => 'gallery_permalinks_enabled', // 'title' => __( 'Enable Friendly URL\'s', 'foogallery' ), // 'desc' => sprintf( __( 'If enabled, you will be able to access your galleries from a friendly URL e.g. %s', 'foogallery' ), $example_url ), // 'default' => foogallery_get_default( 'gallery_permalinks_enabled' ), // 'type' => 'checkbox', // 'tab' => 'advanced', // ); // // $settings[] = array( // 'id' => 'gallery_permalink', // 'title' => __( 'Gallery Permalink', 'foogallery' ), // 'desc' => __( 'If friendly URL\'s are enabled, this is used in building up a friendly URL', 'foogallery' ), // 'default' => foogallery_get_default( 'gallery_permalink' ), // 'type' => 'text', // 'tab' => 'advanced', // ); // //endregion Advanced
//region Language Tab $tabs['language'] = __( 'Language', 'foogallery' );
$settings[] = array( 'id' => 'language_images_count_none_text', 'title' => __( 'Image Count None Text', 'foogallery' ), 'type' => 'text', 'default' => __( 'No images', 'foogallery' ), 'tab' => 'language' );
$settings[] = array( 'id' => 'language_images_count_single_text', 'title' => __( 'Image Count Single Text', 'foogallery' ), 'type' => 'text', 'default' => __( '1 image', 'foogallery' ), 'tab' => 'language' );
$settings[] = array( 'id' => 'language_images_count_plural_text', 'title' => __( 'Image Count Many Text', 'foogallery' ), 'type' => 'text', 'default' => __( '%s images', 'foogallery' ), 'tab' => 'language' ); //endregion Language Tab
//region Advanced Tab $tabs['advanced'] = __( 'Advanced', 'foogallery' );
$settings[] = array( 'id' => 'enable_custom_ready', 'title' => __( 'Custom Ready Event', 'foogallery' ), 'desc' => sprintf( __( 'By default the jQuery ready event is used, but there are sometimes unavoidable javascript errors on the page, which could result in the default gallery templates not initializing correctly. Enable this setting to use a built-in custom ready event to overcome this if needed.', 'foogallery' ), foogallery_plugin_name() ), 'type' => 'checkbox', 'tab' => 'advanced' );
$settings[] = array( 'id' => 'enable_legacy_thumb_cropping', 'title' => __( 'Enable Legacy Thumb Cropping', 'foogallery' ), 'desc' => __( 'For when you want to enable legacy cropping options in certain gallery templates. This is not recommended.', 'foogallery' ), 'type' => 'checkbox', 'tab' => 'advanced' );
$settings[] = array( 'id' => 'output_json_to_script_block', 'title' => __( 'Output Gallery JSON to Script Block', 'foogallery' ), 'desc' => __( 'Some plugins conflict with the default way of rendering gallery items to the container. Enabling this setting will output gallery items to a separate script block.', 'foogallery' ), 'type' => 'checkbox', 'tab' => 'advanced' );
$settings[] = array( 'id' => 'enable_debugging', 'title' => __( 'Enable Debugging', 'foogallery' ), 'desc' => sprintf( __( 'Helps to debug problems and diagnose issues. Enable debugging if you need support for an issue you are having.', 'foogallery' ), foogallery_plugin_name() ), 'type' => 'checkbox', 'tab' => 'advanced' );
$settings[] = array( 'id' => 'uninstall', 'title' => __( 'Full Uninstall', 'foogallery' ), 'desc' => sprintf( __( 'Run a full uninstall of %s, which includes removing all galleries, settings and metadata. This basically removes all traces of the plugin from your system. Please be careful - there is no undo!', 'foogallery' ), foogallery_plugin_name() ), 'type' => 'uninstall', 'tab' => 'advanced' );
$settings[] = array( 'id' => 'use_future_endpoint', 'title' => __( 'Use Beta Endpoint', 'foogallery' ), 'desc' => __( 'The list of available extensions are pulled from an external URL. You can also pull from a "beta" endpoint which will sometimes contain beta extensions that are not publicly available.', 'foogallery' ), 'type' => 'checkbox', 'tab' => 'advanced', );
$settings[] = array( 'id' => 'override_thumb_test', 'title' => __( 'Override Thumb Test', 'foogallery' ), 'desc' => __( 'Sometimes there are problems running the thumbnail generation test. This overrides the test to use a remote image from our CDN.', 'foogallery' ), 'type' => 'checkbox', 'tab' => 'advanced', );
//endregion Advanced Tab
return apply_filters( 'foogallery_admin_settings_override', array( 'tabs' => $tabs, 'sections' => array(), 'settings' => $settings, ) ); }
/** * Render any custom setting types to the settings page */ function render_custom_setting_types( $args ) { if ( 'clear_optimization_button' === $args['type'] ) { ?> <div id="foogallery_clear_css_optimizations_container"> <input type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_clear_css_optimizations' ) ); ?>" class="button-primary foogallery_clear_css_optimizations" value="<?php _e( 'Clear CSS Optimization Cache', 'foogallery' ); ?>"> <span id="foogallery_clear_css_cache_spinner" style="position: absolute" class="spinner"></span> </div> <?php } else if ( 'uninstall' === $args['type'] ) { ?> <div id="foogallery_uninstall_container"> <input type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_uninstall' ) ); ?>" class="button-primary foogallery_uninstall" value="<?php _e( 'Run Full Uninstall', 'foogallery' ); ?>"> <span id="foogallery_uninstall_spinner" style="position: absolute" class="spinner"></span> </div> <?php } else if ( 'thumb_generation_test' === $args['type'] ) { ?> <div id="foogallery_thumb_generation_test_container"> <input type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_thumb_generation_test' ) ); ?>" class="button-primary foogallery_thumb_generation_test" value="<?php _e( 'Run Tests', 'foogallery' ); ?>"> <span id="foogallery_thumb_generation_test_spinner" style="position: absolute" class="spinner"></span> </div> <?php } }
function after_render_setting( $args ) { if ( 'default_retina_support' === $args['id'] ) {
//build up a list of retina options and add them to a hidden input // so we can get the values on the client $input_ids = array(); $count = 0; foreach( foogallery_retina_options() as $retina_option ) { $input_ids[] = '#default_retina_support' . $count; $count++; } $nonce = wp_create_nonce( 'foogallery_apply_retina_defaults' ); ?><div id="foogallery_apply_retina_support_container"> <input type="button" data-inputs="<?php echo implode( ',', $input_ids ); ?>" data-nonce="<?php echo esc_attr( $nonce ); ?>" class="button-primary foogallery_apply_retina_support" value="<?php _e( 'Apply Defaults to all Galleries', 'foogallery' ); ?>"> <span id="foogallery_apply_retina_support_spinner" style="position: absolute" class="spinner"></span> </div> <?php } }
/** * AJAX endpoint for clearing all CSS optimizations */ function ajax_clear_css_optimizations() { if ( check_admin_referer( 'foogallery_clear_css_optimizations' ) ) { foogallery_clear_all_css_load_optimizations();
_e('The CSS optimization cache was successfully cleared!', 'foogallery' ); die(); } }
/** * AJAX endpoint for testing thumbnail generation using WPThumb */ function ajax_thumb_generation_test() { if ( check_admin_referer( 'foogallery_thumb_generation_test' ) ) { foogallery_output_thumbnail_generation_results(); die(); } }
/** * AJAX endpoint for applying the retina defaults to all galleries */ function ajax_apply_retina_defaults() { if ( check_admin_referer( 'foogallery_apply_retina_defaults' ) ) {
$defaults = $_POST['defaults'];
//extract the settings using a regex $regex = '/foogallery\[default_retina_support\|(?<setting>.+?)\]/';
preg_match_all($regex, $defaults, $matches);
$gallery_retina_settings = array();
if ( isset( $matches[1] ) ) { foreach ( $matches[1] as $match ) { $gallery_retina_settings[$match] = "true"; } }
//go through all galleries and update the retina settings $galleries = foogallery_get_all_galleries(); $gallery_update_count = 0; foreach ( $galleries as $gallery ) { update_post_meta( $gallery->ID, FOOGALLERY_META_RETINA, $gallery_retina_settings ); $gallery_update_count++; }
echo sprintf( _n( '1 gallery successfully updated to use the default retina settings.', '%s galleries successfully updated to use the default retina settings.', $gallery_update_count, 'foogallery' ), $gallery_update_count );
die(); } }
function ajax_uninstall() { if ( check_admin_referer( 'foogallery_uninstall' ) && current_user_can( 'install_plugins' ) ) { foogallery_uninstall();
_e('All traces of the plugin were removed from your system!', 'foogallery' ); die(); } } } }
|