Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#20929 closed defect (bug) (fixed)

wp_list_filter Notice

Reported by: wpsmith's profile wpsmith Owned by: nacin's profile 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)

functions.wp_list_filter.patch (435 bytes) - added by wpsmith 14 years ago.
20929-unit-test.patch (1.7 KB) - added by kurtpayne 14 years ago.
First pass unit test

Download all attachments as: .zip

Change History (8)

#1 @bpetty
14 years ago

  • Cc bpetty added

I was able to reproduce this bug very easily.

I have also reviewed and tested this patch with 3.4, and this looks good.

#2 follow-up: @nacin
14 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 be isset( $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: @wpsmith
14 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 @SergeyBiryukov
14 years ago

Replying to wpsmith:

Any tips/links on how to do the test or run the test suite?

http://codex.wordpress.org/Automated_Testing

@kurtpayne
14 years ago

First pass unit test

#5 @kurtpayne
14 years ago

  • Cc kpayne@… added
  • Keywords needs-unit-tests removed

Attached the first attempt at a unit test. I'm sure it could be improved upon.

It doesn't rely on the user passing "-d" in, and will force E_NOTICE on to capture the notice message, since that's the symptom we're testing.

#6 @nacin
14 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [21184]:

Check if array key exists in wp_list_filter(). props wpsmith. fixes #20929.

Note: See TracTickets for help on using tickets.