diff --git a/wp-includes/version.php b/wp-includes/version.php index 7289f20059..9cc4371360 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.6-alpha-48980'; +$wp_version = '5.6-alpha-48981'; /** * 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 9761de99a8..ebcadb6ef0 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -1369,7 +1369,9 @@ class wpdb { // Count the number of valid placeholders in the query. $placeholders = preg_match_all( "/(^|[^%]|(%%)+)%($allowed_format)?[sdF]/", $query, $matches ); - if ( count( $args ) !== $placeholders ) { + $args_count = count( $args ); + + if ( $args_count !== $placeholders ) { if ( 1 === $placeholders && $passed_as_array ) { // If the passed query only expected one argument, but the wrong number of arguments were sent as an array, bail. wp_load_translations_early(); @@ -1392,10 +1394,22 @@ class wpdb { /* translators: 1: Number of placeholders, 2: Number of arguments passed. */ __( 'The query does not contain the correct number of placeholders (%1$d) for the number of arguments passed (%2$d).' ), $placeholders, - count( $args ) + $args_count ), '4.8.3' ); + + /* + * If we don't have enough arguments to match the placeholders, + * return an empty string to avoid a fatal error on PHP 8. + */ + if ( $args_count < $placeholders ) { + $max_numbered_placeholder = ! empty( $matches[3] ) ? max( array_map( 'intval', $matches[3] ) ) : 0; + + if ( ! $max_numbered_placeholder || $args_count < $max_numbered_placeholder ) { + return ''; + } + } } }