Conditions | 4 |
Paths | 8 |
Total Lines | 310 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
26 | function create_settings() { |
||
27 | |||
28 | //region General Tab |
||
29 | $tabs['general'] = __( 'General', 'foogallery' ); |
||
30 | |||
31 | $settings[] = array( |
||
32 | 'id' => 'clear_css_optimizations', |
||
33 | 'title' => __( 'Clear CSS Cache', 'foogallery' ), |
||
34 | '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() ), |
||
35 | 'type' => 'clear_optimization_button', |
||
36 | 'tab' => 'general', |
||
37 | 'section' => __( 'Cache', 'foogallery' ) |
||
38 | ); |
||
39 | |||
40 | $gallery_templates = foogallery_gallery_templates(); |
||
41 | $gallery_templates_choices = array(); |
||
42 | foreach ( $gallery_templates as $template ) { |
||
43 | $gallery_templates_choices[ $template['slug'] ] = $template['name']; |
||
44 | } |
||
45 | |||
46 | $settings[] = array( |
||
47 | 'id' => 'gallery_template', |
||
48 | 'title' => __( 'Default Gallery Template', 'foogallery' ), |
||
49 | 'desc' => __( 'The default gallery template to use for new galleries', 'foogallery' ), |
||
50 | 'default' => foogallery_get_default( 'gallery_template' ) , |
||
51 | 'type' => 'select', |
||
52 | 'choices' => $gallery_templates_choices, |
||
53 | 'tab' => 'general', |
||
54 | 'section' => __( 'Gallery Defaults', 'foogallery' ) |
||
55 | ); |
||
56 | |||
57 | $settings[] = array( |
||
58 | 'id' => 'gallery_sorting', |
||
59 | 'title' => __( 'Default Gallery Sorting', 'foogallery' ), |
||
60 | 'desc' => __( 'The default attachment sorting to use for new galleries', 'foogallery' ), |
||
61 | 'default' => '', |
||
62 | 'type' => 'select', |
||
63 | 'choices' => foogallery_sorting_options(), |
||
64 | 'tab' => 'general', |
||
65 | 'section' => __( 'Gallery Defaults', 'foogallery' ) |
||
66 | ); |
||
67 | |||
68 | $gallery_posts = get_posts( array( |
||
69 | 'post_type' => FOOGALLERY_CPT_GALLERY, |
||
70 | 'post_status' => array( 'publish', 'draft' ), |
||
71 | 'cache_results' => false, |
||
72 | 'nopaging' => true, |
||
73 | ) ); |
||
74 | |||
75 | $galleries = array(); |
||
76 | |||
77 | foreach ( $gallery_posts as $post ) { |
||
78 | $galleries[] = array( |
||
79 | 'ID' => $post->ID, |
||
80 | 'name' => $post->post_title |
||
81 | ); |
||
82 | } |
||
83 | |||
84 | $gallery_choices = array(); |
||
85 | $gallery_choices[] = __( 'No default', 'foogallery' ); |
||
86 | foreach ( $galleries as $gallery ) { |
||
87 | $gallery_choices[ $gallery['ID'] ] = $gallery['name']; |
||
88 | } |
||
89 | |||
90 | $settings[] = array( |
||
91 | 'id' => 'default_gallery_settings', |
||
92 | 'title' => __( 'Default Gallery Settings', 'foogallery' ), |
||
93 | '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' ), |
||
94 | 'type' => 'select', |
||
95 | 'choices' => $gallery_choices, |
||
96 | 'tab' => 'general', |
||
97 | 'section' => __( 'Gallery Defaults', 'foogallery' ) |
||
98 | ); |
||
99 | |||
100 | $settings[] = array( |
||
101 | 'id' => 'caption_title_source', |
||
102 | 'title' => __( 'Caption Title Source', 'foogallery' ), |
||
103 | 'desc' => __( 'By default, image caption titles are pulled from the attachment "Caption" field. Alternatively, you can choose to use other fields.', 'foogallery' ), |
||
104 | 'type' => 'select', |
||
105 | 'choices' => array( |
||
106 | 'title' => foogallery_get_attachment_field_friendly_name( 'title' ), |
||
107 | 'caption' => foogallery_get_attachment_field_friendly_name( 'caption' ), |
||
108 | 'alt' => foogallery_get_attachment_field_friendly_name( 'alt' ), |
||
109 | 'desc' => foogallery_get_attachment_field_friendly_name( 'desc' ) |
||
110 | ), |
||
111 | 'default' => 'caption', |
||
112 | 'tab' => 'general', |
||
113 | 'section' => __( 'Captions', 'foogallery' ), |
||
114 | 'spacer' => '<span class="spacer"></span>' |
||
115 | ); |
||
116 | |||
117 | $settings[] = array( |
||
118 | 'id' => 'caption_desc_source', |
||
119 | 'title' => __( 'Caption Description Source', 'foogallery' ), |
||
120 | 'desc' => __( 'By default, image caption descriptions are pulled from the attachment "Description" field. Alternatively, you can choose to use other fields.', 'foogallery' ), |
||
121 | 'type' => 'select', |
||
122 | 'choices' => array( |
||
123 | 'title' => foogallery_get_attachment_field_friendly_name( 'title' ), |
||
124 | 'caption' => foogallery_get_attachment_field_friendly_name( 'caption' ), |
||
125 | 'alt' => foogallery_get_attachment_field_friendly_name( 'alt' ), |
||
126 | 'desc' => foogallery_get_attachment_field_friendly_name( 'desc' ) |
||
127 | ), |
||
128 | 'default' => 'desc', |
||
129 | 'tab' => 'general', |
||
130 | 'section' => __( 'Captions', 'foogallery' ), |
||
131 | 'spacer' => '<span class="spacer"></span>' |
||
132 | ); |
||
133 | |||
134 | $settings[] = array( |
||
135 | 'id' => 'hide_gallery_template_help', |
||
136 | 'title' => __( 'Hide Gallery Template Help', 'foogallery' ), |
||
137 | 'desc' => __( 'Some gallery templates show helpful tips, which are useful for new users. You can choose to hide these tips.', 'foogallery' ), |
||
138 | 'type' => 'checkbox', |
||
139 | 'tab' => 'general', |
||
140 | 'section' => __( 'Admin', 'foogallery' ) |
||
141 | ); |
||
142 | |||
143 | $settings[] = array( |
||
144 | 'id' => 'hide_editor_button', |
||
145 | 'title' => __( 'Hide WYSIWYG Editor Button', 'foogallery' ), |
||
146 | 'desc' => sprintf( __( 'If enabled, this will hide the "Add %s" button in the WYSIWYG editor.', 'foogallery' ), foogallery_plugin_name() ), |
||
147 | 'type' => 'checkbox', |
||
148 | 'tab' => 'general', |
||
149 | 'section' => __( 'Admin', 'foogallery' ) |
||
150 | ); |
||
151 | |||
152 | //endregion General |
||
153 | |||
154 | //region Images Tab |
||
155 | $tabs['thumb'] = __( 'Images', 'foogallery' ); |
||
156 | |||
157 | $settings[] = array( |
||
158 | 'id' => 'thumb_jpeg_quality', |
||
159 | 'title' => __( 'Thumbnail JPEG Quality', 'foogallery' ), |
||
160 | 'desc' => __( 'The image quality to be used when resizing JPEG images.', 'foogallery' ), |
||
161 | 'type' => 'text', |
||
162 | 'default' => '80', |
||
163 | 'tab' => 'thumb' |
||
164 | ); |
||
165 | |||
166 | $settings[] = array( |
||
167 | 'id' => 'default_retina_support', |
||
168 | 'title' => __( 'Default Retina Support', 'foogallery' ), |
||
169 | 'desc' => __( 'Default retina support for all new galleries that are created. This can also be overridden for each gallery.', 'foogallery' ), |
||
170 | 'type' => 'checkboxlist', |
||
171 | 'choices' => foogallery_retina_options(), |
||
172 | 'tab' => 'thumb' |
||
173 | ); |
||
174 | |||
175 | $settings[] = array( |
||
176 | 'id' => 'use_original_thumbs', |
||
177 | 'title' => __( 'Use Original Thumbnails', 'foogallery' ), |
||
178 | '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' ), |
||
179 | 'type' => 'checkbox', |
||
180 | 'tab' => 'thumb' |
||
181 | ); |
||
182 | |||
183 | $settings[] = array( |
||
184 | 'id' => 'thumb_resize_animations', |
||
185 | 'title' => __( 'Resize Animated GIFs', 'foogallery' ), |
||
186 | 'desc' => __( 'Should animated gifs be resized or not. If enabled, only the first frame is used in the resize.', 'foogallery' ), |
||
187 | 'type' => 'checkbox', |
||
188 | 'tab' => 'thumb' |
||
189 | ); |
||
190 | |||
191 | $settings[] = array( |
||
192 | 'id' => 'animated_gif_use_original_image', |
||
193 | 'title' => __( 'Show Animated Thumbnails', 'foogallery' ), |
||
194 | 'desc' => __( 'If animated GIFs are used, then show the original GIF as the thumbnail.', 'foogallery' ), |
||
195 | 'type' => 'checkbox', |
||
196 | 'tab' => 'thumb' |
||
197 | ); |
||
198 | |||
199 | $settings[] = array( |
||
200 | 'id' => 'thumb_generation_test', |
||
201 | 'title' => __( 'Thumbnail Generation Test', 'foogallery' ), |
||
202 | 'desc' => sprintf( __( 'Test to see if %s can generate the thumbnails it needs.', 'foogallery' ), foogallery_plugin_name() ), |
||
203 | 'type' => 'thumb_generation_test', |
||
204 | 'tab' => 'thumb' |
||
205 | ); |
||
206 | |||
207 | //endregion Thumbnail Tab |
||
208 | |||
209 | // //region Advanced Tab |
||
|
|||
210 | // $tabs['advanced'] = __( 'Advanced', 'foogallery' ); |
||
211 | // |
||
212 | // $example_url = '<code>' . trailingslashit( site_url() ) . foogallery_permalink() . '/my-cool-gallery</code>'; |
||
213 | // |
||
214 | // $settings[] = array( |
||
215 | // 'id' => 'gallery_permalinks_enabled', |
||
216 | // 'title' => __( 'Enable Friendly URL\'s', 'foogallery' ), |
||
217 | // 'desc' => sprintf( __( 'If enabled, you will be able to access your galleries from a friendly URL e.g. %s', 'foogallery' ), $example_url ), |
||
218 | // 'default' => foogallery_get_default( 'gallery_permalinks_enabled' ), |
||
219 | // 'type' => 'checkbox', |
||
220 | // 'tab' => 'advanced', |
||
221 | // ); |
||
222 | // |
||
223 | // $settings[] = array( |
||
224 | // 'id' => 'gallery_permalink', |
||
225 | // 'title' => __( 'Gallery Permalink', 'foogallery' ), |
||
226 | // 'desc' => __( 'If friendly URL\'s are enabled, this is used in building up a friendly URL', 'foogallery' ), |
||
227 | // 'default' => foogallery_get_default( 'gallery_permalink' ), |
||
228 | // 'type' => 'text', |
||
229 | // 'tab' => 'advanced', |
||
230 | // ); |
||
231 | // //endregion Advanced |
||
232 | |||
233 | //region Language Tab |
||
234 | $tabs['language'] = __( 'Language', 'foogallery' ); |
||
235 | |||
236 | $settings[] = array( |
||
237 | 'id' => 'language_images_count_none_text', |
||
238 | 'title' => __( 'Image Count None Text', 'foogallery' ), |
||
239 | 'type' => 'text', |
||
240 | 'default' => __( 'No images', 'foogallery' ), |
||
241 | 'tab' => 'language' |
||
242 | ); |
||
243 | |||
244 | $settings[] = array( |
||
245 | 'id' => 'language_images_count_single_text', |
||
246 | 'title' => __( 'Image Count Single Text', 'foogallery' ), |
||
247 | 'type' => 'text', |
||
248 | 'default' => __( '1 image', 'foogallery' ), |
||
249 | 'tab' => 'language' |
||
250 | ); |
||
251 | |||
252 | $settings[] = array( |
||
253 | 'id' => 'language_images_count_plural_text', |
||
254 | 'title' => __( 'Image Count Many Text', 'foogallery' ), |
||
255 | 'type' => 'text', |
||
256 | 'default' => __( '%s images', 'foogallery' ), |
||
257 | 'tab' => 'language' |
||
258 | ); |
||
259 | //endregion Language Tab |
||
260 | |||
261 | //region Advanced Tab |
||
262 | $tabs['advanced'] = __( 'Advanced', 'foogallery' ); |
||
263 | |||
264 | $settings[] = array( |
||
265 | 'id' => 'enable_custom_ready', |
||
266 | 'title' => __( 'Custom Ready Event', 'foogallery' ), |
||
267 | 'desc' => sprintf( __( 'By default the jQuery ready event is used, but there are sometimes unavoidable javascript errors on the page, which could result in the default gallery templates not initializing correctly. Enable this setting to use a built-in custom ready event to overcome this if needed.', 'foogallery' ), foogallery_plugin_name() ), |
||
268 | 'type' => 'checkbox', |
||
269 | 'tab' => 'advanced' |
||
270 | ); |
||
271 | |||
272 | $settings[] = array( |
||
273 | 'id' => 'enable_legacy_thumb_cropping', |
||
274 | 'title' => __( 'Enable Legacy Thumb Cropping', 'foogallery' ), |
||
275 | 'desc' => __( 'For when you want to enable legacy cropping options in certain gallery templates. This is not recommended.', 'foogallery' ), |
||
276 | 'type' => 'checkbox', |
||
277 | 'tab' => 'advanced' |
||
278 | ); |
||
279 | |||
280 | $settings[] = array( |
||
281 | 'id' => 'output_json_to_script_block', |
||
282 | 'title' => __( 'Output Gallery JSON to Script Block', 'foogallery' ), |
||
283 | 'desc' => __( 'Some plugins conflict with the default way of rendering gallery items to the container. Enabling this setting will output gallery items to a separate script block.', 'foogallery' ), |
||
284 | 'type' => 'checkbox', |
||
285 | 'tab' => 'advanced' |
||
286 | ); |
||
287 | |||
288 | $settings[] = array( |
||
289 | 'id' => 'enable_debugging', |
||
290 | 'title' => __( 'Enable Debugging', 'foogallery' ), |
||
291 | '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() ), |
||
292 | 'type' => 'checkbox', |
||
293 | 'tab' => 'advanced' |
||
294 | ); |
||
295 | |||
296 | $settings[] = array( |
||
297 | 'id' => 'uninstall', |
||
298 | 'title' => __( 'Full Uninstall', 'foogallery' ), |
||
299 | '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() ), |
||
300 | 'type' => 'uninstall', |
||
301 | 'tab' => 'advanced' |
||
302 | ); |
||
303 | |||
304 | // $settings[] = array( |
||
305 | // 'id' => 'force_https', |
||
306 | // 'title' => __( 'Force HTTPS', 'foogallery' ), |
||
307 | // 'desc' => __( 'Force all thumbnails to use HTTPS protocol.', 'foogallery' ), |
||
308 | // 'type' => 'checkbox', |
||
309 | // 'tab' => 'advanced' |
||
310 | // ); |
||
311 | |||
312 | $settings[] = array( |
||
313 | 'id' => 'use_future_endpoint', |
||
314 | 'title' => __( 'Use Beta Endpoint', 'foogallery' ), |
||
315 | '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' ), |
||
316 | 'type' => 'checkbox', |
||
317 | 'tab' => 'advanced', |
||
318 | ); |
||
319 | |||
320 | $settings[] = array( |
||
321 | 'id' => 'override_thumb_test', |
||
322 | 'title' => __( 'Override Thumb Test', 'foogallery' ), |
||
323 | 'desc' => __( 'Sometimes there are problems running the thumbnail generation test. This overrides the test to use a remote image from our CDN.', 'foogallery' ), |
||
324 | 'type' => 'checkbox', |
||
325 | 'tab' => 'advanced', |
||
326 | ); |
||
327 | |||
328 | //endregion Advanced Tab |
||
329 | |||
330 | return apply_filters( 'foogallery_admin_settings_override', array( |
||
331 | 'tabs' => $tabs, |
||
332 | 'sections' => array(), |
||
333 | 'settings' => $settings, |
||
334 | ) ); |
||
335 | } |
||
336 | |||
448 |
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.