Make WordPress Core


Ignore:
Timestamp:
11/22/2010 05:17:26 PM (14 years ago)
Author:
nacin
Message:

Revert [15688], [15689], [15691]. Try again in 3.2. see #14966.

File:
1 edited

Legend:

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

    r16459 r16535  
    362362}
    363363
    364 
     364/**
     365 * Default post information to use when populating the "Write Post" form.
     366 *
     367 * @since unknown
     368 *
     369 * @param string $post_type A post type string, defaults to 'post'.
     370 * @return object stdClass object containing all the default post data as attributes
     371 */
     372function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
     373    global $wpdb;
     374
     375    $post_title = '';
     376    if ( !empty( $_REQUEST['post_title'] ) )
     377        $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
     378
     379    $post_content = '';
     380    if ( !empty( $_REQUEST['content'] ) )
     381        $post_content = esc_html( stripslashes( $_REQUEST['content'] ));
     382
     383    $post_excerpt = '';
     384    if ( !empty( $_REQUEST['excerpt'] ) )
     385        $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
     386
     387    if ( $create_in_db ) {
     388        // Cleanup old auto-drafts more than 7 days old
     389        $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
     390        foreach ( (array) $old_posts as $delete )
     391            wp_delete_post( $delete, true ); // Force delete
     392        $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
     393        $post = get_post( $post_id );
     394    } else {
     395        $post->ID = 0;
     396        $post->post_author = '';
     397        $post->post_date = '';
     398        $post->post_date_gmt = '';
     399        $post->post_password = '';
     400        $post->post_type = $post_type;
     401        $post->post_status = 'draft';
     402        $post->to_ping = '';
     403        $post->pinged = '';
     404        $post->comment_status = get_option( 'default_comment_status' );
     405        $post->ping_status = get_option( 'default_ping_status' );
     406        $post->post_pingback = get_option( 'default_pingback_flag' );
     407        $post->post_category = get_option( 'default_category' );
     408        $post->page_template = 'default';
     409        $post->post_parent = 0;
     410        $post->menu_order = 0;
     411    }
     412
     413    $post->post_content = apply_filters( 'default_content', $post_content, $post );
     414    $post->post_title   = apply_filters( 'default_title',   $post_title, $post   );
     415    $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );
     416    $post->post_name = '';
     417
     418    return $post;
     419}
    365420
    366421/**
Note: See TracChangeset for help on using the changeset viewer.