WordPress.org

Make WordPress Core

Ticket #1595: prerendering__functions-post.php.diff

File prerendering__functions-post.php.diff, 3.1 KB (added by markjaquith, 10 years ago)

for WP 1.6 SVN

  • functions-post.php

     
    77 */ 
    88function wp_insert_post($postarr = array()) { 
    99        global $wpdb, $allowedtags, $user_ID; 
     10         
     11        // for content prerendering, to simulate the loop 
     12        global $post, $id; 
    1013 
    1114        // export array as variables 
    1215        extract($postarr); 
     
    1518        $update = false; 
    1619        if ( !empty($ID) ) { 
    1720                $update = true; 
    18                 $post = & get_post($ID); 
    19                 $previous_status = $post->post_status; 
     21                $previous_version = & get_post($ID); 
     22                $previous_status = $previous_version->post_status; 
    2023        } 
    2124 
    2225        // Get the basics. 
     
    104107                        $post_name = $alt_post_name; 
    105108                } 
    106109        } 
     110         
     111        /* WP Content Prerendering by Mark Jaquith */ 
     112        // In order to maintain backwards compatability with plugins that may be designed to be run from within the loop, we 
     113        // will now "simulate" the conditions of the loop, so that all expected global variables are availiable to the filters. 
     114        $post = $previous_version; 
     115        $fields = array( 
     116                'post_author',  'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 
     117                'post_status', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 
     118                'post_modified', 'post_modified_gmt', 'post_parent','menu_order' 
     119                ); 
    107120 
     121        // creating the post object, as it would look in the loop 
     122        foreach ( $fields as $field ) { 
     123                $post->$field = $$field;         
     124        } 
     125        $post->ID = $post_ID; 
     126        $id = $post_ID; 
     127         
     128        $post_content_filtered = apply_filters('the_content_filtered', $post_content); 
     129 
     130 
    108131        if ($update) { 
    109132                $postquery = 
    110133                        "UPDATE $wpdb->posts SET 
     
    112135                        post_date = '$post_date', 
    113136                        post_date_gmt = '$post_date_gmt', 
    114137                        post_content = '$post_content', 
     138                        post_content_filtered = '$post_content_filtered', 
    115139                        post_title = '$post_title', 
    116140                        post_excerpt = '$post_excerpt', 
    117141                        post_status = '$post_status', 
     
    128152        } else { 
    129153                $postquery = 
    130154                        "INSERT INTO $wpdb->posts 
    131                         (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent, menu_order) 
     155                        (ID, post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent, menu_order) 
    132156                        VALUES 
    133                         ('$post_ID', '$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$post_excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order')"; 
     157                        ('$post_ID', '$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_content_filtered', '$post_title', '$post_excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order')"; 
    134158        } 
    135159         
    136160        $result = $wpdb->query($postquery);