When querying for terms in hierarchical taxonomies, `get_terms()` initially
queries for all matching terms, and then trims the located results based on the
`$number` and `$offset` arguments passed to the function. See #8832. However,
a flaw in the original logic meant that results were failing to be trimmed
properly in cases where `$offset` exceeds the total number of matching terms;
in these cases, we should force an empty array.
Props danielbachhuber.
Fixes#35935.
Built from https://develop.svn.wordpress.org/trunk@36691
git-svn-id: http://core.svn.wordpress.org/trunk@36658 1a063a9b-81f0-0310-95a4-ce76da25c4cd
`get_terms()` has historically required that a taxonomy be specified when
querying terms. This requirement is related to the fact that terms could
formerly be shared between taxonomies, making `$taxonomies` critical for
disambiguation. Since terms can no longer be shared as of 4.4, it'
s desirable to be able to query for terms regardless of what taxonomy they're in.
Because it's now optional to pass taxonomies, it's no longer necessary to have
`$taxonomies` as the first (and required) parameter for `get_terms()`. The new
function signature is `get_terms( $args )`, where 'taxonomy' can (optionally) be
passed as part of the `$args` array. This syntax is more consistent with
functions like `get_users()` and `get_posts()`.
We've maintained backward compatibility by always giving precedence to the old
argument format. If a second parameter is detected, or if it's detected that
the first parameter is a list of taxonomy names rather than an `$args` array,
`get_terms()` will parse the function arguments in the legacy fashion.
Props flixos90, swissspidy, DrewAPicture, boonebgorges.
Fixes#35495.
Built from https://develop.svn.wordpress.org/trunk@36614
git-svn-id: http://core.svn.wordpress.org/trunk@36581 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The `$orderby` parameter of `get_terms()` now accepts the following values,
related to term meta:
* 'meta_value'
* 'meta_value_num'
* the value of the `$meta_key` parameter
* any key from the `$meta_query` array
This brings order-by-meta support for terms in line with post, comment, and
user queries.
As a byproduct of these improvements, `$meta_key` and `$meta_value` parameters
have been introduced to `get_terms()`. They interact with `$meta_query` in the
same way as in `WP_Query` and other query classes.
Props jadpm, eherman24.
Fixes#34996.
Built from https://develop.svn.wordpress.org/trunk@36485
git-svn-id: http://core.svn.wordpress.org/trunk@36452 1a063a9b-81f0-0310-95a4-ce76da25c4cd
[32353] changed the way the 'name' param in `get_terms()` is sanitized, by
running it through `sanitize_term_field( 'name' )` before performing the SQL
query. An unintentional side effect of this change was that the string is
double-escaped: once by `wp_filter_kses()`, and once by `esc_sql()`. The
double-escaping was causing 'name' queries to fail when the param contained
apostrophes or other escaped characters.
Fixes#35493.
Built from https://develop.svn.wordpress.org/trunk@36348
git-svn-id: http://core.svn.wordpress.org/trunk@36315 1a063a9b-81f0-0310-95a4-ce76da25c4cd
[34999] modified the cache strategy for terms in the context of
`wp_get_object_terms()`. As part of these changes, the `object_id` property of
term objects had to be unset before being cached. To avoid modifying passed-by-
reference terms, `update_term_cache()` attempted to make a copy of the terms
passed to the function; however, it failed to use the `clone` keyword, and thus
only created a reference instead of a copy.
Props berengerzyla.
Fixes#35462.
Built from https://develop.svn.wordpress.org/trunk@36323
git-svn-id: http://core.svn.wordpress.org/trunk@36290 1a063a9b-81f0-0310-95a4-ce76da25c4cd
`array_slice()` must be told to preserve keys when the query results exceed the
limit specified the 'number' parameter, so that `id=>parent` and other
id-indexed return value formats don't get mangled.
Props fantasyworld, wpdelighter.
Fixes#35382.
Built from https://develop.svn.wordpress.org/trunk@36252
git-svn-id: http://core.svn.wordpress.org/trunk@36219 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Passing `'description' => null` when creating a term can cause MySQL notices,
as the description column in the terms table does not allow for null values.
We correct this by intepreting a `null` description as an empty string.
Props TimothyBlynJacobs.
Fixes#35321.
Built from https://develop.svn.wordpress.org/trunk@36214
git-svn-id: http://core.svn.wordpress.org/trunk@36181 1a063a9b-81f0-0310-95a4-ce76da25c4cd
[35333] implemented `public=false` for taxonomies. The implementation prevented
non-public taxonomies from having their archives accessed via query_var during
a normal request. But it didn't prevent non-public taxonomies from registering
their query vars in the `$wp_taxonomies` global. The latter implementation
details causes problems specifically when a taxonomy is registered with
`query_var=true`; for public taxonomies, `register_taxonomy()` translates this
into a query_var equivalent to the taxonomy name, but in the case of non-public
taxonomies, the query_var was set to the boolean itself. The boolean then
causes problems when using non-strict comparison to filter taxonomy objects by
query_var, as when using `get_taxonomies()`.
This changeset addresses the issue by forcing the query_var property of
non-public taxonomies to `false`.
Fixes#35089.
Built from https://develop.svn.wordpress.org/trunk@36108
git-svn-id: http://core.svn.wordpress.org/trunk@36073 1a063a9b-81f0-0310-95a4-ce76da25c4cd
[34217] removed the `ORDER BY` clause from `update_object_term_cache()`, for
improved performance. But this proved to cause problems in cases where users
were expecting the results of `get_the_terms()` to be ordered by 'name'. Let's
revert the change for the time being, and look into more disciplined ordering
in a future release.
Props afercia.
See #28922. Fixes#35180.
Built from https://develop.svn.wordpress.org/trunk@36056
git-svn-id: http://core.svn.wordpress.org/trunk@36021 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The introduction of 'meta_query' to `get_terms()` in 4.4 made it possible for
`get_terms()` to erroneously return duplicate results. To address the issue,
we add the `DISTINCT` keyword to the SQL query when a 'meta_query' parameter
has been provided.
Props @jadpm.
Fixes#35137.
Built from https://develop.svn.wordpress.org/trunk@36003
git-svn-id: http://core.svn.wordpress.org/trunk@35968 1a063a9b-81f0-0310-95a4-ce76da25c4cd
`get_term()` now returns a `WP_Term` object, instead of a `stdClass` object.
Cache support and sanitization filters for individual terms are now more
centralized. For example, `get_term_by()` is able to cast results of its query
to a `WP_Term` object by passing it through `get_term()`.
The `$taxonomy` parameter for `get_term()` is now optional, as terms ought to
be unique to a taxonomy (ie, shared terms no longer exist). In cases where
`get_term()` detects that the term matching the specified term_id is from the
wrong taxonomy, it checks to see if you've requested a shared term, and if so,
it splits the term. This is used only for fallback purposes.
The elimination of shared terms allows the caching strategy for terms to be
simplified. Individual terms are now cached in a single 'terms' bucket.
Props flixos90, boonebgorges, scribu, dipesh.kakadiya.
See #14162.
Built from https://develop.svn.wordpress.org/trunk@34997
git-svn-id: http://core.svn.wordpress.org/trunk@34962 1a063a9b-81f0-0310-95a4-ce76da25c4cd
`wp_suspend_cache_invalidation()` was originally added to increase performance,
but the switch to batch processing in [33615] mitigates serious performance
concerns.
As a precaution against timeouts, the batch size has been reduced from 20 to 10.
Props Chouby.
See #30261.
Built from https://develop.svn.wordpress.org/trunk@33619
git-svn-id: http://core.svn.wordpress.org/trunk@33586 1a063a9b-81f0-0310-95a4-ce76da25c4cd
[32814] introduced a routine to split shared terms, which was run during the
regular WP database upgrade. This turned out to be problematic because plugins
are not loaded during the db upgrade (due to `WP_INSTALLING`), with the result
that plugins were not able to hook into the 'split_shared_term' action during
the bulk split. We work around this limitation by moving the term splitting
routine to a separate process, triggered by a wp-cron hook.
Props boonebgorges, Chouby, peterwilsoncc, pento, dd32.
Fixes#30261.
Built from https://develop.svn.wordpress.org/trunk@33615
git-svn-id: http://core.svn.wordpress.org/trunk@33582 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This changeset adds two new filters:
* 'wp_unique_term_slug_is_bad_slug' lets developers control whether a test slug needs to be made unique, before the queries required to build a suffix are performed.
* 'wp_unique_term_slug' filters the output of the function.
These changes introduce parity with the filters in `wp_unique_post_slug()`.
Props coffee2code, bolo1988, boonebgorges.
Fixes#20783.
Built from https://develop.svn.wordpress.org/trunk@32837
git-svn-id: http://core.svn.wordpress.org/trunk@32808 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* Introduce a `$record` parameter, which defaults to true. When set to false, `_split_shared_term()` will not keep a record of split term data in wp_options. The judicious use of this flag can greatly improve performance when processing shared terms in batches.
* Allow term/tt objects to be passed to the `$term_id` and `$term_taxonomy_id` parameters. This has the potential to save database queries when the objects are already available.
See #30261.
Built from https://develop.svn.wordpress.org/trunk@32813
git-svn-id: http://core.svn.wordpress.org/trunk@32784 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Correct some `@return` values.
Some functions can `return new WP_Error` without setting it to a variable.
Some functions can return their `apply_filters(...)` call without first setting it to a variable.
`is_object_in_taxonomy()` can return its conditional instead of if/else true/false.
See #32444.
Built from https://develop.svn.wordpress.org/trunk@32627
git-svn-id: http://core.svn.wordpress.org/trunk@32597 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This new argument allows developers to specify which term field should be
matched by the value of the `$term` parameter (in particular, 'name' and
'term_taxonomy_id' are now supported).
Props sudar, mordauk.
Fixes#14156.
Built from https://develop.svn.wordpress.org/trunk@32553
git-svn-id: http://core.svn.wordpress.org/trunk@32523 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Using an array keyed by term_id allows us to use `isset()` rather than the
slower `in_array()`. In addition, it lets us avoid the use of `wp_list_pluck()`
on large arrays, and helps us to avoid arrays that are unnecessarily large due
to duplicate entries.
Fixes#32144 for trunk.
Built from https://develop.svn.wordpress.org/trunk@32326
git-svn-id: http://core.svn.wordpress.org/trunk@32297 1a063a9b-81f0-0310-95a4-ce76da25c4cd
`wp_insert_term()` protects against the creation of terms with duplicate names
at the same level of a taxonomy hierarchy. However, it's historically been
possible to override this protection by explicitly providing a value of `$slug`
that is unique at the hierarchy tier. This ability was broken in [31734], and
the current changeset restores the original behavior.
A number of unit tests are added and refactored in support of these changes.
See #17689 for discussion of a fix that was superceded by [31734]. This commit
retains the fix for the underlying bug described in that ticket.
See #31328.
Built from https://develop.svn.wordpress.org/trunk@31792
git-svn-id: http://core.svn.wordpress.org/trunk@31774 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Previously, it was noted that -1 would return all possible results. However, as the value of `$number` is passed through `absint()`, -1 would actually be converted to 1, thereby producing unexpected results.
Props iandunn.
Fixes#31526.
Built from https://develop.svn.wordpress.org/trunk@31638
git-svn-id: http://core.svn.wordpress.org/trunk@31619 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The existing 'wp_get_object_terms' filter accepts a parameter `$taxonomies`,
which is a list of taxonomy names formatted for direct use in a MySQL IN clause.
This formatting makes it difficult to make use of the taxonomy list in filter
callbacks. However, changing the parameters passed to the existing filter
raises backward compatibility concerns, so we introduce a new filter that
receives a structured `$taxonomy_array` parameter.
We also take this opportunity to correct and clean up some of the documentation
on the 'wp_get_object_terms' filter.
Props postpostmodern, doublesharp, wonderboymusic, nacin.
Fixes#18828.
Built from https://develop.svn.wordpress.org/trunk@31581
git-svn-id: http://core.svn.wordpress.org/trunk@31562 1a063a9b-81f0-0310-95a4-ce76da25c4cd
These actions are fired in a number of different places, and in some cases
the tax name is passed, while in others the taxonomy object is passed. This
inconsistency made it difficult for plugins to use the `$taxonomy` value.
Props ipm-frommen.
Fixes#30999.
Built from https://develop.svn.wordpress.org/trunk@31525
git-svn-id: http://core.svn.wordpress.org/trunk@31506 1a063a9b-81f0-0310-95a4-ce76da25c4cd
When updating an existing taxonomy term that shares its `term_id` with
another term, we generate a new row in `wp_terms` and associate the updated
term_taxonomy_id with the new term. This separates the terms, such that
updating the name of one term does not change the name of any others.
In cases where a plugin or theme stores term IDs in the database, term splitting
can cause backward compatibility issues. The current changeset introduces
two utilities to aid developers with the transition. The `'split_shared_term'`
action fires when the split takes place, and should be used to catch changes in
term_id. In cases where `'split_shared_term'` cannot be used, the
`wp_get_split_term()` function gives developers access to data about terms
that have previously been split. Documentation for these functions, with
examples, can be found in the Plugin Developer Handbook. WordPress itself
stores term IDs in this way in two places; `_wp_check_split_default_terms()`
and `_wp_check_split_terms_in_menus()` are hooked to `'split_shared_term'` to
perform the necessary cleanup.
See [30241] for a previous attempt at the split. It was reverted in [30585]
for 4.1.0.
Props boonebgorges, mboynes.
See #5809.
Built from https://develop.svn.wordpress.org/trunk@31418
git-svn-id: http://core.svn.wordpress.org/trunk@31399 1a063a9b-81f0-0310-95a4-ce76da25c4cd
When terms are entered into the database, term fields are sanitized with
`sanitize_term_field()`. To ensure that the `SELECT ... WHERE` queries in
`WP_Tax_Query::transform_query()` are not broken by overzealous sanitization,
`sanitize_term_field()` should be used in that case as well. This fixes a bug
where a tax_query using 'field=name' would fail if the 'terms' parameter
contained characters (like spaces) that were improperly removed by
`sanitize_title_for_query()`.
Fixes#27810.
Built from https://develop.svn.wordpress.org/trunk@31346
git-svn-id: http://core.svn.wordpress.org/trunk@31327 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Setting 'show_in_quick_edit' to false when registering a custom taxonomy will
hide the taxonomy when editing posts using Quick Edit.
The new 'quick_edit_show_taxonomy' filter allows this behavior to be filtered
on a finer scale, as when you want a given taxonomy to be hidden for one post
type but not for others.
Props hlashbrooke.
Fixes#26948.
Built from https://develop.svn.wordpress.org/trunk@31307
git-svn-id: http://core.svn.wordpress.org/trunk@31288 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Uncached results pulled from `wp_get_object_terms()` are zero-indexed (ie 0,
1, 2...). As a result, `get_the_terms()` was returning a strictly different
array when pulling from the cache and when the cache was empty.
Props joshlevinson.
Fixes#31086.
Built from https://develop.svn.wordpress.org/trunk@31287
git-svn-id: http://core.svn.wordpress.org/trunk@31268 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Previously, attempts to descend the family tree of each term were done using
the first taxonomy in the `$taxonomies` array, with the result that terms not
belonging to that taxonomy were not found and their children not properly
parsed. We fix this bug by fetching each term's taxonomy with the SQL query,
and then using that taxonomy to get the correct children for each term.
Fixes#31118.
Built from https://develop.svn.wordpress.org/trunk@31285
git-svn-id: http://core.svn.wordpress.org/trunk@31266 1a063a9b-81f0-0310-95a4-ce76da25c4cd
There is a pre-check in `get_terms()` that prevents an unnecessary database
query if the 'parent' or 'child_of' parameter is not found in the cached term
hierarchy (since a term without an index in the hierarchy cache has no
descendants). Previously, only the first item in the `$taxonomies` array was
being checked, with the result that an empty array was being erroneously
returned in cases where the 'parent' or 'child_of' term is in a subsequent
taxonomy.
See #31118.
Built from https://develop.svn.wordpress.org/trunk@31276
git-svn-id: http://core.svn.wordpress.org/trunk@31257 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This new parameter allows developers to limit queried terms to terminal nodes -
ie, those without any descendants.
As part of the improvement, some internal logic in `get_terms()` has been
consolidated. Parameters that resolve to a NOT IN clause containing term IDs
('exclude', 'exclude_tree', and 'childless') are now parsed into a single
"exclusions" array before the SQL clause is generated.
Props theMikeD, horike.
Fixes#29839.
Built from https://develop.svn.wordpress.org/trunk@31275
git-svn-id: http://core.svn.wordpress.org/trunk@31256 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Taxonomy hierarchy loops should not occur naturally, but when they do, the
logic of `_pad_term_counts()` could result in infinite loops, leading to
timeouts. We avoid this by breaking when a loop is detected.
Fixes#20635.
Built from https://develop.svn.wordpress.org/trunk@31206
git-svn-id: http://core.svn.wordpress.org/trunk@31187 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This enhancement requires a modification in the way that `wp_dropdown_categories()`
prepares its arguments for `get_terms()`, so that its unrelated 'name' param is
not mistaken for the new 'name' argument in `get_terms()`.
Props danielbachhuber.
Fixes#30611.
Built from https://develop.svn.wordpress.org/trunk@31024
git-svn-id: http://core.svn.wordpress.org/trunk@31005 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The `$resource_type` argument was added to the `get_ancestors()` function in
[30141]. In that changeset, the documentation for the filter was updated to
indicate that it would receive `$resource_type` as a param, but the filter
itself was not updated accordingly.
Props tmatsuur, DrewAPicture.
Fixes#30843.
Built from https://develop.svn.wordpress.org/trunk@30993
git-svn-id: http://core.svn.wordpress.org/trunk@30975 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In 4.1 [30240], `wp_insert_term()` was modified to allow the creation of terms
with duplicate slugs, as long as the terms are in different taxonomies.
`wp_update_term()` didn't get the corresponding modification, with the result
that term updates fail when the term being updated shares a slug with an older
term, regardless of that older term's taxonomy.
Props ipm-frommen.
Fixes#30780 for trunk.
Built from https://develop.svn.wordpress.org/trunk@30985
git-svn-id: http://core.svn.wordpress.org/trunk@30971 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This was removed in [29915] as part of the attempt to add cache support to
`get_term_by()`. When that support was removed in [30900], it was not properly
restored.
This changeset includes a unit test to verify that the cache is properly primed
for terms found in `get_terms()`, as well as tests to verify the other cache
setting that was touched by [30900].
Fixes#30749. See #21760.
Built from https://develop.svn.wordpress.org/trunk@30954
git-svn-id: http://core.svn.wordpress.org/trunk@30942 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The new cache group scheme causes term invalidation to be overly broad, so
that busting the cache for one term will bust the cache for all terms in the
taxonomy. We'll have another go at more focused use of the 'last_changed'
incrementor in a future release.
Reverts [29915], [30073], [30080], [30108], [30112].
See #21760.
Built from https://develop.svn.wordpress.org/trunk@30900
git-svn-id: http://core.svn.wordpress.org/trunk@30890 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This is a revert of [30494], [30492], [30347], and [30334]. The latter
changeset was a revert of [30336], which was a revert of [30241].
Watch for Term Splitting, Version III in version 4.2, coming soon to a
WordPress trunk near you.
See #30335, #5809.
Built from https://develop.svn.wordpress.org/trunk@30585
git-svn-id: http://core.svn.wordpress.org/trunk@30575 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Affects DocBlocks for the following core elements:
* Backtick-escape code snippets in the description for `get_object_taxonomies()`
* Backtick-escape inline code in a markdown-formatted unordered list in the description for `get_taxonomy_labels()`
* Remove an HTML tag from the summary for the `Walker_Category_Checklist` class
* Remove an HTML tag from the summary for `wp_category_checklist()`, various formatting
* Remove an HTML tag from the summary for `wp_terms_checklist()`
* Backtick-escape an HTML tag in the description for `wp_popular_terms_checklist()`
* Remove HTML tags from the summaries for `page_template_dropdown()`, `parent_dropdown()`, and `wp_dropdown_roles()`
* Backtick-escape HTML tags in a parameter description for `add_settings_error()`
* Various formatting in the description and summary for `settings_errors()`
* Markdown-indent code snippets in the descriptions for `wpdb::prepare()`, `wpdb::insert()`, `wpdb::replace()`, `wpdb::update()`, and `wpdb::delete()`
* Backtick-escape an HTML tag in a parameter description for `login_header()`
* Remove HTML tags from the summaries for the `lostpassword_form` and `signup_header` hooks
Props rarst.
See #30473.
Built from https://develop.svn.wordpress.org/trunk@30546
git-svn-id: http://core.svn.wordpress.org/trunk@30535 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* If the split term ID is stored as 'default_category', 'default_link_category', or 'default_email_category', update it to the new ID.
* If the split term ID is associated with a nav menu item, update that piece of postmeta to the new ID.
Props mboynes.
See #30335.
Built from https://develop.svn.wordpress.org/trunk@30494
git-svn-id: http://core.svn.wordpress.org/trunk@30483 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Splitting shared terms means assigning a new term_id to a given term_taxonomy_id.
It was uncovered that this change could cause problems for sites that have
cached the original term_id somehow - say, in postmeta - since future lookups
using that term_id will now fail.
Removing for 4.1-beta1. We'll look at improvements to backward compatibility
to try to get this back into a later beta.
Props mboynes.
See #30335.
Built from https://develop.svn.wordpress.org/trunk@30336
git-svn-id: http://core.svn.wordpress.org/trunk@30335 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This forcing appears to have been introduced to save unnecessary queries, but
(a) in some cases it appeared to be causing *more* queries, and (b) it caused
incorrect results when the 'exclude_tree' param of `get_terms()` called
`get_terms()` on each item in the tree using the 'child_of' param.
Fixes#30275.
Built from https://develop.svn.wordpress.org/trunk@30265
git-svn-id: http://core.svn.wordpress.org/trunk@30265 1a063a9b-81f0-0310-95a4-ce76da25c4cd
When updating an existing taxonomy term that shares its `term_id` with
another term, we generate a new row in `wp_terms` and associate the updated
term_taxonomy_id with the new term. This separates the terms, such that
updating the name of one term does not change the name of any others.
Note that this term splitting only occurs on installations whose database
schemas have been upgraded to version 30133 or higher. Note also that shared
terms are only split when run through `wp_update_term()`, as on edit-tags.php;
we will wait until a future release of WordPress to force the splitting of all
shared taxonomy terms.
Props boonebgorges, rmccue, greuben, garyc40, wonderboymusic, imath, jesin.
Fixes#5809.
Built from https://develop.svn.wordpress.org/trunk@30241
git-svn-id: http://core.svn.wordpress.org/trunk@30241 1a063a9b-81f0-0310-95a4-ce76da25c4cd
A "shared" term occurs when two entries in the `wp_term_taxonomy` table share a
single `term_id`, and thereby correspond to the same row in `wp_terms`. This
changeset stops the practice of creating shared terms: each new row in
`wp_term_taxonomy` will receive its own row in `wp_terms`. The new strategy
for term creation depends on whether the installation's database schema is up
to date for 4.1:
* If so, terms are allowed to be created with the same slug as an existing term, as long as they are in different taxonomies and do not share a parent. Thus, a new tag with the slug 'wordpress' can exist alongside a category with the slug 'wordpress'.
* If not, new terms will be forced to have unique slugs. Thus, on an installation containing a category with the slug 'wordpress', a new tag 'WordPress' will get the slug 'wordpress-2'.
Fixes#21950. See #5809.
Built from https://develop.svn.wordpress.org/trunk@30240
git-svn-id: http://core.svn.wordpress.org/trunk@30240 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In case of edge cases where a duplicate term might exist in a replicated
database for a split second, these explicit query clauses ensure that
`term_exists()` will always recognize the oldest matched term as the
canonical one. See [30238] for background.
Props pento.
See #22023, #5809.
Built from https://develop.svn.wordpress.org/trunk@30239
git-svn-id: http://core.svn.wordpress.org/trunk@30239 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In [30056], the UNIQUE index was removed from the 'slug' column of `wp_terms`.
While we have numerous checks in place to avoid the creation of unwanted
duplicate term+term_taxonomy pairs, it's possible that in certain edge cases -
such as during the lag caused by database replication, or a race condition
involving near-simultaneous creation of more than one term - we'll end up
unwittingly inserting two identical rows.
The current changeset minimizes this risk by introducing a failsafe mechanism
into `wp_insert_term()`. After a term and term_taxonomy are INSERTed, we check
to see whether the term just created is a duplicate of an existing term; if so,
we delete the new one and keep the old one. This prevents problems caused by
replication lag, because SELECT queries that take place after an INSERT will
hit the master database; it mitigates race conditions by enforcing that the
term that was created first (ie, the one with the lowest `term_id`) is
always the "canonical" one.
Props nacin, markjaquith.
See #22023, #5809.
Built from https://develop.svn.wordpress.org/trunk@30238
git-svn-id: http://core.svn.wordpress.org/trunk@30238 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* In `the_taxonomies()`, only document those arguments that are specific to the function. Arguments shared with `get_the_taxonomies()` should be documented in the later function's docblock.
* Add $args hash documentation to `get_the_taxonomies()`.
* Remove the redundant default argument definition in `the_taxonomies()`.
Fixes#27238.
Built from https://develop.svn.wordpress.org/trunk@30210
git-svn-id: http://core.svn.wordpress.org/trunk@30210 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The previous behavior resulted in descendant terms being improperly excluded
from the results when passing a 'parent', even when 'hierarchical' had been
set to true.
The patch also adds unit tests that demonstrate the various interactions
between the 'child_of', 'parent', and 'hierarchical' parameters of `get_terms()`.
Props landakram.
Fixes#29815.
Built from https://develop.svn.wordpress.org/trunk@30107
git-svn-id: http://core.svn.wordpress.org/trunk@30107 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Per our inline documentation standards, no further use of the `@uses` tag is recommended as used and used-by relationships can be derived through other means. This removes most uses of the tag in core documentation, with remaining tags to be converted to `@global` or `@see` as they apply.
Fixes#30191.
Built from https://develop.svn.wordpress.org/trunk@30105
git-svn-id: http://core.svn.wordpress.org/trunk@30105 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* Add a helper function, `wp_get_last_changed()`, to retrieve a last-modified timestamp by cache group
* When caching a term, also make cache entries for slug and name via `slug:{$term_id}` and `name:{$term_id}` keys in the `$taxonomy:$last_changed` bucket that reference the term_id
* In `clean_term_cache()` and `update_term_cache()`, respect `$_wp_suspend_cache_invalidation`
* Original term cache entries maintain BC
Adds unit tests.
Props wonderboymusic, tollmanz, boonebgorges.
Fixes#21760.
Built from https://develop.svn.wordpress.org/trunk@29915
git-svn-id: http://core.svn.wordpress.org/trunk@29668 1a063a9b-81f0-0310-95a4-ce76da25c4cd
IN clauses that are connected by OR require only a single table join. To avoid
extraneous joins, keep track of generated table aliases, and let sibling
clauses piggy-back on those aliases when possible.
Introduces WP_Tax_Query::sanitize_relation() to reduce some repeated code.
Adds unit tests to verify the JOIN consolidation, and integration tests for
cases where JOINS are being combined.
Props boonebgorges, otto42, jakub.tyrcha.
Fixes#18105.
Built from https://develop.svn.wordpress.org/trunk@29902
git-svn-id: http://core.svn.wordpress.org/trunk@29657 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Previously, tax query arguments could be joined by a single AND or OR relation.
Now, these queries can be arbitrarily nested, allowing clauses to be linked
together with multiple relations.
In a few places, WP_Query runs through a list of clauses in a tax_query in order
to set certain query vars for backward compatibility. The necessary changes have
been made to WP_Query to support this feature with the new complex structure of
tax_query. Unit tests are included for these backward compatibility fixes.
Unit tests for the new nesting syntax are included.
Props boonebgorges.
Fixes#29718. See #29738.
Built from https://develop.svn.wordpress.org/trunk@29891
git-svn-id: http://core.svn.wordpress.org/trunk@29647 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This change brings return values for failures of this sort in line with other
failed lookups in term_exists(): a null value is now returned in all cases
where the queried term is not found.
Adds unit test for the sanitization issue. Modifies existing unit test to
reflect the change in return value for empty term strings.
Props boonebgorges, georgestephanis.
Fixes#29589.
Built from https://develop.svn.wordpress.org/trunk@29865
git-svn-id: http://core.svn.wordpress.org/trunk@29625 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Using get_term_by() rather than direct SQL queries to fetch the alias term
fixes a number of issues:
* Object cache for aliased term is properly cleared after update.
* If the aliased term is in the object cache, it's served from there, saving a database query.
* Duplicate 'edit_terms' and 'edited_terms' hooks can be removed.
* Fix a PHP notice when the 'alias_of' term is not found.
* Prevent the incorrect creation of a new term group for the primary term when the 'alias_of' term is not found.
Adds unit tests for 'alias_of' functionality in both functions.
Fixes#29848.
Built from https://develop.svn.wordpress.org/trunk@29862
git-svn-id: http://core.svn.wordpress.org/trunk@29622 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In certain edge cases, such as during the automated test suite,
create_initial_taxonomies() can be called in a situation where a non-default
permastruct setting has been saved outside of wp-admin. This causes the
'hierarchical' setting for the post_tag taxonomy to remain unset, leading to
PHP notices in get_term_link().
See #29827.
Built from https://develop.svn.wordpress.org/trunk@29859
git-svn-id: http://core.svn.wordpress.org/trunk@29620 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Not having the count caused queries with 'fields' values of 'id=>name' and
'id=>slug' to return incorrect results when querying a hierarchical taxonomy
with 'hide_empty=true'.
Includes unit tests for get_terms() when using various combinations of 'fields',
'hide_empty', and 'hierarchical' arguments.
Props technical_mastermind.
Fixes#29859.
Built from https://develop.svn.wordpress.org/trunk@29845
git-svn-id: http://core.svn.wordpress.org/trunk@29608 1a063a9b-81f0-0310-95a4-ce76da25c4cd
There will be "dupes" when the function is called with `'fields' => 'all_with_object_id'`, but the objects will actually be unique due to the `object_id` addition, so they shouldn't be filtered out.
Adds unit tests. All other unit tests pass.
Fixes#11003.
Built from https://develop.svn.wordpress.org/trunk@28583
git-svn-id: http://core.svn.wordpress.org/trunk@28408 1a063a9b-81f0-0310-95a4-ce76da25c4cd
"The cache invalidation with static was introduced in r9102 with version 2.7. Multisite wasn't in core back then, so something like switch_to_blog() wasn't a concern, but now it breaks if you switch the blog in between calls to clean_term_cache."
This solution is simpler. All unit tests pass. Removes unnecessary tests linked to removed functions.
Props kovshenin.
Fixes#14485, #22526.
Built from https://develop.svn.wordpress.org/trunk@27163
git-svn-id: http://core.svn.wordpress.org/trunk@27029 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In [27108], #26903 was fixed, but only because we were using the example in the ticket, leaving out infinite depth for hierarchical taxonomies.
Adds unit tests, including `Tests_Term_getTerms::test_get_terms_seven_levels_deep()`.
Fixes#26903. Again.
Built from https://develop.svn.wordpress.org/trunk@27125
git-svn-id: http://core.svn.wordpress.org/trunk@26992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
In `_get_term_children()`, don't skip a top-level term without first including its children in the returned term list. Ironically, the call to `_get_term_children()` in `get_terms()` has a comment stating `"Make sure we show empty categories that have children."`, but it didn't work if you were retrieving top-level categories only.
All unit tests pass. Added a unit test based on the use case described in this ticket.
Fixes#26903.
Built from https://develop.svn.wordpress.org/trunk@27108
git-svn-id: http://core.svn.wordpress.org/trunk@26975 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Introduces `taxonomy_hierarchy_is_fresh()`, which is only called in `_get_term_hierarchy()`. The taxonomy's `last_changed` value is checked against the value of `wp_cache_get( 'hierarchy_last_changed', $taxonomy )`.
Adds a unit test - `Tests_Term:test_hierachy_invalidation()`.
See [27101], which makes this type of cache invalidation possible.
Fixes#14485.
Built from https://develop.svn.wordpress.org/trunk@27102
git-svn-id: http://core.svn.wordpress.org/trunk@26971 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Introduce `get_taxonomy_last_changed()`, `set_taxonomy_last_changed()`, and `post_taxonomy_is_fresh()`.
`post_taxonomy_is_fresh()` is only called in `get_object_term_cache()` - at which point the taxonomy's `last_changed` value is checked against the post's `{$taxonomy}_last_changed` value.
`set_taxonomy_last_changed()` is called whenever directory database queries are made that insert new terms or affect existing terms.
Fixes#22526.
Built from https://develop.svn.wordpress.org/trunk@27101
git-svn-id: http://core.svn.wordpress.org/trunk@26970 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* register_taxonomy: Use the same doc format for the associative array arg as used for register_post_type()
* register_taxonomy: Improve docs for _builtin, capabilities, hierarchical and rewrite args
* register_taxonomy: Use the same order in $defaults as in docblock
* register_taxonomy: Replace is_null with null ===, to be consistent
* register_post_type: Use the same order in $defaults as in docblock
* register_post_type: Improve docs for @uses and default fallbacks
And while we're on it: Whitespaces.
fixes#25150.
Built from https://develop.svn.wordpress.org/trunk@25130
git-svn-id: http://core.svn.wordpress.org/trunk@25110 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The exceptions to this are update_post_meta() and add_post_meta() which are often used by plugins in POST handlers and will continue accepting slashed data for now.
Introduce wp_upate_post_meta() and wp_add_post_meta() as unslashed alternatives to update_post_meta() and add_post_meta(). These functions could become methods in WP_Post so don't use them too heavily yet.
Remove all escape() calls from wp_xmlrpc_server. Now that core expects unslashed data this is no longer needed.
Remove addslashes(), addslashes_gpc(), add_magic_quotes() calls on data being prepared for handoff to core functions that until now expected slashed data. Adding slashes in no longer necessary.
Introduce wp_unslash() and use to it remove slashes from GPCS data before using it in core API. Almost every instance of stripslashes() in core should now be wp_unslash(). In the future (a release or three) when GPCS is no longer slashed, wp_unslash() will stop stripping slashes and simply return what is passed. At this point wp_unslash() calls can be removed from core.
Introduce wp_slash() for slashing GPCS data. This will also turn into a noop once GPCS is no longer slashed. wp_slash() should almost never be used. It is mainly of use in unit tests.
Plugins should use wp_unslash() on data being passed to core API.
Plugins should no longer slash data being passed to core. So when you get_post() and then wp_insert_post() the post data from get_post() no longer needs addslashes(). Most plugins were not bothering with this. They will magically start doing the right thing. Unfortunately, those few souls who did it properly will now have to avoid calling addslashes() for 3.6 and newer.
Use wp_kses_post() and wp_kses_data(), which expect unslashed data, instead of wp_filter_post_kses() and wp_filter_kses(), which expect slashed data. Filters are no longer passed slashed data.
Remove many no longer necessary calls to $wpdb->escape() and esc_sql().
In wp_get_referer() and wp_get_original_referer(), return unslashed data.
Remove old stripslashes() calls from WP_Widget::update() handlers. These haven't been necessary since WP_Widget.
Switch several queries over to prepare().
Expect something to break.
Props alexkingorg
see #21767
git-svn-id: http://core.svn.wordpress.org/trunk@23416 1a063a9b-81f0-0310-95a4-ce76da25c4cd
To register a column for a list table, use the new manage_taxonomies_for_{$post_type}_columns
filter. Introduces show_admin_column => true for register_taxonomy(), which automatically
displays that column on all associated post types.
props jtsternberg, SergeyBiryukov for initial patches.
fixes#21240.
git-svn-id: http://core.svn.wordpress.org/trunk@21788 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Return WP_Post from get_default_post_to_edit()
Replace all calls to get_page() with get_post()
see #21309
git-svn-id: http://core.svn.wordpress.org/trunk@21597 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Enforce this by denying the 'manage_links' capability, which hides the All Links, Add New Link, and Link Categories screens. Hide WP_Widget_Links and the UI for the default_link_category as well.
Convert all references to 'posts and links' when handling reassignment on user deletion to just 'posts'.
see #21307.
git-svn-id: http://core.svn.wordpress.org/trunk@21501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Use array_intersect_key() to keep WP_Rewrite::$extra_permastructs free of unnecessary/unknown keys + values.
git-svn-id: http://svn.automattic.com/wordpress/trunk@19779 1a063a9b-81f0-0310-95a4-ce76da25c4cd