Advertisement
SergeyBiryukov

Remove Post Status From Date Column

Feb 20th, 2017
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.14 KB | None | 0 0
  1. <?php
  2. class Remove_Post_Status_From_Date_Column {
  3.  
  4.     function __construct() {
  5.         add_filter( 'manage_posts_columns',              array( $this, 'replace_date_column' ) );
  6.         add_filter( 'manage_edit-post_sortable_columns', array( $this, 'replace_sortable_date_column' ) );
  7.         add_action( 'manage_posts_custom_column',        array( $this, 'display_short_date_column' ) );
  8.         add_action( 'admin_enqueue_scripts',             array( $this, 'add_inline_style' ) );
  9.     }
  10.  
  11.     function replace_date_column( $posts_columns ) {
  12.         unset( $posts_columns['date'] );
  13.  
  14.         $posts_columns['date-short'] = __( 'Date' );
  15.  
  16.         return $posts_columns;
  17.     }
  18.  
  19.     function replace_sortable_date_column( $sortable_columns ) {
  20.         unset( $sortable_columns['date'] );
  21.  
  22.         $sortable_columns['date-short'] = array( 'date', true );
  23.  
  24.         return $sortable_columns;
  25.     }
  26.  
  27.     function display_short_date_column( $column_name ) {
  28.         global $mode;
  29.  
  30.         if ( 'date-short' !== $column_name ) {
  31.             return;
  32.         }
  33.  
  34.         $post = get_post();
  35.  
  36.         if ( '0000-00-00 00:00:00' === $post->post_date ) {
  37.             $t_time = $h_time = __( 'Unpublished' );
  38.             $time_diff = 0;
  39.         } else {
  40.             $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
  41.             $m_time = $post->post_date;
  42.             $time = get_post_time( 'G', true, $post );
  43.  
  44.             $time_diff = time() - $time;
  45.  
  46.             if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
  47.                 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
  48.             } else {
  49.                 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
  50.             }
  51.         }
  52.  
  53.         if ( 'excerpt' === $mode ) {
  54.             /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
  55.             echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
  56.         } else {
  57.             /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
  58.             echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</abbr>';
  59.         }
  60.     }
  61.  
  62.     function add_inline_style( $hook_suffix ) {
  63.         if ( 'edit.php' !== $hook_suffix ) {
  64.             return;
  65.         }
  66.  
  67.         wp_add_inline_style( 'wp-admin', '.fixed .column-date-short { width: 10% }' );
  68.     }
  69.  
  70. }
  71.  
  72. new Remove_Post_Status_From_Date_Column;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement