WordPress.org

Make WordPress Core

Changeset 27073


Ignore:
Timestamp:
02/02/2014 09:46:07 PM (6 years ago)
Author:
nacin
Message:

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

props ounziw.
fixes #25604.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/wp-db.php

    r27072 r27073  
    10531053        if ( is_null( $query ) )
    10541054            return;
     1055
     1056        if ( strpos( $query, '%' ) === false ) {
     1057            _doing_it_wrong( 'wpdb::prepare', sprintf( __( 'The query argument of %s must have a placeholder.' ), 'wpdb::prepare()' ), '3.9' );
     1058        }
    10551059
    10561060        $args = func_get_args();
  • trunk/tests/phpunit/tests/db.php

    r27072 r27073  
    194194        return $modes;
    195195    }
     196
     197    /**
     198     * @ticket 25604
     199     * @expectedIncorrectUsage wpdb::prepare
     200     */
     201    function test_prepare_without_arguments() {
     202        global $wpdb;
     203        $id = 0;
     204        // This, obviously, is an incorrect prepare.
     205        $prepared = $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE id = $id", $id );
     206        $this->assertEquals( "SELECT * FROM $wpdb->users WHERE id = 0", $prepared );
     207    }
    196208}
Note: See TracChangeset for help on using the changeset viewer.