PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.2.5
Pods – Custom Content Types and Fields v3.2.5
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 years ago boolean.php 3 years ago code.php 2 years ago color.php 3 years ago comment.php 4 years ago currency.php 3 years ago date.php 2 years ago datetime.php 2 years ago email.php 3 years ago file.php 1 year ago heading.php 2 years ago html.php 2 years ago link.php 3 years ago number.php 2 years ago oembed.php 2 years ago paragraph.php 2 years ago password.php 3 years ago phone.php 3 years ago pick.php 1 year ago slug.php 3 years ago taxonomy.php 4 years ago text.php 2 years ago time.php 2 years ago website.php 3 years ago wysiwyg.php 2 years ago
date.php
185 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 . '_type' => array(
54 'label' => __( 'Date Format Type', 'pods' ),
55 'default' => 'format',
56 // Backwards compatibility
57 'type' => 'pick',
58 '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' ),
59 'data' => array(
60 'wp' => __( 'WordPress default', 'pods' ) . ': ' . date_i18n( get_option( 'date_format' ) ),
61 'format' => __( 'Predefined format', 'pods' ),
62 'custom' => __( 'Custom format', 'pods' ),
63 ),
64 'pick_format_single' => 'dropdown',
65 'pick_show_select_text' => 0,
66 'dependency' => true,
67 ),
68 static::$type . '_format_custom' => array(
69 'label' => __( 'Date format for display', 'pods' ),
70 'depends-on' => array( static::$type . '_type' => 'custom' ),
71 'default' => '',
72 'type' => 'text',
73 'help' => sprintf(
74 '<a href="http://php.net/manual/function.date.php" target="_blank" rel="noopener noreferrer">%s</a>',
75 esc_html__( 'PHP date documentation', 'pods' )
76 ),
77 ),
78 static::$type . '_format_custom_js' => array(
79 'label' => __( 'Date format for input', 'pods' ),
80 'depends-on' => array( static::$type . '_type' => 'custom' ),
81 'default' => '',
82 'type' => 'text',
83 'help' => sprintf(
84 '<a href="https://api.jqueryui.com/datepicker/" target="_blank" rel="noopener noreferrer">%1$s</a><br />%2$s',
85 esc_html__( 'jQuery UI datepicker documentation', 'pods' ),
86 esc_html__( 'Leave empty to auto-generate from PHP format.', 'pods' )
87 ),
88 ),
89 static::$type . '_format' => array(
90 'label' => __( 'Date Format', 'pods' ),
91 'depends-on' => array( static::$type . '_type' => 'format' ),
92 'default' => 'mdy',
93 'type' => 'pick',
94 'data' => array(
95 'mdy' => date_i18n( 'm/d/Y' ),
96 'mdy_dash' => date_i18n( 'm-d-Y' ),
97 'mdy_dot' => date_i18n( 'm.d.Y' ),
98 'ymd_slash' => date_i18n( 'Y/m/d' ),
99 'ymd_dash' => date_i18n( 'Y-m-d' ),
100 'ymd_dot' => date_i18n( 'Y.m.d' ),
101 'fjy' => date_i18n( 'F j, Y' ),
102 'fjsy' => date_i18n( 'F jS, Y' ),
103 'y' => date_i18n( 'Y' ),
104 ),
105 'pick_format_single' => 'dropdown',
106 'pick_show_select_text' => 0,
107 'dependency' => true,
108 ),
109 static::$type . '_year_range_custom' => array(
110 'label' => __( 'Year range', 'pods' ),
111 'default' => '',
112 'type' => 'text',
113 'help' => sprintf(
114 '%1$s<br /><a href="https://api.jqueryui.com/datepicker/#option-yearRange" target="_blank" rel="noopener noreferrer">%2$s</a>',
115 sprintf(
116 esc_html__( 'Example: %1$s for specifying a hard coded year range or %2$s for the last and next 10 years.', 'pods' ),
117 '<code>2010:2030</code>',
118 '<code>-10:+10</code>'
119 ),
120 esc_html__( 'jQuery UI datepicker documentation', 'pods' )
121 ),
122 ),
123 static::$type . '_allow_empty' => array(
124 'label' => __( 'Allow empty value', 'pods' ),
125 'default' => 1,
126 'type' => 'boolean',
127 ),
128 static::$type . '_html5' => array(
129 'label' => __( 'Enable HTML5 Input Field', 'pods' ),
130 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ),
131 'type' => 'boolean',
132 ),
133 );
134
135 // Check if PHP DateTime::createFromFormat exists for additional supported formats
136 if ( method_exists( 'DateTime', 'createFromFormat' ) || apply_filters( 'pods_form_ui_field_datetime_custom_formatter', false ) ) {
137 $options[ static::$type . '_format' ]['data'] = array_merge(
138 $options[ static::$type . '_format' ]['data'], array(
139 'dmy' => date_i18n( 'd/m/Y' ),
140 'dmy_dash' => date_i18n( 'd-m-Y' ),
141 'dmy_dot' => date_i18n( 'd.m.Y' ),
142 'dMy' => date_i18n( 'd/M/Y' ),
143 'dMy_dash' => date_i18n( 'd-M-Y' ),
144 )
145 );
146 }
147
148 $options[ static::$type . '_format' ]['data'] = apply_filters( 'pods_form_ui_field_date_format_options', $options[ static::$type . '_format' ]['data'] );
149 $options[ static::$type . '_format' ]['default'] = apply_filters( 'pods_form_ui_field_date_format_default', $options[ static::$type . '_format' ]['default'] );
150
151 return $options;
152 }
153
154 /**
155 * {@inheritdoc}
156 */
157 public function schema( $options = null ) {
158
159 $schema = 'DATE NOT NULL default \'0000-00-00\'';
160
161 return $schema;
162 }
163
164 /**
165 * {@inheritdoc}
166 */
167 public function format_display( $options, $js = false ) {
168
169 if ( $js && 'custom' === pods_v( static::$type . '_type', $options, 'format' ) ) {
170 $format = $this->format_datetime( $options, $js );
171 return $this->convert_format( $format, array( 'source' => 'jquery_ui', 'type' => 'date' ) );
172 }
173
174 return parent::format_display( $options, $js );
175 }
176
177 /**
178 * {@inheritdoc}
179 */
180 public function format_datetime( $options, $js = false ) {
181
182 return $this->format_date( $options, $js );
183 }
184 }
185