wp_dashboard_recent_drafts

The timeline below displays how wordpress function wp_dashboard_recent_drafts has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.8

/**
 * Show recent drafts of the user on the dashboard.
 *
 * @since 2.7.0
 *
 * @param WP_Post[]|false $drafts Optional. Array of posts to display. Default false.
 */
function wp_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $query_args = array('post_type' => 'post', 'post_status' => 'draft', 'author' => get_current_user_id(), 'posts_per_page' => 4, 'orderby' => 'modified', 'order' => 'DESC');
        /**
         * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
         *
         * @since 4.4.0
         *
         * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
         */
        $query_args = apply_filters('dashboard_recent_drafts_query_args', $query_args);
        $drafts = get_posts($query_args);
        if (!$drafts) {
            return;
        }
    }
    echo '<div class="drafts">';
    if (count($drafts) > 3) {
        printf('<p class="view-all"><a href="%s">%s</a></p>' . "\n", esc_url(admin_url('edit.php?post_status=draft')), __('View all drafts'));
    }
    echo '<h2 class="hide-if-no-js">' . __('Your Recent Drafts') . "</h2>\n";
    echo '<ul>';
    /* translators: Maximum number of words used in a preview of a draft on the dashboard. */
    $draft_length = (int) _x('10', 'draft_length');
    $drafts = array_slice($drafts, 0, 3);
    foreach ($drafts as $draft) {
        $url = get_edit_post_link($draft->ID);
        $title = _draft_or_post_title($draft->ID);
        echo "<li>\n";
        printf(
            '<div class="draft-title"><a href="%s" aria-label="%s">%s</a><time datetime="%s">%s</time></div>',
            esc_url($url),
            /* translators: %s: Post title. */
            esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)),
            esc_html($title),
            get_the_time('c', $draft),
            get_the_time(__('F j, Y'), $draft)
        );
        $the_content = wp_trim_words($draft->post_content, $draft_length);
        if ($the_content) {
            echo '<p>' . $the_content . '</p>';
        }
        echo "</li>\n";
    }
    echo "</ul>\n";
    echo '</div>';
}

WordPress Version: 5.7

/**
 * Show recent drafts of the user on the dashboard.
 *
 * @since 2.7.0
 *
 * @param WP_Post[]|false $drafts Optional. Array of posts to display. Default false.
 */
function wp_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $query_args = array('post_type' => 'post', 'post_status' => 'draft', 'author' => get_current_user_id(), 'posts_per_page' => 4, 'orderby' => 'modified', 'order' => 'DESC');
        /**
         * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
         *
         * @since 4.4.0
         *
         * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
         */
        $query_args = apply_filters('dashboard_recent_drafts_query_args', $query_args);
        $drafts = get_posts($query_args);
        if (!$drafts) {
            return;
        }
    }
    echo '<div class="drafts">';
    if (count($drafts) > 3) {
        printf('<p class="view-all"><a href="%s">%s</a></p>' . "\n", esc_url(admin_url('edit.php?post_status=draft')), __('View all drafts'));
    }
    echo '<h2 class="hide-if-no-js">' . __('Your Recent Drafts') . "</h2>\n<ul>";
    /* translators: Maximum number of words used in a preview of a draft on the dashboard. */
    $draft_length = (int) _x('10', 'draft_length');
    $drafts = array_slice($drafts, 0, 3);
    foreach ($drafts as $draft) {
        $url = get_edit_post_link($draft->ID);
        $title = _draft_or_post_title($draft->ID);
        echo "<li>\n";
        printf(
            '<div class="draft-title"><a href="%s" aria-label="%s">%s</a><time datetime="%s">%s</time></div>',
            esc_url($url),
            /* translators: %s: Post title. */
            esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)),
            esc_html($title),
            get_the_time('c', $draft),
            get_the_time(__('F j, Y'), $draft)
        );
        $the_content = wp_trim_words($draft->post_content, $draft_length);
        if ($the_content) {
            echo '<p>' . $the_content . '</p>';
        }
        echo "</li>\n";
    }
    echo "</ul>\n</div>";
}

WordPress Version: 5.6

