-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExpiredField.php
More file actions
43 lines (35 loc) · 1.23 KB
/
ExpiredField.php
File metadata and controls
43 lines (35 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace OWC\OpenPub\Base\RestAPI\ItemFields;
use DateTime;
use DateTimeZone;
use OWC\OpenPub\Base\Support\CreatesFields;
use WP_Post;
class ExpiredField extends CreatesFields
{
public function create(WP_Post $post): array
{
return $this->getExpiredStatus($post);
}
/**
* Get the expired status to the post.
*/
private function getExpiredStatus(WP_Post $post): array
{
$date = \get_post_meta($post->ID, '_owc_openpub_expirationdate', true); // Is timestamp.
if (empty($date) || ! is_numeric($date)) {
return [
'message' => '',
'status' => false,
'on' => false
];
}
$timezone = \wp_timezone_string();
$dateNow = new DateTime('now', new DateTimeZone($timezone));
$date = (new DateTime())->setTimestamp($date)->setTimezone(new DateTimeZone($timezone)); // The date is saved in the timezone of the Wordpress installation.
return [
'message' => ($date->getTimestamp() < $dateNow->getTimestamp()) ? 'Item is expired' : '',
'status' => ($date->getTimestamp() < $dateNow->getTimestamp()),
'on' => $date->format('Y-m-d H:i')
];
}
}