Conditions | 3 |
Paths | 4 |
Total Lines | 228 |
Code Lines | 147 |
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 |
||
25 | function create_settings() { |
||
26 | |||
27 | //region General Tab |
||
28 | $tabs['general'] = __( 'General', 'foogallery' ); |
||
29 | |||
30 | $settings[] = array( |
||
31 | 'id' => 'clear_css_optimizations', |
||
32 | 'title' => __( 'Clear CSS Cache', 'foogallery' ), |
||
33 | '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() ), |
||
34 | 'type' => 'clear_optimization_button', |
||
35 | 'tab' => 'general', |
||
36 | 'section' => __( 'Cache', 'foogallery' ) |
||
37 | ); |
||
38 | |||
39 | $gallery_templates = foogallery_gallery_templates(); |
||
40 | $gallery_templates_choices = array(); |
||
41 | foreach ( $gallery_templates as $template ) { |
||
42 | $gallery_templates_choices[ $template['slug'] ] = $template['name']; |
||
43 | } |
||
44 | |||
45 | $settings[] = array( |
||
46 | 'id' => 'gallery_template', |
||
47 | 'title' => __( 'Default Gallery Template', 'foogallery' ), |
||
48 | 'desc' => __( 'The default gallery template to use for new galleries', 'foogallery' ), |
||
49 | 'default' => foogallery_get_default( 'gallery_template' ) , |
||
50 | 'type' => 'select', |
||
51 | 'choices' => $gallery_templates_choices, |
||
52 | 'tab' => 'general', |
||
53 | 'section' => __( 'Gallery Defaults', 'foogallery' ) |
||
54 | ); |
||
55 | |||
56 | $settings[] = array( |
||
57 | 'id' => 'gallery_sorting', |
||
58 | 'title' => __( 'Default Gallery Sorting', 'foogallery' ), |
||
59 | 'desc' => __( 'The default attachment sorting to use for new galleries', 'foogallery' ), |
||
60 | 'default' => '', |
||
61 | 'type' => 'select', |
||
62 | 'choices' => foogallery_sorting_options(), |
||
63 | 'tab' => 'general', |
||
64 | 'section' => __( 'Gallery Defaults', 'foogallery' ) |
||
65 | ); |
||
66 | |||
67 | $galleries = foogallery_get_all_galleries(); |
||
68 | $gallery_choices = array(); |
||
69 | $gallery_choices[] = __( 'No default', 'foogallery' ); |
||
70 | foreach ( $galleries as $gallery ) { |
||
71 | $gallery_choices[ $gallery->ID ] = $gallery->name; |
||
72 | } |
||
73 | |||
74 | $settings[] = array( |
||
75 | 'id' => 'default_gallery_settings', |
||
76 | 'title' => __( 'Default Gallery Settings', 'foogallery' ), |
||
77 | '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' ), |
||
78 | 'type' => 'select', |
||
79 | 'choices' => $gallery_choices, |
||
80 | 'tab' => 'general', |
||
81 | 'section' => __( 'Gallery Defaults', 'foogallery' ) |
||
82 | ); |
||
83 | |||
84 | $settings[] = array( |
||
85 | 'id' => 'caption_title_source', |
||
86 | 'title' => __( 'Caption Title Source', 'foogallery' ), |
||
87 | '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' ), |
||
88 | 'type' => 'select', |
||
89 | 'choices' => array( |
||
90 | 'caption' => __('Attachment Caption Field', 'foogallery'), |
||
91 | 'title' => __('Attachment Title Field', 'foogallery') |
||
92 | ), |
||
93 | 'default' => 'caption', |
||
94 | 'tab' => 'general', |
||
95 | 'section' => __( 'Captions', 'foogallery' ), |
||
96 | 'spacer' => '<span class="spacer"></span>' |
||
97 | ); |
||
98 | |||
99 | $settings[] = array( |
||
100 | 'id' => 'caption_desc_source', |
||
101 | 'title' => __( 'Caption Description Source', 'foogallery' ), |
||
102 | 'desc' => __( 'By default, image caption descriptions are pulled from the attachment "Description" field. Alternatively, you can choose to use other fields.', 'foogallery' ), |
||
103 | 'type' => 'select', |
||
104 | 'choices' => array( |
||
105 | 'desc' => __('Attachment Description Field', 'foogallery'), |
||
106 | 'title' => __('Attachment Title Field', 'foogallery'), |
||
107 | 'caption' => __('Attachment Caption Field', 'foogallery'), |
||
108 | 'alt' => __('Attachment Alt Field', 'foogallery') |
||
109 | ), |
||
110 | 'default' => 'desc', |
||
111 | 'tab' => 'general', |
||
112 | 'section' => __( 'Captions', 'foogallery' ), |
||
113 | 'spacer' => '<span class="spacer"></span>' |
||
114 | ); |
||
115 | |||
116 | $settings[] = array( |
||
117 | 'id' => 'hide_gallery_template_help', |
||
118 | 'title' => __( 'Hide Gallery Template Help', 'foogallery' ), |
||
119 | 'desc' => __( 'Some gallery templates show helpful tips, which are useful for new users. You can choose to hide these tips.', 'foogallery' ), |
||
120 | 'type' => 'checkbox', |
||
121 | 'tab' => 'general', |
||
122 | 'section' => __( 'Admin', 'foogallery' ) |
||
123 | ); |
||
124 | |||
125 | $settings[] = array( |
||
126 | 'id' => 'hide_editor_button', |
||
127 | 'title' => __( 'Hide WYSIWYG Editor Button', 'foogallery' ), |
||
128 | 'desc' => sprintf( __( 'If enabled, this will hide the "Add %s" button in the WYSIWYG editor.', 'foogallery' ), foogallery_plugin_name() ), |
||
129 | 'type' => 'checkbox', |
||
130 | 'tab' => 'general', |
||
131 | 'section' => __( 'Admin', 'foogallery' ) |
||
132 | ); |
||
133 | |||
134 | //endregion General |
||
135 | |||
136 | //region Extensions Tab |
||
137 | $tabs['extensions'] = __( 'Extensions', 'foogallery' ); |
||
138 | |||
139 | $settings[] = array( |
||
140 | 'id' => 'use_future_endpoint', |
||
141 | 'title' => __( 'Use Beta Endpoint', 'foogallery' ), |
||
142 | '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' ), |
||
143 | 'type' => 'checkbox', |
||
144 | 'tab' => 'extensions', |
||
145 | ); |
||
146 | //endregion Extensions Tab |
||
147 | |||
148 | //region Images Tab |
||
149 | $tabs['thumb'] = __( 'Images', 'foogallery' ); |
||
150 | |||
151 | $settings[] = array( |
||
152 | 'id' => 'thumb_jpeg_quality', |
||
153 | 'title' => __( 'Thumbnail JPEG Quality', 'foogallery' ), |
||
154 | 'desc' => __( 'The image quality to be used when resizing JPEG images.', 'foogallery' ), |
||
155 | 'type' => 'text', |
||
156 | 'default' => '80', |
||
157 | 'tab' => 'thumb' |
||
158 | ); |
||
159 | |||
160 | $settings[] = array( |
||
161 | 'id' => 'default_retina_support', |
||
162 | 'title' => __( 'Default Retina Support', 'foogallery' ), |
||
163 | 'desc' => __( 'Default retina support for all new galleries that are created. This can also be overridden for each gallery.', 'foogallery' ), |
||
164 | 'type' => 'checkboxlist', |
||
165 | 'choices' => foogallery_retina_options(), |
||
166 | 'tab' => 'thumb' |
||
167 | ); |
||
168 | |||
169 | $settings[] = array( |
||
170 | 'id' => 'use_original_thumbs', |
||
171 | 'title' => __( 'Use Original Thumbnails', 'foogallery' ), |
||
172 | 'desc' => __( 'Allow for the original thumbnails to be used when possible. This can be useful if your thumbs are animated gifs.', 'foogallery' ), |
||
173 | 'type' => 'checkbox', |
||
174 | 'tab' => 'thumb' |
||
175 | ); |
||
176 | |||
177 | $settings[] = array( |
||
178 | 'id' => 'thumb_resize_animations', |
||
179 | 'title' => __( 'Resize Animated GIFs', 'foogallery' ), |
||
180 | 'desc' => __( 'Should animated gifs be resized or not. If enabled, only the first frame is used in the resize.', 'foogallery' ), |
||
181 | 'type' => 'checkbox', |
||
182 | 'tab' => 'thumb' |
||
183 | ); |
||
184 | |||
185 | $settings[] = array( |
||
186 | 'id' => 'thumb_generation_test', |
||
187 | 'title' => __( 'Thumbnail Generation Test', 'foogallery' ), |
||
188 | 'desc' => sprintf( __( 'Test to see if %s can generate the thumbnails it needs.', 'foogallery' ), foogallery_plugin_name() ), |
||
189 | 'type' => 'thumb_generation_test', |
||
190 | 'tab' => 'thumb' |
||
191 | ); |
||
192 | |||
193 | //endregion Thumbnail Tab |
||
194 | |||
195 | // //region Advanced Tab |
||
|
|||
196 | // $tabs['advanced'] = __( 'Advanced', 'foogallery' ); |
||
197 | // |
||
198 | // $example_url = '<code>' . trailingslashit( site_url() ) . foogallery_permalink() . '/my-cool-gallery</code>'; |
||
199 | // |
||
200 | // $settings[] = array( |
||
201 | // 'id' => 'gallery_permalinks_enabled', |
||
202 | // 'title' => __( 'Enable Friendly URL\'s', 'foogallery' ), |
||
203 | // 'desc' => sprintf( __( 'If enabled, you will be able to access your galleries from a friendly URL e.g. %s', 'foogallery' ), $example_url ), |
||
204 | // 'default' => foogallery_get_default( 'gallery_permalinks_enabled' ), |
||
205 | // 'type' => 'checkbox', |
||
206 | // 'tab' => 'advanced', |
||
207 | // ); |
||
208 | // |
||
209 | // $settings[] = array( |
||
210 | // 'id' => 'gallery_permalink', |
||
211 | // 'title' => __( 'Gallery Permalink', 'foogallery' ), |
||
212 | // 'desc' => __( 'If friendly URL\'s are enabled, this is used in building up a friendly URL', 'foogallery' ), |
||
213 | // 'default' => foogallery_get_default( 'gallery_permalink' ), |
||
214 | // 'type' => 'text', |
||
215 | // 'tab' => 'advanced', |
||
216 | // ); |
||
217 | // //endregion Advanced |
||
218 | |||
219 | //region Language Tab |
||
220 | $tabs['language'] = __( 'Language', 'foogallery' ); |
||
221 | |||
222 | $settings[] = array( |
||
223 | 'id' => 'language_images_count_none_text', |
||
224 | 'title' => __( 'Image Count None Text', 'foogallery' ), |
||
225 | 'type' => 'text', |
||
226 | 'default' => __( 'No images', 'foogallery' ), |
||
227 | 'tab' => 'language' |
||
228 | ); |
||
229 | |||
230 | $settings[] = array( |
||
231 | 'id' => 'language_images_count_single_text', |
||
232 | 'title' => __( 'Image Count Single Text', 'foogallery' ), |
||
233 | 'type' => 'text', |
||
234 | 'default' => __( '1 image', 'foogallery' ), |
||
235 | 'tab' => 'language' |
||
236 | ); |
||
237 | |||
238 | $settings[] = array( |
||
239 | 'id' => 'language_images_count_plural_text', |
||
240 | 'title' => __( 'Image Count Many Text', 'foogallery' ), |
||
241 | 'type' => 'text', |
||
242 | 'default' => __( '%s images', 'foogallery' ), |
||
243 | 'tab' => 'language' |
||
244 | ); |
||
245 | //endregion Language Tab |
||
246 | |||
247 | return apply_filters( 'foogallery_admin_settings_override', array( |
||
248 | 'tabs' => $tabs, |
||
249 | 'sections' => array(), |
||
250 | 'settings' => $settings, |
||
251 | ) ); |
||
252 | } |
||
253 | |||
349 |
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.