PluginProbe ʕ •ᴥ•ʔ
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel / trunk
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel vtrunk
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 7 months ago class-admin-notices.php 7 months ago class-admin.php 7 months ago class-attachment-fields.php 7 months ago class-columns.php 7 months ago class-demo-content.php 7 months ago class-extensions.php 7 months ago class-gallery-attachment-modal.php 7 months ago class-gallery-datasources.php 7 months ago class-gallery-editor.php 7 months ago class-gallery-metabox-fields.php 7 months ago class-gallery-metabox-items.php 7 months ago class-gallery-metabox-settings-helper.php 7 months ago class-gallery-metabox-settings.php 7 months ago class-gallery-metabox-template.php 7 months ago class-gallery-metaboxes.php 7 months ago class-menu.php 7 months ago class-pro-promotion.php 7 months ago class-settings.php 7 months ago class-silent-installer-skin.php 7 months ago class-trial-mode.php 7 months ago demo-content-galleries.php 7 months ago demo-content-images.php 7 months ago index.php 11 years ago pro-features.php 7 months ago view-features.php 7 months ago view-help-demos.php 7 months ago view-help-getting-started.php 7 months ago view-help-pro.php 7 months ago view-help.php 7 months ago view-system-info.php 7 months ago
class-settings.php
815 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_thumb_generation_test', array( $this, 'ajax_thumb_generation_test' ) );
20 add_action( 'wp_ajax_foogallery_apply_retina_defaults', array( $this, 'ajax_apply_retina_defaults' ) );
21 add_action( 'wp_ajax_foogallery_uninstall', array( $this, 'ajax_uninstall' ) );
22 }
23
24 /**
25 * Sanitize the foogallery settings.
26 *
27 * @param mixed $value The value of the settings.
28 * @param mixed $old_value The old value.
29 * @param string $option The setting name. Should be 'foogallery'.
30 *
31 * @return mixed
32 */
33 public function sanitize_settings( $value, $old_value, $option ) {
34 if ( is_array( $value ) && array_key_exists( 'custom_js', $value ) ) {
35 $value['custom_js'] = foogallery_sanitize_code( $value['custom_js'] );
36 }
37 if ( is_array( $value ) && array_key_exists( 'custom_css', $value ) ) {
38 $value['custom_css'] = foogallery_sanitize_code( $value['custom_css'] );
39 }
40 return $value;
41 }
42
43 /**
44 * Create the settings for FooGallery
45 * @return array
46 */
47 function create_settings() {
48
49 //region General Tab
50 $tabs['general'] = __( 'General', 'foogallery' );
51
52 $settings[] = array(
53 'id' => 'clear_css_optimizations',
54 'title' => __( 'Clear CSS Cache', 'foogallery' ),
55 '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() ),
56 'type' => 'clear_optimization_button',
57 'tab' => 'general',
58 'section' => __( 'Performance', 'foogallery' )
59 );
60
61 $gallery_templates = foogallery_gallery_templates();
62 $gallery_templates_choices = array();
63 foreach ( $gallery_templates as $template ) {
64 $gallery_templates_choices[ $template['slug'] ] = $template['name'];
65 }
66
67 $settings[] = array(
68 'id' => 'gallery_template',
69 'title' => __( 'Default Gallery Layout', 'foogallery' ),
70 'desc' => __( 'The default gallery layout to use for new galleries', 'foogallery' ),
71 'default' => foogallery_get_default( 'gallery_template' ) ,
72 'type' => 'select',
73 'choices' => $gallery_templates_choices,
74 'tab' => 'general',
75 'section' => __( 'Gallery Defaults', 'foogallery' )
76 );
77
78 $settings[] = array(
79 'id' => 'default_gallery_attachments',
80 'title' => __( 'Default Gallery Items', 'foogallery' ),
81 'desc' => __( 'The default attachments to use for new galleries. Provide a comma separated list of attachment IDs.', 'foogallery' ),
82 'default' => '' ,
83 'type' => 'text',
84 'tab' => 'general',
85 'section' => __( 'Gallery Defaults', 'foogallery' )
86 );
87
88 $settings[] = array(
89 'id' => 'gallery_sorting',
90 'title' => __( 'Default Gallery Sorting', 'foogallery' ),
91 'desc' => __( 'The default attachment sorting to use for new galleries', 'foogallery' ),
92 'default' => '',
93 'type' => 'select',
94 'choices' => foogallery_sorting_options(),
95 'tab' => 'general',
96 'section' => __( 'Gallery Defaults', 'foogallery' )
97 );
98
99 $gallery_posts = get_posts( array(
100 'post_type' => FOOGALLERY_CPT_GALLERY,
101 'post_status' => array( 'publish', 'draft' ),
102 'cache_results' => false,
103 'nopaging' => true,
104 ) );
105
106 $galleries = array();
107
108 foreach ( $gallery_posts as $post ) {
109 $galleries[] = array(
110 'ID' => $post->ID,
111 'name' => $post->post_title
112 );
113 }
114
115 $gallery_choices = array();
116 $gallery_choices[] = __( 'No default', 'foogallery' );
117 foreach ( $galleries as $gallery ) {
118 $gallery_choices[ $gallery['ID'] ] = esc_html( $gallery['name'] );
119 }
120
121 $settings[] = array(
122 'id' => 'default_gallery_settings',
123 'title' => __( 'Default Gallery Settings', 'foogallery' ),
124 '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' ),
125 'type' => 'select',
126 'choices' => $gallery_choices,
127 'tab' => 'general',
128 'section' => __( 'Gallery Defaults', 'foogallery' )
129 );
130
131 $settings[] = array(
132 'id' => 'caption_title_source',
133 'title' => __( 'Caption Title Source', 'foogallery' ),
134 'desc' => __( 'By default, image caption titles are pulled from the attachment "Caption" field. Alternatively, you can choose to use other fields.', 'foogallery' ),
135 'type' => 'select',
136 'choices' => array(
137 'title' => foogallery_get_attachment_field_friendly_name( 'title' ),
138 'caption' => foogallery_get_attachment_field_friendly_name( 'caption' ),
139 'alt' => foogallery_get_attachment_field_friendly_name( 'alt' ),
140 'desc' => foogallery_get_attachment_field_friendly_name( 'desc' )
141 ),
142 'default' => 'caption',
143 'tab' => 'general',
144 'section' => __( 'Captions', 'foogallery' ),
145 'spacer' => '<span class="spacer"></span>'
146 );
147
148 $settings[] = array(
149 'id' => 'caption_desc_source',
150 'title' => __( 'Caption Description Source', 'foogallery' ),
151 'desc' => __( 'By default, image caption descriptions are pulled from the attachment "Description" field. Alternatively, you can choose to use other fields.', 'foogallery' ),
152 'type' => 'select',
153 'choices' => array(
154 'title' => foogallery_get_attachment_field_friendly_name( 'title' ),
155 'caption' => foogallery_get_attachment_field_friendly_name( 'caption' ),
156 'alt' => foogallery_get_attachment_field_friendly_name( 'alt' ),
157 'desc' => foogallery_get_attachment_field_friendly_name( 'desc' )
158 ),
159 'default' => 'desc',
160 'tab' => 'general',
161 'section' => __( 'Captions', 'foogallery' ),
162 'spacer' => '<span class="spacer"></span>'
163 );
164
165 $settings[] = array(
166 'id' => 'hide_gallery_template_help',
167 'title' => __( 'Hide Gallery Settings Tips', 'foogallery' ),
168 'desc' => __( 'Some gallery settings show helpful tips, which are useful for new users. You can choose to hide these tips.', 'foogallery' ),
169 'type' => 'checkbox',
170 'tab' => 'general',
171 'section' => __( 'Admin', 'foogallery' )
172 );
173
174 $settings[] = array(
175 'id' => 'minimize_gallery_settings_help',
176 'title' => __( 'Minimize Gallery Settings Help Text', 'foogallery' ),
177 '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' ),
178 'type' => 'checkbox',
179 'tab' => 'general',
180 'section' => __( 'Admin', 'foogallery' )
181 );
182
183 $roles = get_editable_roles();
184 $role_choices = array(
185 '' => __( 'Default', 'foogallery' )
186 );
187
188 foreach ( $roles as $role_slug => $role_data ) {
189 $role_choices[ $role_slug ] = $role_data['name'];
190 }
191
192 $settings[] = array(
193 'id' => 'gallery_creator_role',
194 'title' => __( 'Gallery Creator Role', 'foogallery' ),
195 'desc' => __( 'Select the user role allowed to manage galleries. All roles with higher privileges will also be able to manage galleries.', 'foogallery' ),
196 'type' => 'select',
197 'choices' => $role_choices,
198 'tab' => 'general',
199 'section' => __( 'Admin', 'foogallery' ),
200 );
201
202 $settings[] = array(
203 'id' => 'hide_editor_button',
204 'title' => __( 'Classic Editor Button', 'foogallery' ),
205 'desc' => sprintf( __( 'Either show or hide the "Add %s" button in the Classic editor.', 'foogallery' ), foogallery_plugin_name() ),
206 'default' => foogallery_get_default( 'hide_editor_button', 'on' ),
207 'type' => 'select',
208 'choices' => array(
209 'on' => __( 'Hidden', 'foogallery' ),
210 'off' => __( 'Visible', 'foogallery' )
211 ),
212 'tab' => 'general',
213 'section' => __( 'Admin', 'foogallery' )
214 );
215
216 $settings[] = array(
217 'id' => 'advanced_attachment_modal',
218 'title' => __( 'Advanced Attachment Modal', 'foogallery' ),
219 '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' ),
220 'type' => 'select',
221 'default' => foogallery_get_default( 'advanced_attachment_modal', 'on' ),
222 'tab' => 'general',
223 'section' => __( 'Admin', 'foogallery' ),
224 'choices' => array(
225 'on' => __( 'Enabled', 'foogallery' ),
226 'off' => __( 'Disabled', 'foogallery' )
227 )
228 );
229
230 $settings[] = array(
231 'id' => 'limit_gallery_selector_block_editor',
232 'type' => 'text',
233 'title' => __( 'Limit Galleries (Block Editor)', 'foogallery' ),
234 'desc' => __( 'Limit the number of galleries that are returned in the block editor when choosing a gallery.', 'foogallery' ),
235 'tab' => 'general',
236 'class' => 'foogallery_settings_short_text',
237 'section' => __( 'Admin', 'foogallery' )
238 );
239
240 // endregion General
241
242 // region Album Tab.
243 $tabs['albums'] = __( 'Albums', 'foogallery' );
244 $roles = get_editable_roles();
245 $role_choices = array(
246 'inherit' => __( 'Inherit from gallery creator role', 'foogallery' ),
247 );
248
249 foreach ( $roles as $role_slug => $role_data ) {
250 $role_choices[ $role_slug ] = $role_data['name'];
251 }
252
253 $settings[] = array(
254 'id' => 'album_creator_role',
255 'title' => __( 'Album Creator Role', 'foogallery' ),
256 'desc' => __( 'Set the default role for album creators.', 'foogallery' ),
257 'type' => 'select',
258 'choices' => $role_choices,
259 'default' => 'inherit',
260 'tab' => 'albums',
261 );
262 // end of album region.
263
264 //region Images Tab
265 $tabs['thumb'] = __( 'Images', 'foogallery' );
266
267 $engines = array();
268 foreach ( foogallery_thumb_available_engines() as $engine_key => $engine ) {
269 $engines[$engine_key] = '<strong>' . $engine['label'] . '</strong> - ' . $engine['description'];
270 }
271
272 $settings[] = array(
273 'id' => 'thumb_engine',
274 'title' => __( 'Thumbnail Engine', 'foogallery' ),
275 'desc' => __( 'The thumbnail generation engine used when creating different sized thumbnails for your galleries.', 'foogallery' ),
276 'type' => 'radio',
277 'default' => 'default',
278 'choices' => $engines,
279 'tab' => 'thumb'
280 );
281
282 if ( foogallery_thumb_active_engine()->uses_image_editors() ) {
283 $image_editor = str_replace( 'FooGallery_Thumb_Image_Editor_', '', _wp_image_editor_choose( array( 'methods' => array( 'get_image' ) ) ) );
284 $gd_supported = extension_loaded( 'gd' ) ? __( 'yes', 'foogallery' ) : __( 'no', 'foogallery' );
285 $imagick_supported = extension_loaded( 'imagick' ) ? __( 'yes', 'foogallery' ) : __( 'no', 'foogallery' );
286
287 $settings[] = array(
288 'id' => 'thumb_image_library',
289 'title' => __( 'Thumbnail Image Library', 'foogallery' ),
290 'desc' => sprintf( __( 'Currently active : %s.<br />Imagick supported : %s.<br />GD supported : %s.', 'foogallery' ), '<strong>' . $image_editor . '</strong>', $imagick_supported, $gd_supported ),
291 'type' => 'html',
292 'tab' => 'thumb'
293 );
294 }
295
296 if ( foogallery_thumb_active_engine()->has_local_cache() ) {
297 $settings[] = array(
298 'id' => 'thumb_jpeg_quality',
299 'title' => __( 'Thumbnail JPEG Quality', 'foogallery' ),
300 'desc' => __( 'The image quality to be used when resizing JPEG images.', 'foogallery' ),
301 'type' => 'text',
302 'default' => '90',
303 'tab' => 'thumb'
304 );
305 }
306
307 $image_optimization_html = sprintf( __('We recommend %s! An easy-to-use, lightweight WordPress plugin that optimizes images & PDFs.', 'foogallery'),
308 '<a href="https://shortpixel.com/homepage/affiliate/foowww" target="_blank">' . __('ShortPixel Image Optimizer' , 'foogallery') . '</a>' );
309
310 $settings[] = array(
311 'id' => 'image_optimization',
312 'title' => __( 'Image Optimization', 'foogallery' ),
313 'type' => 'html',
314 'desc' => $image_optimization_html,
315 'tab' => 'thumb'
316 );
317
318 $settings[] = array(
319 'id' => 'default_retina_support',
320 'title' => __( 'Default Retina Support', 'foogallery' ),
321 'desc' => __( 'Default retina support for all new galleries that are created. This can also be overridden for each gallery.', 'foogallery' ),
322 'type' => 'checkboxlist',
323 'choices' => foogallery_retina_options(),
324 'tab' => 'thumb'
325 );
326
327 $settings[] = array(
328 'id' => 'use_original_thumbs',
329 'title' => __( 'Use Original Thumbnails', 'foogallery' ),
330 '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' ),
331 'type' => 'checkbox',
332 'tab' => 'thumb'
333 );
334
335 $settings[] = array(
336 'id' => 'animated_gif_use_original_image',
337 'title' => __( 'Show Animated Thumbnails', 'foogallery' ),
338 'desc' => __( 'If animated GIFs are used, then show the original GIF as the thumbnail.', 'foogallery' ),
339 'type' => 'checkbox',
340 'tab' => 'thumb'
341 );
342
343 if ( foogallery_thumb_active_engine()->has_local_cache() ) {
344 $settings[] = array(
345 'id' => 'thumb_resize_upscale_small',
346 'title' => __( 'Upscale Small Images', 'foogallery' ),
347 'desc' => __( 'If the original image is smaller than the thumbnail size, then upscale the image thumbnail to match the size.', 'foogallery' ) . '<br/>' . __( 'PLEASE NOTE : this is only supported if your server supports the GD image library and it is currently active.', 'foogallery' ),
348 'type' => 'checkbox',
349 'tab' => 'thumb'
350 );
351
352 $settings[] = array(
353 'id' => 'thumb_resize_upscale_small_color',
354 'title' => __( 'Upscale Background Color', 'foogallery' ),
355 'desc' => __( 'The background color to use for upscaled images. You can also use "transparent" or "auto".', 'foogallery' ),
356 'type' => 'text',
357 'default' => 'rgb(0,0,0)',
358 'tab' => 'thumb'
359 );
360 }
361
362 if ( foogallery_thumb_active_engine()->requires_thumbnail_generation_tests() ) {
363 $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>';
364
365 $settings[] = array(
366 'id' => 'thumb_generation_test',
367 'title' => __( 'Thumbnail Generation Test', 'foogallery' ),
368 'desc' => sprintf( __( 'Test to see if %s can generate the thumbnails it needs. %s', 'foogallery' ), foogallery_plugin_name(), $thumb_test_html ),
369 'type' => 'thumb_generation_test',
370 'tab' => 'thumb'
371 );
372 }
373
374 if ( foogallery_thumb_active_engine()->uses_image_editors() ) {
375 $settings[] = array(
376 'id' => 'force_gd_library',
377 'title' => __( 'Force GD Library', 'foogallery' ),
378 'desc' => __( 'By default, WordPress will use Imagick as the default Image Editor. This will force GD to be used as the default.', 'foogallery' ),
379 'type' => 'checkbox',
380 'tab' => 'thumb'
381 );
382 }
383
384 //endregion Thumbnail Tab
385
386 // //region Advanced Tab
387 // $tabs['advanced'] = __( 'Advanced', 'foogallery' );
388 //
389 // $example_url = '<code>' . trailingslashit( site_url() ) . foogallery_permalink() . '/my-cool-gallery</code>';
390 //
391 // $settings[] = array(
392 // 'id' => 'gallery_permalinks_enabled',
393 // 'title' => __( 'Enable Friendly URL\'s', 'foogallery' ),
394 // 'desc' => sprintf( __( 'If enabled, you will be able to access your galleries from a friendly URL e.g. %s', 'foogallery' ), $example_url ),
395 // 'default' => foogallery_get_default( 'gallery_permalinks_enabled' ),
396 // 'type' => 'checkbox',
397 // 'tab' => 'advanced',
398 // );
399 //
400 // $settings[] = array(
401 // 'id' => 'gallery_permalink',
402 // 'title' => __( 'Gallery Permalink', 'foogallery' ),
403 // 'desc' => __( 'If friendly URL\'s are enabled, this is used in building up a friendly URL', 'foogallery' ),
404 // 'default' => foogallery_get_default( 'gallery_permalink' ),
405 // 'type' => 'text',
406 // 'tab' => 'advanced',
407 // );
408 // //endregion Advanced
409
410 //region Language Tab
411 $tabs['language'] = __( 'Language', 'foogallery' );
412
413 $settings[] = array(
414 'id' => 'language_imageviewer_prev_text',
415 'title' => __( 'Image Viewer "Prev" Text', 'foogallery' ),
416 'type' => 'text',
417 'default' => __( 'Prev', 'foogallery' ),
418 'section' => __( 'Image Viewer Template', 'foogallery' ),
419 'tab' => 'language'
420 );
421
422 $settings[] = array(
423 'id' => 'language_imageviewer_next_text',
424 'title' => __( 'Image Viewer "Next" Text', 'foogallery' ),
425 'type' => 'text',
426 'default' => __( 'Next', 'foogallery' ),
427 'section' => __( 'Image Viewer Template', 'foogallery' ),
428 'tab' => 'language'
429 );
430
431 $settings[] = array(
432 'id' => 'language_imageviewer_of_text',
433 'title' => __( 'Image Viewer "Of" Text', 'foogallery' ),
434 'type' => 'text',
435 'default' => __( 'of', 'foogallery' ),
436 'section' => __( 'Image Viewer Template', 'foogallery' ),
437 'tab' => 'language'
438 );
439
440 $settings[] = array(
441 'id' => 'language_images_count_none_text',
442 'title' => __( 'Image Count None Text', 'foogallery' ),
443 'type' => 'text',
444 'default' => __( 'No images', 'foogallery' ),
445 'section' => __( 'Admin', 'foogallery' ),
446 'tab' => 'language'
447 );
448
449 $settings[] = array(
450 'id' => 'language_images_count_single_text',
451 'title' => __( 'Image Count Single Text', 'foogallery' ),
452 'type' => 'text',
453 'default' => __( '1 image', 'foogallery' ),
454 'section' => __( 'Admin', 'foogallery' ),
455 'tab' => 'language'
456 );
457
458 $settings[] = array(
459 'id' => 'language_images_count_plural_text',
460 'title' => __( 'Image Count Many Text', 'foogallery' ),
461 'type' => 'text',
462 'default' => __( '%s images', 'foogallery' ),
463 'section' => __( 'Admin', 'foogallery' ),
464 'tab' => 'language'
465 );
466
467 //endregion Language Tab
468
469 //region Advanced Tab
470 $tabs['advanced'] = __( 'Advanced', 'foogallery' );
471
472 $settings[] = array(
473 'id' => 'add_media_button_start',
474 'title' => __( 'Move Add Media Button', 'foogallery' ),
475 '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() ),
476 'type' => 'checkbox',
477 'tab' => 'advanced'
478 );
479
480 $settings[] = array(
481 'id' => 'enable_legacy_thumb_cropping',
482 'title' => __( 'Enable Legacy Thumb Cropping', 'foogallery' ),
483 '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' ),
484 'type' => 'checkbox',
485 'tab' => 'advanced'
486 );
487
488 $settings[] = array(
489 'id' => 'enable_debugging',
490 'title' => __( 'Enable Debugging', 'foogallery' ),
491 '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() ),
492 'type' => 'checkbox',
493 'tab' => 'advanced'
494 );
495
496 $settings[] = array(
497 'id' => 'enqueue_polyfills',
498 'title' => __( 'Enqueue Polyfills', 'foogallery' ),
499 '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() ),
500 'type' => 'checkbox',
501 'tab' => 'advanced'
502 );
503
504 $settings[] = array(
505 'id' => 'uninstall',
506 'title' => __( 'Full Uninstall', 'foogallery' ),
507 '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() ),
508 'type' => 'uninstall',
509 'tab' => 'advanced'
510 );
511
512 if ( foogallery_thumb_active_engine()->has_local_cache() ) {
513 $settings[] = array(
514 'id' => 'override_thumb_test',
515 'title' => __( 'Override Thumb Test', 'foogallery' ),
516 'desc' => __( 'Sometimes there are problems running the thumbnail generation test. This overrides the test to use a remote image from our CDN.', 'foogallery' ),
517 'type' => 'checkbox',
518 'tab' => 'advanced',
519 );
520 }
521
522 if ( !foogallery_is_pro() ) {
523 $settings[] = array(
524 'id' => 'force_hide_trial',
525 'title' => __( 'Force Hide Trial Notice', 'foogallery' ),
526 'desc' => __( 'Force the trial notice admin banner to never show', 'foogallery' ),
527 'type' => 'checkbox',
528 'tab' => 'advanced'
529 );
530 }
531
532 $settings[] = array(
533 'id' => 'demo_content',
534 'type' => 'checkbox',
535 'title' => __( 'Demo Content Created', 'foogallery' ),
536 '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' ),
537 'tab' => 'advanced'
538 );
539
540 $settings[] = array(
541 'id' => 'attachment_id_attribute',
542 'type' => 'radio',
543 'title' => __( 'Item ID Attribute', 'foogallery' ),
544 'desc' => __( 'Each item has an ID attribute which identifies itself. Changing the attribute will change what is used for deeplinking.', 'foogallery' ),
545 'choices' => array(
546 'data-attachment-id' => __( 'data-attachment-id', 'foogallery' ),
547 'data-id' => __( 'data-id', 'foogallery' ),
548 ),
549 'tab' => 'advanced'
550 );
551
552 $custom_post_types = get_post_types( array( 'public' => true, '_builtin' => false ), 'objects' );
553
554 if ( !empty( $custom_post_types ) ) {
555 $post_type_choices = array();
556 foreach ( $custom_post_types as $post_type ) {
557 $post_type_choices[$post_type->name] = $post_type->label;
558 }
559
560 $settings[] = array(
561 'id' => 'allowed_custom_post_types',
562 'title' => __( 'Allowed Custom Post Types', 'foogallery' ),
563 'desc' => __( 'Select the custom post types where galleries can be attached.', 'foogallery' ),
564 'type' => 'checkboxlist',
565 'choices' => $post_type_choices,
566 'tab' => 'advanced'
567 );
568 }
569
570 $settings[] = array(
571 'id' => 'enable_trial_mode',
572 'title' => __( 'Admin Trial Mode', 'foogallery' ),
573 'desc' => __( 'Enables trial mode in the admin, which will highlight features that are only available in the Pro version.', 'foogallery' ),
574 'type' => 'checkbox',
575 'tab' => 'advanced'
576 );
577
578 //endregion Advanced Tab
579
580 //region Custom JS & CSS
581 $tabs['custom_assets'] = __( 'Custom JS & CSS', 'foogallery' );
582
583 $custom_assets = get_option( FOOGALLERY_OPTION_CUSTOM_ASSETS );
584 $custom_style_extra = '';
585 if ( is_array( $custom_assets ) && array_key_exists( 'style', $custom_assets ) ) {
586 $custom_style_extra = '<br /><a target="_blank" href="' . $custom_assets['style'] . '">' . __( 'Open Custom Stylesheet', 'foogallery' ) . '</a>';
587 }
588 $custom_script_extra = '';
589 if ( is_array( $custom_assets ) && array_key_exists( 'script', $custom_assets ) ) {
590 $custom_script_extra = '<br /><a target="_blank" href="' . $custom_assets['script'] . '">' . __( 'Open Custom Script', 'foogallery' ) . '</a>';
591 }
592
593 $custom_js = foogallery_get_setting( 'custom_js', '' );
594 if ( !empty( $custom_js ) && empty( $custom_script_extra ) ) {
595 $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>';
596 }
597
598 $custom_css = foogallery_get_setting( 'custom_css', '' );
599 if ( !empty( $custom_css ) && empty( $custom_style_extra ) ) {
600 $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>';
601 }
602
603 $settings[] = array(
604 'id' => 'custom_js',
605 'title' => __( 'Custom Javascript', 'foogallery' ),
606 'desc' => __( 'Custom Javascript that will be added to the page when a gallery is rendered.', 'foogallery' ) . $custom_script_extra,
607 'type' => 'textarea',
608 'tab' => 'custom_assets',
609 'default' => ''
610 );
611
612 $settings[] = array(
613 'id' => 'custom_css',
614 'title' => __( 'Custom Stylesheet', 'foogallery' ),
615 'desc' => __( 'Custom CSS that will be added to the page when a gallery is rendered.', 'foogallery' ) . $custom_style_extra,
616 'type' => 'textarea',
617 'tab' => 'custom_assets',
618 'default' => ''
619 );
620 //endregion Custom JS & CSS
621
622 return apply_filters( 'foogallery_admin_settings_override', array(
623 'tabs' => $tabs,
624 'sections' => array(),
625 'settings' => $settings,
626 ) );
627 }
628
629 /**
630 * Render any custom setting types to the settings page
631 */
632 function render_custom_setting_types( $args ) {
633 if ( 'clear_optimization_button' === $args['type'] ) { ?>
634 <div id="foogallery_clear_css_optimizations_container">
635 <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' ); ?>">
636 <span id="foogallery_clear_css_cache_spinner" style="position: absolute" class="spinner"></span>
637 </div>
638 <?php } else if ( 'uninstall' === $args['type'] ) { ?>
639 <div id="foogallery_uninstall_container">
640 <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' ); ?>">
641 <span id="foogallery_uninstall_spinner" style="position: absolute" class="spinner"></span>
642 </div>
643 <?php } else if ( 'thumb_generation_test' === $args['type'] ) { ?>
644 <div id="foogallery_thumb_generation_test_container">
645 <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' ); ?>">
646 <span id="foogallery_thumb_generation_test_spinner" style="position: absolute" class="spinner"></span>
647 </div>
648 <?php }
649 }
650
651 function after_render_setting( $args ) {
652 if ( 'default_retina_support' === $args['id'] ) {
653
654 //build up a list of retina options and add them to a hidden input
655 // so we can get the values on the client
656 $input_ids = array();
657 $count = 0;
658 foreach( foogallery_retina_options() as $retina_option ) {
659 $input_ids[] = '#default_retina_support' . $count;
660 $count++;
661 }
662 $nonce = wp_create_nonce( 'foogallery_apply_retina_defaults' );
663 ?><div id="foogallery_apply_retina_support_container">
664 <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' ); ?>">
665 <span id="foogallery_apply_retina_support_spinner" style="position: absolute" class="spinner"></span>
666 </div>
667 <?php }
668 }
669
670 /**
671 * AJAX endpoint for clearing all CSS optimizations
672 */
673 function ajax_clear_css_optimizations() {
674 if ( check_admin_referer( 'foogallery_clear_css_optimizations' ) ) {
675 foogallery_clear_all_css_load_optimizations();
676
677 esc_html_e('The CSS optimization cache was successfully cleared!', 'foogallery' );
678 die();
679 }
680 }
681
682 /**
683 * AJAX endpoint for testing thumbnail generation
684 */
685 function ajax_thumb_generation_test() {
686 if ( check_admin_referer( 'foogallery_thumb_generation_test' ) ) {
687 foogallery_output_thumbnail_generation_results();
688 die();
689 }
690 }
691
692 /**
693 * AJAX endpoint for applying the retina defaults to all galleries
694 */
695 function ajax_apply_retina_defaults() {
696 if ( check_admin_referer( 'foogallery_apply_retina_defaults' ) ) {
697
698 $defaults = $_POST['defaults'];
699
700 //extract the settings using a regex
701 $regex = '/foogallery\[default_retina_support\|(?<setting>.+?)\]/';
702
703 preg_match_all($regex, $defaults, $matches);
704
705 $gallery_retina_settings = array();
706
707 if ( isset( $matches[1] ) ) {
708 foreach ( $matches[1] as $match ) {
709 $gallery_retina_settings[$match] = "true";
710 }
711 }
712
713 //go through all galleries and update the retina settings
714 $galleries = foogallery_get_all_galleries();
715 $gallery_update_count = 0;
716 foreach ( $galleries as $gallery ) {
717 update_post_meta( $gallery->ID, FOOGALLERY_META_RETINA, $gallery_retina_settings );
718 $gallery_update_count++;
719 }
720
721 echo esc_html( sprintf( _n(
722 '1 gallery successfully updated to use the default retina settings.',
723 '%s galleries successfully updated to use the default retina settings.',
724 $gallery_update_count, 'foogallery' ), absint( $gallery_update_count ) ) );
725
726 die();
727 }
728 }
729
730 function ajax_uninstall() {
731 if ( check_admin_referer( 'foogallery_uninstall' ) && current_user_can( 'install_plugins' ) ) {
732 foogallery_uninstall();
733
734 esc_html_e('All traces of the plugin were removed from your system!', 'foogallery' );
735 die();
736 }
737 }
738
739 function generate_assets( $old_value, $value, $option) {
740 if ( !is_admin() ) {
741 return;
742 }
743
744 if ( !current_user_can( 'manage_options' ) ) {
745 return;
746 }
747
748 $custom_assets = array();
749
750 if ( is_array( $value ) && array_key_exists( 'custom_js', $value ) ) {
751 $custom_js = foogallery_prepare_code( $value['custom_js'] );
752
753 if ( !empty( $custom_js ) ) {
754 $custom_js = '/*
755 * FooGallery Custom Javascript
756 * This file is created by adding custom JS on FooGallery Settings page in wp-admin
757 * Created : ' . date( 'j M Y, g:i a', time() ) . '
758 */
759
760 '. $custom_js;
761 //generate script in upload folder
762 $script_url = $this->generate_custom_asset( 'custom.js', $custom_js );
763 if ( $script_url !== false ) {
764 $custom_assets['script'] = $script_url;
765 }
766 }
767 }
768
769 //check if we have saved any custom CSS
770 if ( is_array( $value ) && array_key_exists( 'custom_css', $value ) ) {
771 $custom_css = foogallery_prepare_code( $value['custom_css'] );
772
773 if ( !empty( $custom_css ) ) {
774 $custom_css = '/*
775 * FooGallery Custom CSS
776 * This file is created by adding custom CSS on FooGallery Settings page in wp-admin
777 * Created : ' . date( 'j M Y, g:i a', time() ) . '
778 */
779
780 '. $custom_css;
781 //generate stylesheet in upload folder
782 $style_url = $this->generate_custom_asset( 'custom.css', $custom_css );
783 if ( $style_url !== false ) {
784 $custom_assets['style'] = $style_url;
785 }
786 }
787 }
788
789 //set another option with the details
790 if ( count( $custom_assets ) > 0 ) {
791 update_option( FOOGALLERY_OPTION_CUSTOM_ASSETS, $custom_assets );
792 } else {
793 delete_option( FOOGALLERY_OPTION_CUSTOM_ASSETS );
794 }
795 }
796
797 function generate_custom_asset( $filename, $contents ) {
798 $upload_dir = wp_upload_dir();
799 if ( !empty( $upload_dir['basedir'] ) ) {
800 $dir = trailingslashit( $upload_dir['basedir'] ) . 'foogallery/';
801
802 $fs = foogallery_wp_filesystem();
803 if ( false !== $fs ) {
804 $fs->mkdir( $dir ); // Make a new folder for storing our file
805 if ( $fs->put_contents( $dir . $filename, $contents, 0644 ) ) {
806 return set_url_scheme( trailingslashit( $upload_dir['baseurl'] ) . 'foogallery/' . $filename );
807 }
808 }
809 }
810
811 return false;
812 }
813 }
814 }
815