PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.1.36
Gallery : FooGallery v3.1.36
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / admin / class-settings.php
foogallery / includes / admin Last commit date
class-admin-notice-custom-css.php 2 months ago class-admin-notices.php 2 months ago class-admin.php 2 months ago class-attachment-fields.php 2 months ago class-columns.php 2 months ago class-demo-content.php 2 months ago class-extensions.php 2 months ago class-gallery-attachment-modal.php 2 months ago class-gallery-datasources.php 2 months ago class-gallery-editor.php 2 months ago class-gallery-metabox-fields.php 2 months ago class-gallery-metabox-items.php 2 months ago class-gallery-metabox-settings-helper.php 2 months ago class-gallery-metabox-settings.php 2 months ago class-gallery-metabox-template.php 2 months ago class-gallery-metaboxes.php 2 months ago class-menu.php 2 months ago class-pro-promotion.php 2 months ago class-settings.php 2 months ago class-silent-installer-skin.php 2 months ago class-trial-mode.php 2 months ago demo-content-galleries.php 2 months ago demo-content-images.php 2 months ago index.php 2 months ago pro-features.php 2 months ago view-features.php 2 months ago view-help-demos.php 2 months ago view-help-getting-started.php 2 months ago view-help-pro.php 2 months ago view-help.php 2 months ago view-system-info.php 2 months ago
class-settings.php
1051 lines
1 <?php
2
3 if ( ! class_exists( 'FooGallery_Admin_Settings' ) ) {
4
5 /**
6 * Class FooGallery_Admin_Settings
7 */
8 class FooGallery_Admin_Settings {
9
10 function __construct() {
11 add_filter( 'foogallery_admin_settings', array( $this, 'create_settings' ), 10, 2 );
12 add_action( 'foogallery_admin_settings_custom_type_render_setting', array( $this, 'render_custom_setting_types' ) );
13 add_action( 'foogallery_admin_settings_after_render_setting', array( $this, 'after_render_setting' ) );
14 add_action( 'update_option_foogallery', array( $this, 'generate_assets' ), 10, 3 );
15 add_filter( 'pre_update_option_foogallery', array( $this, 'sanitize_settings' ), 10, 3 );
16
17 // Ajax calls.
18 add_action( 'wp_ajax_foogallery_clear_css_optimizations', array( $this, 'ajax_clear_css_optimizations' ) );
19 add_action( 'wp_ajax_foogallery_clear_thumbnail_cache', array( $this, 'ajax_clear_thumbnail_cache' ) );
20 add_action( 'wp_ajax_foogallery_thumb_generation_test', array( $this, 'ajax_thumb_generation_test' ) );
21 add_action( 'wp_ajax_foogallery_apply_retina_defaults', array( $this, 'ajax_apply_retina_defaults' ) );
22 add_action( 'wp_ajax_foogallery_uninstall', array( $this, 'ajax_uninstall' ) );
23 }
24
25 /**
26 * Sanitize the foogallery settings.
27 *
28 * @param mixed $value The value of the settings.
29 * @param mixed $old_value The old value.
30 * @param string $option The setting name. Should be 'foogallery'.
31 *
32 * @return mixed
33 */
34 public function sanitize_settings( $value, $old_value, $option ) {
35 if ( is_array( $value ) && array_key_exists( 'custom_js', $value ) ) {
36 $value['custom_js'] = foogallery_sanitize_code( $value['custom_js'] );
37 }
38 if ( is_array( $value ) && array_key_exists( 'custom_css', $value ) ) {
39 $value['custom_css'] = foogallery_sanitize_code( $value['custom_css'] );
40 }
41 return $value;
42 }
43
44 /**
45 * Create the settings for FooGallery
46 * @return array
47 */
48 function create_settings() {
49
50 //region General Tab
51 $tabs['general'] = __( 'General', 'foogallery' );
52
53 $settings[] = array(
54 'id' => 'clear_css_optimizations',
55 'title' => __( 'Clear CSS Cache', 'foogallery' ),
56 '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() ),
57 'type' => 'clear_optimization_button',
58 'tab' => 'general',
59 'section' => __( 'Performance', 'foogallery' )
60 );
61
62 $gallery_templates = foogallery_gallery_templates();
63 $gallery_templates_choices = array();
64 foreach ( $gallery_templates as $template ) {
65 $gallery_templates_choices[ $template['slug'] ] = $template['name'];
66 }
67
68 $settings[] = array(
69 'id' => 'gallery_template',
70 'title' => __( 'Default Gallery Layout', 'foogallery' ),
71 'desc' => __( 'The default gallery layout to use for new galleries', 'foogallery' ),
72 'default' => foogallery_get_default( 'gallery_template' ) ,
73 'type' => 'select',
74 'choices' => $gallery_templates_choices,
75 'tab' => 'general',
76 'section' => __( 'Gallery Defaults', 'foogallery' )
77 );
78
79 $settings[] = array(
80 'id' => 'default_gallery_attachments',
81 'title' => __( 'Default Gallery Items', 'foogallery' ),
82 'desc' => __( 'The default attachments to use for new galleries. Provide a comma separated list of attachment IDs.', 'foogallery' ),
83 'default' => '' ,
84 'type' => 'text',
85 'tab' => 'general',
86 'section' => __( 'Gallery Defaults', 'foogallery' )
87 );
88
89 $settings[] = array(
90 'id' => 'gallery_sorting',
91 'title' => __( 'Default Gallery Sorting', 'foogallery' ),
92 'desc' => __( 'The default attachment sorting to use for new galleries', 'foogallery' ),
93 'default' => '',
94 'type' => 'select',
95 'choices' => foogallery_sorting_options(),
96 'tab' => 'general',
97 'section' => __( 'Gallery Defaults', 'foogallery' )
98 );
99
100 $gallery_posts = get_posts( array(
101 'post_type' => FOOGALLERY_CPT_GALLERY,
102 'post_status' => array( 'publish', 'draft' ),
103 'cache_results' => false,
104 'nopaging' => true,
105 ) );
106
107 $galleries = array();
108
109 foreach ( $gallery_posts as $post ) {
110 $galleries[] = array(
111 'ID' => $post->ID,
112 'name' => $post->post_title
113 );
114 }
115
116 $gallery_choices = array();
117 $gallery_choices[] = __( 'No default', 'foogallery' );
118 foreach ( $galleries as $gallery ) {
119 $gallery_choices[ $gallery['ID'] ] = esc_html( $gallery['name'] );
120 }
121
122 $settings[] = array(
123 'id' => 'default_gallery_settings',
124 'title' => __( 'Default Gallery Settings', 'foogallery' ),
125 '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' ),
126 'type' => 'select',
127 'choices' => $gallery_choices,
128 'tab' => 'general',
129 'section' => __( 'Gallery Defaults', 'foogallery' )
130 );
131
132 $settings[] = array(
133 'id' => 'caption_title_source',
134 'title' => __( 'Caption Title Source', 'foogallery' ),
135 'desc' => __( 'By default, image caption titles are pulled from the attachment "Caption" field. Alternatively, you can choose to use other fields.', 'foogallery' ),
136 'type' => 'select',
137 'choices' => array(
138 'title' => foogallery_get_attachment_field_friendly_name( 'title' ),
139 'caption' => foogallery_get_attachment_field_friendly_name( 'caption' ),
140 'alt' => foogallery_get_attachment_field_friendly_name( 'alt' ),
141 'desc' => foogallery_get_attachment_field_friendly_name( 'desc' )
142 ),
143 'default' => 'caption',
144 'tab' => 'general',
145 'section' => __( 'Captions', 'foogallery' ),
146 'spacer' => '<span class="spacer"></span>'
147 );
148
149 $settings[] = array(
150 'id' => 'caption_desc_source',
151 'title' => __( 'Caption Description Source', 'foogallery' ),
152 'desc' => __( 'By default, image caption descriptions are pulled from the attachment "Description" field. Alternatively, you can choose to use other fields.', 'foogallery' ),
153 'type' => 'select',
154 'choices' => array(
155 'title' => foogallery_get_attachment_field_friendly_name( 'title' ),
156 'caption' => foogallery_get_attachment_field_friendly_name( 'caption' ),
157 'alt' => foogallery_get_attachment_field_friendly_name( 'alt' ),
158 'desc' => foogallery_get_attachment_field_friendly_name( 'desc' )
159 ),
160 'default' => 'desc',
161 'tab' => 'general',
162 'section' => __( 'Captions', 'foogallery' ),
163 'spacer' => '<span class="spacer"></span>'
164 );
165
166 $settings[] = array(
167 'id' => 'hide_gallery_template_help',
168 'title' => __( 'Hide Gallery Settings Tips', 'foogallery' ),
169 'desc' => __( 'Some gallery settings show helpful tips, which are useful for new users. You can choose to hide these tips.', 'foogallery' ),
170 'type' => 'checkbox',
171 'tab' => 'general',
172 'section' => __( 'Admin', 'foogallery' )
173 );
174
175 $settings[] = array(
176 'id' => 'minimize_gallery_settings_help',
177 'title' => __( 'Minimize Gallery Settings Help Text', 'foogallery' ),
178 'desc' => __( 'By default, help text is displayed under each gallery setting. You can choose to minimize this and rather show a help icon that opens the help text in a tooltip.', 'foogallery' ),
179 'type' => 'checkbox',
180 'tab' => 'general',
181 'section' => __( 'Admin', 'foogallery' )
182 );
183
184 if ( ! function_exists( 'get_editable_roles' ) ) {
185 require_once ABSPATH . 'wp-admin/includes/user.php';
186 }
187
188 $roles = get_editable_roles();
189 $role_choices = array(
190 '' => __( 'Default', 'foogallery' )
191 );
192
193 foreach ( $roles as $role_slug => $role_data ) {
194 $role_choices[ $role_slug ] = $role_data['name'];
195 }
196
197 $settings[] = array(
198 'id' => 'gallery_creator_role',
199 'title' => __( 'Gallery Creator Role', 'foogallery' ),
200 'desc' => __( 'Select the user role allowed to manage galleries. All roles with higher privileges will also be able to manage galleries.', 'foogallery' ),
201 'type' => 'select',
202 'choices' => $role_choices,
203 'tab' => 'general',
204 'section' => __( 'Admin', 'foogallery' ),
205 );
206
207 $settings[] = array(
208 'id' => 'hide_editor_button',
209 'title' => __( 'Classic Editor Button', 'foogallery' ),
210 'desc' => sprintf( __( 'Either show or hide the "Add %s" button in the Classic editor.', 'foogallery' ), foogallery_plugin_name() ),
211 'default' => foogallery_get_default( 'hide_editor_button', 'on' ),
212 'type' => 'select',
213 'choices' => array(
214 'on' => __( 'Hidden', 'foogallery' ),
215 'off' => __( 'Visible', 'foogallery' )
216 ),
217 'tab' => 'general',
218 'section' => __( 'Admin', 'foogallery' )
219 );
220
221 $settings[] = array(
222 'id' => 'advanced_attachment_modal',
223 'title' => __( 'Advanced Attachment Modal', 'foogallery' ),
224 'desc' => __( 'If enabled, this will use the advanced attachment modal which allows for faster and easier editing of attachment details, when creating your galleries.', 'foogallery' ),
225 'type' => 'select',
226 'default' => foogallery_get_default( 'advanced_attachment_modal', 'on' ),
227 'tab' => 'general',
228 'section' => __( 'Admin', 'foogallery' ),
229 'choices' => array(
230 'on' => __( 'Enabled', 'foogallery' ),
231 'off' => __( 'Disabled', 'foogallery' )
232 )
233 );
234
235 $settings[] = array(
236 'id' => 'limit_gallery_selector_block_editor',
237 'type' => 'text',
238 'title' => __( 'Limit Galleries (Block Editor)', 'foogallery' ),
239 'desc' => __( 'Limit the number of galleries that are returned in the block editor when choosing a gallery.', 'foogallery' ),
240 'tab' => 'general',
241 'class' => 'foogallery_settings_short_text',
242 'section' => __( 'Admin', 'foogallery' )
243 );
244
245 // endregion General
246
247 // region Album Tab.
248 $tabs['albums'] = __( 'Albums', 'foogallery' );
249
250 // end of album region.
251
252 //region Images Tab
253 $tabs['thumb'] = __( 'Images', 'foogallery' );
254
255 $engines = array();
256 foreach ( foogallery_thumb_available_engines() as $engine_key => $engine ) {
257 $engines[$engine_key] = '<strong>' . $engine['label'] . '</strong> - ' . $engine['description'];
258 }
259
260 $settings[] = array(
261 'id' => 'thumb_engine',
262 'title' => __( 'Thumbnail Engine', 'foogallery' ),
263 'desc' => __( 'The thumbnail generation engine used when creating different sized thumbnails for your galleries.', 'foogallery' ),
264 'type' => 'radio',
265 'default' => 'default',
266 'choices' => $engines,
267 'tab' => 'thumb'
268 );
269
270 if ( foogallery_thumb_active_engine()->uses_image_editors() ) {
271 $image_editor = str_replace( 'FooGallery_Thumb_Image_Editor_', '', _wp_image_editor_choose( array( 'methods' => array( 'get_image' ) ) ) );
272 $gd_supported = extension_loaded( 'gd' ) ? __( 'yes', 'foogallery' ) : __( 'no', 'foogallery' );
273 $imagick_supported = extension_loaded( 'imagick' ) ? __( 'yes', 'foogallery' ) : __( 'no', 'foogallery' );
274
275 $settings[] = array(
276 'id' => 'thumb_image_library',
277 'title' => __( 'Thumbnail Image Library', 'foogallery' ),
278 'desc' => sprintf( __( 'Currently active : %s.<br />Imagick supported : %s.<br />GD supported : %s.', 'foogallery' ), '<strong>' . $image_editor . '</strong>', $imagick_supported, $gd_supported ),
279 'type' => 'html',
280 'tab' => 'thumb'
281 );
282 }
283
284 if ( foogallery_thumb_active_engine()->has_local_cache() ) {
285 $settings[] = array(
286 'id' => 'thumb_jpeg_quality',
287 'title' => __( 'Thumbnail JPEG Quality', 'foogallery' ),
288 'desc' => __( 'The image quality to be used when resizing JPEG images.', 'foogallery' ),
289 'type' => 'text',
290 'default' => '90',
291 'tab' => 'thumb'
292 );
293
294 $settings[] = array(
295 'id' => 'clear_thumbnail_cache',
296 'title' => __( 'Clear Thumbnail Cache', 'foogallery' ),
297 'desc' => __( 'Clear all the previously cached thumbnails that have been generated across every gallery on your site.', 'foogallery' ),
298 'type' => 'clear_thumbnail_cache_button',
299 'tab' => 'thumb'
300 );
301 }
302
303 $image_optimization_html = sprintf( __('We recommend %s! An easy-to-use, lightweight WordPress plugin that optimizes images & PDFs.', 'foogallery'),
304 '<a href="https://shortpixel.com/homepage/affiliate/foowww" target="_blank">' . __('ShortPixel Image Optimizer' , 'foogallery') . '</a>' );
305
306 $settings[] = array(
307 'id' => 'image_optimization',
308 'title' => __( 'Image Optimization', 'foogallery' ),
309 'type' => 'html',
310 'desc' => $image_optimization_html,
311 'tab' => 'thumb'
312 );
313
314 $settings[] = array(
315 'id' => 'default_retina_support',
316 'title' => __( 'Default Retina Support', 'foogallery' ),
317 'desc' => __( 'Default retina support for all new galleries that are created. This can also be overridden for each gallery.', 'foogallery' ),
318 'type' => 'checkboxlist',
319 'choices' => foogallery_retina_options(),
320 'tab' => 'thumb'
321 );
322
323 $settings[] = array(
324 'id' => 'use_original_thumbs',
325 'title' => __( 'Use Original Thumbnails', 'foogallery' ),
326 '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' ),
327 'type' => 'checkbox',
328 'tab' => 'thumb'
329 );
330
331 $settings[] = array(
332 'id' => 'animated_gif_use_original_image',
333 'title' => __( 'Show Animated Thumbnails', 'foogallery' ),
334 'desc' => __( 'If animated GIFs are used, then show the original GIF as the thumbnail.', 'foogallery' ),
335 'type' => 'checkbox',
336 'tab' => 'thumb'
337 );
338
339 if ( foogallery_thumb_active_engine()->has_local_cache() ) {
340 $settings[] = array(
341 'id' => 'thumb_resize_upscale_small',
342 'title' => __( 'Background Fill', 'foogallery' ),
343 'desc' => __( 'If the image is smaller than the thumbnail size, then use a background color to fill the space. (Previously called Upscale Small Images)', 'foogallery' ),
344 'default' => 'on',
345 'type' => 'checkbox',
346 'tab' => 'thumb'
347 );
348
349 $settings[] = array(
350 'id' => 'thumb_resize_upscale_small_color',
351 'title' => __( 'Background Fill Color', 'foogallery' ),
352 'desc' => __( 'The background color to use for upscaled images. You can also use "transparent" or "auto".', 'foogallery' ),
353 'type' => 'text',
354 'default' => 'auto',
355 'tab' => 'thumb'
356 );
357 }
358
359 if ( foogallery_thumb_active_engine()->requires_thumbnail_generation_tests() ) {
360 $thumb_test_html = '<a href="' . admin_url( add_query_arg( array( 'page' => 'foogallery_thumb_test' ), foogallery_admin_menu_parent_slug() ) ) . '">' . __( 'View Thumb Test Page', 'foogallery' ) . '</a>';
361
362 $settings[] = array(
363 'id' => 'thumb_generation_test',
364 'title' => __( 'Thumbnail Generation Test', 'foogallery' ),
365 'desc' => sprintf( __( 'Test to see if %s can generate the thumbnails it needs. %s', 'foogallery' ), foogallery_plugin_name(), $thumb_test_html ),
366 'type' => 'thumb_generation_test',
367 'tab' => 'thumb'
368 );
369 }
370
371 if ( foogallery_thumb_active_engine()->uses_image_editors() ) {
372 $settings[] = array(
373 'id' => 'force_gd_library',
374 'title' => __( 'Force GD Library', 'foogallery' ),
375 'desc' => __( 'By default, WordPress will use Imagick as the default Image Editor. This will force GD to be used as the default.', 'foogallery' ),
376 'type' => 'checkbox',
377 'tab' => 'thumb'
378 );
379 }
380
381 //endregion Thumbnail Tab
382
383 // //region Advanced Tab
384 // $tabs['advanced'] = __( 'Advanced', 'foogallery' );
385 //
386 // $example_url = '<code>' . trailingslashit( site_url() ) . foogallery_permalink() . '/my-cool-gallery</code>';
387 //
388 // $settings[] = array(
389 // 'id' => 'gallery_permalinks_enabled',
390 // 'title' => __( 'Enable Friendly URL\'s', 'foogallery' ),
391 // 'desc' => sprintf( __( 'If enabled, you will be able to access your galleries from a friendly URL e.g. %s', 'foogallery' ), $example_url ),
392 // 'default' => foogallery_get_default( 'gallery_permalinks_enabled' ),
393 // 'type' => 'checkbox',
394 // 'tab' => 'advanced',
395 // );
396 //
397 // $settings[] = array(
398 // 'id' => 'gallery_permalink',
399 // 'title' => __( 'Gallery Permalink', 'foogallery' ),
400 // 'desc' => __( 'If friendly URL\'s are enabled, this is used in building up a friendly URL', 'foogallery' ),
401 // 'default' => foogallery_get_default( 'gallery_permalink' ),
402 // 'type' => 'text',
403 // 'tab' => 'advanced',
404 // );
405 // //endregion Advanced
406
407 //region Language Tab
408 $tabs['language'] = __( 'Language', 'foogallery' );
409
410 $settings[] = array(
411 'id' => 'language_imageviewer_prev_text',
412 'title' => __( 'Image Viewer "Prev" Text', 'foogallery' ),
413 'type' => 'text',
414 'default' => __( 'Prev', 'foogallery' ),
415 'section' => __( 'Image Viewer Template', 'foogallery' ),
416 'tab' => 'language'
417 );
418
419 $settings[] = array(
420 'id' => 'language_imageviewer_next_text',
421 'title' => __( 'Image Viewer "Next" Text', 'foogallery' ),
422 'type' => 'text',
423 'default' => __( 'Next', 'foogallery' ),
424 'section' => __( 'Image Viewer Template', 'foogallery' ),
425 'tab' => 'language'
426 );
427
428 $settings[] = array(
429 'id' => 'language_imageviewer_of_text',
430 'title' => __( 'Image Viewer "Of" Text', 'foogallery' ),
431 'type' => 'text',
432 'default' => __( 'of', 'foogallery' ),
433 'section' => __( 'Image Viewer Template', 'foogallery' ),
434 'tab' => 'language'
435 );
436
437 $settings[] = array(
438 'id' => 'language_carousel_previous_text',
439 'title' => __( 'Carousel "Previous" Text', 'foogallery' ),
440 'desc' => __( 'The text that is shown when you hover over the previous arrow in the carousel.'),
441 'type' => 'text',
442 'default' => __( 'Previous', 'foogallery' ),
443 'section' => __( 'Carousel Template', 'foogallery' ),
444 'tab' => 'language'
445 );
446
447 $settings[] = array(
448 'id' => 'language_carousel_next_text',
449 'title' => __( 'Carousel "Next" Text', 'foogallery' ),
450 'desc' => __( 'The text that is shown when you hover over the next arrow in the carousel.'),
451 'type' => 'text',
452 'default' => __( 'Next', 'foogallery' ),
453 'section' => __( 'Carousel Template', 'foogallery' ),
454 'tab' => 'language'
455 );
456
457 $settings[] = array(
458 'id' => 'language_carousel_bullet_text',
459 'title' => __( 'Carousel "Bullet" Text', 'foogallery' ),
460 'desc' => __( 'The text that is shown when you hover over the bullet in the carousel.'),
461 'type' => 'text',
462 'default' => __( 'Item {ITEM}', 'foogallery' ),
463 'section' => __( 'Carousel Template', 'foogallery' ),
464 'tab' => 'language'
465 );
466
467 $settings[] = array(
468 'id' => 'language_carousel_bullet_active_text',
469 'title' => __( 'Carousel "Bullet" Active Text', 'foogallery' ),
470 'desc' => __( 'The text that is shown when you hover over the bullet in the carousel that is currently active.'),
471 'type' => 'text',
472 'default' => __( 'Item {ITEM} - Current', 'foogallery' ),
473 'section' => __( 'Carousel Template', 'foogallery' ),
474 'tab' => 'language'
475 );
476
477 $settings[] = array(
478 'id' => 'language_images_count_none_text',
479 'title' => __( 'Image Count None Text', 'foogallery' ),
480 'type' => 'text',
481 'default' => __( 'No images', 'foogallery' ),
482 'section' => __( 'Admin', 'foogallery' ),
483 'tab' => 'language'
484 );
485
486 $settings[] = array(
487 'id' => 'language_images_count_single_text',
488 'title' => __( 'Image Count Single Text', 'foogallery' ),
489 'type' => 'text',
490 'default' => __( '1 image', 'foogallery' ),
491 'section' => __( 'Admin', 'foogallery' ),
492 'tab' => 'language'
493 );
494
495 $settings[] = array(
496 'id' => 'language_images_count_plural_text',
497 'title' => __( 'Image Count Many Text', 'foogallery' ),
498 'type' => 'text',
499 'default' => __( '%s images', 'foogallery' ),
500 'section' => __( 'Admin', 'foogallery' ),
501 'tab' => 'language'
502 );
503
504 //endregion Language Tab
505
506 //region Advanced Tab
507 $tabs['advanced'] = __( 'Advanced', 'foogallery' );
508
509 $settings[] = array(
510 'id' => 'add_media_button_start',
511 'title' => __( 'Move Add Media Button', 'foogallery' ),
512 'desc' => sprintf( __( 'You can move the Add Media button to the beginning of the attachment list. This can help when your galleries have a large number of images, so you do not have to scroll.', 'foogallery' ), foogallery_plugin_name() ),
513 'type' => 'checkbox',
514 'tab' => 'advanced'
515 );
516
517 $settings[] = array(
518 'id' => 'enable_legacy_thumb_cropping',
519 'title' => __( 'Enable Legacy Thumb Cropping', 'foogallery' ),
520 'desc' => __( 'Enables legacy thumbnail cropping for the Simple Portfolio gallery template, meaning it will not crop thumbnails.<br/>PLEASE NOTE : only enable this if you have been asked to by our support team.', 'foogallery' ),
521 'type' => 'checkbox',
522 'tab' => 'advanced'
523 );
524
525 $settings[] = array(
526 'id' => 'enable_debugging',
527 'title' => __( 'Enable Debugging', 'foogallery' ),
528 '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() ),
529 'type' => 'checkbox',
530 'tab' => 'advanced'
531 );
532
533 $settings[] = array(
534 'id' => 'enqueue_polyfills',
535 'title' => __( 'Enqueue Polyfills', 'foogallery' ),
536 'desc' => sprintf( __( '%s uses modern JavaScript API\'s which may not be supported in older browsers. Enable the enqueueing of polyfills for better backwards compatibility.', 'foogallery' ), foogallery_plugin_name() ),
537 'type' => 'checkbox',
538 'tab' => 'advanced'
539 );
540
541 $settings[] = array(
542 'id' => 'force_legacy_runtime_scripts',
543 'title' => __( 'Force Legacy Runtime Loading', 'foogallery' ),
544 'desc' => __( 'Always enqueue the FooGallery runtime scripts through WordPress immediately instead of using delayed runtime loading. Existing sites upgraded from older FooGallery versions keep this enabled automatically. Disable it to opt in to delayed runtime loading.', 'foogallery' ),
545 'type' => 'checkbox',
546 'tab' => 'advanced'
547 );
548
549 $settings[] = array(
550 'id' => 'uninstall',
551 'title' => __( 'Full Uninstall', 'foogallery' ),
552 '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() ),
553 'type' => 'uninstall',
554 'tab' => 'advanced'
555 );
556
557 if ( foogallery_thumb_active_engine()->has_local_cache() ) {
558 $settings[] = array(
559 'id' => 'override_thumb_test',
560 'title' => __( 'Override Thumb Test', 'foogallery' ),
561 'desc' => __( 'Sometimes there are problems running the thumbnail generation test. This overrides the test to use a remote image from our CDN.', 'foogallery' ),
562 'type' => 'checkbox',
563 'tab' => 'advanced',
564 );
565 }
566
567 if ( !foogallery_is_pro() ) {
568 $settings[] = array(
569 'id' => 'force_hide_trial',
570 'title' => __( 'Force Hide Trial Notice', 'foogallery' ),
571 'desc' => __( 'Force the trial notice admin banner to never show', 'foogallery' ),
572 'type' => 'checkbox',
573 'tab' => 'advanced'
574 );
575 }
576
577 $settings[] = array(
578 'id' => 'demo_content',
579 'type' => 'checkbox',
580 'title' => __( 'Demo Content Created', 'foogallery' ),
581 'desc' => __( 'If the demo content has been created, then this will be checked. You can uncheck this to allow for demo content to be created again.', 'foogallery' ),
582 'tab' => 'advanced'
583 );
584
585 $settings[] = array(
586 'id' => 'attachment_id_attribute',
587 'type' => 'radio',
588 'title' => __( 'Item ID Attribute', 'foogallery' ),
589 'desc' => __( 'Each item has an ID attribute which identifies itself. Changing the attribute will change what is used for deeplinking.', 'foogallery' ),
590 'choices' => array(
591 'data-attachment-id' => __( 'data-attachment-id', 'foogallery' ),
592 'data-id' => __( 'data-id', 'foogallery' ),
593 ),
594 'tab' => 'advanced'
595 );
596
597 $custom_post_types = get_post_types( array( 'public' => true, '_builtin' => false ), 'objects' );
598
599 if ( !empty( $custom_post_types ) ) {
600 $post_type_choices = array();
601 foreach ( $custom_post_types as $post_type ) {
602 $post_type_choices[$post_type->name] = $post_type->label;
603 }
604
605 $settings[] = array(
606 'id' => 'allowed_custom_post_types',
607 'title' => __( 'Allowed Custom Post Types', 'foogallery' ),
608 'desc' => __( 'Select the custom post types where galleries can be attached.', 'foogallery' ),
609 'type' => 'checkboxlist',
610 'choices' => $post_type_choices,
611 'tab' => 'advanced'
612 );
613 }
614
615 $settings[] = array(
616 'id' => 'enable_trial_mode',
617 'title' => __( 'Admin Trial Mode', 'foogallery' ),
618 'desc' => __( 'Enables trial mode in the admin, which will highlight features that are only available in the Pro version.', 'foogallery' ),
619 'type' => 'checkbox',
620 'tab' => 'advanced'
621 );
622
623 //endregion Advanced Tab
624
625 //region Custom JS & CSS
626 $tabs['custom_assets'] = __( 'Custom JS & CSS', 'foogallery' );
627
628 $custom_assets = get_option( FOOGALLERY_OPTION_CUSTOM_ASSETS );
629 $custom_style_extra = '';
630 if ( is_array( $custom_assets ) && array_key_exists( 'style', $custom_assets ) ) {
631 $custom_style_extra = '<br /><a target="_blank" href="' . $custom_assets['style'] . '">' . __( 'Open Custom Stylesheet', 'foogallery' ) . '</a>';
632 }
633 $custom_script_extra = '';
634 if ( is_array( $custom_assets ) && array_key_exists( 'script', $custom_assets ) ) {
635 $custom_script_extra = '<br /><a target="_blank" href="' . $custom_assets['script'] . '">' . __( 'Open Custom Script', 'foogallery' ) . '</a>';
636 }
637
638 $custom_js = foogallery_get_setting( 'custom_js', '' );
639 if ( !empty( $custom_js ) && empty( $custom_script_extra ) ) {
640 $custom_script_extra = '<br /><strong>' . __( 'There was a problem generating the custom JS file! This is usually caused by a permissions issue on your server.', 'foogallery' ) . '</strong>';
641 }
642
643 $custom_css = foogallery_get_setting( 'custom_css', '' );
644 if ( !empty( $custom_css ) && empty( $custom_style_extra ) ) {
645 $custom_style_extra = '<br /><strong>' . __( 'There was a problem generating the custom CSS file! This is usually caused by a permissions issue on your server.', 'foogallery' ) . '</strong>';
646 }
647
648 $settings[] = array(
649 'id' => 'custom_js',
650 'title' => __( 'Custom Javascript', 'foogallery' ),
651 'desc' => __( 'Custom Javascript that will be added to the page when a gallery is rendered.', 'foogallery' ) . $custom_script_extra,
652 'type' => 'textarea',
653 'tab' => 'custom_assets',
654 'default' => ''
655 );
656
657 $settings[] = array(
658 'id' => 'custom_css',
659 'title' => __( 'Custom Stylesheet', 'foogallery' ),
660 'desc' => __( 'Custom CSS that will be added to the page when a gallery is rendered.', 'foogallery' ) . $custom_style_extra,
661 'type' => 'textarea',
662 'tab' => 'custom_assets',
663 'default' => ''
664 );
665 //endregion Custom JS & CSS
666
667 return apply_filters( 'foogallery_admin_settings_override', array(
668 'tabs' => $tabs,
669 'sections' => array(),
670 'settings' => $settings,
671 ) );
672 }
673
674 /**
675 * Render any custom setting types to the settings page
676 */
677 function render_custom_setting_types( $args ) {
678 if ( 'clear_optimization_button' === $args['type'] ) { ?>
679 <div id="foogallery_clear_css_optimizations_container">
680 <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 esc_attr_e( 'Clear CSS Optimization Cache', 'foogallery' ); ?>">
681 <span id="foogallery_clear_css_cache_spinner" style="position: absolute" class="spinner"></span>
682 </div>
683 <?php } else if ( 'clear_thumbnail_cache_button' === $args['type'] ) { ?>
684 <div id="foogallery_clear_thumbnail_cache_container">
685 <input type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_clear_thumbnail_cache' ) ); ?>" class="button-primary foogallery_clear_thumbnail_cache" value="<?php esc_attr_e( 'Clear Thumbnail Cache', 'foogallery' ); ?>">
686 <span id="foogallery_clear_thumbnail_cache_spinner" style="position: absolute" class="spinner"></span>
687 </div>
688 <?php } else if ( 'uninstall' === $args['type'] ) { ?>
689 <div id="foogallery_uninstall_container">
690 <?php
691 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
692 echo $this->get_uninstall_markup();
693 ?>
694 </div>
695 <?php } else if ( 'thumb_generation_test' === $args['type'] ) { ?>
696 <div id="foogallery_thumb_generation_test_container">
697 <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 esc_attr_e( 'Run Tests', 'foogallery' ); ?>">
698 <span id="foogallery_thumb_generation_test_spinner" style="position: absolute" class="spinner"></span>
699 </div>
700 <?php }
701 }
702
703 /**
704 * Build the uninstall control markup.
705 *
706 * @param bool $show_confirmation Whether to include the confirmation UI.
707 * @param string $error_message Optional validation error to show in the danger zone.
708 *
709 * @return string
710 */
711 private function get_uninstall_markup( $show_confirmation = false, $error_message = '' ) {
712 ob_start();
713 ?>
714 <input type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_uninstall' ) ); ?>" class="button-primary foogallery_uninstall" value="<?php esc_attr_e( 'Run Full Uninstall', 'foogallery' ); ?>">
715 <span id="foogallery_uninstall_spinner" style="position: absolute" class="spinner"></span>
716 <?php if ( $show_confirmation ) { ?>
717 <div class="foogallery-uninstall-danger-zone">
718 <p class="foogallery-uninstall-danger-zone__title"><?php esc_html_e( 'Danger Zone', 'foogallery' ); ?></p>
719 <p class="description"><?php esc_html_e( 'Type UNINSTALL to confirm permanent removal of all FooGallery galleries, settings, and metadata.', 'foogallery' ); ?></p>
720 <?php if ( ! empty( $error_message ) ) { ?>
721 <p class="foogallery-uninstall-danger-zone__error"><?php echo esc_html( $error_message ); ?></p>
722 <?php } ?>
723 <label class="screen-reader-text" for="foogallery_uninstall_confirmation"><?php esc_html_e( 'Type UNINSTALL to confirm the full uninstall.', 'foogallery' ); ?></label>
724 <input type="text" id="foogallery_uninstall_confirmation" class="regular-text foogallery-uninstall-danger-zone__input" value="" autocomplete="off" autocapitalize="characters" spellcheck="false" placeholder="<?php echo esc_attr__( 'UNINSTALL', 'foogallery' ); ?>">
725 <input type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_uninstall' ) ); ?>" class="button button-secondary foogallery_uninstall_confirm" value="<?php esc_attr_e( 'Confirm Full Uninstall', 'foogallery' ); ?>">
726 </div>
727 <?php }
728
729 return ob_get_clean();
730 }
731
732 /**
733 * Build the uninstall success message markup.
734 *
735 * @return string
736 */
737 private function get_uninstall_success_markup() {
738 ob_start();
739 ?>
740 <div class="notice notice-success inline">
741 <p><?php esc_html_e( 'All traces of the plugin were removed from your system!', 'foogallery' ); ?></p>
742 </div>
743 <?php
744
745 return ob_get_clean();
746 }
747
748 function after_render_setting( $args ) {
749 if ( 'default_retina_support' === $args['id'] ) {
750
751 //build up a list of retina options and add them to a hidden input
752 // so we can get the values on the client
753 $input_ids = array();
754 $count = 0;
755 foreach( foogallery_retina_options() as $retina_option ) {
756 $input_ids[] = '#default_retina_support' . $count;
757 $count++;
758 }
759 $nonce = wp_create_nonce( 'foogallery_apply_retina_defaults' );
760 ?><div id="foogallery_apply_retina_support_container">
761 <input type="button" data-inputs="<?php echo esc_attr( implode( ',', $input_ids ) ); ?>" data-nonce="<?php echo esc_attr( $nonce ); ?>" class="button-primary foogallery_apply_retina_support" value="<?php esc_attr_e( 'Apply Defaults to all Galleries', 'foogallery' ); ?>">
762 <span id="foogallery_apply_retina_support_spinner" style="position: absolute" class="spinner"></span>
763 </div>
764 <?php }
765 }
766
767 /**
768 * AJAX endpoint for clearing all CSS optimizations
769 */
770 function ajax_clear_css_optimizations() {
771 if ( ! check_ajax_referer( 'foogallery_clear_css_optimizations', '_wpnonce', false ) ) {
772 wp_send_json_error(
773 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
774 403
775 );
776 }
777
778 if ( ! current_user_can( 'manage_options' ) ) {
779 wp_send_json_error(
780 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
781 403
782 );
783 }
784
785 foogallery_clear_all_css_load_optimizations();
786
787 wp_send_json_success(
788 array( 'html' => esc_html__( 'The CSS optimization cache was successfully cleared!', 'foogallery' ) )
789 );
790 }
791
792 /**
793 * AJAX endpoint for clearing thumbnail cache across all galleries.
794 */
795 function ajax_clear_thumbnail_cache() {
796 if ( ! check_ajax_referer( 'foogallery_clear_thumbnail_cache', '_wpnonce', false ) ) {
797 wp_send_json_error(
798 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
799 403
800 );
801 }
802
803 if ( ! current_user_can( 'manage_options' ) ) {
804 wp_send_json_error(
805 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
806 403
807 );
808 }
809
810 $engine = foogallery_thumb_active_engine();
811 if ( ! $engine->has_local_cache() ) {
812 wp_send_json_success(
813 array( 'html' => esc_html__( 'There was no thumbnail cache to clear.', 'foogallery' ) )
814 );
815 }
816
817 $galleries = foogallery_get_all_galleries(
818 false,
819 array(
820 'post_status' => 'any',
821 )
822 );
823
824 $gallery_clear_count = 0;
825 foreach ( $galleries as $gallery ) {
826 FooGallery_Admin_Gallery_MetaBoxes::clear_gallery_thumbnail_cache( $gallery );
827 $gallery_clear_count++;
828 }
829
830 if ( 0 === $gallery_clear_count ) {
831 wp_send_json_success(
832 array( 'html' => esc_html__( 'There were no galleries found to clear.', 'foogallery' ) )
833 );
834 }
835
836 /* translators: %s: number of galleries cleared. */
837 $message = sprintf(
838 _n(
839 '1 gallery successfully cleared of cached thumbnails.',
840 '%s galleries successfully cleared of cached thumbnails.',
841 $gallery_clear_count,
842 'foogallery'
843 ),
844 absint( $gallery_clear_count )
845 );
846
847 wp_send_json_success(
848 array( 'html' => esc_html( $message ) )
849 );
850 }
851
852 /**
853 * AJAX endpoint for testing thumbnail generation
854 */
855 function ajax_thumb_generation_test() {
856 if ( ! check_ajax_referer( 'foogallery_thumb_generation_test', '_wpnonce', false ) ) {
857 wp_send_json_error(
858 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
859 403
860 );
861 }
862
863 if ( ! current_user_can( 'manage_options' ) ) {
864 wp_send_json_error(
865 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
866 403
867 );
868 }
869
870 ob_start();
871 foogallery_output_thumbnail_generation_results();
872 $html = ob_get_clean();
873
874 wp_send_json_success( array( 'html' => $html ) );
875 }
876
877 /**
878 * AJAX endpoint for applying the retina defaults to all galleries
879 */
880 function ajax_apply_retina_defaults() {
881 if ( ! check_ajax_referer( 'foogallery_apply_retina_defaults', '_wpnonce', false ) ) {
882 wp_send_json_error(
883 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
884 403
885 );
886 }
887
888 if ( ! current_user_can( 'manage_options' ) ) {
889 wp_send_json_error(
890 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
891 403
892 );
893 }
894
895 $defaults = isset( $_POST['defaults'] ) ? sanitize_text_field( wp_unslash( $_POST['defaults'] ) ) : '';
896
897 //extract the settings using a regex
898 $regex = '/foogallery\[default_retina_support\|(?<setting>.+?)\]/';
899
900 preg_match_all( $regex, $defaults, $matches );
901
902 $gallery_retina_settings = array();
903
904 if ( isset( $matches[1] ) ) {
905 foreach ( $matches[1] as $match ) {
906 $gallery_retina_settings[ $match ] = 'true';
907 }
908 }
909
910 //go through all galleries and update the retina settings
911 $galleries = foogallery_get_all_galleries();
912 $gallery_update_count = 0;
913 foreach ( $galleries as $gallery ) {
914 update_post_meta( $gallery->ID, FOOGALLERY_META_RETINA, $gallery_retina_settings );
915 $gallery_update_count++;
916 }
917
918 /* translators: %s: number of galleries updated. */
919 $message = sprintf(
920 _n(
921 '1 gallery successfully updated to use the default retina settings.',
922 '%s galleries successfully updated to use the default retina settings.',
923 $gallery_update_count,
924 'foogallery'
925 ),
926 absint( $gallery_update_count )
927 );
928
929 wp_send_json_success( array( 'html' => esc_html( $message ) ) );
930 }
931
932 function ajax_uninstall() {
933 if ( ! check_ajax_referer( 'foogallery_uninstall', '_wpnonce', false ) ) {
934 wp_send_json_error(
935 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
936 403
937 );
938 }
939
940 if ( ! current_user_can( 'install_plugins' ) ) {
941 wp_send_json_error(
942 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
943 403
944 );
945 }
946
947 $confirmation = '';
948 if ( isset( $_POST['confirmation'] ) ) {
949 $confirmation = sanitize_text_field( wp_unslash( $_POST['confirmation'] ) );
950 $confirmation = trim( $confirmation );
951 }
952
953 if ( '' === $confirmation ) {
954 wp_send_json_success(
955 array( 'html' => $this->get_uninstall_markup( true ) )
956 );
957 }
958
959 if ( 'UNINSTALL' !== $confirmation ) {
960 wp_send_json_error(
961 array(
962 'html' => $this->get_uninstall_markup(
963 true,
964 __( 'Type UNINSTALL exactly to confirm the full uninstall.', 'foogallery' )
965 ),
966 'message' => __( 'Type UNINSTALL exactly to confirm the full uninstall.', 'foogallery' ),
967 ),
968 400
969 );
970 }
971
972 foogallery_uninstall();
973
974 wp_send_json_success(
975 array( 'html' => $this->get_uninstall_success_markup() )
976 );
977 }
978
979 function generate_assets( $old_value, $value, $option) {
980 if ( !current_user_can( 'manage_options' ) ) {
981 return;
982 }
983
984 $custom_assets = array();
985
986 if ( is_array( $value ) && array_key_exists( 'custom_js', $value ) ) {
987 $custom_js = foogallery_prepare_code( $value['custom_js'] );
988
989 if ( !empty( $custom_js ) ) {
990 $custom_js = '/*
991 * FooGallery Custom Javascript
992 * This file is created by adding custom JS on FooGallery Settings page in wp-admin
993 * Created : ' . date( 'j M Y, g:i a', time() ) . '
994 */
995
996 '. $custom_js;
997 //generate script in upload folder
998 $script_url = $this->generate_custom_asset( 'custom.js', $custom_js );
999 if ( $script_url !== false ) {
1000 $custom_assets['script'] = $script_url;
1001 }
1002 }
1003 }
1004
1005 //check if we have saved any custom CSS
1006 if ( is_array( $value ) && array_key_exists( 'custom_css', $value ) ) {
1007 $custom_css = foogallery_prepare_code( $value['custom_css'] );
1008
1009 if ( !empty( $custom_css ) ) {
1010 $custom_css = '/*
1011 * FooGallery Custom CSS
1012 * This file is created by adding custom CSS on FooGallery Settings page in wp-admin
1013 * Created : ' . date( 'j M Y, g:i a', time() ) . '
1014 */
1015
1016 '. $custom_css;
1017 //generate stylesheet in upload folder
1018 $style_url = $this->generate_custom_asset( 'custom.css', $custom_css );
1019 if ( $style_url !== false ) {
1020 $custom_assets['style'] = $style_url;
1021 }
1022 }
1023 }
1024
1025 //set another option with the details
1026 if ( count( $custom_assets ) > 0 ) {
1027 update_option( FOOGALLERY_OPTION_CUSTOM_ASSETS, $custom_assets );
1028 } else {
1029 delete_option( FOOGALLERY_OPTION_CUSTOM_ASSETS );
1030 }
1031 }
1032
1033 function generate_custom_asset( $filename, $contents ) {
1034 $upload_dir = wp_upload_dir();
1035 if ( !empty( $upload_dir['basedir'] ) ) {
1036 $dir = trailingslashit( $upload_dir['basedir'] ) . 'foogallery/';
1037
1038 $fs = foogallery_wp_filesystem();
1039 if ( false !== $fs ) {
1040 $fs->mkdir( $dir ); // Make a new folder for storing our file
1041 if ( $fs->put_contents( $dir . $filename, $contents, 0644 ) ) {
1042 return set_url_scheme( trailingslashit( $upload_dir['baseurl'] ) . 'foogallery/' . $filename );
1043 }
1044 }
1045 }
1046
1047 return false;
1048 }
1049 }
1050 }
1051