WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#31001 closed defect (bug) (fixed)

New notices and warnings in WP_Date_Query

Reported by: dlh Owned by: boonebgorges
Milestone: 4.1.1 Priority: normal
Severity: normal Version: 4.1
Component: Query Keywords: has-patch fixed-major commit
Focuses: Cc:

Description

Some parameters of WP_Date_Query now generate Array to string conversion and _doing_it_wrong() notices when passed an array.

For example:

new WP_Query( array(
    'date_query' => array(
        array(
            'compare' => 'BETWEEN',
            'day' => array( 4, 7 ),
        ),
    ),
) );
new WP_Query( array(
    'date_query' => array(
        array(
            'compare' => 'BETWEEN',
            'dayofweek' => array( 2, 6 ),
        ),
    ),
) );

dayofyear, month, year, week, and hour, minute, and second also generate notices.

Passing an array to year also generates new warnings:

  • mktime() expects parameter 6 to be long, array given in /wp-includes/date.php on line 309
  • DateTime::setISODate() expects parameter 1 to be long, array given in /wp-includes/date.php on line 342

Related: #29822.

Attachments (2)

31001.diff (4.3 KB) - added by boonebgorges 5 years ago.
31001.2.patch (5.0 KB) - added by dlh 5 years ago.

Download all attachments as: .zip

Change History (11)

#1 @boonebgorges
5 years ago

  • Milestone changed from Awaiting Review to 4.1.1

Thanks for the ticket and for the research, dlh. Date validation was introduced in [29925] #25834, but it did not properly account for arrays being passed as the value of 'day', 'dayofweek', etc.

31001.diff should fix the problem. Could you give it a look?

@boonebgorges
5 years ago

#2 @boonebgorges
5 years ago

  • Keywords has-patch added

#3 @dlh
5 years ago

boonebgorges: I tested the patch against my original queries, and each query worked as expected without notices or warnings.

One minor question: If my array has two incorrect values, such as 'hour' => array( 0, 25 ), should I get two notices? Right now I get only a notice for the 0.

Thanks also for pointing me to the better source of context for this in #25834.

#4 @boonebgorges
5 years ago

dlh - Thanks for having a look. I'll make a fix to ensure that notices are thrown for all incorrect values.

#5 @boonebgorges
5 years ago

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

In 31179:

Support array values in WP_Date_Query::validate_date_values().

Introduced in [29925], validate_date_values() throws _doing_it_wrong()
notices when values passed as part of a WP_Date_Query do not reflect actual
dates. However, the validation did not account properly for the case where an
array of multiple values is passed, as when doing IN or BETWEEN queries.

Props dlh.
Fixes #31001 for trunk.

#6 @boonebgorges
5 years ago

  • Keywords fixed-major commit added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for 4.1.1 consideration.

@dlh
5 years ago

#7 @dlh
5 years ago

31001.2.patch attempts to update the documentation with the support for arrays, but I'm not sure about the best way to handle the repetition involved.

#8 @boonebgorges
5 years ago

dlh - Excellent, thanks. I've opened #31036 for the docs issue, as I'd like to keep it out of the 4.1.1 milestone.

#9 @dd32
5 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 31396:

Support array values in WP_Date_Query::validate_date_values().

Introduced in [29925], validate_date_values() throws _doing_it_wrong()
notices when values passed as part of a WP_Date_Query do not reflect actual
dates. However, the validation did not account properly for the case where an
array of multiple values is passed, as when doing IN or BETWEEN queries.

Props dlh.
Merges [31179] to the 4.1 branch.
Fixes #31001.

Note: See TracTickets for help on using tickets.