Opened 13 years ago
Closed 13 years ago
#20929 closed defect (bug) (fixed)
wp_list_filter Notice
Reported by: | wpsmith | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | has-patch needs-refresh |
Focuses: | Cc: |
Description
If someone wanted to add an argument for easy filtering on a taxonomy and then used get_taxonomies to query that non-standard key, it generates notices.
E.g., Given labels,
$args = array( 'mycustomkey' => true, 'hierarchical' => 0, 'rewrite' => array( 'slug' ), ); register_taxonomy( 'my_taxonomy', array( 'my_post_type' ), $args);
Then later, if I used:
get_taxonomies( array( 'mycustomkey' => true ) );
it generates:
Notice: Undefined index: mycustomkey in C:\xampp\htdocs\www\sandbox\wp-includes\functions.php on line 2499.
This is a simple fix:
if ( isset($to_match[ $m_key ]) && $m_value == $to_match[ $m_key ] )
Attachments (2)
Change History (8)
#2
follow-up:
↓ 3
@
13 years ago
- Keywords needs-refresh needs-unit-tests added; dev-feedback removed
- Milestone changed from Awaiting Review to 3.5
Looks good at a glance. Some thoughts and housekeeping:
- Let's use array_key_exists() here instead. isset() will return false if the value is null, and that may not be expected behavior here.
- If we had kept isset(),
isset($to_match[ $m_key ]) &&
would beisset( $to_match[ $m_key ] ) &&
per our coding standards.
- Please diff from the root of WordPress, rather than from within wp-includes. This will provide for a patch path of wp-includes/functions.php, rather than just functions.php. There happens to be only one functions.php file in core (outside of default themes), so when prompted someone applying the patch could guess, but there are three post.php files.
- Some tests here would be cool. They could go into TestListFilter. If you run the test suite with the -d flag, it forces WP_DEBUG, and thus you can write a test that could normally generate a notice. Be sure to test the NULL case :-)
#3
in reply to:
↑ 2
;
follow-up:
↓ 4
@
13 years ago
Replying to nacin:
- Some tests here would be cool. They could go into TestListFilter. If you run the test suite with the -d flag, it forces WP_DEBUG, and thus you can write a test that could normally generate a notice. Be sure to test the NULL case :-)
Thanks Nacin! Any tips/links on how to do the test or run the test suite?
#4
in reply to:
↑ 3
@
13 years ago
Replying to wpsmith:
Any tips/links on how to do the test or run the test suite?
Note: See
TracTickets for help on using
tickets.
I was able to reproduce this bug very easily.
I have also reviewed and tested this patch with 3.4, and this looks good.