PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.7.31.4
Pods – Custom Content Types and Fields v2.7.31.4
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 2 days ago boolean.php 2 days ago code.php 2 days ago color.php 2 days ago comment.php 2 days ago currency.php 2 days ago date.php 2 days ago datetime.php 2 days ago email.php 2 days ago file.php 2 days ago html.php 2 days ago link.php 2 days ago number.php 2 days ago oembed.php 2 days ago paragraph.php 2 days ago password.php 2 days ago phone.php 2 days ago pick.php 2 days ago slug.php 2 days ago taxonomy.php 2 days ago text.php 2 days ago time.php 2 days ago website.php 2 days ago wysiwyg.php 2 days ago
date.php
190 lines
1 <?php
2 require_once PODS_DIR . 'classes/fields/datetime.php';
3
4 /**
5 * @package Pods\Fields
6 */
7 class PodsField_Date extends PodsField_DateTime {
8
9 /**
10 * {@inheritdoc}
11 */
12 public static $group = 'Date / Time';
13
14 /**
15 * {@inheritdoc}
16 */
17 public static $type = 'date';
18
19 /**
20 * {@inheritdoc}
21 */
22 public static $label = 'Date';
23
24 /**
25 * {@inheritdoc}
26 */
27 public static $prepare = '%s';
28
29 /**
30 * {@inheritdoc}
31 */
32 public static $storage_format = 'Y-m-d';
33
34 /**
35 * {@inheritdoc}
36 */
37 public static $empty_value = '0000-00-00';
38
39 /**
40 * {@inheritdoc}
41 */
42 public function setup() {
43
44 static::$label = __( 'Date', 'pods' );
45 }
46
47 /**
48 * {@inheritdoc}
49 */
50 public function options() {
51
52 $options = array(
53 static::$type . '_repeatable' => array(
54 'label' => __( 'Repeatable Field', 'pods' ),
55 'default' => 0,
56 'type' => 'boolean',
57 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ),
58 'boolean_yes_label' => '',
59 'dependency' => true,
60 'developer_mode' => true,
61 ),
62 static::$type . '_type' => array(
63 'label' => __( 'Date Format Type', 'pods' ),
64 'default' => 'format',
65 // Backwards compatibility
66 'type' => 'pick',
67 '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' ),
68 'data' => array(
69 'wp' => __( 'WordPress default', 'pods' ) . ': ' . date_i18n( get_option( 'date_format' ) ),
70 'format' => __( 'Predefined format', 'pods' ),
71 'custom' => __( 'Custom format', 'pods' ),
72 ),
73 'dependency' => true,
74 ),
75 static::$type . '_format_custom' => array(
76 'label' => __( 'Date format for display', 'pods' ),
77 'depends-on' => array( static::$type . '_type' => 'custom' ),
78 'default' => '',
79 'type' => 'text',
80 'help' => sprintf(
81 '<a href="http://php.net/manual/function.date.php" target="_blank" rel="noopener noreferrer">%s</a>',
82 esc_html__( 'PHP date documentation', 'pods' )
83 ),
84 ),
85 static::$type . '_format_custom_js' => array(
86 'label' => __( 'Date format for input', 'pods' ),
87 'depends-on' => array( static::$type . '_type' => 'custom' ),
88 'default' => '',
89 'type' => 'text',
90 'help' => sprintf(
91 '<a href="https://api.jqueryui.com/datepicker/" target="_blank" rel="noopener noreferrer">%1$s</a><br />%2$s',
92 esc_html__( 'jQuery UI datepicker documentation', 'pods' ),
93 esc_html__( 'Leave empty to auto-generate from PHP format.', 'pods' )
94 ),
95 ),
96 static::$type . '_format' => array(
97 'label' => __( 'Date Format', 'pods' ),
98 'depends-on' => array( static::$type . '_type' => 'format' ),
99 'default' => 'mdy',
100 'type' => 'pick',
101 'data' => array(
102 'mdy' => date_i18n( 'm/d/Y' ),
103 'mdy_dash' => date_i18n( 'm-d-Y' ),
104 'mdy_dot' => date_i18n( 'm.d.Y' ),
105 'ymd_slash' => date_i18n( 'Y/m/d' ),
106 'ymd_dash' => date_i18n( 'Y-m-d' ),
107 'ymd_dot' => date_i18n( 'Y.m.d' ),
108 'fjy' => date_i18n( 'F j, Y' ),
109 'fjsy' => date_i18n( 'F jS, Y' ),
110 'y' => date_i18n( 'Y' ),
111 ),
112 'dependency' => true,
113 ),
114 static::$type . '_year_range_custom' => array(
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 esc_html__( 'Example: %1$s for specifying a hard coded year range or %2$s for the last and next 10 years.', 'pods' ),
122 '<code>2010:2030</code>',
123 '<code>-10:+10</code>'
124 ),
125 esc_html__( 'jQuery UI datepicker documentation', 'pods' )
126 ),
127 ),
128 static::$type . '_allow_empty' => array(
129 'label' => __( 'Allow empty value?', 'pods' ),
130 'default' => 1,
131 'type' => 'boolean',
132 ),
133 static::$type . '_html5' => array(
134 'label' => __( 'Enable HTML5 Input Field?', 'pods' ),
135 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
136 'type' => 'boolean',
137 ),
138 );
139
140 // Check if PHP DateTime::createFromFormat exists for additional supported formats
141 if ( method_exists( 'DateTime', 'createFromFormat' ) || apply_filters( 'pods_form_ui_field_datetime_custom_formatter', false ) ) {
142 $options[ static::$type . '_format' ]['data'] = array_merge(
143 $options[ static::$type . '_format' ]['data'], array(
144 'dmy' => date_i18n( 'd/m/Y' ),
145 'dmy_dash' => date_i18n( 'd-m-Y' ),
146 'dmy_dot' => date_i18n( 'd.m.Y' ),
147 'dMy' => date_i18n( 'd/M/Y' ),
148 'dMy_dash' => date_i18n( 'd-M-Y' ),
149 )
150 );
151 }
152
153 $options[ static::$type . '_format' ]['data'] = apply_filters( 'pods_form_ui_field_date_format_options', $options[ static::$type . '_format' ]['data'] );
154 $options[ static::$type . '_format' ]['default'] = apply_filters( 'pods_form_ui_field_date_format_default', $options[ static::$type . '_format' ]['default'] );
155
156 return $options;
157 }
158
159 /**
160 * {@inheritdoc}
161 */
162 public function schema( $options = null ) {
163
164 $schema = 'DATE NOT NULL default "0000-00-00"';
165
166 return $schema;
167 }
168
169 /**
170 * {@inheritdoc}
171 */
172 public function format_display( $options, $js = false ) {
173
174 if ( $js && 'custom' === pods_v( static::$type . '_type', $options, 'format' ) ) {
175 $format = $this->format_datetime( $options, $js );
176 return $this->convert_format( $format, array( 'source' => 'jquery_ui', 'type' => 'date' ) );
177 }
178
179 return parent::format_display( $options, $js );
180 }
181
182 /**
183 * {@inheritdoc}
184 */
185 public function format_datetime( $options, $js = false ) {
186
187 return $this->format_date( $options, $js );
188 }
189 }
190