Make WordPress Core


Ignore:
Timestamp:
10/31/2017 11:59:43 AM (8 years ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

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

    r40603 r42056  
    365365
    366366    if ( $delete_all ) {
    367         $value_clause = '';
    368367        if ( '' !== $meta_value && null !== $meta_value && false !== $meta_value ) {
    369             $value_clause = $wpdb->prepare( " AND meta_value = %s", $meta_value );
    370         }
    371 
    372         $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s $value_clause", $meta_key ) );
     368            $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s AND meta_value = %s", $meta_key, $meta_value ) );
     369        } else {
     370            $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) );
     371        }
    373372    }
    374373
Note: See TracChangeset for help on using the changeset viewer.