checkbox.php
3 weeks ago
date.php
3 weeks ago
datetime.php
3 weeks ago
field.php
3 weeks ago
gallery.php
3 weeks ago
media.php
3 weeks ago
number.php
3 weeks ago
post.php
3 weeks ago
radio.php
3 weeks ago
repeater.php
3 weeks ago
select.php
3 weeks ago
switcher.php
3 weeks ago
text.php
3 weeks ago
time.php
3 weeks ago
toggle.php
3 weeks ago
user.php
3 weeks ago
date.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\AddonAPI; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 6 | |
| 7 | class PMXE_Addon_Date_Field extends PMXE_Addon_Field { |
| 8 | |
| 9 | public function isTimestamp( $string ) { |
| 10 | try { |
| 11 | new \DateTime( '@' . $string ); |
| 12 | } catch ( \Exception $e ) { |
| 13 | return false; |
| 14 | } |
| 15 | |
| 16 | return true; |
| 17 | } |
| 18 | |
| 19 | public function toString() { |
| 20 | if ( ! $this->value ) { |
| 21 | return ''; |
| 22 | } |
| 23 | |
| 24 | $timestamp = $this->isTimestamp( $this->value ) ? |
| 25 | $this->value : strtotime( $this->value ); |
| 26 | |
| 27 | // We need a default value for the settings if they're blank. |
| 28 | $this->settings = $this->settings ?: 'Y-m-d'; |
| 29 | |
| 30 | return prepare_date_field_value( |
| 31 | $this->settings, |
| 32 | $timestamp, |
| 33 | "Y-m-d" |
| 34 | ); |
| 35 | } |
| 36 | } |
| 37 |