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