As of WordPress 4.5, taxonomies should be passed to `get_terms()` via the `taxonomy` argument in the `$args` array:
{{{
$terms = get_terms( array(
'taxonomy' => 'post_tag',
'hide_empty' => false,
) );
}}}
The legacy way of passing a taxonomy via the function's first parameter was still mentioned in the documentation, causing some confusion.
This commit updates the function documentation to better highlight the currently recommended approach.
Follow-up to [36614].
Props ramon-fincken, sabernhardt, SergeyBiryukov.
Fixes#57380.
Built from https://develop.svn.wordpress.org/trunk@55018
git-svn-id: http://core.svn.wordpress.org/trunk@54551 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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 `$object` parameter to `$object_type` in `get_object_taxonomies()`.
* Renames the `$parent` parameter to `$parent_term` in:
* `term_exists()`
* `wp_check_term_hierarchy_for_loops()`
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], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947], [54948], [54950], [54951], [54952], [54956], [54959], [54960], [54961], [54962], [54964], [54965], [54969], [54970], [54971], [54972], [54996], [55000].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@55011
git-svn-id: http://core.svn.wordpress.org/trunk@54544 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Includes minor formatting edits for consistency.
Follow-up to [53/tests], [12179], [12946], [35288], [37884], [38810], [38928], [46596], [48131], [52955], [53548], [53813], [53873], [54118], [54316], [54420], [54421], [54803].
See #56792.
Built from https://develop.svn.wordpress.org/trunk@54855
git-svn-id: http://core.svn.wordpress.org/trunk@54407 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Remove the private delegation from the following cache priming functions for various object types:
- `_prime_post_caches()`
- `_prime_term_caches()`
- `_prime_comment_caches()`
- `_prime_network_caches()`
- `_prime_site_caches()`
- `_get_non_cached_ids() `
Plugins and themes are now encouraged to use these functions to improve the performance of their code by reducing the number of database queries.
Props robinwpdeveloper, desrosj, SergeyBiryukov, mukesh27, costdev.
Fixes#56386.
Built from https://develop.svn.wordpress.org/trunk@53944
git-svn-id: http://core.svn.wordpress.org/trunk@53503 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This is the taxonomy term counterpart to the `is_post_publicly_viewable()` function. Although the logic for terms is more straight forward this serves the same purpose as introducing the corresponding function for posts -- to centralise and reduce the logic needed to validate a term and determine if it's publicly viewable.
Props peterwilsoncc, costdev, johnbillion
Fixes#56215
Built from https://develop.svn.wordpress.org/trunk@53893
git-svn-id: http://core.svn.wordpress.org/trunk@53452 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This changeset adds an `is_string( $taxonomy )` check to the condition in `taxonomy_exists()`, to ensure `false` is returned when the `$taxonomy` is not a string.
Follow-up to [35718].
Props costdev, peterwilsoncc, mukesh27.
Fixes#56338.
See #56336.
Built from https://develop.svn.wordpress.org/trunk@53869
git-svn-id: http://core.svn.wordpress.org/trunk@53428 1a063a9b-81f0-0310-95a4-ce76da25c4cd
No longer delete the default term option in `unregister_taxonomy()` to improve database performance.
Since taxonomies are registered at runtime and can't be unregistered unless they're already registered, prior to this
change the option was created and deleted on each request.
Deleting the option should occur on a one-time opperation such as plugin deactivation.
Follow up to [48480].
Props dlh.
Fixes#54472.
Built from https://develop.svn.wordpress.org/trunk@53669
git-svn-id: http://core.svn.wordpress.org/trunk@53228 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Add post type and taxonomy specific registration argument hooks.
Introduces the filters `register_{$post_type}_post_type_args` and `register_{$taxonomy}_taxonomy_args`. Introduces the actions `registered_post_type_{$post_type}` and `registered_taxonomy_{$taxonomy}`.
Props pbiron, dlh, davidbaumwald, hellofromTonya, milana_cap.
Fixes#53212.
Built from https://develop.svn.wordpress.org/trunk@53126
git-svn-id: http://core.svn.wordpress.org/trunk@52715 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Improve the translation of post type and taxonomy labels by caching the translations during runtime. To account for internationalisation plugins, the runtime cache is cleared as the post types/taxonomies are reinitiated on `change_local` hook.
The same property and methods are added to both `WP_Post_Type` and `WP_Taxonomy`:
* `$default_labels`: for storing the translated strings at runtime
* `get_default_labels()`: for getting the default labels, these are translated on the first run and stored in the new property.
* `reset_default_labels()`: to clear the runtime cache and force a re-translation of the default labels
Props Chouby, nacin, SergeyBiryukov, Rarst, chriscct7, ocean90, audrasjb, costdev.
Fixes#26746.
Built from https://develop.svn.wordpress.org/trunk@53058
git-svn-id: http://core.svn.wordpress.org/trunk@52647 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In [52921] `term_exists` was converted to use `get_terms`. This change adds a filter called `term_exists_default_query_args`
to the `term_exists` function to allow developers to modify the arguments passed to `get_terms` before the query is run.
Props Chouby, Spacedmonkey, peterwilsoncc.
Fixes#55439.
Built from https://develop.svn.wordpress.org/trunk@52987
git-svn-id: http://core.svn.wordpress.org/trunk@52576 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Replace raw SQL queries to the terms table, with a call to the `get_terms` function. Using `get_terms` means that `term_exists` is now cached. For developers using `term_exists` where cache invalidation is disabled, such as importing, a workaround was added to ensure that queries are uncached.
Props Spacedmonkey, boonebgorges, flixos90, peterwilsoncc.
Fixes#36949.
Built from https://develop.svn.wordpress.org/trunk@52921
git-svn-id: http://core.svn.wordpress.org/trunk@52510 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Remove the second parameter on the call to `update_term_cache()` from within the function `_prime_term_caches()`. The since deprecated parameter of the former was at one point a string, never a boolean.
Props david.binda, SergeyBiryukov, azouamauriac.
Fixes#55162.
Built from https://develop.svn.wordpress.org/trunk@52830
git-svn-id: http://core.svn.wordpress.org/trunk@52419 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Implement the `wp_cache_add_multiple`, `wp_cache_set_multiple` and `wp_cache_delete_multiple` in a number of core functions after they were introduced in [52700]
Props: spacedmonkey, adamsilverstein, flixos90, mitogh.
Fixes: #55029.
Built from https://develop.svn.wordpress.org/trunk@52707
git-svn-id: http://core.svn.wordpress.org/trunk@52296 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Remove the one day expiry limitation from query caches found in the `WP_Term_Qurery` class. Removing this limitation means that the caches will remain in object caching, as long as possible. Ensure that all term / taxonomy cache clear functions invalidate query caches, by deleting the last_changed value in the terms cache group.
Props spacedmonkey, adamsilverstein, boonebgorges, tillkruess, dlh, flixos90.
Fixes#54511.
Built from https://develop.svn.wordpress.org/trunk@52669
git-svn-id: http://core.svn.wordpress.org/trunk@52258 1a063a9b-81f0-0310-95a4-ce76da25c4cd
While `AS` is an optional keyword in SQL, it is commonly considered best practice to include it for better readability and compatibility. This also makes the queries more consistent with other queries using aliases in core.
Follow-up to [6359], [30238].
Props costdev, domainsupport.
Fixes#54769.
Built from https://develop.svn.wordpress.org/trunk@52553
git-svn-id: http://core.svn.wordpress.org/trunk@52143 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* Update the label names to make it clear that these descriptions are not for the term name or slug itself, but for the Name, Slug, Parent, and Description fields:
* `name_field_description`
* `slug_field_description`
* `parent_field_description`
* `desc_field_description`
* Update the array structure to make it clear that the default values for these labels are the same for both hierarchical and non-hierarchical taxonomies, with the exception of `parent_field_description`.
* Add documentation and a `@since` note for the new labels.
Follow-up to [52094].
Fixes#43060.
Built from https://develop.svn.wordpress.org/trunk@52163
git-svn-id: http://core.svn.wordpress.org/trunk@51755 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The `get_terms` filter currently documents that the filter passes an array as both the first and second parameters, which is normally true, except that the second can be `null` when not specified. This change updates the filter's docblock to indicate that the second parameter can also be of a `null` type.
Props dd32, audrasjb, mukesh27.
Fixes#54222.
Built from https://develop.svn.wordpress.org/trunk@52131
git-svn-id: http://core.svn.wordpress.org/trunk@51723 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Add additional label options to `register_taxonomy()` to allow developers further flexibility for customizing the edit taxonomy screen.
Props mclaurent, swissspidy, johnbillion, jeremyescott, theMikeD, jeremyfelt, dontgo2sleep, SergeyBiryukov, audrasjb, Boniu91.
Fixes#43060.
Built from https://develop.svn.wordpress.org/trunk@52094
git-svn-id: http://core.svn.wordpress.org/trunk@51686 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit introduces the `/wp/v2/menus`, `/wp/v2/menu-items` and `/wp/v2/menu-locations` REST API endpoints. These endpoints are fully available to users with the `edit_theme_options` capability, but can be read by any user who can edit a REST API available post type.
The `nav_menu` taxonomy and `nav_menu_item` post type now map their capabilities to the `edit_theme_options` primitive capability. This allows developers to provide more fine-grained access control. However, if a developer is currently dynamically removing the `edit_theme_options` capability using `map_meta_cap`, they should use the `user_has_cap` filter instead.
The `wp_update_nav_menu_item()` function has been adjusted to return an error if saving the menu item post or assigning the menu item to a menu generate an error.
Lastly, a new menu item type is introduced, `block`, that can be used to store a Block as a menu item.
Props andraganescu, antonvlasenko, dingo_d, dlh, isabel_brison, kadamwhite, Mamaduka, NateWr, noisysocks, peterwilsoncc, ryelle, schlessera, soean, Spacedmonkey, talldanwp, TimothyBlynJacobs, tobifjellner, westonruter, wpscholar, zieladam.
Fixes#40878.
Built from https://develop.svn.wordpress.org/trunk@52079
git-svn-id: http://core.svn.wordpress.org/trunk@51671 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit adds the wp_global_styles custom post type following the same approach used to add other core custom post types. It also updates the wp_theme taxonomy to include the wp_global_styles post type.
The post type is registered in the same way it is on the plugin we just adapt the location for the core.
See #54336.
Props oandregal.
Built from https://develop.svn.wordpress.org/trunk@52041
git-svn-id: http://core.svn.wordpress.org/trunk@51633 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Use 3-digit, x.x.x-style semantic versioning for `@since` tags of the `$rest_namespace` property in `WP_Post_Type` and `WP_Taxonomy`.
Add a `@since` note to `WP_REST_Taxonomies_Controller::get_item_schema()` for the `visibility` and `rest_namespace` properties.
The `rest_base` property was also added after the method was initially introduced, but that happened during the same release cycle, so it doesn't need a separate `@since` note.
Follow-up to [38832], [39191], [42729], [51959], [51961], [51962], [51964].
See #53399.
Built from https://develop.svn.wordpress.org/trunk@51965
git-svn-id: http://core.svn.wordpress.org/trunk@51554 1a063a9b-81f0-0310-95a4-ce76da25c4cd
While a taxonomy can define a custom route by using the rest_base argument, a namespace of wp/v2 was assumed. This commit introduces support for a rest_namespace argument.
A new rest_get_route_for_taxonomy_items function has been introduced and the rest_get_route_for_term function updated to facilitate getting the correct route for taxonomies.
For maximum compatibility sticking with the default wp/v2 namespace is recommended until the API functions see wider use.
Props spacedmonkey.
Fixes#54267.
See [51962].
Built from https://develop.svn.wordpress.org/trunk@51964
git-svn-id: http://core.svn.wordpress.org/trunk@51553 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* 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
The `term_exists()` function expects a string or an integer for the `$term` parameter. It validates for integer, but not for string or `null`.
One of the pre-existing test cases, passed `null` to the function, leading to a `trim(): Passing null to parameter #1 ($string) of type string is deprecated` notice on PHP 8.1.
Fixed now by doing a cursory check on the variable at the start of the function and bowing out early in case the `$term` is `null`.
The issue was discovered via and is already covered by the `Tests_TermExists::test_term_exists_unknown()` test method.
Follow-up to [15220]. [38716].
Props jrf, hellofromTonya.
See #53635.
Built from https://develop.svn.wordpress.org/trunk@51796
git-svn-id: http://core.svn.wordpress.org/trunk@51403 1a063a9b-81f0-0310-95a4-ce76da25c4cd
As `term_id` is the actual property name of the `WP_Term`, it should appear first and we should make it more clear that `id` and `ID` are aliases.
Follow-up to [6254], [25334], [38677], [47865], [47870].
Props gazchap, audrasjb.
Fixes#54065.
Built from https://develop.svn.wordpress.org/trunk@51731
git-svn-id: http://core.svn.wordpress.org/trunk@51337 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Previously, these properties could be unexpectedly converted to strings in some contexts.
This applies to the following functions:
* `sanitize_post_field()`
* `sanitize_term_field()`
* `sanitize_user_field()`
and the following properties:
* `WP_Post::ID`
* `WP_Post::post_parent`
* `WP_Post::menu_order`
* `WP_Term::term_id`
* `WP_Term::term_taxonomy_id`
* `WP_Term::parent`
* `WP_Term::count`
* `WP_Term::term_group`
* `WP_User::ID`
Props grantmkin, SergeyBiryukov.
Fixes#53235. See #52995.
Built from https://develop.svn.wordpress.org/trunk@50935
git-svn-id: http://core.svn.wordpress.org/trunk@50544 1a063a9b-81f0-0310-95a4-ce76da25c4cd
[48658] documented that various metadata functions return false for an invalid ID. However, that does not clarify what an invalid ID is: a non-numeric, zero, or negative value. This change adds the clarification in all relevant metadata function docblocks.
Props icopydoc, SergeyBiryukov, davidkryzaniak, audrasjb.
Fixes#51797.
Built from https://develop.svn.wordpress.org/trunk@50641
git-svn-id: http://core.svn.wordpress.org/trunk@50253 1a063a9b-81f0-0310-95a4-ce76da25c4cd