PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.3.0
Gallery : FooGallery v3.3.0
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 1 week ago class-admin-notices.php 1 week ago class-admin.php 1 week ago class-attachment-fields.php 1 week ago class-columns.php 1 week ago class-demo-content.php 1 week ago class-extensions.php 1 week ago class-gallery-attachment-modal.php 1 week ago class-gallery-datasources.php 1 week ago class-gallery-editor.php 1 week ago class-gallery-metabox-fields.php 1 week ago class-gallery-metabox-items.php 1 week ago class-gallery-metabox-settings-helper.php 1 week ago class-gallery-metabox-settings.php 1 week ago class-gallery-metabox-template.php 1 week ago class-gallery-metaboxes.php 1 week ago class-menu.php 1 week ago class-pro-promotion.php 1 week ago class-settings.php 1 week ago class-silent-installer-skin.php 1 week ago class-trial-mode.php 1 week ago demo-content-galleries.php 1 week ago demo-content-images.php 1 week ago index.php 1 week ago pro-features.php 1 week ago view-features.php 1 week ago view-help-demos.php 1 week ago view-help-getting-started.php 1 week ago view-help-pro.php 1 week ago view-help.php 1 week ago view-system-info.php 1 week ago
class-settings.php
1218 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' => __( 'Move the Add Media button to the beginning of the gallery item list, making it easier to reach in galleries with many images.', 'foogallery' ),
523 'type' => 'checkbox',
524 'tab' => 'advanced',
525 'section' => __( 'Gallery Builder & Output', 'foogallery' ),
526 );
527
528 $settings[] = array(
529 'id' => 'enable_legacy_thumb_cropping',
530 'title' => __( 'Enable Legacy Thumb Cropping', 'foogallery' ),
531 'desc' => __( 'Restore the older Portfolio behavior that does not crop thumbnails to fixed dimensions. Enable this only for galleries created with that behavior or when requested by support.', 'foogallery' ),
532 'type' => 'checkbox',
533 'tab' => 'advanced',
534 'section' => __( 'Troubleshooting & Legacy Support', 'foogallery' ),
535 );
536
537 $settings[] = array(
538 'id' => 'enable_debugging',
539 'title' => __( 'Enable Debugging', 'foogallery' ),
540 'desc' => __( 'Show additional diagnostic information that can help investigate gallery problems. Enable this temporarily while troubleshooting or when requested by support.', 'foogallery' ),
541 'type' => 'checkbox',
542 'tab' => 'advanced',
543 'section' => __( 'Troubleshooting & Legacy Support', 'foogallery' ),
544 );
545
546 $settings[] = array(
547 'id' => 'enqueue_polyfills',
548 'title' => __( 'Enqueue Polyfills', 'foogallery' ),
549 'desc' => __( 'Load additional compatibility scripts for older browsers that do not support the modern JavaScript features used by gallery layouts.', 'foogallery' ),
550 'type' => 'checkbox',
551 'tab' => 'advanced',
552 'section' => __( 'Gallery Loading & Compatibility', 'foogallery' ),
553 );
554
555 $settings[] = array(
556 'id' => 'force_legacy_runtime_scripts',
557 'title' => __( 'Force Legacy Runtime Loading', 'foogallery' ),
558 'desc' => __( 'Load gallery scripts immediately through WordPress instead of using delayed runtime loading. Enable this if galleries do not start correctly with delayed loading. Existing sites upgraded from older versions may have this enabled automatically.', 'foogallery' ),
559 'type' => 'checkbox',
560 'tab' => 'advanced',
561 'section' => __( 'Gallery Loading & Compatibility', 'foogallery' ),
562 );
563
564 $settings[] = array(
565 'id' => 'uninstall',
566 'title' => __( 'Full Uninstall', 'foogallery' ),
567 'desc' => __( 'Permanently remove all galleries created with this plugin, along with its settings and related metadata. This cannot be undone, so create a backup before continuing.', 'foogallery' ),
568 'type' => 'uninstall',
569 'tab' => 'advanced',
570 'section' => __( 'Data Removal', 'foogallery' ),
571 );
572
573 if ( foogallery_thumb_active_engine()->has_local_cache() ) {
574 $settings[] = array(
575 'id' => 'override_thumb_test',
576 'title' => __( 'Override Thumb Test', 'foogallery' ),
577 'desc' => __( 'Use a remote test image instead of an image from the Media Library when checking thumbnail generation. Enable this only if the normal thumbnail test cannot run successfully.', 'foogallery' ),
578 'type' => 'checkbox',
579 'tab' => 'advanced',
580 'section' => __( 'Troubleshooting & Legacy Support', 'foogallery' ),
581 );
582 }
583
584 if ( !foogallery_is_pro() ) {
585 $settings[] = array(
586 'id' => 'force_hide_trial',
587 'title' => __( 'Force Hide Trial Notice', 'foogallery' ),
588 'desc' => __( 'Permanently hide the trial notice in the WordPress admin.', 'foogallery' ),
589 'type' => 'checkbox',
590 'tab' => 'advanced',
591 'section' => __( 'WordPress Admin', 'foogallery' ),
592 );
593 }
594
595 $settings[] = array(
596 'id' => 'demo_content',
597 'type' => 'checkbox',
598 'title' => __( 'Demo Content Created', 'foogallery' ),
599 'desc' => __( 'This is checked after demo content has been created. Clear it and save the settings to allow the demo content to be created again. Existing demo galleries are not removed.', 'foogallery' ),
600 'tab' => 'advanced',
601 'section' => __( 'WordPress Admin', 'foogallery' ),
602 );
603
604 $settings[] = array(
605 'id' => 'attachment_id_attribute',
606 'type' => 'radio',
607 'title' => __( 'Item ID Attribute', 'foogallery' ),
608 'desc' => __( 'Choose the HTML attribute used to identify gallery items for deeplinking and integrations. Keep the default unless a theme, extension, or custom script requires the alternative.', 'foogallery' ),
609 'choices' => array(
610 'data-attachment-id' => __( 'data-attachment-id', 'foogallery' ),
611 'data-id' => __( 'data-id', 'foogallery' ),
612 ),
613 'tab' => 'advanced',
614 'section' => __( 'Gallery Builder & Output', 'foogallery' ),
615 );
616
617 $custom_post_types = get_post_types( array( 'public' => true, '_builtin' => false ), 'objects' );
618
619 if ( !empty( $custom_post_types ) ) {
620 $post_type_choices = array();
621 foreach ( $custom_post_types as $post_type ) {
622 $post_type_choices[$post_type->name] = $post_type->label;
623 }
624
625 $settings[] = array(
626 'id' => 'allowed_custom_post_types',
627 'title' => __( 'Allowed Custom Post Types', 'foogallery' ),
628 'desc' => __( 'Select the custom post types where galleries can be attached or selected. Posts and pages are always supported.', 'foogallery' ),
629 'type' => 'checkboxlist',
630 'choices' => $post_type_choices,
631 'tab' => 'advanced',
632 'section' => __( 'Gallery Builder & Output', 'foogallery' ),
633 );
634 }
635
636 $settings[] = array(
637 'id' => 'enable_trial_mode',
638 'title' => __( 'Admin Trial Mode', 'foogallery' ),
639 'desc' => __( 'Highlight gallery layouts and features available in other plans. This does not activate those features or start a trial.', 'foogallery' ),
640 'type' => 'checkbox',
641 'tab' => 'advanced',
642 'section' => __( 'WordPress Admin', 'foogallery' ),
643 );
644
645 //endregion Advanced Tab
646
647 //region Custom JS & CSS
648 $tabs['custom_assets'] = __( 'Custom JS & CSS', 'foogallery' );
649
650 $custom_assets = get_option( FOOGALLERY_OPTION_CUSTOM_ASSETS );
651 $custom_style_extra = '';
652 if ( is_array( $custom_assets ) && array_key_exists( 'style', $custom_assets ) ) {
653 $custom_style_extra = '<br /><a target="_blank" href="' . $custom_assets['style'] . '">' . __( 'Open Custom Stylesheet', 'foogallery' ) . '</a>';
654 }
655 $custom_script_extra = '';
656 if ( is_array( $custom_assets ) && array_key_exists( 'script', $custom_assets ) ) {
657 $custom_script_extra = '<br /><a target="_blank" href="' . $custom_assets['script'] . '">' . __( 'Open Custom Script', 'foogallery' ) . '</a>';
658 }
659
660 $custom_js = foogallery_get_setting( 'custom_js', '' );
661 if ( !empty( $custom_js ) && empty( $custom_script_extra ) ) {
662 $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>';
663 }
664
665 $custom_css = foogallery_get_setting( 'custom_css', '' );
666 if ( !empty( $custom_css ) && empty( $custom_style_extra ) ) {
667 $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>';
668 }
669
670 $settings[] = array(
671 'id' => 'custom_js',
672 'title' => __( 'Custom Javascript', 'foogallery' ),
673 'desc' => __( 'Custom Javascript that will be added to the page when a gallery is rendered.', 'foogallery' ) . $custom_script_extra,
674 'type' => 'textarea',
675 'tab' => 'custom_assets',
676 'default' => ''
677 );
678
679 $settings[] = array(
680 'id' => 'custom_css',
681 'title' => __( 'Custom Stylesheet', 'foogallery' ),
682 'desc' => __( 'Custom CSS that will be added to the page when a gallery is rendered.', 'foogallery' ) . $custom_style_extra,
683 'type' => 'textarea',
684 'tab' => 'custom_assets',
685 'default' => ''
686 );
687 //endregion Custom JS & CSS
688
689 $settings = apply_filters( 'foogallery_admin_settings_override', array(
690 'tabs' => $tabs,
691 'sections' => array(),
692 'settings' => $settings,
693 ) );
694
695 return $this->organize_advanced_settings( $settings );
696 }
697
698 /**
699 * Group and order global Advanced settings after all feature filters have run.
700 *
701 * @param array $settings The complete global settings configuration.
702 *
703 * @return array The organized settings configuration.
704 */
705 public function organize_advanced_settings( $settings ) {
706 if ( empty( $settings['settings'] ) || ! is_array( $settings['settings'] ) ) {
707 return $settings;
708 }
709
710 $groups = array(
711 'gallery_loading' => array(
712 'name' => __( 'Gallery Loading & Compatibility', 'foogallery' ),
713 'settings' => array(
714 'lazy_loading_mode',
715 'disable_no_js_thumbnail_fallback',
716 'enqueue_polyfills',
717 'force_legacy_runtime_scripts',
718 'force_https',
719 ),
720 ),
721 'gallery_builder' => array(
722 'name' => __( 'Gallery Builder & Output', 'foogallery' ),
723 'settings' => array(
724 'add_media_button_start',
725 'attachment_id_attribute',
726 'allowed_custom_post_types',
727 ),
728 ),
729 'media_library' => array(
730 'name' => __( 'Media Library & Sources', 'foogallery' ),
731 'settings' => array(
732 'disable_attachment_taxonomies',
733 'disable_media_category_sidebar',
734 'show_media_folders_in_all_media_modals',
735 'override_media_category_taxonomy',
736 'root_folder',
737 ),
738 ),
739 'troubleshooting' => array(
740 'name' => __( 'Troubleshooting & Legacy Support', 'foogallery' ),
741 'settings' => array(
742 'enable_legacy_thumb_cropping',
743 'enable_debugging',
744 'override_thumb_test',
745 ),
746 ),
747 'wordpress_admin' => array(
748 'name' => __( 'WordPress Admin', 'foogallery' ),
749 'settings' => array(
750 'force_hide_trial',
751 'pro_promo_disabled',
752 'enable_trial_mode',
753 'demo_content',
754 ),
755 ),
756 'data_removal' => array(
757 'name' => __( 'Data Removal', 'foogallery' ),
758 'settings' => array(
759 'uninstall',
760 ),
761 ),
762 );
763
764 $setting_positions = array();
765 $group_positions = array();
766 $group_names = array();
767
768 foreach ( $groups as $group_position => $group ) {
769 $group_positions[ $group_position ] = count( $group_positions );
770 $group_names[ $group['name'] ] = $group_positions[ $group_position ];
771
772 foreach ( $group['settings'] as $setting_position => $setting_id ) {
773 $setting_positions[ $setting_id ] = array(
774 'group' => $group_positions[ $group_position ],
775 'position' => $setting_position,
776 'section' => $group['name'],
777 );
778 }
779 }
780
781 $advanced_settings = array();
782 $other_settings = array();
783 $advanced_insert_position = null;
784
785 foreach ( $settings['settings'] as $original_position => $setting ) {
786 if ( isset( $setting['tab'] ) && 'advanced' === $setting['tab'] ) {
787 if ( null === $advanced_insert_position ) {
788 $advanced_insert_position = count( $other_settings );
789 }
790
791 $setting_id = isset( $setting['id'] ) ? $setting['id'] : '';
792 if ( isset( $setting_positions[ $setting_id ] ) ) {
793 $setting['section'] = $setting_positions[ $setting_id ]['section'];
794 $group_position = $setting_positions[ $setting_id ]['group'];
795 $setting_position = $setting_positions[ $setting_id ]['position'];
796 } else {
797 $section = isset( $setting['section'] ) ? $setting['section'] : '';
798 $group_position = isset( $group_names[ $section ] ) ? $group_names[ $section ] : count( $groups ) - 3;
799 $setting_position = PHP_INT_MAX;
800 }
801
802 $advanced_settings[] = array(
803 'field' => $setting,
804 'group_position' => $group_position,
805 'setting_position' => $setting_position,
806 'original_position' => $original_position,
807 );
808 } else {
809 $other_settings[] = $setting;
810 }
811 }
812
813 if ( empty( $advanced_settings ) ) {
814 return $settings;
815 }
816
817 usort( $advanced_settings, function ( $left, $right ) {
818 if ( $left['group_position'] !== $right['group_position'] ) {
819 return $left['group_position'] - $right['group_position'];
820 }
821
822 if ( $left['setting_position'] !== $right['setting_position'] ) {
823 return $left['setting_position'] - $right['setting_position'];
824 }
825
826 return $left['original_position'] - $right['original_position'];
827 } );
828
829 $advanced_settings = array_map( function ( $setting ) {
830 return $setting['field'];
831 }, $advanced_settings );
832
833 array_splice( $other_settings, $advanced_insert_position, 0, $advanced_settings );
834 $settings['settings'] = $other_settings;
835
836 return $settings;
837 }
838
839 /**
840 * Render any custom setting types to the settings page
841 */
842 function render_custom_setting_types( $args ) {
843 if ( 'clear_optimization_button' === $args['type'] ) { ?>
844 <div id="foogallery_clear_css_optimizations_container">
845 <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' ); ?>">
846 <span id="foogallery_clear_css_cache_spinner" style="position: absolute" class="spinner"></span>
847 </div>
848 <?php } else if ( 'clear_thumbnail_cache_button' === $args['type'] ) { ?>
849 <div id="foogallery_clear_thumbnail_cache_container">
850 <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' ); ?>">
851 <span id="foogallery_clear_thumbnail_cache_spinner" style="position: absolute" class="spinner"></span>
852 </div>
853 <?php } else if ( 'uninstall' === $args['type'] ) { ?>
854 <div id="foogallery_uninstall_container">
855 <?php
856 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
857 echo $this->get_uninstall_markup();
858 ?>
859 </div>
860 <?php } else if ( 'thumb_generation_test' === $args['type'] ) { ?>
861 <div id="foogallery_thumb_generation_test_container">
862 <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' ); ?>">
863 <span id="foogallery_thumb_generation_test_spinner" style="position: absolute" class="spinner"></span>
864 </div>
865 <?php }
866 }
867
868 /**
869 * Build the uninstall control markup.
870 *
871 * @param bool $show_confirmation Whether to include the confirmation UI.
872 * @param string $error_message Optional validation error to show in the danger zone.
873 *
874 * @return string
875 */
876 private function get_uninstall_markup( $show_confirmation = false, $error_message = '' ) {
877 ob_start();
878 ?>
879 <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' ); ?>">
880 <span id="foogallery_uninstall_spinner" style="position: absolute" class="spinner"></span>
881 <?php if ( $show_confirmation ) { ?>
882 <div class="foogallery-uninstall-danger-zone">
883 <p class="foogallery-uninstall-danger-zone__title"><?php esc_html_e( 'Danger Zone', 'foogallery' ); ?></p>
884 <p class="description"><?php esc_html_e( 'Type UNINSTALL to confirm permanent removal of all FooGallery galleries, settings, and metadata.', 'foogallery' ); ?></p>
885 <?php if ( ! empty( $error_message ) ) { ?>
886 <p class="foogallery-uninstall-danger-zone__error"><?php echo esc_html( $error_message ); ?></p>
887 <?php } ?>
888 <label class="screen-reader-text" for="foogallery_uninstall_confirmation"><?php esc_html_e( 'Type UNINSTALL to confirm the full uninstall.', 'foogallery' ); ?></label>
889 <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' ); ?>">
890 <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' ); ?>">
891 </div>
892 <?php }
893
894 return ob_get_clean();
895 }
896
897 /**
898 * Build the uninstall success message markup.
899 *
900 * @return string
901 */
902 private function get_uninstall_success_markup() {
903 ob_start();
904 ?>
905 <div class="notice notice-success inline">
906 <p><?php esc_html_e( 'All traces of the plugin were removed from your system!', 'foogallery' ); ?></p>
907 </div>
908 <?php
909
910 return ob_get_clean();
911 }
912
913 function after_render_setting( $args ) {
914 if ( 'default_retina_support' === $args['id'] ) {
915
916 //build up a list of retina options and add them to a hidden input
917 // so we can get the values on the client
918 $input_ids = array();
919 $count = 0;
920 foreach( foogallery_retina_options() as $retina_option ) {
921 $input_ids[] = '#default_retina_support' . $count;
922 $count++;
923 }
924 $nonce = wp_create_nonce( 'foogallery_apply_retina_defaults' );
925 ?><div id="foogallery_apply_retina_support_container">
926 <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' ); ?>">
927 <span id="foogallery_apply_retina_support_spinner" style="position: absolute" class="spinner"></span>
928 </div>
929 <?php }
930 }
931
932 /**
933 * AJAX endpoint for clearing all CSS optimizations
934 */
935 function ajax_clear_css_optimizations() {
936 if ( ! check_ajax_referer( 'foogallery_clear_css_optimizations', '_wpnonce', false ) ) {
937 wp_send_json_error(
938 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
939 403
940 );
941 }
942
943 if ( ! current_user_can( 'manage_options' ) ) {
944 wp_send_json_error(
945 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
946 403
947 );
948 }
949
950 foogallery_clear_all_css_load_optimizations();
951
952 wp_send_json_success(
953 array( 'html' => esc_html__( 'The CSS optimization cache was successfully cleared!', 'foogallery' ) )
954 );
955 }
956
957 /**
958 * AJAX endpoint for clearing thumbnail cache across all galleries.
959 */
960 function ajax_clear_thumbnail_cache() {
961 if ( ! check_ajax_referer( 'foogallery_clear_thumbnail_cache', '_wpnonce', false ) ) {
962 wp_send_json_error(
963 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
964 403
965 );
966 }
967
968 if ( ! current_user_can( 'manage_options' ) ) {
969 wp_send_json_error(
970 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
971 403
972 );
973 }
974
975 $engine = foogallery_thumb_active_engine();
976 if ( ! $engine->has_local_cache() ) {
977 wp_send_json_success(
978 array( 'html' => esc_html__( 'There was no thumbnail cache to clear.', 'foogallery' ) )
979 );
980 }
981
982 $galleries = foogallery_get_all_galleries(
983 false,
984 array(
985 'post_status' => 'any',
986 )
987 );
988
989 $gallery_clear_count = 0;
990 foreach ( $galleries as $gallery ) {
991 FooGallery_Admin_Gallery_MetaBoxes::clear_gallery_thumbnail_cache( $gallery );
992 $gallery_clear_count++;
993 }
994
995 if ( 0 === $gallery_clear_count ) {
996 wp_send_json_success(
997 array( 'html' => esc_html__( 'There were no galleries found to clear.', 'foogallery' ) )
998 );
999 }
1000
1001 /* translators: %s: number of galleries cleared. */
1002 $message = sprintf(
1003 /* translators: %s: Value inserted at runtime. */
1004 _n(
1005 '1 gallery successfully cleared of cached thumbnails.',
1006 '%s galleries successfully cleared of cached thumbnails.',
1007 $gallery_clear_count,
1008 'foogallery'
1009 ),
1010 absint( $gallery_clear_count )
1011 );
1012
1013 wp_send_json_success(
1014 array( 'html' => esc_html( $message ) )
1015 );
1016 }
1017
1018 /**
1019 * AJAX endpoint for testing thumbnail generation
1020 */
1021 function ajax_thumb_generation_test() {
1022 if ( ! check_ajax_referer( 'foogallery_thumb_generation_test', '_wpnonce', false ) ) {
1023 wp_send_json_error(
1024 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
1025 403
1026 );
1027 }
1028
1029 if ( ! current_user_can( 'manage_options' ) ) {
1030 wp_send_json_error(
1031 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
1032 403
1033 );
1034 }
1035
1036 ob_start();
1037 foogallery_output_thumbnail_generation_results();
1038 $html = ob_get_clean();
1039
1040 wp_send_json_success( array( 'html' => $html ) );
1041 }
1042
1043 /**
1044 * AJAX endpoint for applying the retina defaults to all galleries
1045 */
1046 function ajax_apply_retina_defaults() {
1047 if ( ! check_ajax_referer( 'foogallery_apply_retina_defaults', '_wpnonce', false ) ) {
1048 wp_send_json_error(
1049 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
1050 403
1051 );
1052 }
1053
1054 if ( ! current_user_can( 'manage_options' ) ) {
1055 wp_send_json_error(
1056 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
1057 403
1058 );
1059 }
1060
1061 $defaults = isset( $_POST['defaults'] ) ? sanitize_text_field( wp_unslash( $_POST['defaults'] ) ) : '';
1062
1063 //extract the settings using a regex
1064 $regex = '/foogallery\[default_retina_support\|(?<setting>.+?)\]/';
1065
1066 preg_match_all( $regex, $defaults, $matches );
1067
1068 $gallery_retina_settings = array();
1069
1070 if ( isset( $matches[1] ) ) {
1071 foreach ( $matches[1] as $match ) {
1072 $gallery_retina_settings[ $match ] = 'true';
1073 }
1074 }
1075
1076 //go through all galleries and update the retina settings
1077 $galleries = foogallery_get_all_galleries();
1078 $gallery_update_count = 0;
1079 foreach ( $galleries as $gallery ) {
1080 update_post_meta( $gallery->ID, FOOGALLERY_META_RETINA, $gallery_retina_settings );
1081 $gallery_update_count++;
1082 }
1083
1084 /* translators: %s: number of galleries updated. */
1085 $message = sprintf(
1086 /* translators: %s: Value inserted at runtime. */
1087 _n(
1088 '1 gallery successfully updated to use the default retina settings.',
1089 '%s galleries successfully updated to use the default retina settings.',
1090 $gallery_update_count,
1091 'foogallery'
1092 ),
1093 absint( $gallery_update_count )
1094 );
1095
1096 wp_send_json_success( array( 'html' => esc_html( $message ) ) );
1097 }
1098
1099 function ajax_uninstall() {
1100 if ( ! check_ajax_referer( 'foogallery_uninstall', '_wpnonce', false ) ) {
1101 wp_send_json_error(
1102 array( 'message' => __( 'Invalid security token.', 'foogallery' ) ),
1103 403
1104 );
1105 }
1106
1107 if ( ! current_user_can( 'install_plugins' ) ) {
1108 wp_send_json_error(
1109 array( 'message' => __( 'Insufficient permissions.', 'foogallery' ) ),
1110 403
1111 );
1112 }
1113
1114 $confirmation = '';
1115 if ( isset( $_POST['confirmation'] ) ) {
1116 $confirmation = sanitize_text_field( wp_unslash( $_POST['confirmation'] ) );
1117 $confirmation = trim( $confirmation );
1118 }
1119
1120 if ( '' === $confirmation ) {
1121 wp_send_json_success(
1122 array( 'html' => $this->get_uninstall_markup( true ) )
1123 );
1124 }
1125
1126 if ( 'UNINSTALL' !== $confirmation ) {
1127 wp_send_json_error(
1128 array(
1129 'html' => $this->get_uninstall_markup(
1130 true,
1131 __( 'Type UNINSTALL exactly to confirm the full uninstall.', 'foogallery' )
1132 ),
1133 'message' => __( 'Type UNINSTALL exactly to confirm the full uninstall.', 'foogallery' ),
1134 ),
1135 400
1136 );
1137 }
1138
1139 foogallery_uninstall();
1140
1141 wp_send_json_success(
1142 array( 'html' => $this->get_uninstall_success_markup() )
1143 );
1144 }
1145
1146 function generate_assets( $old_value, $value, $option) {
1147 if ( !current_user_can( 'manage_options' ) ) {
1148 return;
1149 }
1150
1151 $custom_assets = array();
1152
1153 if ( is_array( $value ) && array_key_exists( 'custom_js', $value ) ) {
1154 $custom_js = foogallery_prepare_code( $value['custom_js'] );
1155
1156 if ( !empty( $custom_js ) ) {
1157 $custom_js = '/*
1158 * FooGallery Custom Javascript
1159 * This file is created by adding custom JS on FooGallery Settings page in wp-admin
1160 * Created : ' . date( 'j M Y, g:i a', time() ) . '
1161 */
1162
1163 '. $custom_js;
1164 //generate script in upload folder
1165 $script_url = $this->generate_custom_asset( 'custom.js', $custom_js );
1166 if ( $script_url !== false ) {
1167 $custom_assets['script'] = $script_url;
1168 }
1169 }
1170 }
1171
1172 //check if we have saved any custom CSS
1173 if ( is_array( $value ) && array_key_exists( 'custom_css', $value ) ) {
1174 $custom_css = foogallery_prepare_code( $value['custom_css'] );
1175
1176 if ( !empty( $custom_css ) ) {
1177 $custom_css = '/*
1178 * FooGallery Custom CSS
1179 * This file is created by adding custom CSS on FooGallery Settings page in wp-admin
1180 * Created : ' . date( 'j M Y, g:i a', time() ) . '
1181 */
1182
1183 '. $custom_css;
1184 //generate stylesheet in upload folder
1185 $style_url = $this->generate_custom_asset( 'custom.css', $custom_css );
1186 if ( $style_url !== false ) {
1187 $custom_assets['style'] = $style_url;
1188 }
1189 }
1190 }
1191
1192 //set another option with the details
1193 if ( count( $custom_assets ) > 0 ) {
1194 update_option( FOOGALLERY_OPTION_CUSTOM_ASSETS, $custom_assets );
1195 } else {
1196 delete_option( FOOGALLERY_OPTION_CUSTOM_ASSETS );
1197 }
1198 }
1199
1200 function generate_custom_asset( $filename, $contents ) {
1201 $upload_dir = wp_upload_dir();
1202 if ( !empty( $upload_dir['basedir'] ) ) {
1203 $dir = trailingslashit( $upload_dir['basedir'] ) . 'foogallery/';
1204
1205 $fs = foogallery_wp_filesystem();
1206 if ( false !== $fs ) {
1207 $fs->mkdir( $dir ); // Make a new folder for storing our file
1208 if ( $fs->put_contents( $dir . $filename, $contents, 0644 ) ) {
1209 return set_url_scheme( trailingslashit( $upload_dir['baseurl'] ) . 'foogallery/' . $filename );
1210 }
1211 }
1212 }
1213
1214 return false;
1215 }
1216 }
1217 }
1218