#21987 closed defect (bug) (fixed)
function get_post_time - if gmt (unset)
Reported by: | soficgr | Owned by: | |
---|---|---|---|
Milestone: | 5.3 | Priority: | normal |
Severity: | minor | Version: | |
Component: | Date/Time | Keywords: | |
Focuses: | Cc: |
Description
For no publish items and mode auto-draft = close
if GMT is unset ('0000-00-00 00:00:00' == $post->post_date_gmt)
at wp-includes/general-template.php function get_post_time effect list table -> date column (Last Modified -> %s hours)
Effect code : wordpress\wp-admin\includes\class-wp-posts-list-table.php
class WP_Posts_List_Table -> function single_row
Line 579 : $time = get_post_time( 'G', true, $post );
I don't know if it affects something else ...
Attachments (1)
Change History (8)
#2
@
12 years ago
Sorry, my approach was wrong.
WordPress is using the "0000-00-00 00:00:00" value as magic value for "no value". If we would set any valid 32-bit value in query.php, functions relying on the "no value" value would stop working as expected.
So the initial problem is, that years ago, someone used "0000-00-00 00:00:00" as a magic value for null instead of NULL. This was working on 32-bit systems, because "00-00-00 00:00:00" is an invalid date on 32-bit systems (see https://bugs.php.net/bug.php?id=53662). But on 64-bit systems, it is now a valid date.
=> A real solution would change the database schema to use NULL instead of "0000-00-00 00:00:00".
I will create another bug for that.
Unti this get fixed I would recommend:
- Fork get_post_time() function (this will be easier to maintain)
- Modify get_post_time() to set post_date_gmt when no value was set and you cannot or don't want to fork
#3
@
12 years ago
sorry for my late answer (work)
The problem starts here wordpress\wp-includes\post.php
function wp_insert_post ... (at line 2789)
// If the post date is empty (due to having been new or a draft) //and status is not 'draft' or 'pending', set date to now if ( empty($post_date) || '0000-00-00 00:00:00' == $post_date ) $post_date = current_time('mysql');
is not set and gmt date time. also same file at line :2802
if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) { if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) $post_date_gmt = get_gmt_from_date($post_date); else $post_date_gmt = '0000-00-00 00:00:00'; }
if the post status is 'draft', 'pending', 'auto-draft' has not gtm time but this use for wp as default and i think it is difficult to change this. This will create many compatibility problems if change. I'm not sure why they did this all type have status (not need to check for the gmt) but at several points wp check for this.
For example if the is not set gtm wp "now" the post is not publish but the post have status and can "now" this without gmt check. but this does :\
I gave one easy fix for the display problem ... but is true the problem is all this code who checks for gmt and not for status.
why the not publish types don't have gtm time? xmmm
#4
@
12 years ago
I forgot to say that, when we save type we have this info at $_POST
array (size=83) 'post_status' => string 'draft' 'post_type' => string 'post' ..... 'original_post_status' => string 'draft' ....
if the original_post_status is different from the post_status then we have change status.
we have everything except post_date_gmt (is empty)... because the wp don't set for not publish status.
only when we have new type (auto-draft - insert). we don't have at $_POST original_post_status, post_date, post_date_gmt, post_modified, post_modified_gmt.
array (size=15) 'post_status' => string 'auto-draft' 'post_type' => string 'post' .....
and this is definitely correct.
#6
@
5 years ago
- Keywords needs-testing dev-feedback needs-refresh removed
- Resolution set to fixed
- Status changed from new to closed
We shipped major get_post_time()
update in #25002 which is more robust and shouldn't rely on gmt field being set.
This is pretty ancient, so closing and will keep an eye out if anything related crops up (hopefully not).
I think you are fixing the problem in the wrong function. The root problem is, that some methods like get_post_time rely on a set post_date_gmt value. But this value isn't set on non-published items.
So I think we should fix it in WP_Post class in the get_posts() method in wp-includes/query.php at line ~2691:
should be
So every function/method relying on post_date_gmt will now work with drafts.