Commit Graph

125 Commits

Author SHA1 Message Date
Sergey Biryukov
cc6dcc2623 Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wp-query.php.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.

This commit:
* Renames the `$array` parameter to `$query_vars` in `WP_Query::fill_query_vars()`.
* Renames the `$default` parameter to `$default_value` in `WP_Query::get()`.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53277


git-svn-id: http://core.svn.wordpress.org/trunk@52866 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-26 13:32:11 +00:00
Sergey Biryukov
ed4829b0ee Query: Restore late compact() call for SQL clauses in wp-includes/class-wp-*-query.php.
This addresses a backward compatibility break where `posts_groupby` and other filters were applied, but their results were subsequently discarded and earlier values were used instead.

Follow-up to [52974].

Props nextend_ramona.
See #54728, #meta6273.
Built from https://develop.svn.wordpress.org/trunk@53175


git-svn-id: http://core.svn.wordpress.org/trunk@52764 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-14 00:04:11 +00:00
Peter Wilson
4127a17a0a Query: Cache comments feeds in WP_Query.
Cache queries to the comments table in `WP_Query` for various comments feeds. Only comment IDs are stored for each feeds cache to avoid doubling up caching with each individual comment's cache.

Props spacedmonkey, boonebgorges, pbearne.
Fixes #36904.


Built from https://develop.svn.wordpress.org/trunk@53065


git-svn-id: http://core.svn.wordpress.org/trunk@52654 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-05 01:55:03 +00:00
spacedmonkey
ff1e74602d Query: Ensure that sticky post query returns all sticky posts.
Ensure that the `posts_per_page` parameter submit to sticky post query matches the number of sticky posts requested. 

Follow-up to [52982]

Props Spacedmonkey, peterwilsoncc.
See #36907.


Built from https://develop.svn.wordpress.org/trunk@52990


git-svn-id: http://core.svn.wordpress.org/trunk@52579 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-25 09:56:05 +00:00
Sergey Biryukov
4499c7a17f Tests: Use a more descriptive name for the sticky posts test that verifies the parameters from the main query.
Reorder the parameters of the `get_posts()` call for consistency with similar calls elsewhere.

Follow-up to [52982].

See #36907.
Built from https://develop.svn.wordpress.org/trunk@52985


git-svn-id: http://core.svn.wordpress.org/trunk@52574 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-23 16:28:06 +00:00
spacedmonkey
e8bf92cf76 Query: Improved sticky post query
Ensure that the parameters `update_post_meta_cache`, `update_post_term_cache`, `cache_results`, `suppress_filters` and 
`lazy_load_term_meta` that are passed to WP_Query, are also passed down to the secondary query used to get sticky 
posts. 

Props Spacedmonkey, peterwilsoncc, rehanali, uday17035. 
Fixes #36907.


Built from https://develop.svn.wordpress.org/trunk@52982


git-svn-id: http://core.svn.wordpress.org/trunk@52571 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-23 10:39:06 +00:00
Sergey Biryukov
6f5f187574 Coding Standards: Use multi-line strings for the $this->request property in wp-includes/class-wp-*-query.php.
This further improves the readability by replacing `implode()` calls with string interpolation.

Follow-up to [52973].

Props jrf.
See #54728.
Built from https://develop.svn.wordpress.org/trunk@52977


git-svn-id: http://core.svn.wordpress.org/trunk@52566 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-22 14:56:05 +00:00
Sergey Biryukov
41de51364a Coding Standards: Remove a one-time $pieces variable in wp-includes/class-wp-*-query.php.
Use the existing `$clauses` variable instead for consistency.

See #54728.
Built from https://develop.svn.wordpress.org/trunk@52974


git-svn-id: http://core.svn.wordpress.org/trunk@52563 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-21 12:22:01 +00:00
Sergey Biryukov
38dbd506e7 Coding Standards: Wrap the $this->request property in wp-includes/class-wp-*-query.php.
This aims to improve readability by fitting the values on a single screen to avoid horizontal scrolling. 

See #54728.
Built from https://develop.svn.wordpress.org/trunk@52973


