Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Remove_Post_Status_From_Date_Column {
- function __construct() {
- add_filter( 'manage_posts_columns', array( $this, 'replace_date_column' ) );
- add_filter( 'manage_edit-post_sortable_columns', array( $this, 'replace_sortable_date_column' ) );
- add_action( 'manage_posts_custom_column', array( $this, 'display_short_date_column' ) );
- add_action( 'admin_enqueue_scripts', array( $this, 'add_inline_style' ) );
- }
- function replace_date_column( $posts_columns ) {
- unset( $posts_columns['date'] );
- $posts_columns['date-short'] = __( 'Date' );
- return $posts_columns;
- }
- function replace_sortable_date_column( $sortable_columns ) {
- unset( $sortable_columns['date'] );
- $sortable_columns['date-short'] = array( 'date', true );
- return $sortable_columns;
- }
- function display_short_date_column( $column_name ) {
- global $mode;
- if ( 'date-short' !== $column_name ) {
- return;
- }
- $post = get_post();
- if ( '0000-00-00 00:00:00' === $post->post_date ) {
- $t_time = $h_time = __( 'Unpublished' );
- $time_diff = 0;
- } else {
- $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
- $m_time = $post->post_date;
- $time = get_post_time( 'G', true, $post );
- $time_diff = time() - $time;
- if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
- $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
- } else {
- $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
- }
- }
- if ( 'excerpt' === $mode ) {
- /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
- echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
- } else {
- /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
- echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</abbr>';
- }
- }
- function add_inline_style( $hook_suffix ) {
- if ( 'edit.php' !== $hook_suffix ) {
- return;
- }
- wp_add_inline_style( 'wp-admin', '.fixed .column-date-short { width: 10% }' );
- }
- }
- new Remove_Post_Status_From_Date_Column;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement