[wp-trac] [WordPress Trac] #53294: Adding filter hook to current_time() function
WordPress Trac
noreply at wordpress.org
Sun May 30 14:42:20 UTC 2021
#53294: Adding filter hook to current_time() function
-------------------------+------------------------------
Reporter: wpvar | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Date/Time | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch | Focuses: accessibility
-------------------------+------------------------------
Comment (by wpvar):
Problem is many theme and plugin developers are still using
`current_time()`, Just few examples:
https://github.com/elementor/elementor/search?q=current_time%28
https://github.com/rankmath/seo-by-rank-math/search?q=current_time%28
https://github.com/wp-media/wp-rocket/search?q=current_time%28
Without hooks we cannot convert gregorian date or stamp generated by
datetime class to other forms of dates e.g.
[https://en.wikipedia.org/wiki/Solar_Hijri_calendar Solar calendar].
Currently we are developing shamsi calendar plugin called
[https://wordpress.org/plugins/wp-shamsi/ WP Shamsi] which has more than
10,000 installs. There are many more date system plugins with hundreds of
thousands installations as well, now for example there is a plugin that
prints or stores date like this example:
{{{#!php
<?php
$date = wp_date('Y-m-d H:i:s');
echo $date;
}}}
by using `wp_date` We can convert gregorian date to other date systems
like:
{{{#!php
<?php
public function shamsi_date($date, $format, $timestamp, $timezone)
{
return $this->convert($date, $format);
}
add_filter('wp_date', array($this, 'shamsi_date'), 10, 4);
}}}
but for `current_time()`:
{{{#!php
<?php
$date = current_time( 'mysql' );
echo $date;
}}}
There isnt such a functionality and there is no way to alter returned
values.
To summarize what the topic is about, i think its fair to say there are
many plugins, themes and core as well that are using `current_time()`
function and it will return always uneditable values without existing of
hook. This applies to many WordPress users. applying filter can help lots
of local users.
Replying to [comment:1 Rarst]:
> `current_time()` is only retained for backwards compatibility, by now
it's just a thin wrapper around native PHP with unfortunate logic branch
producing the problematic "WordPress timestamp" (summed with a time zone
offset) case.
>
> In current WordPress code this function ''shouldn't even be used'', so
introducing new functionality to it is not on the table.
>
> Adjustments to date output in WordPress are usually handled on
localization level, such as `wp_date()` function/filter.
>
> However I am not sure what you want counts as localization or more
fundamental adjustment to whole date calculation?
>
> Open to see some example to understand the needs better, please. :)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53294#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list