diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index 8738231b98..9b84e9fe76 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -383,18 +383,20 @@ function wp_dashboard_right_now() { do_action( 'activity_box_end' ); } -function wp_dashboard_quick_press() { +function wp_dashboard_quick_press_output() { + global $post_ID; + $drafts = false; if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) { $view = get_permalink( $_POST['post_ID'] ); $edit = esc_url( get_edit_post_link( $_POST['post_ID'] ) ); if ( 'post-quickpress-publish' == $_POST['action'] ) { if ( current_user_can('publish_posts') ) - printf( '

' . __( 'Post Published. View post | Edit post' ) . '

', esc_url( $view ), $edit ); + printf( '

' . __( 'Post published. View post | Edit post' ) . '

', esc_url( $view ), $edit ); else - printf( '

' . __( 'Post submitted. Preview post | Edit post' ) . '

', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit ); + printf( '

' . __( 'Post submitted. Preview post | Edit post' ) . '

', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit ); } else { - printf( '

' . __( 'Draft Saved. Preview post | Edit post' ) . '

', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit ); + printf( '

' . __( 'Draft saved. Preview post | Edit post' ) . '

', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit ); $drafts_query = new WP_Query( array( 'post_type' => 'post', 'post_status' => 'draft', @@ -407,11 +409,26 @@ function wp_dashboard_quick_press() { if ( $drafts_query->posts ) $drafts =& $drafts_query->posts; } - printf('

' . __('You can also try %s, easy blogging from anywhere on the Web.') . '

', '' . __('Press This') . '' ); + printf('

' . __('You can also try %s, easy blogging from anywhere on the Web.') . '

', '' . __('Press This') . '' ); $_REQUEST = array(); // hack for get_default_post_to_edit() } - $post = get_default_post_to_edit(); + /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */ + $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID + if ( $last_post_id ) { + $post = get_post( $last_post_id ); + if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore + $post = get_default_post_to_edit('post', true); + update_user_option( (int) $GLOBALS['current_user']->ID, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID + } else { + $post->post_title = ''; // Remove the auto draft title + } + } else { + $post = get_default_post_to_edit('post', true); + update_user_option( (int) $GLOBALS['current_user']->ID, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID + } + + $post_ID = (int) $post->ID; ?>
@@ -440,7 +457,7 @@ function wp_dashboard_quick_press() {

- + @@ -459,6 +476,10 @@ function wp_dashboard_quick_press() { wp_dashboard_recent_drafts( $drafts ); } +function wp_dashboard_quick_press() { + echo '

' . __( 'Loading…' ) . '

' . __('This widget requires JavaScript.') . '

'; +} + function wp_dashboard_recent_drafts( $drafts = false ) { if ( !$drafts ) { $drafts_query = new WP_Query( array( diff --git a/wp-admin/index-extra.php b/wp-admin/index-extra.php index 5308ac1025..07260efc17 100644 --- a/wp-admin/index-extra.php +++ b/wp-admin/index-extra.php @@ -32,6 +32,10 @@ case 'dashboard_secondary' : case 'dashboard_plugins' : wp_dashboard_plugins_output(); break; + +case 'dashboard_quick_press' : + wp_dashboard_quick_press_output(); + break; } diff --git a/wp-admin/js/dashboard.dev.js b/wp-admin/js/dashboard.dev.js index c6a1797c86..4969113ccc 100644 --- a/wp-admin/js/dashboard.dev.js +++ b/wp-admin/js/dashboard.dev.js @@ -6,7 +6,8 @@ jQuery(document).ready( function($) { 'dashboard_incoming_links', 'dashboard_primary', 'dashboard_secondary', - 'dashboard_plugins' + 'dashboard_plugins', + 'dashboard_quick_press' ]; ajaxPopulateWidgets = function(el) { @@ -20,6 +21,10 @@ jQuery(document).ready( function($) { $(this).css('display', ''); if ( 'dashboard_plugins' == id && $.isFunction(tb_init) ) tb_init('#dashboard_plugins a.thickbox'); + if ( 'dashboard_quick_press' == id && $.isFunction(tb_init) ) { + tb_init('#dashboard_quick_press a.thickbox'); + quickPressLoad(); + } }); }); }, i * 500 ); @@ -53,6 +58,7 @@ jQuery(document).ready( function($) { $('#dashboard_quick_press div.inside').load( t.attr( 'action' ), t.serializeArray(), function() { $('#dashboard_quick_press #publishing-action img.waiting').css('visibility', 'hidden'); $('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').attr('disabled',''); + $('#dashboard_quick_press ul').next('p').remove(); $('#dashboard_quick_press ul').find('li').each( function() { $('#dashboard_recent_drafts ul').prepend( this ); } ).end().remove(); @@ -65,6 +71,5 @@ jQuery(document).ready( function($) { $('#publish').click( function() { act.val( 'post-quickpress-publish' ); } ); }; - quickPressLoad(); } ); diff --git a/wp-admin/js/dashboard.js b/wp-admin/js/dashboard.js index 3a6ab645e0..f391e1342e 100644 --- a/wp-admin/js/dashboard.js +++ b/wp-admin/js/dashboard.js @@ -1 +1 @@ -var ajaxWidgets,ajaxPopulateWidgets,quickPressLoad;jQuery(document).ready(function(a){ajaxWidgets=["dashboard_incoming_links","dashboard_primary","dashboard_secondary","dashboard_plugins"];ajaxPopulateWidgets=function(b){show=function(g,c){var f,d=a("#"+g+" div.inside:visible").find(".widget-loading");if(d.length){f=d.parent();setTimeout(function(){f.load("index-extra.php?jax="+g,"",function(){f.hide().slideDown("normal",function(){a(this).css("display","");if("dashboard_plugins"==g&&a.isFunction(tb_init)){tb_init("#dashboard_plugins a.thickbox")}})})},c*500)}};if(b){b=b.toString();if(a.inArray(b,ajaxWidgets)!=-1){show(b,0)}}else{a.each(ajaxWidgets,function(c){show(this,c)})}};ajaxPopulateWidgets();postboxes.add_postbox_toggles("dashboard",{pbshow:ajaxPopulateWidgets});quickPressLoad=function(){var b=a("#quickpost-action"),c;c=a("#quick-press").submit(function(){a("#dashboard_quick_press #publishing-action img.waiting").css("visibility","visible");a('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').attr("disabled","disabled");if("post"==b.val()){b.val("post-quickpress-publish")}a("#dashboard_quick_press div.inside").load(c.attr("action"),c.serializeArray(),function(){a("#dashboard_quick_press #publishing-action img.waiting").css("visibility","hidden");a('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').attr("disabled","");a("#dashboard_quick_press ul").find("li").each(function(){a("#dashboard_recent_drafts ul").prepend(this)}).end().remove();tb_init("a.thickbox");quickPressLoad()});return false});a("#publish").click(function(){b.val("post-quickpress-publish")})};quickPressLoad()}); \ No newline at end of file +var ajaxWidgets,ajaxPopulateWidgets,quickPressLoad;jQuery(document).ready(function(a){ajaxWidgets=["dashboard_incoming_links","dashboard_primary","dashboard_secondary","dashboard_plugins","dashboard_quick_press"];ajaxPopulateWidgets=function(b){show=function(g,c){var f,d=a("#"+g+" div.inside:visible").find(".widget-loading");if(d.length){f=d.parent();setTimeout(function(){f.load("index-extra.php?jax="+g,"",function(){f.hide().slideDown("normal",function(){a(this).css("display","");if("dashboard_plugins"==g&&a.isFunction(tb_init)){tb_init("#dashboard_plugins a.thickbox")}if("dashboard_quick_press"==g&&a.isFunction(tb_init)){tb_init("#dashboard_quick_press a.thickbox");quickPressLoad()}})})},c*500)}};if(b){b=b.toString();if(a.inArray(b,ajaxWidgets)!=-1){show(b,0)}}else{a.each(ajaxWidgets,function(c){show(this,c)})}};ajaxPopulateWidgets();postboxes.add_postbox_toggles("dashboard",{pbshow:ajaxPopulateWidgets});quickPressLoad=function(){var b=a("#quickpost-action"),c;c=a("#quick-press").submit(function(){a("#dashboard_quick_press #publishing-action img.waiting").css("visibility","visible");a('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').attr("disabled","disabled");if("post"==b.val()){b.val("post-quickpress-publish")}a("#dashboard_quick_press div.inside").load(c.attr("action"),c.serializeArray(),function(){a("#dashboard_quick_press #publishing-action img.waiting").css("visibility","hidden");a('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').attr("disabled","");a("#dashboard_quick_press ul").next("p").remove();a("#dashboard_quick_press ul").find("li").each(function(){a("#dashboard_recent_drafts ul").prepend(this)}).end().remove();tb_init("a.thickbox");quickPressLoad()});return false});a("#publish").click(function(){b.val("post-quickpress-publish")})}}); \ No newline at end of file diff --git a/wp-admin/post.php b/wp-admin/post.php index a8c006c4c4..548007f7f0 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -131,7 +131,7 @@ case 'post-quickpress-save': $_POST['post_ID'] = $post_id; // output the quickpress dashboard widget require_once(ABSPATH . 'wp-admin/includes/dashboard.php'); - wp_dashboard_quick_press(); + wp_dashboard_quick_press_output(); exit; } diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index f0f9a16c3a..99584d4658 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -360,7 +360,7 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' ); - $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox' ), '20100213' ); + $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox' ), '20100523' ); $scripts->add_data( 'dashboard', 'group', 1 ); $scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array('jquery'), '20090102' );