Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Add_Last_Modified_Date_To_Post_Columns {
- function __construct() {
- add_filter( 'manage_posts_columns', array( $this, 'add_column' ), 10, 2 );
- add_filter( 'manage_edit-post_sortable_columns', array( $this, 'add_sortable_column' ), 10, 2 );
- add_action( 'manage_posts_custom_column', array( $this, 'display_column' ), 10, 2 );
- add_action( 'admin_enqueue_scripts', array( $this, 'add_inline_style' ) );
- }
- function add_column( $posts_columns, $post_type ) {
- $posts_columns['modified'] = __( 'Last Modified' );
- return $posts_columns;
- }
- function add_sortable_column( $sortable_columns ) {
- $sortable_columns['modified'] = array( 'modified', true );
- return $sortable_columns;
- }
- function display_column( $column_name, $post_id ) {
- global $mode;
- if ( 'modified' !== $column_name ) {
- return;
- }
- $post = get_post( $post_id );
- if ( '0000-00-00 00:00:00' == $post->post_date ) {
- $t_time = $h_time = __( 'Unpublished' );
- } else {
- $t_time = get_the_modified_time( __( 'Y/m/d g:i:s A' ) );
- $m_time = $post->post_modified;
- $time = get_post_modified_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 ) {
- echo $t_time;
- } else {
- echo '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
- }
- }
- function add_inline_style( $hook_suffix ) {
- if ( 'edit.php' !== $hook_suffix ) {
- return;
- }
- wp_add_inline_style( 'wp-admin', '.fixed .column-modified { width: 10% }' );
- }
- }
- new Add_Last_Modified_Date_To_Post_Columns;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment