Opened 10 years ago
Closed 10 years ago
#34751 closed enhancement (fixed)
Improve the readability of the default arguments of the wp_list_categories()
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.5 | Priority: | normal |
| Severity: | normal | Version: | 4.4 |
| Component: | Taxonomy | Keywords: | has-patch commit |
| Focuses: | Cc: |
Description
When skimming through the defaults arguments of some core functions, it's easy to miss some attributes, because there are multiple arguments per line.
Here's an example how the default arguments of the wp_list_categories() are written out:
$defaults = array(
'show_option_all' => '', 'show_option_none' => __('No categories'),
'orderby' => 'name', 'order' => 'ASC',
'style' => 'list',
'show_count' => 0, 'hide_empty' => 1,
'use_desc_for_title' => 1, 'child_of' => 0,
'feed' => '', 'feed_type' => '',
'feed_image' => '', 'exclude' => '',
'exclude_tree' => '', 'current_category' => 0,
'hierarchical' => true, 'title_li' => __( 'Categories' ),
'hide_title_if_empty' => false,
'echo' => 1, 'depth' => 0,
'separator' => '<br />',
'taxonomy' => 'category'
);
I think it would improve readability if we only had a single argument per line:
$defaults = array(
'show_option_all' => '',
'show_option_none' => __('No categories'),
'orderby' => 'name',
'order' => 'ASC',
'style' => 'list',
'show_count' => 0,
'hide_empty' => 1,
'use_desc_for_title' => 1,
'child_of' => 0,
'feed' => '',
'feed_type' => '',
'feed_image' => '',
'exclude' => '',
'exclude_tree' => '',
'current_category' => 0,
'hierarchical' => true,
'title_li' => __( 'Categories' ),
'hide_title_if_empty' => false,
'echo' => 1, 'depth' => 0,
'separator' => '<br />',
'taxonomy' => 'category'
);
Even better to have it alphabetically ordered:
$defaults = array(
'child_of' => 0,
'current_category' => 0,
'depth' => 0,
'echo' => 1,
'exclude' => '',
'exclude_tree' => '',
'feed' => '',
'feed_type' => '',
'feed_image' => '',
'hide_empty' => 1,
'hide_title_if_empty' => false,
'hierarchical' => true,
'orderby' => 'name',
'order' => 'ASC',
'show_option_all' => '',
'show_option_none' => __('No categories'),
'style' => 'list',
'show_count' => 0,
'separator' => '<br />',
'taxonomy' => 'category'
'title_li' => __( 'Categories' ),
'use_desc_for_title' => 1,
);
I actually prefer this:
$defaults = array(
'child_of' => 0,
'current_category' => 0,
'depth' => 0,
'echo' => 1,
'exclude' => '',
'exclude_tree' => '',
'feed' => '',
'feed_type' => '',
'feed_image' => '',
'hide_empty' => 1,
'hide_title_if_empty' => false,
'hierarchical' => true,
'orderby' => 'name',
'order' => 'ASC',
'show_option_all' => '',
'show_option_none' => __('No categories'),
'style' => 'list',
'show_count' => 0,
'separator' => '<br />',
'taxonomy' => 'category'
'title_li' => __( 'Categories' ),
'use_desc_for_title' => 1,
);
Attachments (2)
Change History (8)
#3
@
10 years ago
- Component changed from General to Taxonomy
- Keywords commit added
- Milestone changed from Awaiting Review to 4.5
#4
follow-up:
↓ 5
@
10 years ago
ps: there are tons of similar adjustments possible in the core.
I could add the patches under this current ticket (I guess we would need to change the title?) or I could just create another ticket to combine them all?
#5
in reply to:
↑ 4
@
10 years ago
Replying to birgire:
ps: there are tons of similar adjustments possible in the core.
I could add the patches under this current ticket (I guess we would need to change the title?) or I could just create another ticket to combine them all?
I totally believe that there are tons of similar "bugs" in the code base. If you find any other areas where it definitely makes sense to improve readability / documentation, feel free to open another ticket.
Just note that we don't refactor just for the sake of refactoring: https://make.wordpress.org/core/2011/03/23/code-refactoring/.
wp_list_categories() stands out because there are lots of arguments which are hard to read and not all of them are properly documented in the function's DocBlock (see [35140]).
ps: my alphabetical ordering above can be improved ;-)