返回介绍

wp_dashboard_recent_drafts()

发布于 2017-09-11 11:46:20 字数 3701 浏览 1000 评论 0 收藏 0

wp_dashboard_recent_drafts( array $drafts = false )

Show recent drafts of the user on the dashboard.


description


参数

$drafts

(array) (Optional)

Default value: false


源代码

File: wp-admin/includes/dashboard.php

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 “%s”' ), $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>";
}

更新日志

Versiondescription
2.7.0Introduced.

相关函数

Uses

  • wp-admin/includes/dashboard.php: dashboard_recent_drafts_query_args
  • wp-admin/includes/template.php: _draft_or_post_title()
  • wp-includes/l10n.php: __()
  • wp-includes/l10n.php: _x()
  • wp-includes/formatting.php: esc_url()
  • wp-includes/formatting.php: esc_attr()
  • wp-includes/formatting.php: esc_html()
  • wp-includes/formatting.php: wp_trim_words()
  • wp-includes/general-template.php: get_the_time()
  • wp-includes/link-template.php: admin_url()
  • wp-includes/link-template.php: get_edit_post_link()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/user.php: get_current_user_id()
  • wp-includes/post.php: get_posts()
  • Show 9 more uses Hide more uses

Used By

  • wp-admin/includes/dashboard.php: wp_dashboard_quick_press()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文