Make WordPress Core


Ignore:
Timestamp:
06/18/2004 12:22:09 AM (22 years ago)
Author:
rboren
Message:

stripslashes() elimination. Remove extra slashes during upgrade. Bugs 0000059 and 0000018

File:
1 edited

Legend:

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

    r1429 r1435  
    8989    }
    9090    return $all_options;
     91}
     92
     93function deslash($content) {
     94    // Note: \\\ inside a regex denotes a single backslash.
     95
     96    // Replace one or more backslashes followed by a single quote with
     97    // a single quote.
     98    $content = preg_replace("/\\\+'/", "'", $content);
     99
     100    // Replace one or more backslashes followed by a double quote with
     101    // a double quote.
     102    $content = preg_replace('/\\\+"/', '"', $content);
     103
     104    // Replace one or more backslashes with one backslash.
     105    $content = preg_replace("/\\\+/", "\\", $content);
     106
     107    return $content;
    91108}
    92109
     
    872889        $wpdb->query("UPDATE $wpdb->options SET `autoload` = 'no' WHERE option_name = '$fatoption'");
    873890    endforeach;
     891
     892    // Remove extraneous backslashes.
     893    $posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt FROM $wpdb->posts");
     894    if ($posts) {
     895        foreach($posts as $post) {
     896            $post_content = addslashes(deslash($post->post_content));
     897            $post_title = addslashes(deslash($post->post_title));
     898            $post_excerpt = addslashes(deslash($post->post_excerpt));
     899            $wpdb->query("UPDATE $wpdb->posts SET post_title = '$post_title', post_content = '$post_content', post_excerpt = '$post_excerpt' WHERE ID = '$post->ID'");
     900        }
     901    }
     902
     903    // Remove extraneous backslashes.
     904    $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments");
     905    if ($comments) {
     906        foreach($comments as $comment) {
     907            $comment_content = addslashes(deslash($comment->comment_content));
     908            $comment_author = addslashes(deslash($comment->comment_author));
     909            $wpdb->query("UPDATE $wpdb->comments SET comment_content = '$comment_content', comment_author = '$comment_author' WHERE comment_ID = '$comment->comment_ID'");
     910        }
     911    }
    874912}
    875913
Note: See TracChangeset for help on using the changeset viewer.