From c51c4ab7294fc6d3ceeaf20a52f3444cfebcbd71 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 10 Jul 2021 11:15:59 +0000 Subject: [PATCH] Code Modernization: Only check collation in `wpdb` methods if the query is not empty. This avoids a deprecation notice on PHP 8.1 caused by passing `null` instead of a string to `ltrim()` in `wpdb::check_safe_collation()`, and maintains the current behaviour. Follow-up to [30345], [32162], [33455]. See #53635. Built from https://develop.svn.wordpress.org/trunk@51396 git-svn-id: http://core.svn.wordpress.org/trunk@51007 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/version.php | 2 +- wp-includes/wp-db.php | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/wp-includes/version.php b/wp-includes/version.php index 1c127f70fb..c3194ab78f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51395'; +$wp_version = '5.9-alpha-51396'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index c5d3b15434..f6eb404765 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -2573,11 +2573,11 @@ class wpdb { public function get_var( $query = null, $x = 0, $y = 0 ) { $this->func_call = "\$db->get_var(\"$query\", $x, $y)"; - if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { - $this->check_current_query = false; - } - if ( $query ) { + if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { + $this->check_current_query = false; + } + $this->query( $query ); } @@ -2607,11 +2607,11 @@ class wpdb { public function get_row( $query = null, $output = OBJECT, $y = 0 ) { $this->func_call = "\$db->get_row(\"$query\",$output,$y)"; - if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { - $this->check_current_query = false; - } - if ( $query ) { + if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { + $this->check_current_query = false; + } + $this->query( $query ); } else { return null; @@ -2649,11 +2649,11 @@ class wpdb { * @return array Database query result. Array indexed from 0 by SQL result row number. */ public function get_col( $query = null, $x = 0 ) { - if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { - $this->check_current_query = false; - } - if ( $query ) { + if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { + $this->check_current_query = false; + } + $this->query( $query ); } @@ -2687,11 +2687,11 @@ class wpdb { public function get_results( $query = null, $output = OBJECT ) { $this->func_call = "\$db->get_results(\"$query\", $output)"; - if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { - $this->check_current_query = false; - } - if ( $query ) { + if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { + $this->check_current_query = false; + } + $this->query( $query ); } else { return null;