_post_states( WP_Post $post )


Description Description


Parameters Parameters

$post

(WP_Post) (Required)


Top ↑

Source Source

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 ) {
		if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
			$post_states[] = __( 'Customization Draft' );
		} elseif ( 'draft' !== $post_status ) {
			$post_states['draft'] = __( 'Draft' );
		}
	} elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
		$post_states[] = __( 'Customization 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>";
		}
	}

}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.