Make WordPress Core

Opened 7 years ago

Last modified 6 years ago

#39120 new enhancement

Add get/set methods to remaining main query classes (comments and terms)

Reported by: offereins's profile Offereins Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Query Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Interacting with the $query_vars property in WP_Query or WP_User_Query is handled through the get() and set() methods. It would be great if this could be a unified generic interface for WP's other main query classes, WP_Comment_Query and WP_Term_Query.

Patches attached.

Attachments (7)

39120.comment-query.patch (1.0 KB) - added by Offereins 7 years ago.
Comment Query methods
39120.term-query.patch (1.1 KB) - added by Offereins 7 years ago.
Term Query methods
39120.comment-query.2.patch (1.1 KB) - added by birgire 7 years ago.
Default as null instead of empty string for $default.
39120.comment-query-test.patch (1.1 KB) - added by birgire 7 years ago.
Added tests
39120.term-query.2.patch (1.1 KB) - added by birgire 7 years ago.
Default as null instead of empty string for $default
39120.term-query-test.patch (1.2 KB) - added by birgire 7 years ago.
Added tests
39120.diff (4.9 KB) - added by birgire 6 years ago.

Download all attachments as: .zip

Change History (9)

@Offereins
7 years ago

Comment Query methods

@Offereins
7 years ago

Term Query methods

@birgire
7 years ago

Default as null instead of empty string for $default.

@birgire
7 years ago

Added tests

@birgire
7 years ago

Default as null instead of empty string for $default

@birgire
7 years ago

Added tests

#1 @birgire
7 years ago

  • Keywords has-patch has-unit-tests added

I agree with @Offereins here, I think it's good to have a get/set methods consistency in the query classes.

Above I attached the Tests_Comment_Query::test_get_and_set() and Tests_Term_Query::test_get_and_set() tests based on the Tests_User_Query::test_get_and_set() test.

I also updated the patches, based on the WP_User_Query::get() discussion here:

https://core.trac.wordpress.org/ticket/21426

regarding the null vs empty string return value for non-existing query variables.

@birgire
6 years ago

#2 @birgire
6 years ago

The 39120.diff patch:

  • combines all the above patches + tests into a single patch.
  • removes @access public from the docBlocks.
  • Adds comments to tests.
  • Adjustments according to the Coding Standard.
Note: See TracTickets for help on using tickets.