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
This commit is contained in:
Sergey Biryukov 2021-07-10 11:15:59 +00:00
parent e304c93a58
commit c51c4ab729
2 changed files with 17 additions and 17 deletions

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -2573,11 +2573,11 @@ class wpdb {
public function get_var( $query = null, $x = 0, $y = 0 ) { public function get_var( $query = null, $x = 0, $y = 0 ) {
$this->func_call = "\$db->get_var(\"$query\", $x, $y)"; $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 ( $query ) {
if ( $this->check_current_query && $this->check_safe_collation( $query ) ) {
$this->check_current_query = false;
}
$this->query( $query ); $this->query( $query );
} }
@ -2607,11 +2607,11 @@ class wpdb {
public function get_row( $query = null, $output = OBJECT, $y = 0 ) { public function get_row( $query = null, $output = OBJECT, $y = 0 ) {
$this->func_call = "\$db->get_row(\"$query\",$output,$y)"; $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 ( $query ) {
if ( $this->check_current_query && $this->check_safe_collation( $query ) ) {
$this->check_current_query = false;
}
$this->query( $query ); $this->query( $query );
} else { } else {
return null; return null;
@ -2649,11 +2649,11 @@ class wpdb {
* @return array Database query result. Array indexed from 0 by SQL result row number. * @return array Database query result. Array indexed from 0 by SQL result row number.
*/ */
public function get_col( $query = null, $x = 0 ) { 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 ( $query ) {
if ( $this->check_current_query && $this->check_safe_collation( $query ) ) {
$this->check_current_query = false;
}
$this->query( $query ); $this->query( $query );
} }
@ -2687,11 +2687,11 @@ class wpdb {
public function get_results( $query = null, $output = OBJECT ) { public function get_results( $query = null, $output = OBJECT ) {
$this->func_call = "\$db->get_results(\"$query\", $output)"; $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 ( $query ) {
if ( $this->check_current_query && $this->check_safe_collation( $query ) ) {
$this->check_current_query = false;
}
$this->query( $query ); $this->query( $query );
} else { } else {
return null; return null;