Database: Restore numbered placeholders in wpdb::prepare().

[41496] removed support for numbered placeholders in queries send through `wpdb::prepare()`, which, despite being undocumented, were quite commonly used.

This change restores support for numbered placeholders (as well as a subset of placeholder formatting), while also adding extra checks to ensure the correct number of arguments are being passed to `wpdb::prepare()`, given the number of placeholders.

See #41925.



git-svn-id: https://develop.svn.wordpress.org/trunk@42056 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2017-10-31 11:59:43 +00:00
parent 15f74e83fa
commit a39d599adf
9 changed files with 492 additions and 53 deletions

View File

@@ -1218,22 +1218,24 @@ class Tests_Comment_Query extends WP_UnitTestCase {
* @ticket 35513
*/
public function test_search_int_0_should_not_be_ignored() {
global $wpdb;
$q = new WP_Comment_Query();
$q->query( array(
'search' => 0,
) );
$this->assertContains( "comment_author LIKE '%0%'", $q->request );
$this->assertContains( "comment_author LIKE '%0%'", $wpdb->remove_placeholder_escape( $q->request ) );
}
/**
* @ticket 35513
*/
public function test_search_string_0_should_not_be_ignored() {
global $wpdb;
$q = new WP_Comment_Query();
$q->query( array(
'search' => '0',
) );
$this->assertContains( "comment_author LIKE '%0%'", $q->request );
$this->assertContains( "comment_author LIKE '%0%'", $wpdb->remove_placeholder_escape( $q->request ) );
}
public function test_orderby_default() {