git-svn-id: http://core.svn.wordpress.org/trunk@52562 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-21 12:05:04 +00:00
Sergey Biryukov
4ae0744585 Query: Make sure WP_Query::get_queried_object() works for author_name before ::get_posts() is run.
Previously, the queried object with author data was not available before the posts loop when `author_name` is used in the query instead of `author`. With block themes, this use case appears to be more common to display the author name in the header.

This commit adjusts the logic in `WP_Query::get_queried_object()` to fall back to the `author_name` field if `author` is not present, similar to how taxonomy slugs are handled.

Follow-up to [1728], [3290], [10992].

Props dd32, swissspidy, SergeyBiryukov.
Fixes #55100.
Built from https://develop.svn.wordpress.org/trunk@52822


git-svn-id: http://core.svn.wordpress.org/trunk@52411 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-05 15:35:04 +00:00
John Blackbourn
39bff93b6b Docs: Various inline documentation corrections and improvements.
See #53399

Built from https://develop.svn.wordpress.org/trunk@52332


git-svn-id: http://core.svn.wordpress.org/trunk@51924 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-07 12:20:02 +00:00
John Blackbourn
9a982b4ae8 Docs: Various docblock corrections.
See #53399

Built from https://develop.svn.wordpress.org/trunk@52299


git-svn-id: http://core.svn.wordpress.org/trunk@51891 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-01 12:17:00 +00:00
John Blackbourn
fa62df0774 Query: Correct and standardise the meta query documentation.
Also improves the formatting of some surrounding documentation.

Props audrasjb, johnbillion

Fixes #53467

Built from https://develop.svn.wordpress.org/trunk@52226


git-svn-id: http://core.svn.wordpress.org/trunk@51818 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-20 00:07:59 +00:00
John Blackbourn
41995176f6 Docs: Miscellaneous inline documentation improvements, including:
* Document the post statuses global as an array of `stdClass` objects
* Document the taxonomies global as an array of `WP_Taxonomy` objects
* Document the return value of the post count functions as `stdClass` objects
* Fix some typos

See #53399

Built from https://develop.svn.wordpress.org/trunk@51885


git-svn-id: http://core.svn.wordpress.org/trunk@51478 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-10-04 20:44:02 +00:00
John Blackbourn
a4bdae8122 Docs: Add missing documentation for the minute parameter of WP_Query.
See #53399

Built from https://develop.svn.wordpress.org/trunk@51514


git-svn-id: http://core.svn.wordpress.org/trunk@51125 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-30 10:53:58 +00:00
John Blackbourn
ab9ed33f1d Docs: Correct the documented allowed range for the minute and second parameters of WP_Query.
These are correctly documented and validated in `WP_Date_Query` as 0-59.

See #53399

Built from https://develop.svn.wordpress.org/trunk@51513


git-svn-id: http://core.svn.wordpress.org/trunk@51124 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-30 10:23:57 +00:00
John Blackbourn
e4cfebe92e Docs: Undo the accidental revert of [51299] made in [51300].
See #53399

Built from https://develop.svn.wordpress.org/trunk@51301


git-svn-id: http://core.svn.wordpress.org/trunk@50910 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-01 21:29:56 +00:00
John Blackbourn
ea60cd8191 Docs: Descriptive improvements and corrections for various docblocks.
See #53399

Built from https://develop.svn.wordpress.org/trunk@51300


git-svn-id: http://core.svn.wordpress.org/trunk@50909 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-01 21:12:58 +00:00
John Blackbourn
9146628ae1 Docs: Miscellaneous formatting corrections for docblocks.
See #53399

Built from https://develop.svn.wordpress.org/trunk@51299


git-svn-id: http://core.svn.wordpress.org/trunk@50908 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-07-01 21:10:56 +00:00
Sergey Biryukov
e7b6a4dce8 Coding Standards: Remove redundant type casting to array in WP_Query::get_posts().
This brings some consistency with other instances of using `get_post_stati()` in core.

`get_post_stati()` always returns an array, so the type casting is not needed.

