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
|
|
|
|
14
|
|
|
// Ajax calls for clearing CSS optimization cache |
15
|
|
|
add_action( 'wp_ajax_foogallery_clear_css_optimizations', array( $this, 'ajax_clear_css_optimizations' ) ); |
16
|
|
|
add_action( 'wp_ajax_foogallery_thumb_generation_test', array( $this, 'ajax_thumb_generation_test' ) ); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
function create_settings() { |
20
|
|
|
|
21
|
|
|
//region General Tab |
22
|
|
|
$tabs['general'] = __( 'General', 'foogallery' ); |
23
|
|
|
|
24
|
|
|
$settings[] = array( |
25
|
|
|
'id' => 'clear_css_optimizations', |
26
|
|
|
'title' => __( 'Clear CSS Cache', 'foogallery' ), |
27
|
|
|
'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() ), |
28
|
|
|
'type' => 'clear_optimization_button', |
29
|
|
|
'tab' => 'general', |
30
|
|
|
'section' => __( 'Cache', 'foogallery' ) |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
$gallery_templates = foogallery_gallery_templates(); |
34
|
|
|
$gallery_templates_choices = array(); |
35
|
|
|
foreach ( $gallery_templates as $template ) { |
36
|
|
|
$gallery_templates_choices[ $template['slug'] ] = $template['name']; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$settings[] = array( |
40
|
|
|
'id' => 'gallery_template', |
41
|
|
|
'title' => __( 'Default Gallery Template', 'foogallery' ), |
42
|
|
|
'desc' => __( 'The default gallery template to use for new galleries', 'foogallery' ), |
43
|
|
|
'default' => foogallery_get_default( 'gallery_template' ) , |
44
|
|
|
'type' => 'select', |
45
|
|
|
'choices' => $gallery_templates_choices, |
46
|
|
|
'tab' => 'general', |
47
|
|
|
'section' => __( 'Gallery Defaults', 'foogallery' ) |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$settings[] = array( |
51
|
|
|
'id' => 'gallery_sorting', |
52
|
|
|
'title' => __( 'Default Gallery Sorting', 'foogallery' ), |
53
|
|
|
'desc' => __( 'The default attachment sorting to use for new galleries', 'foogallery' ), |
54
|
|
|
'default' => '', |
55
|
|
|
'type' => 'select', |
56
|
|
|
'choices' => foogallery_sorting_options(), |
57
|
|
|
'tab' => 'general', |
58
|
|
|
'section' => __( 'Gallery Defaults', 'foogallery' ) |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
$galleries = foogallery_get_all_galleries(); |
62
|
|
|
$gallery_choices = array(); |
63
|
|
|
$gallery_choices[] = __( 'No default', 'foogallery' ); |
64
|
|
|
foreach ( $galleries as $gallery ) { |
65
|
|
|
$gallery_choices[ $gallery->ID ] = $gallery->name; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$settings[] = array( |
69
|
|
|
'id' => 'default_gallery_settings', |
70
|
|
|
'title' => __( 'Default Gallery Settings', 'foogallery' ), |
71
|
|
|
'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' ), |
72
|
|
|
'type' => 'select', |
73
|
|
|
'choices' => $gallery_choices, |
74
|
|
|
'tab' => 'general', |
75
|
|
|
'section' => __( 'Gallery Defaults', 'foogallery' ) |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$settings[] = array( |
79
|
|
|
'id' => 'caption_title_source', |
80
|
|
|
'title' => __( 'Caption Title Source', 'foogallery' ), |
81
|
|
|
'desc' => __( 'By default, image caption titles are pulled from the attachment "Caption" field. Alternatively, you can also choose to pull from the attachment "Title" field.', 'foogallery' ), |
82
|
|
|
'type' => 'select', |
83
|
|
|
'choices' => array( |
84
|
|
|
'caption' => __('Attachment Caption Field', 'foogallery'), |
85
|
|
|
'title' => __('Attachment Title Field', 'foogallery') |
86
|
|
|
), |
87
|
|
|
'default' => 'caption', |
88
|
|
|
'tab' => 'general', |
89
|
|
|
'section' => __( 'Captions', 'foogallery' ), |
90
|
|
|
'spacer' => '<span class="spacer"></span>' |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$settings[] = array( |
94
|
|
|
'id' => 'caption_desc_source', |
95
|
|
|
'title' => __( 'Caption Description Source', 'foogallery' ), |
96
|
|
|
'desc' => __( 'By default, image caption descriptions are pulled from the attachment "Description" field. Alternatively, you can choose to use other fields.', 'foogallery' ), |
97
|
|
|
'type' => 'select', |
98
|
|
|
'choices' => array( |
99
|
|
|
'desc' => __('Attachment Description Field', 'foogallery'), |
100
|
|
|
'title' => __('Attachment Title Field', 'foogallery'), |
101
|
|
|
'caption' => __('Attachment Caption Field', 'foogallery'), |
102
|
|
|
'alt' => __('Attachment Alt Field', 'foogallery') |
103
|
|
|
), |
104
|
|
|
'default' => 'desc', |
105
|
|
|
'tab' => 'general', |
106
|
|
|
'section' => __( 'Captions', 'foogallery' ), |
107
|
|
|
'spacer' => '<span class="spacer"></span>' |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$settings[] = array( |
111
|
|
|
'id' => 'hide_gallery_template_help', |
112
|
|
|
'title' => __( 'Hide Gallery Template Help', 'foogallery' ), |
113
|
|
|
'desc' => __( 'Some gallery templates show helpful tips, which are useful for new users. You can choose to hide these tips.', 'foogallery' ), |
114
|
|
|
'type' => 'checkbox', |
115
|
|
|
'tab' => 'general', |
116
|
|
|
'section' => __( 'Admin', 'foogallery' ) |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
$settings[] = array( |
120
|
|
|
'id' => 'hide_editor_button', |
121
|
|
|
'title' => __( 'Hide WYSIWYG Editor Button', 'foogallery' ), |
122
|
|
|
'desc' => sprintf( __( 'If enabled, this will hide the "Add %s" button in the WYSIWYG editor.', 'foogallery' ), foogallery_plugin_name() ), |
123
|
|
|
'type' => 'checkbox', |
124
|
|
|
'tab' => 'general', |
125
|
|
|
'section' => __( 'Admin', 'foogallery' ) |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
//endregion General |
129
|
|
|
|
130
|
|
|
//region Extensions Tab |
131
|
|
|
$tabs['extensions'] = __( 'Extensions', 'foogallery' ); |
132
|
|
|
|
133
|
|
|
$settings[] = array( |
134
|
|
|
'id' => 'use_future_endpoint', |
135
|
|
|
'title' => __( 'Use Beta Endpoint', 'foogallery' ), |
136
|
|
|
'desc' => __( 'The list of available extensions are pulled from an external URL. You can also pull from a "beta" endpoint which will sometimes contain beta extensions that are not publicly available.', 'foogallery' ), |
137
|
|
|
'type' => 'checkbox', |
138
|
|
|
'tab' => 'extensions', |
139
|
|
|
); |
140
|
|
|
//endregion Extensions Tab |
141
|
|
|
|
142
|
|
|
//region Images Tab |
143
|
|
|
$tabs['thumb'] = __( 'Images', 'foogallery' ); |
144
|
|
|
|
145
|
|
|
$settings[] = array( |
146
|
|
|
'id' => 'thumb_jpeg_quality', |
147
|
|
|
'title' => __( 'Thumbnail JPEG Quality', 'foogallery' ), |
148
|
|
|
'desc' => __( 'The image quality to be used when resizing JPEG images.', 'foogallery' ), |
149
|
|
|
'type' => 'text', |
150
|
|
|
'default' => '80', |
151
|
|
|
'tab' => 'thumb' |
152
|
|
|
); |
153
|
|
|
|
154
|
|
|
$settings[] = array( |
155
|
|
|
'id' => 'use_original_thumbs', |
156
|
|
|
'title' => __( 'Use Original Thumbnails', 'foogallery' ), |
157
|
|
|
'desc' => __( 'Allow for the original thumbnails to be used when possible. This can be useful if your thumbs are animated gifs.', 'foogallery' ), |
158
|
|
|
'type' => 'checkbox', |
159
|
|
|
'tab' => 'thumb' |
160
|
|
|
); |
161
|
|
|
|
162
|
|
|
$settings[] = array( |
163
|
|
|
'id' => 'thumb_resize_animations', |
164
|
|
|
'title' => __( 'Resize Animated GIFs', 'foogallery' ), |
165
|
|
|
'desc' => __( 'Should animated gifs be resized or not. If enabled, only the first frame is used in the resize.', 'foogallery' ), |
166
|
|
|
'type' => 'checkbox', |
167
|
|
|
'tab' => 'thumb' |
168
|
|
|
); |
169
|
|
|
|
170
|
|
|
$settings[] = array( |
171
|
|
|
'id' => 'thumb_generation_test', |
172
|
|
|
'title' => __( 'Thumbnail Generation Test', 'foogallery' ), |
173
|
|
|
'desc' => sprintf( __( 'Test to see if %s can generate the thumbnails it needs.', 'foogallery' ), foogallery_plugin_name() ), |
174
|
|
|
'type' => 'thumb_generation_test', |
175
|
|
|
'tab' => 'thumb' |
176
|
|
|
); |
177
|
|
|
|
178
|
|
|
//endregion Thumbnail Tab |
179
|
|
|
|
180
|
|
|
// //region Advanced Tab |
|
|
|
|
181
|
|
|
// $tabs['advanced'] = __( 'Advanced', 'foogallery' ); |
182
|
|
|
// |
183
|
|
|
// $example_url = '<code>' . trailingslashit( site_url() ) . foogallery_permalink() . '/my-cool-gallery</code>'; |
184
|
|
|
// |
185
|
|
|
// $settings[] = array( |
186
|
|
|
// 'id' => 'gallery_permalinks_enabled', |
187
|
|
|
// 'title' => __( 'Enable Friendly URL\'s', 'foogallery' ), |
188
|
|
|
// 'desc' => sprintf( __( 'If enabled, you will be able to access your galleries from a friendly URL e.g. %s', 'foogallery' ), $example_url ), |
189
|
|
|
// 'default' => foogallery_get_default( 'gallery_permalinks_enabled' ), |
190
|
|
|
// 'type' => 'checkbox', |
191
|
|
|
// 'tab' => 'advanced', |
192
|
|
|
// ); |
193
|
|
|
// |
194
|
|
|
// $settings[] = array( |
195
|
|
|
// 'id' => 'gallery_permalink', |
196
|
|
|
// 'title' => __( 'Gallery Permalink', 'foogallery' ), |
197
|
|
|
// 'desc' => __( 'If friendly URL\'s are enabled, this is used in building up a friendly URL', 'foogallery' ), |
198
|
|
|
// 'default' => foogallery_get_default( 'gallery_permalink' ), |
199
|
|
|
// 'type' => 'text', |
200
|
|
|
// 'tab' => 'advanced', |
201
|
|
|
// ); |
202
|
|
|
// //endregion Advanced |
203
|
|
|
|
204
|
|
|
//region Language Tab |
205
|
|
|
$tabs['language'] = __( 'Language', 'foogallery' ); |
206
|
|
|
|
207
|
|
|
$settings[] = array( |
208
|
|
|
'id' => 'language_images_count_none_text', |
209
|
|
|
'title' => __( 'Image Count None Text', 'foogallery' ), |
210
|
|
|
'type' => 'text', |
211
|
|
|
'default' => __( 'No images', 'foogallery' ), |
212
|
|
|
'tab' => 'language' |
213
|
|
|
); |
214
|
|
|
|
215
|
|
|
$settings[] = array( |
216
|
|
|
'id' => 'language_images_count_single_text', |
217
|
|
|
'title' => __( 'Image Count Single Text', 'foogallery' ), |
218
|
|
|
'type' => 'text', |
219
|
|
|
'default' => __( '1 image', 'foogallery' ), |
220
|
|
|
'tab' => 'language' |
221
|
|
|
); |
222
|
|
|
|
223
|
|
|
$settings[] = array( |
224
|
|
|
'id' => 'language_images_count_plural_text', |
225
|
|
|
'title' => __( 'Image Count Many Text', 'foogallery' ), |
226
|
|
|
'type' => 'text', |
227
|
|
|
'default' => __( '%s images', 'foogallery' ), |
228
|
|
|
'tab' => 'language' |
229
|
|
|
); |
230
|
|
|
//endregion Language Tab |
231
|
|
|
|
232
|
|
|
return apply_filters( 'foogallery_admin_settings_override', array( |
233
|
|
|
'tabs' => $tabs, |
234
|
|
|
'sections' => array(), |
235
|
|
|
'settings' => $settings, |
236
|
|
|
) ); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Render any custom setting types to the settings page |
241
|
|
|
*/ |
242
|
|
|
function render_custom_setting_types( $args ) { |
243
|
|
|
if ( 'clear_optimization_button' === $args['type'] ) { ?> |
244
|
|
|
<input type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_clear_css_optimizations' ) ); ?>" class="button-primary foogallery_clear_css_optimizations" value="<?php _e( 'Clear CSS Optimization Cache', 'foogallery' ); ?>"> |
245
|
|
|
<span id="foogallery_clear_css_cache_spinner" style="position: absolute" class="spinner"></span> |
246
|
|
|
<?php } else if ( 'thumb_generation_test' === $args['type'] ) { ?> |
247
|
|
|
<div id="foogallery_thumb_generation_test_container"> |
248
|
|
|
<input type="button" data-nonce="<?php echo esc_attr( wp_create_nonce( 'foogallery_thumb_generation_test' ) ); ?>" class="button-primary foogallery_thumb_generation_test" value="<?php _e( 'Run Tests', 'foogallery' ); ?>"> |
249
|
|
|
<span id="foogallery_thumb_generation_test_spinner" style="position: absolute" class="spinner"></span> |
250
|
|
|
</div> |
251
|
|
|
<?php } |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* AJAX endpoint for clearing all CSS optimizations |
256
|
|
|
*/ |
257
|
|
|
function ajax_clear_css_optimizations() { |
258
|
|
|
if ( check_admin_referer( 'foogallery_clear_css_optimizations' ) ) { |
259
|
|
|
foogallery_clear_all_css_load_optimizations(); |
260
|
|
|
|
261
|
|
|
_e('The CSS optimization cache was successfully cleared!', 'foogallery' ); |
262
|
|
|
die(); |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* AJAX endpoint for testing thumbnail generation using WPThumb |
268
|
|
|
*/ |
269
|
|
|
function ajax_thumb_generation_test() { |
|
|
|
|
270
|
|
|
if ( check_admin_referer( 'foogallery_thumb_generation_test' ) ) { |
271
|
|
|
foogallery_output_thumbnail_generation_results(); |
272
|
|
|
die(); |
|
|
|
|
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.