Conditions | 6 |
Paths | 4 |
Total Lines | 87 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 14 | ||
Bugs | 2 | Features | 6 |
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 |
||
236 | public function admin_page(){ |
||
237 | |||
238 | $html = ""; |
||
239 | |||
240 | $html .= '<div class="wrap" id="options_editor">' . "\n"; |
||
241 | |||
242 | $html .= '<h2>' . __( 'Create Test Data' , 'otm-test-content' ) . '</h2>' . "\n"; |
||
243 | |||
244 | $html .= "<div>"; |
||
245 | |||
246 | $html .= "<div class='test-data-cpt'>"; |
||
247 | $html .= "<h3>"; |
||
248 | $html .= "<span class='label'>".__( 'Quantity', 'otm-test-content' )."</span>"; |
||
249 | $html .= "<input type='number' value='0' id='quantity-adjustment'> <small><i>".__( 'Set to 0 to keep random', 'otm-test-content' )."</i></small>"; |
||
250 | $html .= "</h3>"; |
||
251 | $html .= "</div>"; |
||
252 | |||
253 | $html .= "<input type='hidden' id='connection-status' value='".$this->connected."'>"; |
||
254 | |||
255 | // Loop through every post type available on the site |
||
256 | $post_types = get_post_types( array( 'public' => true ), 'objects' ); |
||
257 | |||
258 | foreach ( $post_types as $post_type ) { |
||
259 | |||
260 | $skipped_cpts = array( |
||
261 | 'attachment' |
||
262 | ); |
||
263 | |||
264 | // Skip banned cpts |
||
265 | if ( in_array( $post_type->name, $skipped_cpts ) ){ |
||
266 | continue; |
||
267 | } |
||
268 | |||
269 | $html .= "<div class='test-data-cpt'>"; |
||
270 | |||
271 | // Create row for the post/page/cpt |
||
272 | $html .= "<h3>"; |
||
273 | |||
274 | $html .= "<span class='label'>" . $post_type->labels->name . "</span>"; |
||
275 | $html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-plus'></span> ".__( 'Create Test Data', 'otm-test-content' )."</a>"; |
||
276 | $html .= " <a href='javascript:void(0);' data-type='post' data-slug='".$post_type->name."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> ".__( 'Delete Test Data', 'otm-test-content' )."</a>"; |
||
277 | |||
278 | $html .= "</h3>"; |
||
279 | |||
280 | // Create row for each taxonomy associated with the post/page/cpt |
||
281 | $taxonomies = get_object_taxonomies( $post_type->name ); |
||
282 | |||
283 | if ( !empty( $taxonomies ) ){ |
||
284 | |||
285 | foreach( $taxonomies as $tax ){ |
||
286 | |||
287 | $html .= "<h3 class='term-box'>"; |
||
288 | |||
289 | $skipped_taxonomies = array( |
||
290 | 'post_format', // We shouldn't be making random post format classes |
||
291 | 'product_shipping_class' // These aren't used visually and are therefore skipped |
||
292 | ); |
||
293 | |||
294 | // Skip banned taxonomies |
||
295 | if ( in_array( $tax, $skipped_taxonomies ) ){ |
||
296 | continue; |
||
297 | } |
||
298 | |||
299 | $taxonomy = get_taxonomy( $tax ); |
||
300 | |||
301 | $html .= "<span class='label'>".$taxonomy->labels->name."</span>"; |
||
302 | |||
303 | $html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='create' class='button-primary handle-test-data' /><span class='dashicons dashicons-category'></span> ".__( 'Create', 'otm-test-content' )." ".$taxonomy->labels->name."</a>"; |
||
304 | |||
305 | $html .= " <a href='javascript:void(0);' data-type='term' data-slug='".$tax."' data-todo='delete' class='button-primary handle-test-data' /><span class='dashicons dashicons-trash'></span> ".__( 'Delete', 'otm-test-content' )." ".$taxonomy->labels->name."</a>"; |
||
306 | |||
307 | $html .= "</h3>"; |
||
308 | |||
309 | } |
||
310 | } |
||
311 | |||
312 | $html .= "</div>"; |
||
313 | |||
314 | } |
||
315 | |||
316 | $html .= "<pre class='test-data-status-box' id='status-updates'></pre>"; |
||
317 | |||
318 | $html .= "</div>"; |
||
319 | |||
320 | echo $html; |
||
321 | |||
322 | } |
||
323 | |||
325 |