/**
 * Show recent drafts of the user on the dashboard.
 *
 * @since 2.7.0
 *
 * @param WP_Post[] $drafts Optional. Array of posts to display. Default false.
 */
function wp_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $query_args = array('post_type' => 'post', 'post_status' => 'draft', 'author' => get_current_user_id(), 'posts_per_page' => 4, 'orderby' => 'modified', 'order' => 'DESC');
        /**
         * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
         *
         * @since 4.4.0
         *
         * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
         */
        $query_args = apply_filters('dashboard_recent_drafts_query_args', $query_args);
        $drafts = get_posts($query_args);
        if (!$drafts) {
            return;
        }
    }
    echo '<div class="drafts">';
    if (count($drafts) > 3) {
        printf('<p class="view-all"><a href="%s">%s</a></p>' . "\n", esc_url(admin_url('edit.php?post_status=draft')), __('View all drafts'));
    }
    echo '<h2 class="hide-if-no-js">' . __('Your Recent Drafts') . "</h2>\n<ul>";
    /* translators: Maximum number of words used in a preview of a draft on the dashboard. */
    $draft_length = (int) _x('10', 'draft_length');
    $drafts = array_slice($drafts, 0, 3);
    foreach ($drafts as $draft) {
        $url = get_edit_post_link($draft->ID);
        $title = _draft_or_post_title($draft->ID);
        echo "<li>\n";
        printf(
            '<div class="draft-title"><a href="%s" aria-label="%s">%s</a><time datetime="%s">%s</time></div>',
            esc_url($url),
            /* translators: %s: Post title. */
            esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)),
            esc_html($title),
            get_the_time('c', $draft),
            get_the_time(__('F j, Y'), $draft)
        );
        $the_content = wp_trim_words($draft->post_content, $draft_length);
        if ($the_content) {
            echo '<p>' . $the_content . '</p>';
        }
        echo "</li>\n";
    }
    echo "</ul>\n</div>";
}

WordPress Version: 5.3

/**
 * Show recent drafts of the user on the dashboard.
 *
 * @since 2.7.0
 *
 * @param WP_Post[] $drafts Optional. Array of posts to display. Default false.
 */
function wp_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $query_args = array('post_type' => 'post', 'post_status' => 'draft', 'author' => get_current_user_id(), 'posts_per_page' => 4, 'orderby' => 'modified', 'order' => 'DESC');
        /**
         * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
         *
         * @since 4.4.0
         *
         * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
         */
        $query_args = apply_filters('dashboard_recent_drafts_query_args', $query_args);
        $drafts = get_posts($query_args);
        if (!$drafts) {
            return;
        }
    }
    echo '<div class="drafts">';
    if (count($drafts) > 3) {
        printf('<p class="view-all"><a href="%s">%s</a></p>' . "\n", esc_url(admin_url('edit.php?post_status=draft')), __('View all drafts'));
    }
    echo '<h2 class="hide-if-no-js">' . __('Your Recent Drafts') . "</h2>\n<ul>";
    /* translators: Maximum number of words used in a preview of a draft on the dashboard. */
    $draft_length = intval(_x('10', 'draft_length'));
    $drafts = array_slice($drafts, 0, 3);
    foreach ($drafts as $draft) {
        $url = get_edit_post_link($draft->ID);
        $title = _draft_or_post_title($draft->ID);
        echo "<li>\n";
        printf(
            '<div class="draft-title"><a href="%s" aria-label="%s">%s</a><time datetime="%s">%s</time></div>',
            esc_url($url),
            /* translators: %s: Post title. */
            esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)),
            esc_html($title),
            get_the_time('c', $draft),
            get_the_time(__('F j, Y'), $draft)
        );
        $the_content = wp_trim_words($draft->post_content, $draft_length);
        if ($the_content) {
            echo '<p>' . $the_content . '</p>';
        }
        echo "</li>\n";
    }
    echo "</ul>\n</div>";
}

WordPress Version: 5.1

/**
 * Show recent drafts of the user on the dashboard.
 *
 * @since 2.7.0
 *
 * @param WP_Post[] $drafts Optional. Array of posts to display. Default false.
 */
