Transitioning posts from `auto-draft` to `publish` via `wp_publish_post()` could result in published posts without the default category or custom taxonomy default terms.
Props frank-klein, TimothyBlynJacobs, peterwilsoncc.
Fixes#51292.
git-svn-id: https://develop.svn.wordpress.org/trunk@49000 602fd350-edb4-49c9-b593-d223f7449a82
Previously, the test had to use an older pattern for catching the generic `Exception` exceptions for compatibility with PHPUnit 3.6 on PHP 5.2.
Now that WordPress supports PHPUnit 5.4 as the minimum version, the `expectException()` method can be used directly.
Follow-up to [41725], [41730].
See #51344.
git-svn-id: https://develop.svn.wordpress.org/trunk@48999 602fd350-edb4-49c9-b593-d223f7449a82
The test ensures that `WP_Locale::get_weekday()` throws an "undefined offset" notice when called with an incorrect `$weekday_number` parameter.
In PHP 8, that notice is now a warning, so the test needs to be adjusted accordingly.
See #50913.
git-svn-id: https://develop.svn.wordpress.org/trunk@48993 602fd350-edb4-49c9-b593-d223f7449a82
This avoids the performance overhead of calling `WP_Comment_Query::get_comments()` twice: first when creating the object instance, then to retrieve the filtered results.
This also makes the filter a bit more consistent with other similar filters, e.g. `posts_pre_query`, `terms_pre_query`, or `users_pre_query`.
Follow-up to [46086].
Props dinhtungdu, imath, spacedmonkey, adamsilverstein, SergeyBiryukov.
Fixes#50521.
git-svn-id: https://develop.svn.wordpress.org/trunk@48990 602fd350-edb4-49c9-b593-d223f7449a82
Previously, the attribute could unintentionally be added to a tag that starts with the same characters, e.g. `<aside>` instead of `<a>`.
Props antonlukin.
Fixes#51313.
git-svn-id: https://develop.svn.wordpress.org/trunk@48983 602fd350-edb4-49c9-b593-d223f7449a82
These tests ensure that a `_doing_it_wrong()` notice is thrown when `wpdb::prepare()` is called incorrectly, but also that the function will still handle the provided input as correctly as possible.
Disabling these tests on PHP 8 hides a problem, i.e. the function will no longer throw a notice and handle things correctly, it will now cause a white screen of death due to a fatal error.
That is a backward compatibility break, and `wpdb::prepare()` should be updated instead to maintain the original behaviour on PHP 8.
Props jrf, ayeshrajans.
See #50913, #50639.
git-svn-id: https://develop.svn.wordpress.org/trunk@48979 602fd350-edb4-49c9-b593-d223f7449a82
On failure, `wpdb::prepare()` returns either an empty string or `null`, not `false`.
The test only passed accidentally due to `assertEquals()` not performing a strict type check.
Follow-up to [41662].
See #38266.
git-svn-id: https://develop.svn.wordpress.org/trunk@48974 602fd350-edb4-49c9-b593-d223f7449a82
These tests ensure that `wpdb::prepare()` throws a `_doing_it_wrong()` notice when called with an incorrect number of arguments, or with arguments of a wrong type.
PHP 8 introduces similar error messages natively, making these tests redundant on PHP 8.0 or later.
Follow-up to [41470], [41662].
See #50913.
git-svn-id: https://develop.svn.wordpress.org/trunk@48973 602fd350-edb4-49c9-b593-d223f7449a82
This avoids parse errors in PHPUnit internals due to `match` being a reserved keyword in PHP 8.
To run on PHP 8, the tests relying on these methods require PHPUnit 9.3 or later.
When the test suite is updated for compatibility with PHPUnit 9.x, these overrides can be removed.
See #50913, #50902.
git-svn-id: https://develop.svn.wordpress.org/trunk@48972 602fd350-edb4-49c9-b593-d223f7449a82
`assertNotFalse()` is available in PHPUnit since version 4.0.
The polyfill was introduced back when WordPress still supported PHP 5.2 and PHPUnit 3.6.x, and is now redundant.
Follow-up to [39919], [45058], [47880].
See #38266.
git-svn-id: https://develop.svn.wordpress.org/trunk@48953 602fd350-edb4-49c9-b593-d223f7449a82
`assertEqualsWithDelta()` was added in PHPUnit 7.5, while WordPress still supports PHPUnit 5.4.x as the minimum version.
See #38266.
git-svn-id: https://develop.svn.wordpress.org/trunk@48952 602fd350-edb4-49c9-b593-d223f7449a82
This method is useful whenever a JSON Schema needs to be converted to a format suitable for argument validation with `WP_REST_Request`. Moving the logic into a standalone function allows developers to use it outside of the `WP_REST_Controller` context.
Props pentatonicfunk.
Fixes#50876.
git-svn-id: https://develop.svn.wordpress.org/trunk@48951 602fd350-edb4-49c9-b593-d223f7449a82
It is possible to store `null` in the cache without it being converted to an empty string.
Follow-up to [20089].
Props johnbillion, SergeyBiryukov.
See #38266.
git-svn-id: https://develop.svn.wordpress.org/trunk@48949 602fd350-edb4-49c9-b593-d223f7449a82
On failure to retrieve contents, `WP_Object_Cache::get()` returns `false`, not `null`.
The test only passed accidentally due to `assertEquals()` not performing a strict type check.
Props johnbillion.
See #38266.
git-svn-id: https://develop.svn.wordpress.org/trunk@48948 602fd350-edb4-49c9-b593-d223f7449a82
#50244 aims to introduce batch processing in the REST API. An important feature is the ability to enforce that all requests have valid data before executing the route callbacks in "pre-validate" mode.
This necessitates splitting `WP_REST_Server::dispatch()` into two methods so the batch controller can determine the request handler to perform pre-validation and then respond to the requests.
The two new methods, `match_request_to_handler` and `respond_to_request`, have a public visibility, but are marked as `@access private`. This is to allow for iteration on the batch controller to happen in the Gutenberg repository. Developers should not rely upon these methods, their visibility may change in the future.
See #50244.
Props andraganescu, zieladam, TimothyBlynJacobs.
git-svn-id: https://develop.svn.wordpress.org/trunk@48947 602fd350-edb4-49c9-b593-d223f7449a82
Most request data is validated on a per-parameter basis. Often, however, additional validation is needed that operates on the entire request object. Currently, this is done in the route callback and often in the `prepare_item_for_database` method specifically.
#50244 aims to introduce batch processing in the REST API. An important feature is the ability to enforce that all requests have valid data before executing the route callbacks in "pre-validate" mode.
This patch introduces support for calling a `validate_callback` after all parameter validation has succeeded. That allows moving more validation outside of the route callback and into `WP_REST_Request` which will improve "pre-validate" support.
Props TimothyBlynJacobs, zieladam.
Fixes#51255.
See #50244.
git-svn-id: https://develop.svn.wordpress.org/trunk@48945 602fd350-edb4-49c9-b593-d223f7449a82
These were previously missed due to incorrect capitalization.
Follow-up to [48937], [48939], [48940].
See #38266.
git-svn-id: https://develop.svn.wordpress.org/trunk@48944 602fd350-edb4-49c9-b593-d223f7449a82
This better reflects the purpose of the method, which doesn't have anything to do with a comment status.
Follow-up to [48521].
Props davidbaumwald, johnbillion, SergeyBiryukov.
Fixes#51248.
git-svn-id: https://develop.svn.wordpress.org/trunk@48943 602fd350-edb4-49c9-b593-d223f7449a82
This ensures that not only the array values being compared are equal, but also that their type is the same.
These new methods replace most of the existing instances of `assertEqualSets()` and `assertEqualSetsWithIndex()`.
Going forward, stricter type checking by using `assertSameSets()` or `assertSameSetsWithIndex()` should generally be preferred, to make the tests more reliable.
Follow-up to [48937].
See #38266.
git-svn-id: https://develop.svn.wordpress.org/trunk@48939 602fd350-edb4-49c9-b593-d223f7449a82
This ensures that not only the return values match the expected results, but also that their type is the same.
Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable.
Props johnbillion, jrf, SergeyBiryukov.
See #38266.
git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
Add some new tests to better cover the functionality, for consistency with `get_the_date()` and `get_the_time()`.
Follow-up to [48911], [48912], [48918].
Props wittich.
Fixes#51184.
git-svn-id: https://develop.svn.wordpress.org/trunk@48924 602fd350-edb4-49c9-b593-d223f7449a82
Technically, the `$format` argument should always be a string, but passing `false` used to work before [47808], so this restores backward compatibility.
The list of affected functions:
* `get_the_date()`
* `get_the_time()`
* `get_comment_date()`
* `get_comment_time()`
Props wittich, Rarst, akabarikalpesh, SergeyBiryukov.
Fixes#51184.
git-svn-id: https://develop.svn.wordpress.org/trunk@48912 602fd350-edb4-49c9-b593-d223f7449a82
* Move some tests from `post.php` to a more appropriate location in the `date` directory.
* Rename `date/postTime.php` to `date/getPostTime.php` to match the function name.
Props Rarst.
See #51184.
git-svn-id: https://develop.svn.wordpress.org/trunk@48911 602fd350-edb4-49c9-b593-d223f7449a82
This ensures consistent results in query var tests, regardless of whether they are run in isolation or as part of a larger group of tests.
Props pbiron, peterwilsoncc.
Fixes#51154.
git-svn-id: https://develop.svn.wordpress.org/trunk@48908 602fd350-edb4-49c9-b593-d223f7449a82
In [48306] support for multi-typed schemas was improved to first detect the data type of the value before applying further validation. The `integer` data type was detected using the new `rest_is_integer` function. This function used logic, however, that assumed that the value had already passed an `is_numeric` check. This meant that if `integer` and `string` were both acceptable types, the value would always be considered an `integer` causing the later accurate type validation to fail.
This commit fixes the `rest_is_integer` logic to include an `is_numeric` check.
Props rtagliento.
Fixes#51146.
git-svn-id: https://develop.svn.wordpress.org/trunk@48881 602fd350-edb4-49c9-b593-d223f7449a82
Even with these values documented as an array of integers, they can technically also accept an array of strings, e.g. as form results.
Add a unit test.
Props brianhogg, TimothyBlynJacobs, SergeyBiryukov.
Fixes#51137.
git-svn-id: https://develop.svn.wordpress.org/trunk@48880 602fd350-edb4-49c9-b593-d223f7449a82
Update `redirect_canonical()` to account for custom pagination and URL format used by sitemaps in order to follow standard practices.
Introduce the function `get_sitemap_url()` to simplify getting the index and provider URLs as needed.
Props jonathanstegall, pbiron, GamerZ, salvoaranzulla, peterwilsoncc.
Fixes#50910.
git-svn-id: https://develop.svn.wordpress.org/trunk@48872 602fd350-edb4-49c9-b593-d223f7449a82
As per the documentation of the `@covers` tag, global functions being covered should be prefixed with `::`. Also, the `()` after the function name is redundant.
Follow-up to [39918].
Props jrf.
See #50267.
git-svn-id: https://develop.svn.wordpress.org/trunk@48848 602fd350-edb4-49c9-b593-d223f7449a82
This fixes random test failures when one of the term IDs from previous tests coincides with the orphan term ID from this test that should not be lazy-loaded.
Follow-up to [34529], [36566].
Fixes#51109.
git-svn-id: https://develop.svn.wordpress.org/trunk@48844 602fd350-edb4-49c9-b593-d223f7449a82
This brings `wp_count_terms()` in line with other taxonomy functions such as `get_terms()` which technically no longer require a taxonomy. Similar to the previously modified functions, no deprecation warning is triggered when using the legacy signature.
Fixes#36399.
git-svn-id: https://develop.svn.wordpress.org/trunk@48840 602fd350-edb4-49c9-b593-d223f7449a82
This addresses a regression in [47808], which caused excerpts to be generated from post content if an empty string is passed, but not for other values considered empty, e.g. `null` or `false`.
Props riaanlom, laxman-prajapati, SergeyBiryukov.
Fixes#51042.
git-svn-id: https://develop.svn.wordpress.org/trunk@48817 602fd350-edb4-49c9-b593-d223f7449a82
In PHP 8, the GD extension uses `GdImage` objects instead of resources for its underlying data structures.
This updates the existing `is_resource()` calls for image resources in core to accomodate for `GdImage` instances as well.
Props ayeshrajans, jrf.
Fixes#50833.
git-svn-id: https://develop.svn.wordpress.org/trunk@48798 602fd350-edb4-49c9-b593-d223f7449a82
Support for the `uniqueItems` keyword was added in [48357], but wasn't included in the list of permitted keywords for `WP_REST_Controller::get_endpoint_args_for_item_schema()`. This prevented the keyword from being automatically supported if specified in a controller's item schema.
Fixes#51021.
git-svn-id: https://develop.svn.wordpress.org/trunk@48796 602fd350-edb4-49c9-b593-d223f7449a82
As it already was not possible to pass the required parameters without also passing the optional one anyway, removing the default value for the (not so) optional parameters should not affect backward compatibility.
This change affects three functions in core:
* `get_comment_delimited_block_content()`
* `do_enclose()`
* `_wp_delete_tax_menu_item()`
Props jrf, ayeshrajans, desrosj.
Fixes#50343.
git-svn-id: https://develop.svn.wordpress.org/trunk@48794 602fd350-edb4-49c9-b593-d223f7449a82
This ensures that those settings don't leak to other tests.
Props david.binda, TimothyBlynJacobs, SergeyBiryukov.
Fixes#50986.
git-svn-id: https://develop.svn.wordpress.org/trunk@48791 602fd350-edb4-49c9-b593-d223f7449a82
`create_function()` has been deprecated in PHP >= 7.2 and removed in PHP 8.
The only instance left in core was used in a test that was being skipped on PHP >= 7.2. This allows the test to run again.
Follow-up to [41722], [41730].
Props jrf.
Fixes#50899.
git-svn-id: https://develop.svn.wordpress.org/trunk@48790 602fd350-edb4-49c9-b593-d223f7449a82
Declaring a `private` method as `final` is an oxymoron, as `private` methods cannot be overloaded anyway.
Using `final private function...` will generate a warning in PHP 8.
Props jrf.
Fixes#50897.
git-svn-id: https://develop.svn.wordpress.org/trunk@48788 602fd350-edb4-49c9-b593-d223f7449a82
This ensures that comment object cache is cleared after changing the comment type to `comment` instead of an empty string.
Add a unit test for `_wp_batch_update_comment_type()`.
Follow-up to [47597], [47626], [48225], [48227].
Props imath, westonruter.
Fixes#49236.
git-svn-id: https://develop.svn.wordpress.org/trunk@48748 602fd350-edb4-49c9-b593-d223f7449a82
Gutenberg no longer uses the assets field to fetch the assets for the installed block so this field can be dropped from the endpoint. This allows us to reintroduce it at a later point without needing to worry about backward compatibility.
See #50732.
git-svn-id: https://develop.svn.wordpress.org/trunk@48656 602fd350-edb4-49c9-b593-d223f7449a82
Prior to the PHPMailer update in 5.5, old version of the PHPMailer was setting the validator to 'auto' resulting in a sophisticated logic for determining what email address validation should be used. But the new version defaults to 'php', possibly leading to rejection of email addresses which were fine prior to the upgrade. Let's use the WordPress core function `is_email()` so that it can be fully pluggable.
Fixes#50720.
Props david.binda, ayeshrajans, Synchro, SergeyBiryukov, whyisjake.
git-svn-id: https://develop.svn.wordpress.org/trunk@48645 602fd350-edb4-49c9-b593-d223f7449a82
In [47559] the `WP_REST_Request::set_param()` method was adjusted to try and overwrite an existing parameter definition before forcing the value in the first parameter slot. If `set_param()` was called on a request with an `application/json` content type and an empty body, a PHP warning would be issued. This was due to the JSON parameter type not being set to an array when the body is empty.
This commit avoids the warning by adding an `is_array()` check before calling `array_key_exists`. Ideally, `WP_REST_Reuest::parse_json_params()` would set the JSON parameter type to an empty array in this case, but that is too large of a change at this point in the cycle.
Props manooweb.
Fixes#50786.
git-svn-id: https://develop.svn.wordpress.org/trunk@48642 602fd350-edb4-49c9-b593-d223f7449a82
This ensures that the correct values are being compared when retrieving the result for custom post types.
Additionally, pass the `$post_type` parameter to `get_lastpostdate` and `get_lastpostmodified` filters.
Props mikaumoto, munyagu, donmhico, johnbillion, SergeyBiryukov.
Fixes#47777.
git-svn-id: https://develop.svn.wordpress.org/trunk@48631 602fd350-edb4-49c9-b593-d223f7449a82
There are two pieces in here:
1) The update to change blacklist to blocklist is moved to disallowed_list. "Block" has a meaning in our code, and there could be ambiguity between this code and code related to blocks.
2) This improves backwards compatibility for code that was accessing the now deprecated code.
Previously: [48477], [48405], [48400], [48121], [48122], [48124], [48142], [48566]
Props: desrosj, SergeyBiryukov, johnjamesjacoby
Fixes: #50413
git-svn-id: https://develop.svn.wordpress.org/trunk@48575 602fd350-edb4-49c9-b593-d223f7449a82
With loading="lazy" being added to all images in [47554], let's ensure that it passes kses attributes too.
Fixes#50731.
Props TimothyBlynJacobs, peterwilsoncc, azaozz.
git-svn-id: https://develop.svn.wordpress.org/trunk@48572 602fd350-edb4-49c9-b593-d223f7449a82
In [47758] a new function `rest_filter_response_by_context` was introduced to expand the JSON schema features supported by the context filtering mechanism.
This commit improves the performance of that function by eliminating repetitive comparisons and loops. Additionally, it improves multi-type support for object + array types.
Fixes#50700.
Props dlh.
git-svn-id: https://develop.svn.wordpress.org/trunk@48555 602fd350-edb4-49c9-b593-d223f7449a82
Following [48536], rename the function to match the rest of the sitemaps logic.
Also eliminates some dead code after [48523].
Props pbiron.
See #50724. See #50643.
git-svn-id: https://develop.svn.wordpress.org/trunk@48540 602fd350-edb4-49c9-b593-d223f7449a82
Before this change, the limit of 50k entries was enforced for the number of providers, not the amount of sitemaps all providers add to the index in total.
Props pbiron, swissspidy.
Fixes#50666.
git-svn-id: https://develop.svn.wordpress.org/trunk@48532 602fd350-edb4-49c9-b593-d223f7449a82
The REST API treats routes without a permission_callback as public. Because this happens without any warning to the user, if the permission callback is unintentionally omitted or misspelled, the endpoint can end up being available to the public. Such a scenario has happened multiple times in the wild, and the results can be catostrophic when it occurs.
For REST API routes that are intended to be public, it is recommended to set the permission callback to the `__return_true` built in function.
Fixes#50075.
Props rmccue, sorenbronsted, whyisjake, SergeyBiryukov, TimothyBlynJacobs.
git-svn-id: https://develop.svn.wordpress.org/trunk@48526 602fd350-edb4-49c9-b593-d223f7449a82
The REST API plugin installation tests use the `upgrader_pre_download` filter to avoid downloading the test plugin from WordPress.org. Previously, this would apply to any upgrader, which caused issues if the testing environment required a language update.
Now, the filter only overwrites the file if the `Plugin_Upgrader` is being used which should hopefully prevent the issue.
Props pfefferle, TimothyBlynJacobs.
Fixes#50671.
git-svn-id: https://develop.svn.wordpress.org/trunk@48524 602fd350-edb4-49c9-b593-d223f7449a82
If sitemaps are disabled, previously there would be a rewrite rule for the sitemap endpoint. This endpoint would display the homepage since there was a rewrite rule. Now, Sitemaps are loaded, and the proper HTTP headers are returned.
Fixes#50643.
Props swissspidy, kraftbj, donmhico.
git-svn-id: https://develop.svn.wordpress.org/trunk@48523 602fd350-edb4-49c9-b593-d223f7449a82
It doesn't make sense to be able to filter the comments list table when there are are no (trashed/spam) comments available.
Fixes#40188.
Props swissspidy, Jim_Panse, menakas, akbarhusen429, dinhtungdu, birgire, SergeyBiryukov, davidbaumwald, rebasaurus, whyisjake.
git-svn-id: https://develop.svn.wordpress.org/trunk@48521 602fd350-edb4-49c9-b593-d223f7449a82
The order of parameters in `get_metadata_default()` did not match the signature of `get_metadata()`. This could be confusing for developers who are familiar with the existing metadata API.
Fixes#43941.
Props SergeyBiryukov, spacedmonkey, johnjamesjacoby.
git-svn-id: https://develop.svn.wordpress.org/trunk@48502 602fd350-edb4-49c9-b593-d223f7449a82
When `wp_count_posts()` is cached, it does so with all statuses defaulted to 0. The problem is however, if this is called before all plugins have registered their desired statuses, they won't have that default.
Fixes#49685.
Props obliviousharmony, SergeyBiryukov.
git-svn-id: https://develop.svn.wordpress.org/trunk@48497 602fd350-edb4-49c9-b593-d223f7449a82
Adjusts the gallery shortcode handler to check for the `link` attribute when outputting to a feed.
Fixes#22101.
Props ifrins, mdgl, SergeyBiryukov, chriscct7, stevenkword, iworks, DrewAPicture, birgire, whyisjake.
git-svn-id: https://develop.svn.wordpress.org/trunk@48496 602fd350-edb4-49c9-b593-d223f7449a82
* Move default term assignment from `wp_set_object_terms()` to `wp_insert_post()`.
* Make sure the passed taxonomy list overwrites the existing list if not empty.
* Remove the default term option on `unregister_taxonomy()`.
* Prevent deletion of the default term in `wp_delete_term()`.
Props enrico.sorcinelli, TimothyBlynJacobs.
See #43517.
git-svn-id: https://develop.svn.wordpress.org/trunk@48480 602fd350-edb4-49c9-b593-d223f7449a82
If there are no pages and no static homepage, there will still be one sitemap including the homepage URL.
This change ensures that this sitemap is correctly listed in the sitemap index.
Props Chouby, pacifika, elrae.
Fixes#50571.
git-svn-id: https://develop.svn.wordpress.org/trunk@48476 602fd350-edb4-49c9-b593-d223f7449a82
Unix vs. Windows EOL style mismatches can cause misleading failures in tests using the heredoc syntax (`<<<`) or multiline strings as the expected result.
Follow-up to [46612], [48443].
See #31432.
git-svn-id: https://develop.svn.wordpress.org/trunk@48466 602fd350-edb4-49c9-b593-d223f7449a82