From d16b885730027a25e01614235869d6b232edff15 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Mon, 2 Oct 2017 02:44:48 +0000 Subject: [PATCH] Database: Fix some PHP errors introduced in [41662]. PHP < 5.4 requires a `$matches` parameter to be passed to `preg_match_all()` `wpdb::prepare()` can be called before translations are loaded, so needs appropriate `wp_load_translations_early()` calls. See #42040. git-svn-id: https://develop.svn.wordpress.org/trunk@41663 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/wp-db.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php index 76b6574453..8787c991be 100644 --- a/src/wp-includes/wp-db.php +++ b/src/wp-includes/wp-db.php @@ -1230,6 +1230,7 @@ class wpdb { // This is not meant to be foolproof -- but it will catch obviously incorrect usage. if ( strpos( $query, '%' ) === false ) { + wp_load_translations_early(); _doing_it_wrong( 'wpdb::prepare', sprintf( __( 'The query argument of %s must have a placeholder.' ), 'wpdb::prepare()' ), '3.9.0' ); } @@ -1243,6 +1244,7 @@ class wpdb { foreach ( $args as $arg ) { if ( ! is_scalar( $arg ) && ! is_null( $arg ) ) { + wp_load_translations_early(); _doing_it_wrong( 'wpdb::prepare', sprintf( __( 'Unsupported value type (%s).' ), gettype( $arg ) ), '4.8.2' ); } } @@ -1254,9 +1256,10 @@ class wpdb { $query = preg_replace( '/%(?:%|$|([^dsF]))/', '%%\\1', $query ); // escape any unescaped percents // Count the number of valid placeholders in the query - $placeholders = preg_match_all( '/(^|[^%]|(%%)+)%[sdF]/', $query ); + $placeholders = preg_match_all( '/(^|[^%]|(%%)+)%[sdF]/', $query, $matches ); if ( count ( $args ) !== $placeholders ) { + wp_load_translations_early(); _doing_it_wrong( 'wpdb::prepare', sprintf( __( 'The query does not contain the correct number of placeholders (%d) for the number of arguments passed (%d).' ), $placeholders,