Follow-up to [13172].

See #53359.
Built from https://develop.svn.wordpress.org/trunk@51285


git-svn-id: http://core.svn.wordpress.org/trunk@50894 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-30 17:44:58 +00:00
Peter Wilson
4c598d36b1 Query: Check each post-type's capabilities when querying multiple post-types.
When querying multiple post types, check the `read_private_posts` capability for each post type when determining which post statuses to return. This ensures private posts appear in search results and archives for users permitted to read them.

Props leogermani, hellofromTonya, jeffpaul, peterwilsoncc.
Fixes #48556.


Built from https://develop.svn.wordpress.org/trunk@51276


git-svn-id: http://core.svn.wordpress.org/trunk@50885 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-06-30 05:00:56 +00:00
Sergey Biryukov
d6cc4f1aec Query: Consistently include a space in parentheses in WP_Meta_Query::get_sql_for_clause().
Props jillebehm, kaavyaiyer, hareesh-pillai.
Fixes #49279.
Built from https://develop.svn.wordpress.org/trunk@50576


git-svn-id: http://core.svn.wordpress.org/trunk@50189 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-03-25 12:39:07 +00:00
Sergey Biryukov
d5a6a1ab44 Taxonomy: Use a consistent check for the $rewrite['hierarchical'] parameter.
This avoids a "Trying to access array offset on value of type bool" PHP warning in `get_term_link()` if the `$rewrite` parameter of `register_taxonomy()` is set as `false`.

Props Tkama, SergeyBiryukov.
Fixes #52882.
Built from https://develop.svn.wordpress.org/trunk@50565


git-svn-id: http://core.svn.wordpress.org/trunk@50178 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-03-23 13:55:03 +00:00
John Blackbourn
6f3a940e64 Plugins: Replace usage of $this in action and filter parameter docblocks with more appropriate variable names.
See #51800, #52217

Fixes #52243

Built from https://develop.svn.wordpress.org/trunk@49946


git-svn-id: http://core.svn.wordpress.org/trunk@49645 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-01-08 14:30:14 +00:00
John Blackbourn
dfe1f9b322 Docs: Promote many bool types to true or false where only that value is used.
See #51800

Built from https://develop.svn.wordpress.org/trunk@49927


git-svn-id: http://core.svn.wordpress.org/trunk@49626 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-01-03 22:04:04 +00:00
Peter Wilson
aaf7710529 Query: Revert post-type specific capability changes.
The modified checks of the `read_private_posts` capability could result in unexpected SQL queries when calling `WP_Query` with invalid parameters.

Reverts [49830], [49832] and [49833].
See #48556.

Built from https://develop.svn.wordpress.org/trunk@49899


git-svn-id: http://core.svn.wordpress.org/trunk@49598 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-12-23 03:02:06 +00:00
Peter Wilson
08acf6606a Coding Standards: Minor fixes following [49830].
See #13509, #48968, #48556.

Built from https://develop.svn.wordpress.org/trunk@49832


git-svn-id: http://core.svn.wordpress.org/trunk@49551 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-12-18 00:19:05 +00:00
Boone Gorges
f124a2e529 Query: Respect post-type specific capabilities when querying for multiple post types.
After this change, the relevant `read_private_posts` capability is checked for
each queried post type. This ensures that private posts appear in search and
archive queries for users who have the ability to view those posts.

Props leogermani.

Fixes #13509, #48968, #48556.
Built from https://develop.svn.wordpress.org/trunk@49830


git-svn-id: http://core.svn.wordpress.org/trunk@49549 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-12-17 16:17:07 +00:00
Sergey Biryukov
43bbbf1176 Docs: Document the usage of $wpdb global in WP_Query::get_posts() and ::set_found_posts().
Props jontyravi.
Fixes #52027.
Built from https://develop.svn.wordpress.org/trunk@49792


git-svn-id: http://core.svn.wordpress.org/trunk@49515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-12-11 16:53:10 +00:00
John Blackbourn
42fcfa5b3d Docs: Various docblock corrections.
See #51800

