WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/10/2014 12:43:32 AM (7 years ago)
Author:
wonderboymusic
Message:

Replace all uses of like_escape() with $wpdb->esc_like().

Props miqrogroove.
See #10041.

File:
1 edited

Legend:

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

    r28305 r28712  
    466466    }
    467467
    468     $wpdb->query("UPDATE $wpdb->options SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
    469     WHERE option_name LIKE 'links_rating_image%'
    470     AND option_value LIKE 'wp-links/links-images/%'");
     468    $sql = "UPDATE $wpdb->options
     469        SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
     470        WHERE option_name LIKE %s
     471        AND option_value LIKE %s";
     472    $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( 'links_rating_image' ) . '%', $wpdb->esc_like( 'wp-links/links-images/' ) . '%' ) );
    471473
    472474    $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM $wpdb->post2cat");
     
    11011103    // 3.0 screen options key name changes.
    11021104    if ( is_main_site() && !defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
    1103         $prefix = like_escape($wpdb->base_prefix);
    1104         $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE '{$prefix}%meta-box-hidden%' OR meta_key LIKE '{$prefix}%closedpostboxes%' OR meta_key LIKE '{$prefix}%manage-%-columns-hidden%' OR meta_key LIKE '{$prefix}%meta-box-order%' OR meta_key LIKE '{$prefix}%metaboxorder%' OR meta_key LIKE '{$prefix}%screen_layout%'
    1105                      OR meta_key = 'manageedittagscolumnshidden' OR meta_key='managecategoriescolumnshidden' OR meta_key = 'manageedit-tagscolumnshidden' OR meta_key = 'manageeditcolumnshidden' OR meta_key = 'categories_per_page' OR meta_key = 'edit_tags_per_page'" );
     1105        $sql = "DELETE FROM $wpdb->usermeta
     1106            WHERE meta_key LIKE %s
     1107            OR meta_key LIKE %s
     1108            OR meta_key LIKE %s
     1109            OR meta_key LIKE %s
     1110            OR meta_key LIKE %s
     1111            OR meta_key LIKE %s
     1112            OR meta_key = 'manageedittagscolumnshidden'
     1113            OR meta_key = 'managecategoriescolumnshidden'
     1114            OR meta_key = 'manageedit-tagscolumnshidden'
     1115            OR meta_key = 'manageeditcolumnshidden'
     1116            OR meta_key = 'categories_per_page'
     1117            OR meta_key = 'edit_tags_per_page'";
     1118        $prefix = $wpdb->esc_like( $wpdb->base_prefix );
     1119        $wpdb->query( $wpdb->prepare( $sql,
     1120            $prefix . '%' . $wpdb->esc_like( 'meta-box-hidden' ) . '%',
     1121            $prefix . '%' . $wpdb->esc_like( 'closedpostboxes' ) . '%',
     1122            $prefix . '%' . $wpdb->esc_like( 'manage-'     ) . '%' . $wpdb->esc_like( '-columns-hidden' ) . '%',
     1123            $prefix . '%' . $wpdb->esc_like( 'meta-box-order'  ) . '%',
     1124            $prefix . '%' . $wpdb->esc_like( 'metaboxorder'    ) . '%',
     1125            $prefix . '%' . $wpdb->esc_like( 'screen_layout'   ) . '%'
     1126        ) );
    11061127    }
    11071128
     
    12851306        // and the corresponding transient_timeout record from table b.
    12861307        $time = time();
    1287         $wpdb->query("DELETE a, b FROM $wpdb->sitemeta a, $wpdb->sitemeta b WHERE
    1288             a.meta_key LIKE '\_site\_transient\_%' AND
    1289             a.meta_key NOT LIKE '\_site\_transient\_timeout\_%' AND
    1290             b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )
    1291             AND b.meta_value < $time");
     1308        $sql = "DELETE a, b FROM $wpdb->sitemeta a, $wpdb->sitemeta b
     1309            WHERE a.meta_key LIKE %s
     1310            AND a.meta_key NOT LIKE %s
     1311            AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )
     1312            AND b.meta_value < %d";
     1313        $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_site_transient_' ) . '%', $wpdb->esc_like ( '_site_transient_timeout_' ) . '%', $time ) );
    12921314    }
    12931315
     
    13831405function maybe_create_table($table_name, $create_ddl) {
    13841406    global $wpdb;
    1385     if ( $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name )
     1407   
     1408    $query = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $table_name ) );
     1409
     1410    if ( $wpdb->get_var( $query ) == $table_name ) {
    13861411        return true;
     1412    }
    13871413    //didn't find it try to create it.
    13881414    $wpdb->query($create_ddl);
    13891415    // we cannot directly tell that whether this succeeded!
    1390     if ( $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name )
     1416    if ( $wpdb->get_var( $query ) == $table_name ) {
    13911417        return true;
     1418    }
    13921419    return false;
    13931420}
Note: See TracChangeset for help on using the changeset viewer.