function wp_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $query_args = array('post_type' => 'post', 'post_status' => 'draft', 'author' => get_current_user_id(), 'posts_per_page' => 4, 'orderby' => 'modified', 'order' => 'DESC');
        /**
         * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
         *
         * @since 4.4.0
         *
         * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
         */
        $query_args = apply_filters('dashboard_recent_drafts_query_args', $query_args);
        $drafts = get_posts($query_args);
        if (!$drafts) {
            return;
        }
    }
    echo '<div class="drafts">';
    if (count($drafts) > 3) {
        echo '<p class="view-all"><a href="' . esc_url(admin_url('edit.php?post_status=draft')) . '">' . __('View all drafts') . "</a></p>\n";
    }
    echo '<h2 class="hide-if-no-js">' . __('Your Recent Drafts') . "</h2>\n<ul>";
    $drafts = array_slice($drafts, 0, 3);
    foreach ($drafts as $draft) {
        $url = get_edit_post_link($draft->ID);
        $title = _draft_or_post_title($draft->ID);
        echo "<li>\n";
        /* translators: %s: post title */
        echo '<div class="draft-title"><a href="' . esc_url($url) . '" aria-label="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)) . '">' . esc_html($title) . '</a>';
        echo '<time datetime="' . get_the_time('c', $draft) . '">' . get_the_time(__('F j, Y'), $draft) . '</time></div>';
        if ($the_content = wp_trim_words($draft->post_content, 10)) {
            echo '<p>' . $the_content . '</p>';
        }
        echo "</li>\n";
    }
    echo "</ul>\n</div>";
}

WordPress Version: 4.9

/**
 * Show recent drafts of the user on the dashboard.
 *
 * @since 2.7.0
 *
 * @param array $drafts
 */
function wp_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $query_args = array('post_type' => 'post', 'post_status' => 'draft', 'author' => get_current_user_id(), 'posts_per_page' => 4, 'orderby' => 'modified', 'order' => 'DESC');
        /**
         * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
         *
         * @since 4.4.0
         *
         * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
         */
        $query_args = apply_filters('dashboard_recent_drafts_query_args', $query_args);
        $drafts = get_posts($query_args);
        if (!$drafts) {
            return;
        }
    }
    echo '<div class="drafts">';
    if (count($drafts) > 3) {
        echo '<p class="view-all"><a href="' . esc_url(admin_url('edit.php?post_status=draft')) . '">' . __('View all drafts') . "</a></p>\n";
    }
    echo '<h2 class="hide-if-no-js">' . __('Your Recent Drafts') . "</h2>\n<ul>";
    $drafts = array_slice($drafts, 0, 3);
    foreach ($drafts as $draft) {
        $url = get_edit_post_link($draft->ID);
        $title = _draft_or_post_title($draft->ID);
        echo "<li>\n";
        /* translators: %s: post title */
        echo '<div class="draft-title"><a href="' . esc_url($url) . '" aria-label="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)) . '">' . esc_html($title) . '</a>';
        echo '<time datetime="' . get_the_time('c', $draft) . '">' . get_the_time(__('F j, Y'), $draft) . '</time></div>';
        if ($the_content = wp_trim_words($draft->post_content, 10)) {
            echo '<p>' . $the_content . '</p>';
        }
        echo "</li>\n";
    }
    echo "</ul>\n</div>";
}

WordPress Version: 4.6

/**
 * Show recent drafts of the user on the dashboard.
 *
 * @since 2.7.0
 *
 * @param array $drafts
 */
function wp_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $query_args = array('post_type' => 'post', 'post_status' => 'draft', 'author' => get_current_user_id(), 'posts_per_page' => 4, 'orderby' => 'modified', 'order' => 'DESC');
        /**
         * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
         *
         * @since 4.4.0
         *
         * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
         */
        $query_args = apply_filters('dashboard_recent_drafts_query_args', $query_args);
        $drafts = get_posts($query_args);
        if (!$drafts) {
            return;
        }
    }
    echo '<div class="drafts">';
    if (count($drafts) > 3) {
        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";
    }
    echo '<h2 class="hide-if-no-js">' . __('Drafts') . "</h2>\n<ul>";
    $drafts = array_slice($drafts, 0, 3);
    foreach ($drafts as $draft) {
        $url = get_edit_post_link($draft->ID);
        $title = _draft_or_post_title($draft->ID);
        echo "<li>\n";
        /* translators: %s: post title */
        echo '<div class="draft-title"><a href="' . esc_url($url) . '" aria-label="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)) . '">' . esc_html($title) . '</a>';
        echo '<time datetime="' . get_the_time('c', $draft) . '">' . get_the_time(__('F j, Y'), $draft) . '</time></div>';
        if ($the_content = wp_trim_words($draft->post_content, 10)) {
            echo '<p>' . $the_content . '</p>';
        }
        echo "</li>\n";
    }
    echo "</ul>\n</div>";
}

