From cf7cc2843bbf6a7038eb822173e0cafab0d243e0 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 10 Jul 2021 11:14:46 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@51396 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/wp-db.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php index c5d3b15434..f6eb404765 100644 --- a/src/wp-includes/wp-db.php +++ b/src/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;