PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.9.2
Pods – Custom Content Types and Fields v3.3.9.2
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / classes / fields / date.php
pods / classes / fields Last commit date
avatar.php 3 days ago boolean.php 3 days ago code.php 3 days ago color.php 3 days ago comment.php 3 days ago currency.php 3 days ago date.php 3 days ago datetime.php 3 days ago email.php 3 days ago file.php 3 days ago heading.php 3 days ago html.php 3 days ago link.php 3 days ago number.php 3 days ago oembed.php 3 days ago paragraph.php 3 days ago password.php 3 days ago phone.php 3 days ago pick.php 3 days ago slug.php 3 days ago taxonomy.php 3 days ago text.php 3 days ago time.php 3 days ago website.php 3 days ago wysiwyg.php 3 days ago
date.php
192 lines
1 <?php
2
3 // Don't load directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 die( '-1' );
6 }
7
8 /**
9 * @package Pods\Fields
10 */
11 class PodsField_Date extends PodsField_DateTime {
12
13 /**
14 * {@inheritdoc}
15 */
16 public static $group = 'Date / Time';
17
18 /**
19 * {@inheritdoc}
20 */
21 public static $type = 'date';
22
23 /**
24 * {@inheritdoc}
25 */
26 public static $label = 'Date';
27
28 /**
29 * {@inheritdoc}
30 */
31 public static $prepare = '%s';
32
33 /**
34 * {@inheritdoc}
35 */
36 public static $storage_format = 'Y-m-d';
37
38 /**
39 * {@inheritdoc}
40 */
41 public static $empty_value = '0000-00-00';
42
43 /**
44 * {@inheritdoc}
45 */
46 public function setup() {
47
48 static::$group = __( 'Date / Time', 'pods' );
49 static::$label = __( 'Date', 'pods' );
50 }
51
52 /**
53 * {@inheritdoc}
54 */
55 public function options() {
56
57 $options = [
58 static::$type . '_type' => [
59 'label' => __( 'Date Format Type', 'pods' ),
60 'default' => 'format',
61 // Backwards compatibility
62 'type' => 'pick',
63 'help' => __( 'WordPress Default is the format used in Settings, General under "Date Format".', 'pods' ) . '<br>' . __( 'Predefined Format will allow you to select from a list of commonly used date formats.', 'pods' ) . '<br>' . __( 'Custom will allow you to enter your own using PHP Date/Time Strings.', 'pods' ),
64 'data' => [
65 'wp' => __( 'WordPress default', 'pods' ) . ': ' . date_i18n( get_option( 'date_format' ) ),
66 'format' => __( 'Predefined format', 'pods' ),
67 'custom' => __( 'Custom format', 'pods' ),
68 ],
69 'pick_format_single' => 'dropdown',
70 'pick_show_select_text' => 0,
71 'dependency' => true,
72 ],
73 static::$type . '_format_custom' => [
74 'label' => __( 'Date format for display', 'pods' ),
75 'depends-on' => [ static::$type . '_type' => 'custom' ],
76 'default' => '',
77 'type' => 'text',
78 'help' => sprintf(
79 '<a href="http://php.net/manual/function.date.php" target="_blank" rel="noopener noreferrer">%s</a>',
80 esc_html__( 'PHP date documentation', 'pods' )
81 ),
82 ],
83 static::$type . '_format_custom_js' => [
84 'label' => __( 'Date format for input', 'pods' ),
85 'depends-on' => [ static::$type . '_type' => 'custom' ],
86 'default' => '',
87 'type' => 'text',
88 'help' => sprintf(
89 '<a href="https://api.jqueryui.com/datepicker/" target="_blank" rel="noopener noreferrer">%1$s</a><br />%2$s',
90 esc_html__( 'jQuery UI datepicker documentation', 'pods' ),
91 esc_html__( 'Leave empty to auto-generate from PHP format.', 'pods' )
92 ),
93 ],
94 static::$type . '_format' => [
95 'label' => __( 'Date Format', 'pods' ),
96 'depends-on' => [ static::$type . '_type' => 'format' ],
97 'default' => 'mdy',
98 'type' => 'pick',
99 'data' => [
100 'mdy' => date_i18n( 'm/d/Y' ),
101 'mdy_dash' => date_i18n( 'm-d-Y' ),
102 'mdy_dot' => date_i18n( 'm.d.Y' ),
103 'ymd_slash' => date_i18n( 'Y/m/d' ),
104 'ymd_dash' => date_i18n( 'Y-m-d' ),
105 'ymd_dot' => date_i18n( 'Y.m.d' ),
106 'fjy' => date_i18n( 'F j, Y' ),
107 'fjsy' => date_i18n( 'F jS, Y' ),
108 'y' => date_i18n( 'Y' ),
109 ],
110 'pick_format_single' => 'dropdown',
111 'pick_show_select_text' => 0,
112 'dependency' => true,
113 ],
114 static::$type . '_year_range_custom' => [
115 'label' => __( 'Year range', 'pods' ),
116 'default' => '',
117 'type' => 'text',
118 'help' => sprintf(
119 '%1$s<br /><a href="https://api.jqueryui.com/datepicker/#option-yearRange" target="_blank" rel="noopener noreferrer">%2$s</a>',
120 sprintf(
121 // translators: %1$s is an example of hard coded year range, %2$s is an example of relative year range.
122 esc_html__( 'Example: %1$s for specifying a hard coded year range or %2$s for the last and next 10 years.', 'pods' ),
123 '<code>2010:2030</code>',
124 '<code>-10:+10</code>'
125 ),
126 esc_html__( 'jQuery UI datepicker documentation', 'pods' )
127 ),
128 ],
129 static::$type . '_allow_empty' => [
130 'label' => __( 'Allow empty value', 'pods' ),
131 'default' => 1,
132 'type' => 'boolean',
133 ],
134 static::$type . '_html5' => [
135 'label' => __( 'Enable HTML5 Input Field', 'pods' ),
136 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
137 'type' => 'boolean',
138 ],
139 ];
140
141 // Check if PHP DateTime::createFromFormat exists for additional supported formats
142 if ( method_exists( 'DateTime', 'createFromFormat' ) || apply_filters( 'pods_form_ui_field_datetime_custom_formatter', false ) ) {
143 $options[ static::$type . '_format' ]['data'] = array_merge(
144 $options[ static::$type . '_format' ]['data'], [
145 'dmy' => date_i18n( 'd/m/Y' ),
146 'dmy_dash' => date_i18n( 'd-m-Y' ),
147 'dmy_dot' => date_i18n( 'd.m.Y' ),
148 'dMy' => date_i18n( 'd/M/Y' ),
149 'dMy_dash' => date_i18n( 'd-M-Y' ),
150 ]
151 );
152 }
153
154 $options[ static::$type . '_format' ]['data'] = apply_filters( 'pods_form_ui_field_date_format_options', $options[ static::$type . '_format' ]['data'] );
155 $options[ static::$type . '_format' ]['default'] = apply_filters( 'pods_form_ui_field_date_format_default', $options[ static::$type . '_format' ]['default'] );
156
157 return $options;
158 }
159
160 /**
161 * {@inheritdoc}
162 */
163 public function schema( $options = null ) {
164
165 $schema = 'DATE NOT NULL default \'0000-00-00\'';
166
167 return $schema;
168 }
169
170 /**
171 * {@inheritdoc}
172 */
173 public function format_display( $options, $js = false ) {
174
175 if ( $js && 'custom' === pods_v( static::$type . '_type', $options, 'format' ) ) {
176 $format = $this->format_datetime( $options, $js );
177
178 return $this->convert_format( $format, [ 'source' => 'jquery_ui', 'type' => 'date' ] );
179 }
180
181 return parent::format_display( $options, $js );
182 }
183
184 /**
185 * {@inheritdoc}
186 */
187 public function format_datetime( $options, $js = false ) {
188
189 return $this->format_date( $options, $js );
190 }
191 }
192