WordPress Version: 4.5

/**
 * Show recent drafts of the user on the dashboard.
 *
 * @since 2.7.0
 *
 * @param array $drafts
 */
function wp_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $query_args = array('post_type' => 'post', 'post_status' => 'draft', 'author' => get_current_user_id(), 'posts_per_page' => 4, 'orderby' => 'modified', 'order' => 'DESC');
        /**
         * Filter the post query arguments for the 'Recent Drafts' dashboard widget.
         *
         * @since 4.4.0
         *
         * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
         */
        $query_args = apply_filters('dashboard_recent_drafts_query_args', $query_args);
        $drafts = get_posts($query_args);
        if (!$drafts) {
            return;
        }
    }
    echo '<div class="drafts">';
    if (count($drafts) > 3) {
        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";
    }
    echo '<h2 class="hide-if-no-js">' . __('Drafts') . "</h2>\n<ul>";
    $drafts = array_slice($drafts, 0, 3);
    foreach ($drafts as $draft) {
        $url = get_edit_post_link($draft->ID);
        $title = _draft_or_post_title($draft->ID);
        echo "<li>\n";
        /* translators: %s: post title */
        echo '<div class="draft-title"><a href="' . esc_url($url) . '" aria-label="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)) . '">' . esc_html($title) . '</a>';
        echo '<time datetime="' . get_the_time('c', $draft) . '">' . get_the_time(__('F j, Y'), $draft) . '</time></div>';
        if ($the_content = wp_trim_words($draft->post_content, 10)) {
            echo '<p>' . $the_content . '</p>';
        }
        echo "</li>\n";
    }
    echo "</ul>\n</div>";
}

WordPress Version: 4.4

/**
 * Show recent drafts of the user on the dashboard.
 *
 * @since 2.7.0
 *
 * @param array $drafts
 */
function wp_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $query_args = array('post_type' => 'post', 'post_status' => 'draft', 'author' => get_current_user_id(), 'posts_per_page' => 4, 'orderby' => 'modified', 'order' => 'DESC');
        /**
         * Filter the post query arguments for the 'Recent Drafts' dashboard widget.
         *
         * @since 4.4.0
         *
         * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
         */
        $query_args = apply_filters('dashboard_recent_drafts_query_args', $query_args);
        $drafts = get_posts($query_args);
        if (!$drafts) {
            return;
        }
    }
    echo '<div class="drafts">';
    if (count($drafts) > 3) {
        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";
    }
    echo '<h2 class="hide-if-no-js">' . __('Drafts') . "</h2>\n<ul>";
    $drafts = array_slice($drafts, 0, 3);
    foreach ($drafts as $draft) {
        $url = get_edit_post_link($draft->ID);
        $title = _draft_or_post_title($draft->ID);
        echo "<li>\n";
        echo '<div class="draft-title"><a href="' . esc_url($url) . '" title="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)) . '">' . esc_html($title) . '</a>';
        echo '<time datetime="' . get_the_time('c', $draft) . '">' . get_the_time(get_option('date_format'), $draft) . '</time></div>';
        if ($the_content = wp_trim_words($draft->post_content, 10)) {
            echo '<p>' . $the_content . '</p>';
        }
        echo "</li>\n";
    }
    echo "</ul>\n</div>";
}

WordPress Version: 4.3

/**
 * Show recent drafts of the user on the dashboard.
 *
 * @since 2.7.0
 *
 * @param array $drafts
 */
function wp_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $query_args = array('post_type' => 'post', 'post_status' => 'draft', 'author' => get_current_user_id(), 'posts_per_page' => 4, 'orderby' => 'modified', 'order' => 'DESC');
        $drafts = get_posts($query_args);
        if (!$drafts) {
            return;
        }
    }
    echo '<div class="drafts">';
    if (count($drafts) > 3) {
        echo '<p class="view-all"><a href="' . esc_url(admin_url('edit.php?post_status=draft')) . '">' . _x('View all', 'drafts') . "</a></p>\n";
    }
    echo '<h4 class="hide-if-no-js">' . __('Drafts') . "</h4>\n<ul>";
    $drafts = array_slice($drafts, 0, 3);
    foreach ($drafts as $draft) {
        $url = get_edit_post_link($draft->ID);
        $title = _draft_or_post_title($draft->ID);
        echo "<li>\n";
        echo '<div class="draft-title"><a href="' . esc_url($url) . '" title="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)) . '">' . esc_html($title) . '</a>';
        echo '<time datetime="' . get_the_time('c', $draft) . '">' . get_the_time(get_option('date_format'), $draft) . '</time></div>';
        if ($the_content = wp_trim_words($draft->post_content, 10)) {
            echo '<p>' . $the_content . '</p>';
        }
        echo "</li>\n";
    }
    echo "</ul>\n</div>";
}

WordPress Version: 3.8

/**
 * Show recent drafts of the user on the dashboard.
 *
 * @since 2.7.0
 */
function wp_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $query_args = array('post_type' => 'post', 'post_status' => 'draft', 'author' => get_current_user_id(), 'posts_per_page' => 4, 'orderby' => 'modified', 'order' => 'DESC');
        $drafts = get_posts($query_args);
        if (!$drafts) {
            return;
        }
    }
    echo '<div class="drafts">';
    if (count($drafts) > 3) {
        echo '<p class="view-all"><a href="' . esc_url(admin_url('edit.php?post_status=draft')) . '">' . _x('View all', 'drafts') . "</a></p>\n";
    }
    echo '<h4 class="hide-if-no-js">' . __('Drafts') . "</h4>\n<ul>";
    $drafts = array_slice($drafts, 0, 3);
    foreach ($drafts as $draft) {
        $url = get_edit_post_link($draft->ID);
        $title = _draft_or_post_title($draft->ID);
        echo "<li>\n";
        echo '<div class="draft-title"><a href="' . esc_url($url) . '" title="' . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)) . '">' . esc_html($title) . '</a>';
        echo '<time datetime="' . get_the_time('c', $draft) . '">' . get_the_time(get_option('date_format'), $draft) . '</time></div>';
        if ($the_content = wp_trim_words($draft->post_content, 10)) {
            echo '<p>' . $the_content . '</p>';
        }
        echo "</li>\n";
    }
    echo "</ul>\n</div>";
}

WordPress Version: 3.7

function wp_dashboard_recent_drafts($drafts = false)
{
    if (!$drafts) {
        $drafts_query = new WP_Query(array('post_type' => 'post', 'post_status' => 'draft', 'author' => $GLOBALS['current_user']->ID, 'posts_per_page' => 5, 'orderby' => 'modified', 'order' => 'DESC'));
        $drafts =& $drafts_query->posts;
    }
    if ($drafts && is_array($drafts)) {
        $list = array();
        foreach ($drafts as $draft) {
            $url = get_edit_post_link($draft->ID);
            $title = _draft_or_post_title($draft->ID);
            $item = "<h4><a href='{$url}' title='" . sprintf(__('Edit &#8220;%s&#8221;'), esc_attr($title)) . "'>" . esc_html($title) . "</a> <abbr title='" . get_the_time(__('Y/m/d g:i:s A'), $draft) . "'>" . get_the_time(get_option('date_format'), $draft) . '</abbr></h4>';
            if ($the_content = wp_trim_words($draft->post_content, 10)) {
                $item .= '<p>' . $the_content . '</p>';
            }
            $list[] = $item;
        }
        ?>
	<ul>
		<li><?php 
        echo join("</li>\n<li>", $list);
        ?></li>
	</ul>
	<p class="textright"><a href="edit.php?post_status=draft" ><?php 
        _e('View all');
        ?></a></p>
<?php 
    } else {
        _e('There are no drafts at the moment');
    }
}