ldc-groupe/content/plugins/wpai-acf-add-on/libraries/acf-fields/fields/fieldDateTimePicker.php
Vincent BRIDIER 134507db43 - Backup DEV
- Add DotEnv
- Fix Bato
- Etc..
2020-05-04 15:59:02 +02:00

70 lines
No EOL
2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace wpai_acf_add_on\acf\fields;
use wpai_acf_add_on\acf\ACFService;
/**
* Class FieldDateTimePicker
* @package wpai_acf_add_on\acf\fields
*/
class FieldDateTimePicker extends Field {
/**
* Field type key
*/
public $type = 'date_time_picker';
/**
*
* Parse field data
*
* @param $xpath
* @param $parsingData
* @param array $args
*/
public function parse($xpath, $parsingData, $args = array()) {
parent::parse($xpath, $parsingData, $args);
if ("" != $xpath) {
$values = $this->getByXPath($xpath);
foreach ($values as $i => $d) {
if ($d == 'now') {
$d = current_time('mysql');
} // Replace 'now' with the WordPress local time to account for timezone offsets (WordPress references its local time during publishing rather than the server’s time so it should use that)
$time = strtotime($d);
if (FALSE === $time) {
$values[$i] = $d;
} else {
$values[$i] = ACFService::isACFNewerThan('5.0.0') ? date('Y-m-d H:i:s', $time) : $time;
}
}
$this->setOption('values', $values);
}
}
/**
* @param $importData
* @param array $args
* @return void
*/
public function import($importData, $args = array()) {
$isUpdated = parent::import($importData, $args);
if ($isUpdated){
ACFService::update_post_meta($this, $this->getPostID(), $this->getFieldName(), $this->getFieldValue());
}
}
/**
* @return false|int|mixed|string
*/
public function getFieldValue() {
$time = strtotime(parent::getFieldValue());
if (FALSE === $time) {
$value = parent::getFieldValue();
}
else{
$value = ACFService::isACFNewerThan('5.0.0') ? date('Y-m-d H:i:s', $time) : $time;
}
return $value;
}
}