wp_dashboard_recent_drafts

Show recent drafts of the user on the dashboard.

Description

wp_dashboard_recent_drafts( (bool) $drafts = false ); 

Parameters (1)

0. $drafts — Optional. (bool) => false
The drafts.

Usage

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

Defined (1)

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

/wp-admin/includes/dashboard.php  
  1. function wp_dashboard_recent_drafts( $drafts = false ) { 
  2. if ( ! $drafts ) { 
  3. $query_args = array( 
  4. 'post_type' => 'post',  
  5. 'post_status' => 'draft',  
  6. 'author' => get_current_user_id(),  
  7. 'posts_per_page' => 4,  
  8. 'orderby' => 'modified',  
  9. 'order' => 'DESC' 
  10. ); 
  11.  
  12. /** 
  13. * Filters the post query arguments for the 'Recent Drafts' dashboard widget. 
  14. * @since 4.4.0 
  15. * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget. 
  16. */ 
  17. $query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args ); 
  18.  
  19. $drafts = get_posts( $query_args ); 
  20. if ( ! $drafts ) { 
  21. return; 
  22.  
  23. echo '<div class="drafts">'; 
  24. if ( count( $drafts ) > 3 ) { 
  25. echo '<p class="view-all"><a href="' . esc_url( admin_url( 'edit.php?post_status=draft' ) ) . '" aria-label="' . __( 'View all drafts' ) . '">' . _x( 'View all', 'drafts' ) . "</a></p>\n"; 
  26. echo '<h2 class="hide-if-no-js">' . __( 'Drafts' ) . "</h2>\n<ul>"; 
  27.  
  28. $drafts = array_slice( $drafts, 0, 3 ); 
  29. foreach ( $drafts as $draft ) { 
  30. $url = get_edit_post_link( $draft->ID ); 
  31. $title = _draft_or_post_title( $draft->ID ); 
  32. echo "<li>\n"; 
  33. /** translators: %s: post title */ 
  34. echo '<div class="draft-title"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . esc_html( $title ) . '</a>'; 
  35. echo '<time datetime="' . get_the_time( 'c', $draft ) . '">' . get_the_time( __( 'F j, Y' ), $draft ) . '</time></div>'; 
  36. if ( $the_content = wp_trim_words( $draft->post_content, 10 ) ) { 
  37. echo '<p>' . $the_content . '</p>'; 
  38. echo "</li>\n"; 
  39. echo "</ul>\n</div>";