PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.4
Pods – Custom Content Types and Fields v2.8.23.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 weeks ago boolean.php 2 weeks ago code.php 2 weeks ago color.php 2 weeks ago comment.php 2 weeks ago currency.php 2 weeks ago date.php 2 weeks ago datetime.php 2 weeks ago email.php 2 weeks ago file.php 2 weeks ago heading.php 2 weeks ago html.php 2 weeks ago link.php 2 weeks ago number.php 2 weeks ago oembed.php 2 weeks ago paragraph.php 2 weeks ago password.php 2 weeks ago phone.php 2 weeks ago pick.php 2 weeks ago slug.php 2 weeks ago taxonomy.php 2 weeks ago text.php 2 weeks ago time.php 2 weeks ago website.php 2 weeks ago wysiwyg.php 2 weeks ago
date.php
192 lines
1 <?php
2
3 /**
4 * @package Pods\Fields
5 */
6 class PodsField_Date extends PodsField_DateTime {
7
8 /**
9 * {@inheritdoc}
10 */
11 public static $group = 'Date / Time';
12
13 /**
14 * {@inheritdoc}
15 */
16 public static $type = 'date';
17
18 /**
19 * {@inheritdoc}
20 */
21 public static $label = 'Date';
22
23 /**
24 * {@inheritdoc}
25 */
26 public static $prepare = '%s';
27
28 /**
29 * {@inheritdoc}
30 */
31 public static $storage_format = 'Y-m-d';
32
33 /**
34 * {@inheritdoc}
35 */
36 public static $empty_value = '0000-00-00';
37
38 /**
39 * {@inheritdoc}
40 */
41 public function setup() {
42
43 static::$group = __( 'Date / Time', 'pods' );
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 'pick_show_select_text' => 0,
74 'dependency' => true,
75 ),
76 static::$type . '_format_custom' => array(
77 'label' => __( 'Date format for display', 'pods' ),
78 'depends-on' => array( static::$type . '_type' => 'custom' ),
79 'default' => '',
80 'type' => 'text',
81 'help' => sprintf(
82 '<a href="http://php.net/manual/function.date.php" target="_blank" rel="noopener noreferrer">%s</a>',
83 esc_html__( 'PHP date documentation', 'pods' )
84 ),
85 ),
86 static::$type . '_format_custom_js' => array(
87 'label' => __( 'Date format for input', 'pods' ),
88 'depends-on' => array( static::$type . '_type' => 'custom' ),
89 'default' => '',
90 'type' => 'text',
91 'help' => sprintf(
92 '<a href="https://api.jqueryui.com/datepicker/" target="_blank" rel="noopener noreferrer">%1$s</a><br />%2$s',
93 esc_html__( 'jQuery UI datepicker documentation', 'pods' ),
94 esc_html__( 'Leave empty to auto-generate from PHP format.', 'pods' )
95 ),
96 ),
97 static::$type . '_format' => array(
98 'label' => __( 'Date Format', 'pods' ),
99 'depends-on' => array( static::$type . '_type' => 'format' ),
100 'default' => 'mdy',
101 'type' => 'pick',
102 'data' => array(
103 'mdy' => date_i18n( 'm/d/Y' ),
104 'mdy_dash' => date_i18n( 'm-d-Y' ),
105 'mdy_dot' => date_i18n( 'm.d.Y' ),
106 'ymd_slash' => date_i18n( 'Y/m/d' ),
107 'ymd_dash' => date_i18n( 'Y-m-d' ),
108 'ymd_dot' => date_i18n( 'Y.m.d' ),
109 'fjy' => date_i18n( 'F j, Y' ),
110 'fjsy' => date_i18n( 'F jS, Y' ),
111 'y' => date_i18n( 'Y' ),
112 ),
113 'pick_show_select_text' => 0,
114 'dependency' => true,
115 ),
116 static::$type . '_year_range_custom' => array(
117 'label' => __( 'Year range', 'pods' ),
118 'default' => '',
119 'type' => 'text',
120 'help' => sprintf(
121 '%1$s<br /><a href="https://api.jqueryui.com/datepicker/#option-yearRange" target="_blank" rel="noopener noreferrer">%2$s</a>',
122 sprintf(
123 esc_html__( 'Example: %1$s for specifying a hard coded year range or %2$s for the last and next 10 years.', 'pods' ),
124 '<code>2010:2030</code>',
125 '<code>-10:+10</code>'
126 ),
127 esc_html__( 'jQuery UI datepicker documentation', 'pods' )
128 ),
129 ),
130 static::$type . '_allow_empty' => array(
131 'label' => __( 'Allow empty value', 'pods' ),
132 'default' => 1,
133 'type' => 'boolean',
134 ),
135 static::$type . '_html5' => array(
136 'label' => __( 'Enable HTML5 Input Field', 'pods' ),
137 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
138 'type' => 'boolean',
139 ),
140 );
141
142 // Check if PHP DateTime::createFromFormat exists for additional supported formats
143 if ( method_exists( 'DateTime', 'createFromFormat' ) || apply_filters( 'pods_form_ui_field_datetime_custom_formatter', false ) ) {
144 $options[ static::$type . '_format' ]['data'] = array_merge(
145 $options[ static::$type . '_format' ]['data'], array(
146 'dmy' => date_i18n( 'd/m/Y' ),
147 'dmy_dash' => date_i18n( 'd-m-Y' ),
148 'dmy_dot' => date_i18n( 'd.m.Y' ),
149 'dMy' => date_i18n( 'd/M/Y' ),
150 'dMy_dash' => date_i18n( 'd-M-Y' ),
151 )
152 );
153 }
154
155 $options[ static::$type . '_format' ]['data'] = apply_filters( 'pods_form_ui_field_date_format_options', $options[ static::$type . '_format' ]['data'] );
156 $options[ static::$type . '_format' ]['default'] = apply_filters( 'pods_form_ui_field_date_format_default', $options[ static::$type . '_format' ]['default'] );
157
158 return $options;
159 }
160
161 /**
162 * {@inheritdoc}
163 */
164 public function schema( $options = null ) {
165
166 $schema = 'DATE NOT NULL default "0000-00-00"';
167
168 return $schema;
169 }
170
171 /**
172 * {@inheritdoc}
173 */
174 public function format_display( $options, $js = false ) {
175
176 if ( $js && 'custom' === pods_v( static::$type . '_type', $options, 'format' ) ) {
177 $format = $this->format_datetime( $options, $js );
178 return $this->convert_format( $format, array( '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