Make WordPress Core

Ticket #10917: 10917-ajax+transient.patch

File 10917-ajax+transient.patch, 6.5 KB (added by ocean90, 15 years ago)

Transient API

  • wp-admin/includes/dashboard.php

     
    383383        do_action( 'activity_box_end' );
    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'] ) {
    389391                $view = get_permalink( $_POST['post_ID'] );
    390392                $edit = esc_url( get_edit_post_link( $_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',
    400402                                'post_status' => 'draft',
     
    407409                        if ( $drafts_query->posts )
    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 we need to generate a new auto-draft or we can use an old one */
     417        $transient_post_id = (int) get_transient( 'dashboard_quick_press_post' ); // Get the last post_ID
     418        if ( $transient_post_id ) {
     419                $post = get_post( $transient_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                        set_transient( 'dashboard_quick_press_post', (int) $post->ID, 172800 ); // Save post_ID for 2 days.
     423                } else {
     424                        $post->post_title = ''; // Remove the auto draft title
     425                }
     426        } else {
     427                $post = get_default_post_to_edit('post', true);
     428                set_transient( 'dashboard_quick_press_post', (int) $post->ID, 172800 ); // Save post_ID for 2 days.
     429        }
     430
     431        $post_ID = (int) $post->ID;
    415432?>
    416433
    417434        <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
     
    440457
    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'); ?>
    446463                        <input type="submit" name="save" id="save-post" class="button" tabindex="4" value="<?php esc_attr_e('Save Draft'); ?>" />
     
    459476                wp_dashboard_recent_drafts( $drafts );
    460477}
    461478
     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>';
     481}
     482
    462483function wp_dashboard_recent_drafts( $drafts = false ) {
    463484        if ( !$drafts ) {
    464485                $drafts_query = new WP_Query( array(
  • wp-admin/index-extra.php

     
    3232case 'dashboard_plugins' :
    3333        wp_dashboard_plugins_output();
    3434        break;
     35       
     36case 'dashboard_quick_press' :
     37        wp_dashboard_quick_press_output();
     38        break;
    3539
    3640}
    3741
  • wp-admin/js/dashboard.dev.js

     
    66                'dashboard_incoming_links',
    77                'dashboard_primary',
    88                'dashboard_secondary',
    9                 'dashboard_plugins'
     9                'dashboard_plugins',
     10                'dashboard_quick_press'
    1011        ];
    1112
    1213        ajaxPopulateWidgets = function(el) {
     
    2021                                                        $(this).css('display', '');
    2122                                                        if ( 'dashboard_plugins' == id && $.isFunction(tb_init) )
    2223                                                                tb_init('#dashboard_plugins a.thickbox');
     24                                                        if ( 'dashboard_quick_press' == id && $.isFunction(tb_init) ) {
     25                                                                tb_init('#dashboard_quick_press a.thickbox');
     26                                                                quickPressLoad();
     27                                                        }
    2328                                                });
    2429                                        });
    2530                                }, i * 500 );
     
    5358                        $('#dashboard_quick_press div.inside').load( t.attr( 'action' ), t.serializeArray(), function() {
    5459                                $('#dashboard_quick_press #publishing-action img.waiting').css('visibility', 'hidden');
    5560                                $('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').attr('disabled','');
     61                                $('#dashboard_quick_press ul').next('p').remove();
    5662                                $('#dashboard_quick_press ul').find('li').each( function() {
    5763                                        $('#dashboard_recent_drafts ul').prepend( this );
    5864                                } ).end().remove();
     
    6571                $('#publish').click( function() { act.val( 'post-quickpress-publish' ); } );
    6672
    6773        };
    68         quickPressLoad();
    6974
    7075} );
  • wp-admin/post.php

     
    131131                $_POST['post_ID'] = $post_id;
    132132                // output the quickpress dashboard widget
    133133                require_once(ABSPATH . 'wp-admin/includes/dashboard.php');
    134                 wp_dashboard_quick_press();
     134                wp_dashboard_quick_press_output();
    135135                exit;
    136136        }
    137137