Make WordPress Core


Ignore:
Timestamp:
02/14/2013 10:51:06 PM (12 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/ms-functions.php

    r23412 r23416  
    280280 */
    281281function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) {
    282     $domain         = addslashes( $domain );
    283     $weblog_title   = addslashes( $weblog_title );
    284 
    285282    if ( empty($path) )
    286283        $path = '/';
     
    583580    $blogname = apply_filters( 'newblogname', $blogname );
    584581
    585     $blog_title = stripslashes(  $blog_title );
     582    $blog_title = $blog_title;
    586583
    587584    if ( empty( $blog_title ) )
     
    636633
    637634    $key = substr( md5( time() . rand() . $domain ), 0, 16 );
    638     $meta = serialize($meta);
    639     $domain = $wpdb->escape($domain);
    640     $path = $wpdb->escape($path);
    641     $title = $wpdb->escape($title);
     635    $meta = serialize( $meta );
    642636
    643637    $wpdb->insert( $wpdb->signups, array(
     
    652646    ) );
    653647
    654     wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta);
     648    wpmu_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta );
    655649}
    656650
     
    842836
    843837    $meta = maybe_unserialize($signup->meta);
    844     $user_login = $wpdb->escape($signup->user_login);
    845     $user_email = $wpdb->escape($signup->user_email);
     838    $user_login = $signup->user_login;
     839    $user_email = $signup->user_email;
    846840    $password = wp_generate_password( 12, false );
    847841
     
    11601154        update_option( 'upload_path', get_blog_option( $current_site->blog_id, 'upload_path' ) );
    11611155
    1162     update_option( 'blogname', stripslashes( $blog_title ) );
     1156    update_option( 'blogname', $blog_title );
    11631157    update_option( 'admin_email', '' );
    11641158
     
    12171211        return false;
    12181212
    1219     $welcome_email = stripslashes( get_site_option( 'welcome_email' ) );
     1213    $welcome_email = get_site_option( 'welcome_email' );
    12201214    if ( $welcome_email == false )
    1221         $welcome_email = stripslashes( __( 'Dear User,
     1215        $welcome_email = __( 'Dear User,
    12221216
    12231217Your new SITE_NAME site has been successfully set up at:
     
    12311225We hope you enjoy your new site. Thanks!
    12321226
    1233 --The Team @ SITE_NAME' ) );
     1227--The Team @ SITE_NAME' );
    12341228
    12351229    $url = get_blogaddress_by_id($blog_id);
     
    12551249        $current_site->site_name = 'WordPress';
    12561250
    1257     $subject = apply_filters( 'update_welcome_subject', sprintf(__('New %1$s Site: %2$s'), $current_site->site_name, stripslashes( $title ) ) );
     1251    $subject = apply_filters( 'update_welcome_subject', sprintf(__('New %1$s Site: %2$s'), $current_site->site_name, $title ) );
    12581252    wp_mail($user->user_email, $subject, $message, $message_headers);
    12591253    return true;
     
    15101504    global $wpdb;
    15111505    $user = get_userdata( (int) $user_id );
    1512     $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '',$_SERVER['REMOTE_ADDR'] ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) );
     1506    $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) );
    15131507}
    15141508
Note: See TracChangeset for help on using the changeset viewer.