From 256272e534f4085a419a56eed5e80ecb435432b1 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Wed, 14 Jun 2023 23:51:22 +0000 Subject: [PATCH] Taxonomy: Prevent deprecation notices clearing terms. 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 --- wp-includes/taxonomy.php | 6 ++++-- wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 71280f0437..35031e3bef 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -2737,7 +2737,7 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { * @param int $object_id The object to relate to. * @param string|int|array $terms A single term slug, single term ID, or array of either term slugs or IDs. * Will replace all existing related terms in this taxonomy. Passing an - * empty value will remove all related terms. + * empty array will remove all related terms. * @param string $taxonomy The context in which to relate the term to the object. * @param bool $append Optional. If false will delete difference of terms. Default false. * @return array|WP_Error Term taxonomy IDs of the affected terms or WP_Error on failure. @@ -2751,7 +2751,9 @@ function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) ); } - if ( ! is_array( $terms ) ) { + if ( empty( $terms ) ) { + $terms = array(); + } elseif ( ! is_array( $terms ) ) { $terms = array( $terms ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index bd5cd5f751..474dc5846b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-55920'; +$wp_version = '6.3-alpha-55921'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.