Make WordPress Core


Ignore:
Timestamp:
05/23/2010 07:58:06 AM (16 years ago)
Author:
westi
Message:

Ensure that QuickPress media uploads get attached to the auto-draft we create for new posts correctly. Fixes #10917 props ocean90.

File:
1 edited

Legend:

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

    r14582 r14815  
    384384}
    385385
    386 function wp_dashboard_quick_press() {
     386function wp_dashboard_quick_press_output() {
     387        global $post_ID;
     388
    387389        $drafts = false;
    388390        if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) {
     
    391393                if ( 'post-quickpress-publish' == $_POST['action'] ) {
    392394                        if ( current_user_can('publish_posts') )
    393                                 printf( '<div class="message"><p>' . __( 'Post Published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( $view ), $edit );
     395                                printf( '<div class="updated"><p>' . __( 'Post published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( $view ), $edit );
    394396                        else
    395                                 printf( '<div class="message"><p>' . __( 'Post submitted. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
     397                                printf( '<div class="updated"><p>' . __( 'Post submitted. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
    396398                } else {
    397                         printf( '<div class="message"><p>' . __( 'Draft Saved. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
     399                        printf( '<div class="updated"><p>' . __( 'Draft saved. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
    398400                        $drafts_query = new WP_Query( array(
    399401                                'post_type' => 'post',
     
    408410                                $drafts =& $drafts_query->posts;
    409411                }
    410                 printf('<p class="textright">' . __('You can also try %s, easy blogging from anywhere on the Web.') . '</p>', '<a href="tools.php">' . __('Press This') . '</a>' );
     412                printf('<p class="textright">' . __('You can also try %s, easy blogging from anywhere on the Web.') . '</p>', '<a href="' . esc_url( admin_url( 'tools.php' ) ) . '">' . __('Press This') . '</a>' );
    411413                $_REQUEST = array(); // hack for get_default_post_to_edit()
    412414        }
    413415
    414         $post = get_default_post_to_edit();
     416        /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
     417        $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID
     418        if ( $last_post_id ) {
     419                $post = get_post( $last_post_id );
     420                if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
     421                        $post = get_default_post_to_edit('post', true);
     422                        update_user_option( (int) $GLOBALS['current_user']->ID, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
     423                } else {
     424                        $post->post_title = ''; // Remove the auto draft title
     425                }
     426        } else {
     427                $post = get_default_post_to_edit('post', true);
     428                update_user_option( (int) $GLOBALS['current_user']->ID, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
     429        }
     430
     431        $post_ID = (int) $post->ID;
    415432?>
    416433
     
    441458                <p class="submit">
    442459                        <input type="hidden" name="action" id="quickpost-action" value="post-quickpress-save" />
    443                         <input type="hidden" name="quickpress_post_ID" value="<?php echo (int) $post->ID; ?>" />
     460                        <input type="hidden" name="quickpress_post_ID" value="<?php echo $post_ID; ?>" />
    444461                        <input type="hidden" name="post_type" value="post" />
    445462                        <?php wp_nonce_field('add-post'); ?>
     
    458475        if ( $drafts )
    459476                wp_dashboard_recent_drafts( $drafts );
     477}
     478
     479function wp_dashboard_quick_press() {
     480        echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
    460481}
    461482
Note: See TracChangeset for help on using the changeset viewer.