Built from https://develop.svn.wordpress.org/trunk@49789


git-svn-id: http://core.svn.wordpress.org/trunk@49512 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-12-10 23:53:07 +00:00
John Blackbourn
40b738335b Docs: Corrections and improvements to docs for properties of the WP_Query class.
This also adds additional type hinting inside some methods to help IDEs.

See #51800

Built from https://develop.svn.wordpress.org/trunk@49700


git-svn-id: http://core.svn.wordpress.org/trunk@49423 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-26 17:04:06 +00:00
John Blackbourn
f4cda1b62f Docs: Upgrade more parameters in docblocks to used typed array notation.
See #51800, #41756

Built from https://develop.svn.wordpress.org/trunk@49693


git-svn-id: http://core.svn.wordpress.org/trunk@49416 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-24 21:27:05 +00:00
John Blackbourn
35f6c356c1 Docs: Document parameters that accept an array of integers using typed array notation.
While many of these parameters also technically accept an array of numerical strings, they are all ultimately cast to an array of integers. Documenting them as such assists developers in understanding the expected types.

See #51800, #41756

Built from https://develop.svn.wordpress.org/trunk@49672


git-svn-id: http://core.svn.wordpress.org/trunk@49395 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-19 18:24:09 +00:00
Sergey Biryukov
ee7ff18b54 Docs: Improve documentation for WP_Query::is_archive() per the documentation standards.
Follow-up to [49504].

See #50545.
Built from https://develop.svn.wordpress.org/trunk@49506


git-svn-id: http://core.svn.wordpress.org/trunk@49261 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-05 09:44:05 +00:00
Sergey Biryukov
f22633f20b Docs: Consistently place @see tags after @since in WP_Query methods, per the documentation standards.
See #50768.
Built from https://develop.svn.wordpress.org/trunk@49505


git-svn-id: http://core.svn.wordpress.org/trunk@49260 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-05 09:42:10 +00:00
Helen Hou-Sandí
cc74786052 General: Make some inline comments more descriptive.
Props jorbin.
Fixes #51683.

Built from https://develop.svn.wordpress.org/trunk@49474


git-svn-id: http://core.svn.wordpress.org/trunk@49233 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-11-02 18:04:07 +00:00
Sergey Biryukov
0e3147c40e Coding Standards: Replace alias PHP functions with the canonical names.
Using the canonical function name for PHP functions is strongly recommended, as aliases may be deprecated or removed without (much) warning.

This replaces all uses of the following:
* `join()` with `implode()`
* `sizeof()` with `count()`
* `is_writeable()` with `is_writable()`
* `doubleval()` with a `(float)` cast

In part, this is a follow-up to #47746.

Props jrf.
See #50767.
Built from https://develop.svn.wordpress.org/trunk@49193


git-svn-id: http://core.svn.wordpress.org/trunk@48955 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-10-18 17:27:06 +00:00
John Blackbourn
6b7ba33d68 Docs: Fix the types for some properties and parameters that use the generic object type.
See #50768

Built from https://develop.svn.wordpress.org/trunk@49119


git-svn-id: http://core.svn.wordpress.org/trunk@48881 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-10-10 19:14:04 +00:00
Sergey Biryukov
897f004a9c General: Replace older-style PHP type conversion functions with type casts.
This improves performance, readability, and consistency throughout core.

* `intval()` → `(int)`
* `strval()` → `(string)`
* `floatval()` → `(float)`

Props ayeshrajans.
Fixes #42918.
Built from https://develop.svn.wordpress.org/trunk@49108


git-svn-id: http://core.svn.wordpress.org/trunk@48870 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-10-08 21:15:13 +00:00
Sergey Biryukov
2670a6ad14 Docs: Synchronize descriptions of some query functions and their counterpart methods in WP and WP_Query classes:
* `set_query_var()`
* `get_query_var()`
* `get_queried_object()`
* `get_queried_object_id()`

Switch to third-person singular verbs, per the documentation standards.

See #50768, #42783.
Built from https://develop.svn.wordpress.org/trunk@49095


git-svn-id: http://core.svn.wordpress.org/trunk@48857 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-10-06 08:59:04 +00:00
Sergey Biryukov
b66ff2f68d Docs: Fix typo in *_pre_query filter DocBlocks.
See #50768.
Built from https://develop.svn.wordpress.org/trunk@48985


git-svn-id: http://core.svn.wordpress.org/trunk@48747 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-09-17 10:45:03 +00:00
Sergey Biryukov
7c60a660f1 Code Modernization: Correct the check for negative post IDs in WP_Query::parse_query() to work as expected on PHP 8.
PHP 8 changes the way string to number comparisons are performed: https://wiki.php.net/rfc/string_to_number_comparison

In particular, checking if an empty string is less than zero in PHP 8 evaluates to `true`, not `false`.

For `WP_Query`, this resulted in unintentionally returning a 404 error for most of front-end requests, instead of the relevant content.

By explicitly casting the value to `int`, we make sure to compare both values as numbers, rather than a string and a number.

Follow-up to [38288].

Props trepmal.
See #50913.
Built from https://develop.svn.wordpress.org/trunk@48960


git-svn-id: http://core.svn.wordpress.org/trunk@48722 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-09-09 02:35:06 +00:00
Sergey Biryukov
7a8df073cd Docs: Correct alignment for some DocBlocks in WP_Query::get_posts().
See #50768.
Built from https://develop.svn.wordpress.org/trunk@48816


git-svn-id: http://core.svn.wordpress.org/trunk@48578 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-08-18 12:39:03 +00:00
John Blackbourn
57a3f803ae Docs: First pass at some inline docs fixes mostly made by PHPCBF.
See #49572, #50744
Built from https://develop.svn.wordpress.org/trunk@48586


git-svn-id: http://core.svn.wordpress.org/trunk@48348 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-23 20:01:04 +00:00
John Blackbourn
124972f2c6 Docs: Further corrections and improvements to various inline docblocks.
See #49572
Built from https://develop.svn.wordpress.org/trunk@48576


git-svn-id: http://core.svn.wordpress.org/trunk@48338 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-23 07:39:02 +00:00
Sergey Biryukov
da43de528f Docs: Correct type and improve description for the $fields parameter of WP_Query::parse_query().
Props ocean90, palmiak, johannadevos, noisysocks.
Fixes #44305.
Built from https://develop.svn.wordpress.org/trunk@48563


git-svn-id: http://core.svn.wordpress.org/trunk@48325 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-22 11:37:02 +00:00
John Blackbourn
6b21db7fb9 Docs: Miscellaneous docblock corrections and improvements.
See #49572
Built from https://develop.svn.wordpress.org/trunk@48462


git-svn-id: http://core.svn.wordpress.org/trunk@48231 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-13 22:10:07 +00:00
Sergey Biryukov
8ef38d34fc Docs: Improve @return tags for various conditional tags.
Props stevenlinx, SergeyBiryukov.
Fixes #50626.
Built from https://develop.svn.wordpress.org/trunk@48426


git-svn-id: http://core.svn.wordpress.org/trunk@48195 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-10 20:23:06 +00:00
Sergey Biryukov
3311bc8783 Docs: Improve documentation for have_posts(), have_comments(), and their WP_Query counterparts.
Props stevenlinx.
Fixes #50610.
Built from https://develop.svn.wordpress.org/trunk@48406


git-svn-id: http://core.svn.wordpress.org/trunk@48175 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-08 11:11:04 +00:00
Sergey Biryukov
4e3bad1770 Query: Make sure the found_posts property of WP_Query is always an integer, to match the documented type.
This makes the property consistent with similar properties of other classes:
* `WP_Comment_Query::$found_comments`
* `WP_Network_Query::$found_networks`
* `WP_Site_Query::$found_sites`
* `WP_User_Query::$total_users`

Props birgire, PressLabs.
Fixes #42469.
Built from https://develop.svn.wordpress.org/trunk@48328


git-svn-id: http://core.svn.wordpress.org/trunk@48097 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-05 21:34:02 +00:00