wp_dashboard_quick_press

The Quick Draft widget display and creation of drafts.

Description

wp_dashboard_quick_press( (bool) $error_msg = false ); 

Parameters (1)

0. $error_msg — Optional. (bool) => false
Error message. Default false.

Usage

  1. if ( !function_exists( 'wp_dashboard_quick_press' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/dashboard.php'; 
  3.  
  4. // Optional. Error message. Default false. 
  5. $error_msg = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_dashboard_quick_press($error_msg); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/dashboard.php  
  1. function wp_dashboard_quick_press( $error_msg = false ) { 
  2. global $post_ID; 
  3.  
  4. if ( ! current_user_can( 'edit_posts' ) ) { 
  5. return; 
  6.  
  7. /** Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */ 
  8. $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID 
  9. if ( $last_post_id ) { 
  10. $post = get_post( $last_post_id ); 
  11. if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore 
  12. $post = get_default_post_to_edit( 'post', true ); 
  13. update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID 
  14. } else { 
  15. $post->post_title = ''; // Remove the auto draft title 
  16. } else { 
  17. $post = get_default_post_to_edit( 'post' , true); 
  18. $user_id = get_current_user_id(); 
  19. // Don't create an option if this is a super admin who does not belong to this site. 
  20. if ( ! ( is_super_admin( $user_id ) && ! in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) ) 
  21. update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID 
  22.  
  23. $post_ID = (int) $post->ID; 
  24. ?> 
  25.  
  26. <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js"> 
  27.  
  28. <?php if ( $error_msg ) : ?> 
  29. <div class="error"><?php echo $error_msg; ?></div> 
  30. <?php endif; ?> 
  31.  
  32. <div class="input-text-wrap" id="title-wrap"> 
  33. <label class="screen-reader-text prompt" for="title" id="title-prompt-text"> 
  34.  
  35. <?php 
  36. /** This filter is documented in wp-admin/edit-form-advanced.php */ 
  37. echo apply_filters( 'enter_title_here', __( 'Title' ), $post ); 
  38. ?> 
  39. </label> 
  40. <input type="text" name="post_title" id="title" autocomplete="off" /> 
  41. </div> 
  42.  
  43. <div class="textarea-wrap" id="description-wrap"> 
  44. <label class="screen-reader-text prompt" for="content" id="content-prompt-text"><?php _e( 'What’s on your mind?' ); ?></label> 
  45. <textarea name="content" id="content" class="mceEditor" rows="3" cols="15" autocomplete="off"></textarea> 
  46. </div> 
  47.  
  48. <p class="submit"> 
  49. <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" /> 
  50. <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" /> 
  51. <input type="hidden" name="post_type" value="post" /> 
  52. <?php wp_nonce_field( 'add-post' ); ?> 
  53. <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?> 
  54. <br class="clear" /> 
  55. </p> 
  56.  
  57. </form> 
  58. <?php