[wp-trac] [WordPress Trac] #39595: date_default_timezone_set in wp-settings.php is set prematurely and ignorantly, regardless of other defined settings
WordPress Trac
noreply at wordpress.org
Wed Aug 3 18:52:30 UTC 2022
#39595: date_default_timezone_set in wp-settings.php is set prematurely and
ignorantly, regardless of other defined settings
-------------------------------+----------------------
Reporter: mkormendy | Owner: (none)
Type: enhancement | Status: closed
Priority: normal | Milestone:
Component: Date/Time | Version: 4.7.1
Severity: minor | Resolution: wontfix
Keywords: reporter-feedback | Focuses:
-------------------------------+----------------------
Comment (by Starbuck):
This is a temporary workaround for a specific scenario:
- The site admin wants debug.log for a specific site to show a specific
timezone.
- The setting does not apply to any other application or site on the
system.
I'm adding this comment because I have the above scenario, looked for a
solution, and was led to this ticket through comments in other venues.
While this isn't suitable as-is as a core solution to the challenge, it
might help folks who are looking for a simple solution or a tip for how to
start creating their own.
----
Create a new pre-setup-functions.php file in the WP root folder (perms
755). Move later after you see how this works.
{{{
#!php
<?php
set_error_handler(function ($err_severity, $err_msg, $err_file, $err_line,
array $err_context) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
}
date_default_timezone_set('America/Los_Angeles'); // change, read from
file or DB, ...
throw new ErrorException($err_msg, 0, $err_severity, $err_file,
$err_line);
});
}}}
In wp-config.php, after "/* Add any custom values...", add this line
(modify as required):
`include_once __DIR__ . '/site-specific-functions.php';`
The result is debug.log with the time in the desired timezone.
The message shows "Uncaught **Error**Exception". As one solution for
showing the correct exception type, see
[https://www.php.net/manual/en/function.set-error-handler.php#112881 this
helpful comment]. Replace the 'throw' line with the 'switch' block, and
add all the class definitions. This results in "Uncaught
**UserNotice**Exception", for example for E_USER_NOTICE.
Pros:
- Easy for anyone to implement, one line in wp-config and one file to
copy/paste.
- No change to core required.
- Implemented way before functions.php, to handle errors early in the
life-cycle.
- Shows callstack, not available by default from unhandled
trigger_error().
- Versatile : Can be extended and copied into multiple sites to show each
preferred timezone.
Cons:
- May interfere with plugin-specific handling or (doesn't look to me like
there are issues) with other core calls to set_error_handler.
- If another error handler is active, it will not use the specified
timezone, so debug.log may have a combination of UTC and local zone.
Inelegant solutions are available for this.
- Not-yet peer-reviewed for other possible concerns.
- Enhancements required to get more trace frames, avoid cutting off trace
text, other details.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39595#comment:23>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list