mirror of
git://develop.git.wordpress.org/
synced 2025-02-13 03:04:42 +01:00
Code Modernization: Correct the check for parent
argument in wp_insert_term()
and wp_update_term()
.
PHP 8 changes the way string to number comparisons are performed: https://wiki.php.net/rfc/string_to_number_comparison In particular, checking if a non-empty, non-numeric string is greater than zero in PHP 8 evaluates to `true`, not `false`. For `wp_insert_term()`, this resulted in a "Parent term does not exist" error for a non-numeric string, instead of discarding the value. By explicitly casting the value to `int`, we make sure to compare both values as numbers, rather than a string and a number. Follow-up to [29196], [29830], [29867]. See #50913. git-svn-id: https://develop.svn.wordpress.org/trunk@49043 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0ae6b563b6
commit
da93663d01
@ -2233,7 +2233,7 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
|
||||
);
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
if ( $args['parent'] > 0 && ! term_exists( (int) $args['parent'] ) ) {
|
||||
if ( (int) $args['parent'] > 0 && ! term_exists( (int) $args['parent'] ) ) {
|
||||
return new WP_Error( 'missing_parent', __( 'Parent term does not exist.' ) );
|
||||
}
|
||||
|
||||
@ -3001,7 +3001,7 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) {
|
||||
return new WP_Error( 'empty_term_name', __( 'A name is required for this term.' ) );
|
||||
}
|
||||
|
||||
if ( $parsed_args['parent'] > 0 && ! term_exists( (int) $parsed_args['parent'] ) ) {
|
||||
if ( (int) $parsed_args['parent'] > 0 && ! term_exists( (int) $parsed_args['parent'] ) ) {
|
||||
return new WP_Error( 'missing_parent', __( 'Parent term does not exist.' ) );
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user