From 35ceac68f421fddea05d70464fe1706ea2eead39 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 16 Sep 2020 01:46:25 +0000 Subject: [PATCH] Code Modernization: Return an empty string from `wpdb::_real_escape()` if a non-scalar value is passed. This avoids a fatal error on PHP 8 caused by passing a non-string value to ` mysqli_real_escape_string()`, and maintains the current behaviour. See #50913, #50639. git-svn-id: https://develop.svn.wordpress.org/trunk@48980 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/wp-db.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php index 2e392d0954..9761de99a8 100644 --- a/src/wp-includes/wp-db.php +++ b/src/wp-includes/wp-db.php @@ -1159,6 +1159,10 @@ class wpdb { * @return string Escaped string. */ function _real_escape( $string ) { + if ( ! is_scalar( $string ) && ! is_null( $string ) ) { + return ''; + } + if ( $this->dbh ) { if ( $this->use_mysqli ) { $escaped = mysqli_real_escape_string( $this->dbh, $string );