Throw an incorrect usage notice when the query argument of wpdb::prepare() does not include a placeholder.

props ounziw.
fixes #25604.


git-svn-id: https://develop.svn.wordpress.org/trunk@27073 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2014-02-02 21:46:07 +00:00
parent 0558df56ce
commit 435df55864
2 changed files with 16 additions and 0 deletions

View File

@ -1053,6 +1053,10 @@ class wpdb {
if ( is_null( $query ) )
return;
if ( strpos( $query, '%' ) === false ) {
_doing_it_wrong( 'wpdb::prepare', sprintf( __( 'The query argument of %s must have a placeholder.' ), 'wpdb::prepare()' ), '3.9' );
}
$args = func_get_args();
array_shift( $args );
// If args were passed as an array (as in vsprintf), move them up

View File

@ -193,4 +193,16 @@ class Tests_DB extends WP_UnitTestCase {
unset( $modes[ $pos ] );
return $modes;
}
/**
* @ticket 25604
* @expectedIncorrectUsage wpdb::prepare
*/
function test_prepare_without_arguments() {
global $wpdb;
$id = 0;
// This, obviously, is an incorrect prepare.
$prepared = $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = $id", $id );
$this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 0", $prepared );
}
}