From 243e75eb416657464870ea9092c8750b7221b8fc Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Fri, 10 Sep 2021 15:03:57 +0000 Subject: [PATCH] Code Modernization: Fix null to non-nullable deprecation in `term_exists()`. The `term_exists()` function expects a string or an integer for the `$term` parameter. It validates for integer, but not for string or `null`. One of the pre-existing test cases, passed `null` to the function, leading to a `trim(): Passing null to parameter #1 ($string) of type string is deprecated` notice on PHP 8.1. Fixed now by doing a cursory check on the variable at the start of the function and bowing out early in case the `$term` is `null`. The issue was discovered via and is already covered by the `Tests_TermExists::test_term_exists_unknown()` test method. Follow-up to [15220]. [38716]. Props jrf, hellofromTonya. See #53635. Built from https://develop.svn.wordpress.org/trunk@51796 git-svn-id: http://core.svn.wordpress.org/trunk@51403 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 4 ++++ wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 4014a62655..531a6f537b 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1480,6 +1480,10 @@ function unregister_term_meta( $taxonomy, $meta_key ) { function term_exists( $term, $taxonomy = '', $parent = null ) { global $wpdb; + if ( null === $term ) { + return null; + } + $select = "SELECT term_id FROM $wpdb->terms as t WHERE "; $tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE "; diff --git a/wp-includes/version.php b/wp-includes/version.php index b97456cec8..1633986cd2 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51795'; +$wp_version = '5.9-alpha-51796'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.