Make WordPress Core

Ticket #14966: 14966.2.diff

File 14966.2.diff, 20.5 KB (added by jorbin, 15 years ago)
  • wp-includes/taxonomy.php

     
    28282828
    28292829        return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);
    28302830}
    2831 
    2832 
    2833 /**
    2834  * {@internal Missing Short Description}}
    2835  *
    2836  * @since unknown
    2837  *
    2838  * @param unknown_type $post_id
    2839  * @return unknown
    2840  */
    2841 function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
    2842         return get_terms_to_edit( $post_id, $taxonomy);
    2843 }
    2844 
    2845 /**
    2846  * {@internal Missing Short Description}}
    2847  *
    2848  * @since unknown
    2849  *
    2850  * @param unknown_type $post_id
    2851  * @return unknown
    2852  */
    2853 function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
    2854         $post_id = (int) $post_id;
    2855         if ( !$post_id )
    2856                 return false;
    2857 
    2858         $tags = wp_get_post_terms($post_id, $taxonomy, array());
    2859 
    2860         if ( !$tags )
    2861                 return false;
    2862 
    2863         if ( is_wp_error($tags) )
    2864                 return $tags;
    2865 
    2866         foreach ( $tags as $tag )
    2867                 $tag_names[] = $tag->name;
    2868         $tags_to_edit = join( ',', $tag_names );
    2869         $tags_to_edit = esc_attr( $tags_to_edit );
    2870         $tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy );
    2871 
    2872         return $tags_to_edit;
    2873 }
  • wp-includes/post.php

     
    47164716
    47174717
    47184718/**
    4719  * Default post information to use when populating the "Write Post" form.
     4719 * Returns or echos a form containing a post box.
    47204720 *
    4721  * @since unknown
     4721 * Used for the QuickPress dashboard module.
    47224722 *
    4723  *@param string A post type string, defaults to 'post'.
    4724  * @return object stdClass object containing all the default post data as attributes
     4723 * @since 3.1.0
     4724 *
     4725 * @param array $args Arguments.
    47254726 */
    4726 function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
    4727         global $wpdb;
     4727function wp_quickpress_form( $args = array() ) {
     4728        $defaults = array(
     4729                'form_id' => '',
     4730                'action' => admin_url( 'post.php' ),
     4731                'post' => null, // Post object, ID, or null.
     4732                'post_type' => null, // Post type. Optional. Overridden if 'post' parameter is specified.
     4733                'fields' => null, // Array of fields.
     4734                'submit_fields' => null, // Array of submit, hidden, and publishing inputs.
     4735                'tabindex' => false, // @todo Can we just kill tabindex?
     4736                'capability' => 'edit_posts',
     4737                'submit_class' => 'submit',
     4738                'publish_action_container' => 'span',
     4739                'publish_action_id' => 'publishing-action',
     4740                'submit_fields_container' => 'p',
     4741                'submit_fields_container_class' => 'submit',
     4742        );
    47284743
    4729         $post_title = '';
    4730         if ( !empty( $_REQUEST['post_title'] ) )
    4731                 $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
     4744        $args = wp_parse_args( $args, $defaults );
    47324745
    4733         $post_content = '';
    4734         if ( !empty( $_REQUEST['content'] ) )
    4735                 $post_content = esc_html( stripslashes( $_REQUEST['content'] ));
     4746        // @todo Kill the cap check and arg. Stick to pure presentation only.
     4747        // We can still handle them on a field-by-field basis.
     4748        if ( ! current_user_can( $args['capability'] ) ) {
     4749                do_action( 'quickpress_form_no_form', $args );
     4750                return;
     4751        }
    47364752
    4737         $post_excerpt = '';
    4738         if ( !empty( $_REQUEST['excerpt'] ) )
    4739                 $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
     4753        if (! function_exists('get_terms_to_edit') )
     4754                require_once (ABSPATH . 'wp-admin/includes/taxonomy.php');
    47404755
    4741         if ( $create_in_db ) {
    4742                 // Cleanup old auto-drafts more than 7 days old
    4743                 $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
    4744                 foreach ( (array) $old_posts as $delete )
    4745                         wp_delete_post( $delete, true ); // Force delete
    4746                 $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
    4747                 $post = get_post( $post_id );
     4756        if (! function_exists('get_default_post_to_edit') )
     4757                require_once (ABSPATH . 'wp-admin/includes/post.php');
     4758
     4759        if ( empty( $args['post'] ) ) {
     4760                if ( null === $args['post_type'] )
     4761                        $args['post_type'] = 'post';
     4762                $args['post'] = 0;
    47484763        } else {
    4749                 $post->ID = 0;
    4750                 $post->post_author = '';
    4751                 $post->post_date = '';
    4752                 $post->post_date_gmt = '';
    4753                 $post->post_password = '';
    4754                 $post->post_type = $post_type;
    4755                 $post->post_status = 'draft';
    4756                 $post->to_ping = '';
    4757                 $post->pinged = '';
    4758                 $post->comment_status = get_option( 'default_comment_status' );
    4759                 $post->ping_status = get_option( 'default_ping_status' );
    4760                 $post->post_pingback = get_option( 'default_pingback_flag' );
    4761                 $post->post_category = get_option( 'default_category' );
    4762                 $post->page_template = 'default';
    4763                 $post->post_parent = 0;
    4764                 $post->menu_order = 0;
     4764                $post = get_post( $args['post'] );
     4765                $args['post_type'] = $post->post_type;
    47654766        }
    47664767
    4767         $post->post_content = apply_filters( 'default_content', $post_content, $post );
    4768         $post->post_title   = apply_filters( 'default_title',   $post_title, $post   );
    4769         $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );
    4770         $post->post_name = '';
     4768        $post_type_obj = get_post_type_object( $args['post_type'] );
    47714769
    4772         return $post;
    4773 }
    4774 
    4775 /**
    4776  * Returns or echos a form containing a post box.
    4777  *
    4778  * Used for the QuickPress dashboard module.
    4779  *
    4780  * @since 3.1.0
    4781  *
    4782  * @param array $args Arguments.
    4783  * @param string $post_type Post type.
    4784  */
    4785 function wp_quickpress_form( $args = array(), $post_type = 'post'){
    4786         global $post_ID;
    4787 
    4788         $fields = array(
     4770        // @todo Clean these up still. Arrays?
     4771        $default_fields = array(
    47894772                'title' => array(
    47904773                        'capability' => '', // Capability to check before outputing field
    4791                         'output' => '<h4 id="%s-title"><label for="title">'. __('Title') .'</label></h4>
     4774                        'output' => '<h4 id="%1$s-title"><label for="title">'. __('Title') .'</label></h4>
    47924775                <div class="input-text-wrap">
    4793                         <input type="text" name="post_title" id="%s-title" tabindex="%d" autocomplete="off" value="'. esc_attr( $post->post_title ).'" />
     4776                        <input type="text" name="post_title" id="%1$s-title" tabindex="%2$d" autocomplete="off" value="' . ( $post && esc_attr( $post->post_title ) ) . '" />
    47944777                </div>'
    47954778                ),
     4779                // @todo This needs JS enqueued to work.
    47964780                'media_buttons' => array(
    47974781                        'capability' => 'upload_files',
    4798                         'output' => '<div id="%s-media-buttons" class="hide-if-no-js">'. get_media_buttons() .'</div>',
     4782                        'output' => '<div id="%1$s-media-buttons" class="hide-if-no-js">'. get_media_buttons() .'</div>',
    47994783                ),
     4784                // @todo The TinyMCE stuff should disappear into a hook, like the ajax spinner.
    48004785                'content' => array(
    48014786                        'capability' => '',
    4802                         'output' => '<h4 id="%s-content-label"><label for="content">'. __('Content') .'</label></h4>
     4787                        'output' => '<h4 id="%1$s-content-label"><label for="content">'. __('Content') .'</label></h4>
    48034788                <div class="textarea-wrap">
    4804                         <textarea name="content" id="%s-content" class="mceEditor" rows="3" cols="15" tabindex="%d">'. $post->post_content.'</textarea>
     4789                        <textarea name="content" id="%1$s-content" class="mceEditor" rows="3" cols="15" tabindex="%2$d">' . ( $post && $post->post_content ) . '</textarea>
    48054790                </div>
    4806                         '."     <script type='text/javascript'>edCanvas = document.getElementById('content');edInsertContent = null;</script>
     4791                        '."     <script type='text/javascript'>edCanvas = document.getElementById('%1$s-content');edInsertContent = null;</script>
    48074792                "
    4808 
    48094793                ),
    48104794                'tags' => array(
    48114795                        'capability' =>'',
    48124796                        'output' => '
    4813                         <h4><label for="%s-tags-input">'. __('Tags') .'</label></h4>
     4797                        <h4><label for="%1$s-tags-input">'. __( 'Tags' ) .'</label></h4>
    48144798                        <div class="input-text-wrap">
    4815                                 <input type="text" name="%s-tags_input" id="tags-input" tabindex="%d" value="'. get_tags_to_edit( $post->ID ) .'" />
    4816                         </div>
    4817 '
     4799                                <input type="text" name="%1$s-tags_input" id="tags-input" tabindex="%2$d" value="' . ( $post && get_tags_to_edit( $post->ID ) ) . '" />
     4800                        </div>'
    48184801                ),
    4819 
    48204802        );
    48214803
    4822         $hidden_fields = array(
    4823                 'action' => '<input type="hidden" name="action" id="quickpost-action" value="'.$post_type.'-quickpress-save" />',
    4824                 'post_id' => '<input type="hidden" name="quickpress_post_ID" value="'. $post_ID .'" />',
    4825                 'post_type' => '<input type="hidden" name="post_type" value="'.$post_type.'" />',
    4826         );
     4804        if ( null === $args['fields'] ) {
     4805                $fields = $default_fields;
     4806        } else {
     4807                $fields = array();
     4808                foreach ( $args['fields'] as $key => $value ) {
     4809                        if ( true === $value ) // i.e. tags => true
     4810                                $fields[] = $default_fields[ $key ];
     4811                        elseif ( is_string( $value ) ) // i.e. array( 'tags' )
     4812                                $fields[] = $default_fields[ $value ];
     4813                        else
     4814                                $fields[] = $value;
     4815                }
     4816        }
     4817        // Sync this so filters are given correct information.
     4818        $args['fields'] = $fields;
    48274819
    4828         $submit_fields = array(
    4829                 'save' => '<input type="submit" name="save" id="save-post" class="button" tabindex="%s" value="'.  esc_attr('Save Draft') .'" />',
    4830                 'reset' => '<input type="reset" tabindex="%s" value="'. esc_attr( 'Reset' ).'" class="button" />',
     4820        $publishing_action = current_user_can( $post_type_obj->cap->publish_posts ) ? __( 'Publish' ) : __( 'Submit for Review' );
     4821
     4822        // These are keyed by input name.
     4823        // Accepted keys: type, value, id (defaults to none).
     4824        // These are also accepted for non-hidden inputs:
     4825        // primary (defaults to false), class (defaults to 'button', except for the primary button, when it is 'button-primary'),
     4826        // tabindex (defaults to true), accesskey (defaults to none).
     4827        $default_submit_fields = array(
     4828                'action'    => array( 'type' => 'hidden', 'id' => 'quickpost-action', 'value' => $post_type . '-quickpress-save' ),
     4829                'quickpress_post_ID' => array( 'type' => 'hidden', 'value' => $post_ID ),
     4830                'post_type' => array( 'type' => 'hidden', 'value' => $post_type ),
     4831                'save'      => array( 'type' => 'submit', 'value' => __( 'Save Draft' ) ),
     4832                'reset'     => array( 'type' => 'reset',  'value' => __( 'Reset' ) ),
     4833                'submit'    => array( 'type' => 'submit', 'primary' => true, 'accesskey' => 'p', 'value' => $publishing_action ),
    48314834        );
    48324835
    4833         $publishing_action = current_user_can('publish_posts') ? esc_attr('Publish') : esc_attr('Submit for Review');
     4836        if ( null === $args['submit_fields'] ) {
     4837                $submit_fields = $default_submit_fields;
     4838        } else {
     4839                $submit_fields = array();
     4840                foreach ( $args['submit_fields'] as $key => $value ) {
     4841                        // @todo If this is going to work like this, then the hidden/submit fields need to be split back up.
     4842                        if ( true === $value ) // i.e. tags => true
     4843                                $submit_fields[] = $default_submit_fields[ $key ];
     4844                        elseif ( is_string( $value ) ) // i.e. array( 'tags' )
     4845                                $submit_fields[] = $default_submit_fields[ $value ];
     4846                        else
     4847                                $submit_fields[] = $value;
     4848                }
     4849        }
    48344850
    4835         $publishing_fields = array(
    4836         'submit' => '<input type="submit" name="publish" id="publish" accesskey="p" tabindex="%s" class="button-primary" value="' . $publishing_action . '" />',
    4837         /*'test' => '<input type="submit" name="publish" id="publish" accesskey="p" tabindex="%n" class="button-primary" value="'. esc_attr('Publish') .'" />', */
     4851        $primary_fields = array();
     4852        foreach ( $submit_fields as $key => $f ) {
     4853                if ( ! isset( $f['type'] ) || ! isset( $f['value'] ) )
     4854                        continue;
     4855                $f['name'] = $key;
     4856                if ( ! isset( $f['id'] ) )
     4857                        $f['id'] = false;
    48384858
    4839         );
     4859                if ( 'hidden' == $f['type'] ) {
     4860                        $f['primary'] = $f['accesskey'] = $f['tabindex'] = $f['class'] = false;
     4861                } else {
     4862                        if ( ! isset( $f['class'] ) )
     4863                                $f['class'] = ! empty( $f['primary'] ) ? 'button-primary' : 'button';
     4864                        $f = wp_parse_args( $f, array( 'accesskey' => false, 'tabindex' => true, 'primary' => false, 'tabindex' => true ) );
     4865                }
     4866        }
    48404867
    4841         $defaults = array(
    4842                 'action' => admin_url( 'post.php' ),
    4843                 'fields' => $fields,
    4844                 'form_id' => '',
    4845                 'default_cap' => 'edit_posts',
    4846                 'tabindex_start' => '1',
    4847                 'ajax' => true,
    4848                 'hidden_fields' => $hidden_fields,
    4849                 'submit_fields' => $submit_fields,
    4850                 'publishing_fields' => $publishing_fields,
    4851                 'submit_class' => 'submit',
    4852                 'publish_action_container' => 'span',
    4853                 'publish_action_id' => 'publishing-action',
    4854                 'hidden_and_submit_fields_container' => 'p',
    4855                 'hidden_and_submit_fields_container_class' => 'submit',
    4856         );
     4868        // Sync this so filters are given correct information.
     4869        $args['submit_fields'] = $submit_fields;
     4870        // Then we can separate the primary fields.
     4871        foreach ( $submit_fields as $key => $f ) {
     4872                if ( $f['primary'] ) {
     4873                        $primary_fields[] = $f;
     4874                        unset( $submit_fields[ $key ] );
     4875                }
     4876        }
    48574877
    4858         $args = wp_parse_args($args, $defaults);
     4878        // @todo :(
     4879        $tabindex = apply_filters( 'quickpress_tabindex', $tabindex, $args );
    48594880
    4860         $tabindex =  apply_filters( 'quickpress_tabindex_start', $args['tabindex_start'], $args['form_id'] );
     4881        do_action('quickpress_before_form', $args );
    48614882
    4862         if ( current_user_can( $args['default_cap'] ) ): ?>
    4863                 <?php do_action('quickpress_form_before_form', $args['form_id'] ); ?>
    4864                 <form name="post" action="<?php echo $args['action'] ?>" method="post" id="<?php echo $args['form_id']; ?>">
    4865                         <?php do_action('quickpress_form_before_fields', $args['form_id']);
     4883        echo '<form name="post" action="' . $args['action'] . '" method="post" id="' . $args['form_id'] . '">';
    48664884
    4867                         $fields = apply_filters( 'quickpress_fields',  $args['fields'], $args['form_id'] );
    4868                         foreach ($fields as $title => $field){
    4869                                 if ( empty( $field['capability'] ) || current_user_can( $field['capability'] ) ){
    4870                                         printf( $field['output'], $args['form_id'], $args['form_id'], $tabindex );
    4871                                         $tabindex++;
    4872                                 }
    4873                         }
    4874                         //Hidden Fields
    4875                         do_action('quickpress_form_after_fields', $args['form_id'] );
     4885        do_action( 'quickpress_before_fields', $args );
    48764886
    4877                         echo "<{$args['hidden_and_submit_fields_container']} class='{$args['hidden_and_submit_fields_container_class']}'>";
     4887        $fields = apply_filters( 'quickpress_fields', $form_fields, $args );
     4888        foreach ( $fields as $title => $field ) {
     4889                if ( empty( $field['capability'] ) || current_user_can( $field['capability'] ) )
     4890                        printf( $field['output'], $args['form_id'], ( $tabindex ? $tabindex++ : '' ) );
     4891        }
    48784892
    4879                         $hidden_fields = apply_filters( 'quickpress_hidden_fields', $args['hidden_fields'] , $args['form_id'] );
     4893        do_action( 'quickpress_after_fields', $form_id );
    48804894
    4881                         foreach( $hidden_fields as $hidden_field )
    4882                                 echo $hidden_field;
     4895        echo "<{$args['submit_fields_container']} class='{$args['submit_fields_container_class']}'>";
    48834896
    4884                         // nonce
    4885                         wp_nonce_field('add-post');
     4897        // nonce
     4898        wp_nonce_field( 'add-post' );
    48864899
    4887                         // submit
    4888                         foreach( $args['submit_fields'] as $submit_field )
    4889                                 printf( $submit_field, $tabindex++ );
     4900        foreach ( array( $args['submit_fields'], $args['primary_fields'] ) as $fields ) {
     4901                foreach( $fields as $f ) {
     4902                        $f['tabindex']  = $tabindex && ! empty( $f['tabindex'] ) ? ' tabindex="' . $tabindex++ . '"'  : '';
     4903                        $f['class']     = ! empty( $f['class'] )     ? ' class="' . $f['class'] . '"' : '';
     4904                        $f['id']        = ! empty( $f['id'] )        ? ' id="' . $f['id'] . '"'       : '';
     4905                        $f['accesskey'] = ! empty( $f['accesskey'] ) ? ' accesskey="' . $f['accesskey'] . '"' : '';
    48904906
    4891                         // publish
    4892                         echo "<{$args['publish_action_container']} id='{$args['publish_action_id']}'>";
     4907                        $f['name']  = ' name="' . $f['name'] . '"';
     4908                        $f['type']  = ' type="' . $f['type'] . '"';
     4909                        $f['value'] = ' value="' . esc_attr( $f['value'] ) . '"';
     4910                }
     4911        }
    48934912
    4894                         $publishing_fields = apply_filters( 'quickpress_publishing_fields', $args['publishing_fields'] , $args['form_id'] );
     4913        // hidden fields and secondary submit buttons
     4914        foreach ( $args['submit_fields'] as $f )
     4915                echo '<input ' . $f['type'] . $f['name'] . $f['id'] . $f['class'] . $f['tabindex'] . $f['value'] . '" />';
    48954916
    4896                         foreach( $publishing_fields as $publishing_field) {
    4897                                 printf( $publishing_field, $tabindex );
    4898                                         $tabindex++;
    4899                         }
     4917        // primary submit buttons
     4918        echo "<{$args['publish_action_container']} id='{$args['publish_action_id']}'>";
    49004919
    4901                         if ($args['ajax'] == true)
    4902                                 echo '<img class="waiting" src="'. esc_url( admin_url( 'images/wpspin_light.gif' ) ) .'" />';
     4920        foreach ( $args['primary_fields'] as $f )
     4921                echo '<input ' . $f['type'] . $f['name'] . $f['id'] . $f['class'] . $f['tabindex'] . $f['value'] . '" />';
    49034922
    4904                         echo "</{$args['publish_action_container']}>";
    4905                         echo "<br class='clear' />";
    4906                         do_action( 'quickpress_form_after_submit_fields', $args['form_id']);
     4923        do_action( 'quickpress_publish_actions', $args );
    49074924
    4908                         echo "</{$args['hidden_and_submit_fields_container']}";
    4909                 do_action( 'quickpress_form_after_form_content', $args['form_id']);
    4910                 echo '</form>';
    4911                 do_action('quickpress_form_after_form', $args['form_id'] );
    4912         else:
    4913                 do_action( 'quickpress_form_no_form', $args['form_id'] );
    4914         endif;
     4925        echo "</{$args['publish_action_container']}>";
     4926
     4927        echo "<br class='clear' />";
     4928
     4929        do_action( 'quickpress_after_submit_fields', $args );
     4930
     4931        echo "</{$args['submit_fields_container']}";
     4932
     4933        do_action( 'quickpress_after_form_content', $args );
     4934
     4935        echo '</form>';
     4936
     4937        do_action( 'quickpress_after_form', $args );
    49154938}
    49164939
     4940// @todo Move this to admin/includes/dashboard.
     4941function _dashboard_quickpress_publish_actions( $args ) {
     4942        if ( ! isset( $args['form_id'] ) || $args['form_id'] != 'dashboard_quick-press' )
     4943                return;
     4944        echo '<img class="waiting" src="'. esc_url( admin_url( 'images/wpspin_light.gif' ) ) .'" />';
     4945}
     4946add_action( 'quickpress_publish_actions', '_dashboard_quickpress_publish_actions' );
     4947
    49174948?>
     4949 No newline at end of file
  • wp-admin/includes/taxonomy.php

     
    208208
    209209        return wp_insert_term($tag_name, $taxonomy);
    210210}
     211
     212
     213
     214/**
     215 * {@internal Missing Short Description}}
     216 *
     217 * @since unknown
     218 *
     219 * @param unknown_type $post_id
     220 * @return unknown
     221 */
     222function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
     223        return get_terms_to_edit( $post_id, $taxonomy);
     224}
     225
     226/**
     227 * {@internal Missing Short Description}}
     228 *
     229 * @since unknown
     230 *
     231 * @param unknown_type $post_id
     232 * @return unknown
     233 */
     234function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
     235        $post_id = (int) $post_id;
     236        if ( !$post_id )
     237                return false;
     238
     239        $tags = wp_get_post_terms($post_id, $taxonomy, array());
     240
     241        if ( !$tags )
     242                return false;
     243
     244        if ( is_wp_error($tags) )
     245                return $tags;
     246
     247        foreach ( $tags as $tag )
     248                $tag_names[] = $tag->name;
     249        $tags_to_edit = join( ',', $tag_names );
     250        $tags_to_edit = esc_attr( $tags_to_edit );
     251        $tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy );
     252
     253        return $tags_to_edit;
     254}
  • wp-admin/includes/post.php

     
    15671567</script>
    15681568<?php
    15691569}
     1570
     1571
     1572/**
     1573 * Default post information to use when populating the "Write Post" form.
     1574 *
     1575 * @since unknown
     1576 *
     1577 *@param string A post type string, defaults to 'post'.
     1578 * @return object stdClass object containing all the default post data as attributes
     1579 */
     1580function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
     1581        global $wpdb;
     1582
     1583        $post_title = '';
     1584        if ( !empty( $_REQUEST['post_title'] ) )
     1585                $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
     1586
     1587        $post_content = '';
     1588        if ( !empty( $_REQUEST['content'] ) )
     1589                $post_content = esc_html( stripslashes( $_REQUEST['content'] ));
     1590
     1591        $post_excerpt = '';
     1592        if ( !empty( $_REQUEST['excerpt'] ) )
     1593                $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
     1594
     1595        if ( $create_in_db ) {
     1596                // Cleanup old auto-drafts more than 7 days old
     1597                $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
     1598                foreach ( (array) $old_posts as $delete )
     1599                        wp_delete_post( $delete, true ); // Force delete
     1600                $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
     1601                $post = get_post( $post_id );
     1602        } else {
     1603                $post->ID = 0;
     1604                $post->post_author = '';
     1605                $post->post_date = '';
     1606                $post->post_date_gmt = '';
     1607                $post->post_password = '';
     1608                $post->post_type = $post_type;
     1609                $post->post_status = 'draft';
     1610                $post->to_ping = '';
     1611                $post->pinged = '';
     1612                $post->comment_status = get_option( 'default_comment_status' );
     1613                $post->ping_status = get_option( 'default_ping_status' );
     1614                $post->post_pingback = get_option( 'default_pingback_flag' );
     1615                $post->post_category = get_option( 'default_category' );
     1616                $post->page_template = 'default';
     1617                $post->post_parent = 0;
     1618                $post->menu_order = 0;
     1619        }
     1620
     1621        $post->post_content = apply_filters( 'default_content', $post_content, $post );
     1622        $post->post_title   = apply_filters( 'default_title',   $post_title, $post   );
     1623        $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );
     1624        $post->post_name = '';
     1625
     1626        return $post;
     1627}