Incorrect Datetime Bug Fix
This plugin was create to work around a problem caused by certain configurations in MySQL that lead to several odd symptoms including but not limited to: Loss of ability to create new posts Loss of ability to update posts Errors regarding invalid timestamps Admin interface reverts to lowest permissi
This plugin was create to work around a problem caused by certain configurations in MySQL that lead to several odd symptoms including but not limited to:
- Loss of ability to create new posts
- Loss of ability to update posts
- Errors regarding invalid timestamps
- Admin interface reverts to lowest permissions ex:‘Publish’ button says ‘Submit Draft’.
In addition, this problem is often accompanied by an error like the following:
WordPress database error: [Incorrect datetime value: '0000-00-00 00:00:00' for column 'post_date_gmt' at row 1] INSERT INTO 'mg_posts' ('post_author','post_date','post_date_gmt','post_content','post_content_filtered','post_title', 'post_excerpt','post_status','post_type','comment_status','ping_status','post_password','post_name','to_ping','pinged', 'post_modified','post_modified_gmt','post_parent','menu_order','guid') VALUES (’1′,’2011-08-23 03:32:43′, ’0000-00-00 00:00:00′,”,”,’Auto Draft’,”,’auto-draft’,'post’,'closed’,'open’,”,”,”,”,’2011-08-23 03:32:43′,’0000-00-00 00:00:00′,’0′,’0′,”)
The inability to pass zero dates breaks the ability to actually create a new post, but it also seems to have the odd secondary effect of confusing the heck out of nonces (noces are a security feature), probably because they too rely on timestamps.
This plugin strips out the sql_modes listed below from @@SESSION, thereby eliminating the problem while only effecting database sessions WordPress starts and not the whole database.
Explanation and history of the problem
The cause of this problem stems from an old (soon to be deprecated) odd behavior/feature of MySQL which WordPress came to depend on. My understanding is that it stems from problems in MySQL with regard to using the MySQL NOW() function in some contexts – so as a workaround it was decided that if a date of all zeros was entered on a column that was set as NOT NULL, then that date would not be rejected, but instead would be converted to the current date – to mimic NOW().
Subsequently this method was marginalized as generally a bad idea – and now values exist for a setting called sql_mode, which turn this behavior off and force errors when a null value is passed to a NOT NULL field. In many cases when there is an actual DBA in charge of the database, they will assign these values to the production database to force what outside of MySQL would be normal SQL behavior.