Make WordPress Core


Ignore:
Timestamp:
06/14/2023 11:49:36 PM (23 months ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r55759 r55921  
    27382738 * @param string|int|array $terms     A single term slug, single term ID, or array of either term slugs or IDs.
    27392739 *                                    Will replace all existing related terms in this taxonomy. Passing an
    2740  *                                    empty value will remove all related terms.
     2740 *                                    empty array will remove all related terms.
    27412741 * @param string           $taxonomy  The context in which to relate the term to the object.
    27422742 * @param bool             $append    Optional. If false will delete difference of terms. Default false.
     
    27522752    }
    27532753
    2754     if ( ! is_array( $terms ) ) {
     2754    if ( empty( $terms ) ) {
     2755        $terms = array();
     2756    } elseif ( ! is_array( $terms ) ) {
    27552757        $terms = array( $terms );
    27562758    }
Note: See TracChangeset for help on using the changeset viewer.