Opened 8 years ago
Last modified 3 years ago
#39678 new defect (bug)
get_term_by slug with "0" as value
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | Taxonomy | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
Executing this code
get_term_by('slug','0','taxonomy_name')
my expectations were to obtain a taxonomy term, considering that one actually exists in my database, but instead the function returned false due to the PHP empty function returning true (see https://core.trac.wordpress.org/browser/tags/4.7/src/wp-includes/taxonomy.php#L844).
The empty function behaves according to documentation (http://php.net/manual/en/function.empty.php) but the string "0" should be accepted to be searched if it is possible to use it to create a taxonomy term.
Change History (2)
This ticket was mentioned in PR #1654 on WordPress/wordpress-develop by costdev.
3 years ago
#1
- Keywords has-patch has-unit-tests added
wp_insert_term()
andwp_update_term()
did not allow a term to be given a slug of(string) '0'
.This was due to:
(int) 0
into(string) '0'
.empty()
to check for an empty value; this returnstrue
for(string) '0'
.This gave a false sense of security, as it correctly captured a disallowed value of
(int) 0
and generated a slug from the term name. Unfortunately, this process also incorrectly prevented a value of(string) '0'
, which the docs suggest is an allowed value.This patch:
(string) '0'
prior to sanitization and adds this to an existing conditional (only in one case).'0' === $args['slug']
,'0' !== $slug
, etc. as needed.wp_insert_term()
andwp_update_term()
.Trac ticket: https://core.trac.wordpress.org/ticket/39678