Skip to content

Commit be223c7

Browse files
committed
v1.3.5
1 parent 1ee198f commit be223c7

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

wordpress-date-shortcodes.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Author URI: https://infinitnet.io/
1111
* Plugin URI: https://github.com/infinitnet/wordpress-date-shortcodes
1212
* Update URI: https://github.com/infinitnet/wordpress-date-shortcodes
13-
* Version: 1.3.2
13+
* Version: 1.3.5
1414
* License: GPLv3
1515
* Text Domain: wordpress-date-shortcodes
1616
*/
@@ -23,28 +23,34 @@ function infinitnet_date_shortcode( $type, $format, $atts ) {
2323

2424
switch ( $type ) {
2525
case 'current':
26-
if ($format == 'Y') {
27-
$adjusted_date = strtotime("$adjustment year");
28-
} elseif ($format == 'F') {
29-
$adjusted_date = strtotime("$adjustment month");
30-
} else {
31-
$adjusted_date = strtotime("$adjustment day");
32-
}
33-
$date = date_i18n($format, $adjusted_date);
26+
$date_obj = new DateTime('now', new DateTimeZone(wp_timezone_string()));
27+
$date_obj->modify("$adjustment days");
28+
$date = date_i18n($format, $date_obj->getTimestamp());
3429
break;
30+
3531
case 'published':
3632
case 'modified':
37-
$post_date = ($type == 'published') ? get_the_date('Y-m-d', get_the_ID()) : get_the_modified_date('Y-m-d', get_the_ID());
38-
if ($format == 'Y') {
39-
$date = date_i18n($format, strtotime("$post_date +$adjustment year"));
40-
} elseif ($format == 'F') {
41-
$date = date_i18n($format, strtotime("$post_date +$adjustment month"));
42-
} else {
43-
$date = date_i18n($format, strtotime("$post_date +$adjustment day"));
33+
$post = get_post();
34+
if (!$post || !$post->ID) {
35+
return apply_filters('infinitnet_date_empty', '', $type, $format);
4436
}
37+
38+
$date_string = ($type === 'published')
39+
? $post->post_date
40+
: $post->post_modified;
41+
42+
$date = DateTime::createFromFormat(
43+
'Y-m-d H:i:s',
44+
$date_string,
45+
new DateTimeZone('UTC')
46+
)->setTimezone(new DateTimeZone(wp_timezone_string()));
47+
48+
$date->modify("$adjustment days");
49+
$date = date_i18n($format, $date->getTimestamp());
4550
break;
51+
4652
default:
47-
$date = '';
53+
return '';
4854
}
4955

5056
return $date;

0 commit comments

Comments
 (0)