• Resolved Sapphire

    (@sapphire)


    WordPress 2.5 does not show the exact time a post was published in the Manage Posts page, like older versions did. For those of us who future post, seeing the time a post goes live is crucial so we can avoid putting posts too close together. It’s very annoying having to open each post to see what time it’s set for.

    So I’m trying to write a plugin, only I’ve never written one before and am finding tutorials only help so much.

    What the plugin needs to do is replace lines 47 – 72 in /wp-admin/edit-post-rows.php:

    case 'date':
    if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
    $t_time = $h_time = __('Unpublished');
    } else {
    if ( 'modified' == $column_name ) {
    $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);
    } else {
    $t_time = get_the_time(__('Y/m/d g:i:s A'));
    $m_time = $post->post_date;
    $time = get_post_time('G', true);
    }
    if ( ( abs(time() - $time) ) < 86400 ) {
    if ( ( 'future' == $post->post_status) )
    $h_time = sprintf( __('%s from now'), human_time_diff( $time ) );
    else
    $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
    } else {
    $h_time = mysql2date(__('Y/m/d'), $m_time);
    }
    }
    ?>
    <td><abbr title="<?php echo $t_time ?>"><?php echo $h_time ?></abbr></td>
    <?php
    break;

    with

    case 'date':
    ?>
    <td><?php if ( '0000-00-00 00:00:00' ==$post->post_date) _e('Unpublished'); else the_time(__('Y-m-d \<\b\r \/\> g:i:s a')); ?></td>
    <?php
    break;

    I changed that in my actual edit-rows-post.php file, and it works.

    The plugin I’ve attempted to write is this:

    <?php
    if (!class_exists("ShowDateManagePosts")) {
    class ShowDateManagePosts {
    function ShowDateManagePosts() { //constructor
    
    }
    
    function showOldDate($h_time = '') {
    $h_time .= "mysql2date(__('Y/m/d \<\b\r \/\> g:i A'), $m_time);";
    return $h_time;
    }
    
    }
    } //End Class ShowDateManagePosts
    
    if (class_exists("ShowDateManagePosts")) {
    $sd_manageposts = new ShowDateManagePosts();
    }
    //Actions and Filters
    if (isset($sd_manageposts)) {
    //Actions
    add_action('restrict_manage_posts', array(&$ShowDateManagePosts, 'showOldDate'), 1);
    
    }
    ?>

    At one point in editing, it was actually replacing the “countdown” style dates with the old style dates, but it wasn’t showing the times. And there was a syntax error, so I edited some more and now it’s doing nothing and returning this error:

    Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'Array' was given in /home/bohemian/public_html/wp-includes/plugin.php on line 311

    Am I even barking up the right tree?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Sapphire,

    I’m not sure if you’re headed down the right path. I’m glad you put forth an effort unlike many people who just seem to say that they want a plugin and don’t even try to do things their way.

    Anyways, after that short tirade, I would go ahead and try the following, or just download the plugin at my site: https://nickohrn.com/wordpress-restore-exact-time-plugin

    /**
     * Avoid name collisions.
     */
    if(!class_exists('NFO_Restore_Exact_Time')) {
    
    	class NFO_Restore_Exact_Time {
    
    		/**
    		 * Constructor.
    		 */
    		function NFO_Restore_Exact_Time() { }
    
    		/**
    		 * Adds the exact time column to the plugin.
    		 */
    		function custom_columns($defaults) {
    			$other = array();
    			$other['cb'] = $defaults['cb'];
    			$other['exact'] = __('Date');
    			unset($defaults['cb']);
    			unset($defaults['date']);
    			return array_merge($other, $defaults);
    		}
    
    		/**
    		 * Echoes the exact time of the post/page that is being iterated over.
    		 */
    		function fill_column($column_name, $id) {
    			if('exact' == $column_name) {
    				$post = get_post($id);
    				echo $post->post_date;
    			}
    		}
    	} //end class
    
    } // end if
    
    /**
     * Insert action and filter hooks here
     */
    add_filter('manage_posts_columns', array('NFO_Restore_Exact_Time', 'custom_columns'));
    add_action('manage_posts_custom_column', array('NFO_Restore_Exact_Time', 'fill_column'), 10, 2);
    add_filter('manage_pages_columns', array('NFO_Restore_Exact_Time', 'custom_columns'));
    add_action('manage_pages_custom_column', array('NFO_Restore_Exact_Time', 'fill_column'), 10, 2);
    Thread Starter Sapphire

    (@sapphire)

    Oh, sweet! Thanks.

    Now I have what I wanted and something to study. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Help writing plugin to change date/time on Manage Posts’ is closed to new replies.