Commit Graph

126 Commits

Author SHA1 Message Date
Sergey Biryukov
90f953603b Query: Restore late compact() call for the posts_clauses_request filter.
This addresses a backward compatibility break where `posts_join_request` and other filters were applied, but their results were subsequently discarded and earlier values were used instead.

Follow-up to [52974], [53175].

Props 5um17, johnbillion, SergeyBiryukov.
Fixes #55699.

git-svn-id: https://develop.svn.wordpress.org/trunk@53370 602fd350-edb4-49c9-b593-d223f7449a82
2022-05-09 13:49:29 +00:00
Sergey Biryukov
c43014f87f 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@53277 602fd350-edb4-49c9-b593-d223f7449a82
2022-04-26 13:30:47 +00:00
Sergey Biryukov
9c208b19c9 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@53175 602fd350-edb4-49c9-b593-d223f7449a82
2022-04-14 00:02:31 +00:00
Peter Wilson
5ac4ec3208 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.



git-svn-id: https://develop.svn.wordpress.org/trunk@53065 602fd350-edb4-49c9-b593-d223f7449a82
2022-04-05 01:53:59 +00:00
Jonny Harris
1792018b4b 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.



git-svn-id: https://develop.svn.wordpress.org/trunk@52990 602fd350-edb4-49c9-b593-d223f7449a82
2022-03-25 09:54:52 +00:00
SergeyBiryukov
55c399ff04 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@52985 602fd350-edb4-49c9-b593-d223f7449a82
2022-03-23 16:26:01 +00:00
Jonny Harris
b3d6638139 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.



git-svn-id: https://develop.svn.wordpress.org/trunk@52982 602fd350-edb4-49c9-b593-d223f7449a82
2022-03-23 10:37:11 +00:00
Sergey Biryukov
f1d94b9085 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@52977 602fd350-edb4-49c9-b593-d223f7449a82
2022-03-22 14:54:45 +00:00
Sergey Biryukov
8182e92220 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@52974 602fd350-edb4-49c9-b593-d223f7449a82
2022-03-21 12:20:22 +00:00
Sergey Biryukov
fbf8cb73ec 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@52973 602fd350-edb4-49c9-b593-d223f7449a82
2022-03-21 12:03:29 +00:00
Sergey Biryukov
f0fdad1c8e 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@52822 602fd350-edb4-49c9-b593-d223f7449a82
2022-03-05 15:33:05 +00:00
John Blackbourn
ba518c2d86 Docs: Various inline documentation corrections and improvements.
See #53399


git-svn-id: https://develop.svn.wordpress.org/trunk@52332 602fd350-edb4-49c9-b593-d223f7449a82
2021-12-07 12:18:50 +00:00
John Blackbourn
08efcf0cb8 Docs: Various docblock corrections.
See #53399


git-svn-id: https://develop.svn.wordpress.org/trunk@52299 602fd350-edb4-49c9-b593-d223f7449a82
2021-12-01 12:15:21 +00:00
John Blackbourn
83e5057151 Query: Correct and standardise the meta query documentation.
Also improves the formatting of some surrounding documentation.

Props audrasjb, johnbillion

Fixes #53467


git-svn-id: https://develop.svn.wordpress.org/trunk@52226 602fd350-edb4-49c9-b593-d223f7449a82
2021-11-20 00:06:06 +00:00
John Blackbourn
4bf908449a 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


git-svn-id: https://develop.svn.wordpress.org/trunk@51885 602fd350-edb4-49c9-b593-d223f7449a82
2021-10-04 20:42:54 +00:00
John Blackbourn
108d4d1ae5 Docs: Add missing documentation for the minute parameter of WP_Query.
See #53399


git-svn-id: https://develop.svn.wordpress.org/trunk@51514 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-30 10:52:39 +00:00
John Blackbourn
ccbfd22833 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


git-svn-id: https://develop.svn.wordpress.org/trunk@51513 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-30 10:22:11 +00:00
John Blackbourn
4aed272097 Docs: Undo the accidental revert of [51299] made in [51300].
See #53399


git-svn-id: https://develop.svn.wordpress.org/trunk@51301 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-01 21:28:38 +00:00
John Blackbourn
d059b898fe Docs: Descriptive improvements and corrections for various docblocks.
See #53399


git-svn-id: https://develop.svn.wordpress.org/trunk@51300 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-01 21:11:48 +00:00
John Blackbourn
5dd7fde41d Docs: Miscellaneous formatting corrections for docblocks.
See #53399


git-svn-id: https://develop.svn.wordpress.org/trunk@51299 602fd350-edb4-49c9-b593-d223f7449a82
2021-07-01 21:09:04 +00:00
Sergey Biryukov
f6f73c48ee 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@51285 602fd350-edb4-49c9-b593-d223f7449a82
2021-06-30 17:43:29 +00:00
Peter Wilson
212c928038 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.



git-svn-id: https://develop.svn.wordpress.org/trunk@51276 602fd350-edb4-49c9-b593-d223f7449a82
2021-06-30 04:59:10 +00:00
Sergey Biryukov
146ad7b142 Query: Consistently include a space in parentheses in WP_Meta_Query::get_sql_for_clause().
Props jillebehm, kaavyaiyer, hareesh-pillai.
Fixes #49279.

git-svn-id: https://develop.svn.wordpress.org/trunk@50576 602fd350-edb4-49c9-b593-d223f7449a82
2021-03-25 12:37:49 +00:00
Sergey Biryukov
accdb47ffb 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@50565 602fd350-edb4-49c9-b593-d223f7449a82
2021-03-23 13:53:50 +00:00
John Blackbourn
31476dc27c Plugins: Replace usage of $this in action and filter parameter docblocks with more appropriate variable names.
See #51800, #52217

Fixes #52243


git-svn-id: https://develop.svn.wordpress.org/trunk@49946 602fd350-edb4-49c9-b593-d223f7449a82
2021-01-08 14:28:46 +00:00
John Blackbourn
679ccc35e6 Docs: Promote many bool types to true or false where only that value is used.
See #51800


git-svn-id: https://develop.svn.wordpress.org/trunk@49927 602fd350-edb4-49c9-b593-d223f7449a82
2021-01-03 22:02:13 +00:00
Peter Wilson
254131d009 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.


git-svn-id: https://develop.svn.wordpress.org/trunk@49899 602fd350-edb4-49c9-b593-d223f7449a82
2020-12-23 03:01:00 +00:00
Peter Wilson
1930427d30 Coding Standards: Minor fixes following [49830].
See #13509, #48968, #48556.


git-svn-id: https://develop.svn.wordpress.org/trunk@49832 602fd350-edb4-49c9-b593-d223f7449a82
2020-12-18 00:17:32 +00:00
Boone Gorges
f7ced48ad8 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@49830 602fd350-edb4-49c9-b593-d223f7449a82
2020-12-17 16:15:38 +00:00
Sergey Biryukov
c167a9425c Docs: Document the usage of $wpdb global in WP_Query::get_posts() and ::set_found_posts().
Props jontyravi.
Fixes #52027.

git-svn-id: https://develop.svn.wordpress.org/trunk@49792 602fd350-edb4-49c9-b593-d223f7449a82
2020-12-11 16:51:15 +00:00
John Blackbourn
81b89682c3 Docs: Various docblock corrections.
See #51800


git-svn-id: https://develop.svn.wordpress.org/trunk@49789 602fd350-edb4-49c9-b593-d223f7449a82
2020-12-10 23:51:52 +00:00
johnbillion
850e31dc58 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


git-svn-id: https://develop.svn.wordpress.org/trunk@49700 602fd350-edb4-49c9-b593-d223f7449a82
2020-11-26 17:02:02 +00:00
John Blackbourn
c8f7440c6a Docs: Upgrade more parameters in docblocks to used typed array notation.
See #51800, #41756


git-svn-id: https://develop.svn.wordpress.org/trunk@49693 602fd350-edb4-49c9-b593-d223f7449a82
2020-11-24 21:25:46 +00:00
John Blackbourn
a47e8924b0 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


git-svn-id: https://develop.svn.wordpress.org/trunk@49672 602fd350-edb4-49c9-b593-d223f7449a82
2020-11-19 18:22:02 +00:00
Sergey Biryukov
33111495b2 Docs: Improve documentation for WP_Query::is_archive() per the documentation standards.
Follow-up to [49504].

See #50545.

git-svn-id: https://develop.svn.wordpress.org/trunk@49506 602fd350-edb4-49c9-b593-d223f7449a82
2020-11-05 09:42:49 +00:00
Sergey Biryukov
e38410c2fd Docs: Consistently place @see tags after @since in WP_Query methods, per the documentation standards.
See #50768.

git-svn-id: https://develop.svn.wordpress.org/trunk@49505 602fd350-edb4-49c9-b593-d223f7449a82
2020-11-05 09:40:38 +00:00
Helen Hou-Sandi
4985f741d3 General: Make some inline comments more descriptive.
Props jorbin.
Fixes #51683.


git-svn-id: https://develop.svn.wordpress.org/trunk@49474 602fd350-edb4-49c9-b593-d223f7449a82
2020-11-02 18:02:11 +00:00
Sergey Biryukov
97b2f07d2e 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@49193 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-18 17:25:10 +00:00
John Blackbourn
6917c731f8 Docs: Fix the types for some properties and parameters that use the generic object type.
See #50768


git-svn-id: https://develop.svn.wordpress.org/trunk@49119 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-10 19:12:04 +00:00
Sergey Biryukov
79703088c4 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@49108 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-08 21:13:57 +00:00
Sergey Biryukov
3ebeaffe80 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@49095 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-06 08:57:38 +00:00
Sergey Biryukov
8621e8d5c8 Docs: Fix typo in *_pre_query filter DocBlocks.
See #50768.

git-svn-id: https://develop.svn.wordpress.org/trunk@48985 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-17 10:43:23 +00:00
Sergey Biryukov
f6f117a0a9 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@48960 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-09 02:33:22 +00:00
Sergey Biryukov
1911eae4a1 Docs: Correct alignment for some DocBlocks in WP_Query::get_posts().
See #50768.

git-svn-id: https://develop.svn.wordpress.org/trunk@48816 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-18 12:37:39 +00:00
John Blackbourn
285fa03b3a Docs: First pass at some inline docs fixes mostly made by PHPCBF.
See #49572, #50744

git-svn-id: https://develop.svn.wordpress.org/trunk@48586 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-23 19:59:16 +00:00
John Blackbourn
7d4c77560c Docs: Further corrections and improvements to various inline docblocks.
See #49572

git-svn-id: https://develop.svn.wordpress.org/trunk@48576 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-23 07:37:57 +00:00
Sergey Biryukov
d6c7a479f4 Docs: Correct type and improve description for the $fields parameter of WP_Query::parse_query().
Props ocean90, palmiak, johannadevos, noisysocks.
Fixes #44305.

git-svn-id: https://develop.svn.wordpress.org/trunk@48563 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-22 11:34:32 +00:00
John Blackbourn
f36c42c700 Docs: Miscellaneous docblock corrections and improvements.
See #49572

git-svn-id: https://develop.svn.wordpress.org/trunk@48462 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-13 22:08:16 +00:00
Sergey Biryukov
72d5862069 Docs: Improve @return tags for various conditional tags.
Props stevenlinx, SergeyBiryukov.
Fixes #50626.

git-svn-id: https://develop.svn.wordpress.org/trunk@48426 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-10 20:21:01 +00:00
Sergey Biryukov
3dc074ed1d Docs: Improve documentation for have_posts(), have_comments(), and their WP_Query counterparts.
Props stevenlinx.
Fixes #50610.

git-svn-id: https://develop.svn.wordpress.org/trunk@48406 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-08 11:09:08 +00:00