display_post_states

最后更新于:2021-11-26 07:53:38

apply_filters( ‘display_post_states’, string[] $post_states, GC_Post $post )

Filters the default post display states used in the posts list table.

参数

$post_states

(string[])
An array of post display states.

$post

(GC_Post)
The current post object.

源文件

文件: gc-admin/includes/template.php

View on Trac

/**
 * This always shows the current post status in the labels.
 *
 * @param array   $states current states.
 * @param GC_Post $post current post object.
 * @return array
 */
function custom_display_post_states( $states, $post ) {
	/* Receive the post status object by post status name */
	$post_status_object = get_post_status_object( $post->post_status );

	/* Checks if the label exists */
	if ( in_array( $post_status_object->label, $states, true ) ) {
		return $states;
	}

	/* Adds the label of the current post status */
	$states[ $post_status_object->name ] = $post_status_object->label;

	return $states;
}

add_filter( 'display_post_states', 'custom_display_post_states', 10, 2 );