_post_states

The WordPress Core post states function.

Description

_post_states( (WP_Post) $post ); 

Parameters (1)

0. $post (WP_Post)
The post.

Usage

  1. if ( !function_exists( '_post_states' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/template.php'; 
  3.  
  4. // The post. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _post_states($post); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/template.php  
  1. function _post_states($post) { 
  2. $post_states = array(); 
  3. if ( isset( $_REQUEST['post_status'] ) ) 
  4. $post_status = $_REQUEST['post_status']; 
  5. else 
  6. $post_status = ''; 
  7.  
  8. if ( !empty($post->post_password) ) 
  9. $post_states['protected'] = __('Password protected'); 
  10. if ( 'private' == $post->post_status && 'private' != $post_status ) 
  11. $post_states['private'] = __('Private'); 
  12. if ( 'draft' == $post->post_status && 'draft' != $post_status ) 
  13. $post_states['draft'] = __('Draft'); 
  14. if ( 'pending' == $post->post_status && 'pending' != $post_status ) 
  15. $post_states['pending'] = _x('Pending', 'post status'); 
  16. if ( is_sticky($post->ID) ) 
  17. $post_states['sticky'] = __('Sticky'); 
  18.  
  19. if ( 'future' === $post->post_status ) { 
  20. $post_states['scheduled'] = __( 'Scheduled' ); 
  21.  
  22. if ( 'page' === get_option( 'show_on_front' ) ) { 
  23. if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) { 
  24. $post_states['page_on_front'] = __( 'Front Page' ); 
  25.  
  26. if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) { 
  27. $post_states['page_for_posts'] = __( 'Posts Page' ); 
  28.  
  29. /** 
  30. * Filters the default post display states used in the posts list table. 
  31. * @since 2.8.0 
  32. * @param array $post_states An array of post display states. 
  33. * @param WP_Post $post The current post object. 
  34. */ 
  35. $post_states = apply_filters( 'display_post_states', $post_states, $post ); 
  36.  
  37. if ( ! empty($post_states) ) { 
  38. $state_count = count($post_states); 
  39. $i = 0; 
  40. echo ' — '; 
  41. foreach ( $post_states as $state ) { 
  42. ++$i; 
  43. ( $i == $state_count ) ? $sep = '' : $sep = ', '; 
  44. echo "<span class='post-state'>$state$sep</span>"; 
  45.