返回介绍

_post_states()

发布于 2017-09-11 13:32:04 字数 2790 浏览 1041 评论 0 收藏 0

_post_states( WP_Post $post )

description


参数

$post

(WP_Post) (Required)


源代码

File: wp-admin/includes/template.php

function _post_states($post) {
	$post_states = array();
	if ( isset( $_REQUEST['post_status'] ) )
		$post_status = $_REQUEST['post_status'];
	else
		$post_status = '';

	if ( !empty($post->post_password) )
		$post_states['protected'] = __('Password protected');
	if ( 'private' == $post->post_status && 'private' != $post_status )
		$post_states['private'] = __('Private');
	if ( 'draft' == $post->post_status && 'draft' != $post_status )
		$post_states['draft'] = __('Draft');
	if ( 'pending' == $post->post_status && 'pending' != $post_status )
		$post_states['pending'] = _x('Pending', 'post status');
	if ( is_sticky($post->ID) )
		$post_states['sticky'] = __('Sticky');

	if ( 'future' === $post->post_status ) {
		$post_states['scheduled'] = __( 'Scheduled' );
	}

	if ( 'page' === get_option( 'show_on_front' ) ) {
		if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) {
			$post_states['page_on_front'] = __( 'Front Page' );
		}

		if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) {
			$post_states['page_for_posts'] = __( 'Posts Page' );
		}
	}

	/**
	 * Filters the default post display states used in the posts list table.
	 *
	 * @since 2.8.0
	 * @since 3.6.0 Added the `$post` parameter.
	 *
	 * @param array   $post_states An array of post display states.
	 * @param WP_Post $post        The current post object.
	 */
	$post_states = apply_filters( 'display_post_states', $post_states, $post );

	if ( ! empty($post_states) ) {
		$state_count = count($post_states);
		$i = 0;
		echo ' — ';
		foreach ( $post_states as $state ) {
			++$i;
			( $i == $state_count ) ? $sep = '' : $sep = ', ';
			echo "<span class='post-state'>$state$sep</span>";
		}
	}

}

Collapse full 源代码 code View on Trac


相关函数

Uses

  • wp-admin/includes/template.php: display_post_states
  • wp-includes/l10n.php: __()
  • wp-includes/l10n.php: _x()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/option.php: get_option()
  • wp-includes/post.php: is_sticky()
  • Show 1 more use Hide more uses

Used By

  • wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::column_title()

User Contributed Notes

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

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

发布评论

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