WordPress Problem: PHP mktime() Not Working/Broken – Wrong Timezone
Quick note for WordPress developers, this one had me scratching my head.
If you use mktime() in your plugin code you will notice the timezone will always reflect GMT. There is a reason for this.
Notice that in settings, WordPress asks you for your locale. It then tells you what the time is in GMT and then what the new locale time is. Somehow, WordPress overrides php.ini, system time, etc and thinks its GMT when using mktime(). You cant change it anywhere, not in .htaccess ,nothing. It’s probably embedded deep within the core of wordpress somewhere, and has something to do with plugin functions called within the Loop.
Anyways, how do we get the current linux timestamp that mktime() normally so easily creates for us? Use the following wordpress function:
This will give you your standard linux timestamp. It also has the ability to create a mysql timestamp using the format:
Test it out, but don’t try using a separate .php to test as mktime() works fine outside of the Loop.
Hope this helps!!
At The Office at 12 AM, Thinking About ReLiC
Quick note for WordPress developers, this one had me scratching my head. If you use...