diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php index cdea417c97..215494fe6e 100644 --- a/src/wp-includes/wp-db.php +++ b/src/wp-includes/wp-db.php @@ -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 diff --git a/tests/phpunit/tests/db.php b/tests/phpunit/tests/db.php index d6430e707d..db4d6a25dc 100644 --- a/tests/phpunit/tests/db.php +++ b/tests/phpunit/tests/db.php @@ -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 ); + } }