Make WordPress Core

02/14/2013 10:51:06 PM (11 years ago)

Change all core API to expect unslashed rather than slashed arguments.

The exceptions to this are update_post_meta() and add_post_meta() which are often used by plugins in POST handlers and will continue accepting slashed data for now.

Introduce wp_upate_post_meta() and wp_add_post_meta() as unslashed alternatives to update_post_meta() and add_post_meta(). These functions could become methods in WP_Post so don't use them too heavily yet.

Remove all escape() calls from wp_xmlrpc_server. Now that core expects unslashed data this is no longer needed.

Remove addslashes(), addslashes_gpc(), add_magic_quotes() calls on data being prepared for handoff to core functions that until now expected slashed data. Adding slashes in no longer necessary.

Introduce wp_unslash() and use to it remove slashes from GPCS data before using it in core API. Almost every instance of stripslashes() in core should now be wp_unslash(). In the future (a release or three) when GPCS is no longer slashed, wp_unslash() will stop stripping slashes and simply return what is passed. At this point wp_unslash() calls can be removed from core.

Introduce wp_slash() for slashing GPCS data. This will also turn into a noop once GPCS is no longer slashed. wp_slash() should almost never be used. It is mainly of use in unit tests.

Plugins should use wp_unslash() on data being passed to core API.

Plugins should no longer slash data being passed to core. So when you get_post() and then wp_insert_post() the post data from get_post() no longer needs addslashes(). Most plugins were not bothering with this. They will magically start doing the right thing. Unfortunately, those few souls who did it properly will now have to avoid calling addslashes() for 3.6 and newer.

Use wp_kses_post() and wp_kses_data(), which expect unslashed data, instead of wp_filter_post_kses() and wp_filter_kses(), which expect slashed data. Filters are no longer passed slashed data.

Remove many no longer necessary calls to $wpdb->escape() and esc_sql().

In wp_get_referer() and wp_get_original_referer(), return unslashed data.

Remove old stripslashes() calls from WP_Widget::update() handlers. These haven't been necessary since WP_Widget.

Switch several queries over to prepare().

Expect something to break.

Props alexkingorg
see #21767

1 edited


  • trunk/wp-admin/includes/upgrade.php

    r23265 r23416  
    134134        if ( empty($first_post) )
    135             $first_post = stripslashes( __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ) );
     135            $first_post = __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' );
    137137        $first_post = str_replace( "SITE_URL", esc_url( network_home_url() ), $first_post );
    637637    foreach ( $users as $user ) :
    638638        if ( !empty( $user->user_firstname ) )
    639             update_user_meta( $user->ID, 'first_name', $wpdb->escape($user->user_firstname) );
     639            update_user_meta( $user->ID, 'first_name', $user->user_firstname );
    640640        if ( !empty( $user->user_lastname ) )
    641             update_user_meta( $user->ID, 'last_name', $wpdb->escape($user->user_lastname) );
     641            update_user_meta( $user->ID, 'last_name', $user->user_lastname );
    642642        if ( !empty( $user->user_nickname ) )
    643             update_user_meta( $user->ID, 'nickname', $wpdb->escape($user->user_nickname) );
     643            update_user_meta( $user->ID, 'nickname', $user->user_nickname );
    644644        if ( !empty( $user->user_level ) )
    645645            update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );
    646646        if ( !empty( $user->user_icq ) )
    647             update_user_meta( $user->ID, 'icq', $wpdb->escape($user->user_icq) );
     647            update_user_meta( $user->ID, 'icq', $user->user_icq );
    648648        if ( !empty( $user->user_aim ) )
    649             update_user_meta( $user->ID, 'aim', $wpdb->escape($user->user_aim) );
     649            update_user_meta( $user->ID, 'aim', $user->user_aim );
    650650        if ( !empty( $user->user_msn ) )
    651             update_user_meta( $user->ID, 'msn', $wpdb->escape($user->user_msn) );
     651            update_user_meta( $user->ID, 'msn', $user->user_msn );
    652652        if ( !empty( $user->user_yim ) )
    653             update_user_meta( $user->ID, 'yim', $wpdb->escape($user->user_icq) );
     653            update_user_meta( $user->ID, 'yim', $user->user_icq );
    654654        if ( !empty( $user->user_description ) )
    655             update_user_meta( $user->ID, 'description', $wpdb->escape($user->user_description) );
     655            update_user_meta( $user->ID, 'description', $user->user_description );
    657657        if ( isset( $user->user_idmode ) ):
    855855            $cat_id = (int) $category->cat_id;
    856856            $term_id = 0;
    857             $name = $wpdb->escape($category->cat_name);
     857            $name = $category->cat_name;
    858858            $slug = sanitize_title($name);
    859859            $term_group = 0;
Note: See TracChangeset for help on using the changeset viewer.