Add the label `template_name` to post types and taxonomies for use by the site editor to display on the templates/add new template screens to allow extenders to customize the display.
For post types the template name applies to templates for a singular pages with the default value "Single item: [singular name]".
For taxonomies the template name applies to templates for term archives with the default value "[singular name] Archives".
Props aljullu, audrasjb, ntsekouras, ellatrix, oglekler, rajinsharwar.
Fixes#60881.
Built from https://develop.svn.wordpress.org/trunk@58377
git-svn-id: http://core.svn.wordpress.org/trunk@57826 1a063a9b-81f0-0310-95a4-ce76da25c4cd
When inserting a new term in the database, `wp_insert_term()` will check if the term is empty and return a corresponding error.
Afterwards the term is sanitized and inserted in the database. However, there is a chance the term is empty after the DB sanitization.
This commit adds a check for an empty term name after the term is sanitized, returning an error in that case.
Follow-up to [5726], [8393].
Props fgiannar, kraftbj.
Fixes#59995.
Built from https://develop.svn.wordpress.org/trunk@57251
git-svn-id: http://core.svn.wordpress.org/trunk@56757 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The phrase "sanity check" unnecessarily references mental health. It's an old phrase used to denote an extra step in verifying code works as expected.
“The WordPress open source community cares about diversity. We strive to maintain a welcoming environment where everyone can feel included.”
While "sanity check" is a well-known phrase with a specific meaning, "confidence check" is a direct replacement that is more clear of its intent while being more inclusive.
Words matter.
Follow-up to [49216], [46271], [40583], [38832], [38637], [37409], [33359], [32162], [30346], [30345], [30238], [30055], [29902], [28763], [26141], [25002], [22227], [13428], [12148], [11025], [8927].
Props dartiss, hellofromTonya.
Fixes#60187.
Built from https://develop.svn.wordpress.org/trunk@57239
git-svn-id: http://core.svn.wordpress.org/trunk@56745 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In the `get_term` function, the filter method is invoked on the `WP_Term` object, which subsequently triggers the execution of `sanitize_term`. The filter method is also executed within `WP_Term::get_instance`.
A common scenario when calling the `get_term` function is to invoke the function with an integer ID for the term and a filter set to "raw." This results in a call to `WP_Term::get_instance`. However, since both `get_term` and `WP_Term::get_instance` invoke the filter method, it leads to double sanitization of the term.
Considering that `get_term` may be called thousands of times on a page, especially when priming a large number of terms into memory, this redundancy can result in thousands of unnecessary calls to `sanitize_term`. Performing the same sanitization operation twice with the same parameters is wasteful and detrimental to performance.
To address this issue, the code has been updated to execute the filter method only when the filter parameter does not match or when changes have been made to the term object within the get_term hook. This optimization ensures that the filter is applied selectively, mitigating performance concerns and avoiding unnecessary sanitization calls.
Props spacedmonkey, flixos90, costdev, mukesh27, joemcgill, oglekler, peterwilsoncc.
Fixes#58329.
Built from https://develop.svn.wordpress.org/trunk@56650
git-svn-id: http://core.svn.wordpress.org/trunk@56162 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Incorporating a new 'cache_results' parameter into the WP_Term_Query class, this commit empowers developers with the ability to bypass query caches, explicitly triggering database queries when needed. This brings the `WP_Term_Query` class inline with `WP_Query` and `WP_User_Query` that already have a 'cache_results' parameter.
Update the `term_exists` function to use this new parameter, so the term query caches are not used while importing.
Props dlh, spacedmonkey, peterwilsoncc.
Fixes#52710.
Built from https://develop.svn.wordpress.org/trunk@56585
git-svn-id: http://core.svn.wordpress.org/trunk@56097 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Prevents `wp_set_object_terms()` throwing a deprecation notice in PHP 8.1+ when passing an empty value as the second parameter to clear the terms.
Props audrasjb, chouby, costdev, jrf, peterwilsoncc, prashantbhivsane, sergeybiryukov.
Fixes#57923.
Built from https://develop.svn.wordpress.org/trunk@55921
git-svn-id: http://core.svn.wordpress.org/trunk@55433 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Passing `update_term_meta_cache` argument value false by default resulting in `get_terms` to not prime the term meta cache in `wp_get_object_terms`. Priming of term meta is not needed in this context.
Props spacedmonkey, rutviksavsani.
Fixes#57701.
Built from https://develop.svn.wordpress.org/trunk@55759
git-svn-id: http://core.svn.wordpress.org/trunk@55271 1a063a9b-81f0-0310-95a4-ce76da25c4cd
`str_starts_with()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) begins with the given substring (needle).
WordPress core includes a polyfill for `str_starts_with()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `0 === strpos( ... )` with `str_starts_with()` in core files, making the code more readable and consistent, as well as improving performance.
While `strpos()` is slightly faster than the polyfill on PHP < 8.0, `str_starts_with()` is noticeably faster on PHP 8.0+, as it is optimized to avoid unnecessarily searching along the whole haystack if it does not find the needle.
Follow-up to [52039], [52040], [52326].
Props spacedmonkey, costdev, sabernhardt, mukesh27, desrosj, jorbin, TobiasBg, ayeshrajans, lgadzhev, SergeyBiryukov.
Fixes#58012.
Built from https://develop.svn.wordpress.org/trunk@55703
git-svn-id: http://core.svn.wordpress.org/trunk@55215 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Add a helper function called `wp_cache_set_last_changed` to set the last changed value for cache groups. This function has a new action called `wp_cache_set_last_changed`, allowing for developers to cache invalidate when last changed value is changed.
Props tillkruess, spacedmonkey, peterwilsoncc, mukesh27, johnjamesjacoby.
Fixes#57905.
Built from https://develop.svn.wordpress.org/trunk@55702
git-svn-id: http://core.svn.wordpress.org/trunk@55214 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In [34529] introduced lazy loading of term meta. However, this was only in the context of `WP_Query`. Other parts of the codebase, like `WP_Term_Query` did not lazily load term meta. In this change, calls to `update_termmeta_cache` are now replaced with `wp_lazyload_term_meta`, that instead of priming term meta caches, just adds them to the queue to be primed it ever called. This results in far less database queries, as there a number of places where term meta is being primed unnecessarily and never used. Adding everything to the term meta queue, also means that if term meta is used, that is all loaded in a single database / cache call.
Props spacedmonkey, mukesh27, peterwilsoncc.
Fixes#57645.
Built from https://develop.svn.wordpress.org/trunk@55671
git-svn-id: http://core.svn.wordpress.org/trunk@55183 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Give developers more control over how query caches are handled within an object caches. Now all caches that cache the result of a query, are cached in a group that is suffixed with -queries. Developers can use these groups, to add custom cache invalidation rules or to make them none persistent.
Props spacedmonkey, owi, tillkruess, skithund, peterwilsoncc, flixos90, sergeybiryukov, mukesh27.
Fixes#57625.
Built from https://develop.svn.wordpress.org/trunk@55526
git-svn-id: http://core.svn.wordpress.org/trunk@55048 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This resolves a few WPCS warnings:
{{{
Variable "$cat_ID" is not in valid snake_case format, try "$cat_i_d"
}}}
Affected functions:
* `wp_delete_category()`
* `get_category_rss_link()`
* `get_catname()`
Follow-up to [836], [2068], [2551], [2695], [6365], [10959], [52958], [55190].
Fixes#56754.
Built from https://develop.svn.wordpress.org/trunk@55334
git-svn-id: http://core.svn.wordpress.org/trunk@54867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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