PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.1-beta6
Secure Custom Fields v6.4.1-beta6
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / fields / class-acf-field-time_picker.php
secure-custom-fields / includes / fields Last commit date
class-acf-field-accordion.php 1 year ago class-acf-field-button-group.php 1 year ago class-acf-field-checkbox.php 1 year ago class-acf-field-clone.php 1 year ago class-acf-field-color_picker.php 1 year ago class-acf-field-date_picker.php 1 year ago class-acf-field-date_time_picker.php 1 year ago class-acf-field-email.php 1 year ago class-acf-field-file.php 1 year ago class-acf-field-flexible-content.php 1 year ago class-acf-field-gallery.php 1 year ago class-acf-field-google-map.php 1 year ago class-acf-field-group.php 1 year ago class-acf-field-icon_picker.php 1 year ago class-acf-field-image.php 1 year ago class-acf-field-link.php 1 year ago class-acf-field-message.php 1 year ago class-acf-field-number.php 1 year ago class-acf-field-oembed.php 1 year ago class-acf-field-output.php 1 year ago class-acf-field-page_link.php 1 year ago class-acf-field-password.php 1 year ago class-acf-field-post_object.php 1 year ago class-acf-field-radio.php 1 year ago class-acf-field-range.php 1 year ago class-acf-field-relationship.php 1 year ago class-acf-field-repeater.php 1 year ago class-acf-field-select.php 1 year ago class-acf-field-separator.php 1 year ago class-acf-field-tab.php 1 year ago class-acf-field-taxonomy.php 1 year ago class-acf-field-text.php 1 year ago class-acf-field-textarea.php 1 year ago class-acf-field-time_picker.php 1 year ago class-acf-field-true_false.php 1 year ago class-acf-field-url.php 1 year ago class-acf-field-user.php 1 year ago class-acf-field-wysiwyg.php 1 year ago class-acf-field.php 1 year ago class-acf-repeater-table.php 1 year ago index.php 1 year ago
class-acf-field-time_picker.php
196 lines
1 <?php
2
3 if ( ! class_exists( 'acf_field_time_picker' ) ) :
4
5 class acf_field_time_picker extends acf_field {
6
7
8 /**
9 * This function will setup the field type data
10 *
11 * @type function
12 * @date 5/03/2014
13 * @since ACF 5.0.0
14 *
15 * @param n/a
16 * @return n/a
17 */
18 function initialize() {
19
20 // vars
21 $this->name = 'time_picker';
22 $this->label = __( 'Time Picker', 'secure-custom-fields' );
23 $this->category = 'advanced';
24 $this->description = __( 'An interactive UI for picking a time. The time format can be customized using the field settings.', 'secure-custom-fields' );
25 $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-time.png';
26 $this->doc_url = 'https://www.advancedcustomfields.com/resources/time-picker/';
27 $this->defaults = array(
28 'display_format' => 'g:i a',
29 'return_format' => 'g:i a',
30 );
31 }
32
33
34 /**
35 * Create the HTML interface for your field
36 *
37 * @param $field - an array holding all the field's data
38 *
39 * @type action
40 * @since ACF 3.6
41 * @date 23/01/13
42 */
43 function render_field( $field ) {
44
45 // Set value.
46 $display_value = '';
47
48 if ( $field['value'] ) {
49 $display_value = acf_format_date( $field['value'], $field['display_format'] );
50 }
51
52 // Elements.
53 $div = array(
54 'class' => 'acf-time-picker acf-input-wrap',
55 'data-time_format' => acf_convert_time_to_js( $field['display_format'] ),
56 );
57 $hidden_input = array(
58 'id' => $field['id'],
59 'class' => 'input-alt',
60 'type' => 'hidden',
61 'name' => $field['name'],
62 'value' => $field['value'],
63 );
64 $text_input = array(
65 'class' => $field['class'] . ' input',
66 'type' => 'text',
67 'value' => $display_value,
68 );
69 foreach ( array( 'readonly', 'disabled' ) as $k ) {
70 if ( ! empty( $field[ $k ] ) ) {
71 $hidden_input[ $k ] = $k;
72 $text_input[ $k ] = $k;
73 }
74 }
75
76 // Output.
77 ?>
78 <div <?php echo acf_esc_attrs( $div ); ?>>
79 <?php acf_hidden_input( $hidden_input ); ?>
80 <?php acf_text_input( $text_input ); ?>
81 </div>
82 <?php
83 }
84
85
86 /**
87 * Create extra options for your field. This is rendered when editing a field.
88 * The value of $field['name'] can be used (like bellow) to save extra data to the $field
89 *
90 * @type action
91 * @since ACF 3.6
92 * @date 23/01/13
93 *
94 * @param $field - an array holding all the field's data
95 */
96 function render_field_settings( $field ) {
97 $g_i_a = date_i18n( 'g:i a' );
98 $H_i_s = date_i18n( 'H:i:s' );
99
100 echo '<div class="acf-field-settings-split">';
101
102 acf_render_field_setting(
103 $field,
104 array(
105 'label' => __( 'Display Format', 'secure-custom-fields' ),
106 'hint' => __( 'The format displayed when editing a post', 'secure-custom-fields' ),
107 'type' => 'radio',
108 'name' => 'display_format',
109 'other_choice' => 1,
110 'choices' => array(
111 'g:i a' => '<span>' . $g_i_a . '</span><code>g:i a</code>',
112 'H:i:s' => '<span>' . $H_i_s . '</span><code>H:i:s</code>',
113 'other' => '<span>' . __( 'Custom:', 'secure-custom-fields' ) . '</span>',
114 ),
115 )
116 );
117
118 acf_render_field_setting(
119 $field,
120 array(
121 'label' => __( 'Return Format', 'secure-custom-fields' ),
122 'hint' => __( 'The format returned via template functions', 'secure-custom-fields' ),
123 'type' => 'radio',
124 'name' => 'return_format',
125 'other_choice' => 1,
126 'choices' => array(
127 'g:i a' => '<span>' . $g_i_a . '</span><code>g:i a</code>',
128 'H:i:s' => '<span>' . $H_i_s . '</span><code>H:i:s</code>',
129 'other' => '<span>' . __( 'Custom:', 'secure-custom-fields' ) . '</span>',
130 ),
131 )
132 );
133
134 echo '</div>';
135 }
136
137 /**
138 * This filter is appied to the $value after it is loaded from the db and before it is returned to the template
139 *
140 * @type filter
141 * @since ACF 3.6
142 * @date 23/01/13
143 *
144 * @param $value (mixed) the value which was loaded from the database
145 * @param $post_id (mixed) the post_id from which the value was loaded
146 * @param $field (array) the field array holding all the field options
147 * @return $value (mixed) the modified value
148 */
149 public function format_value( $value, $post_id, $field ) {
150 return acf_format_date( $value, $field['return_format'] );
151 }
152
153 /**
154 * This filter is applied to the $field after it is loaded from the database
155 * and ensures the return and display values are set.
156 *
157 * @type filter
158 * @since ACF 5.11.0
159 *
160 * @param array $field The field array holding all the field options.
161 * @return array
162 */
163 public function load_field( $field ) {
164 if ( empty( $field['display_format'] ) ) {
165 $field['display_format'] = $this->defaults['display_format'];
166 }
167
168 if ( empty( $field['return_format'] ) ) {
169 $field['return_format'] = $this->defaults['return_format'];
170 }
171
172 return $field;
173 }
174
175 /**
176 * Return the schema array for the REST API.
177 *
178 * @param array $field The field array.
179 * @return array
180 */
181 public function get_rest_schema( array $field ) {
182 return array(
183 'type' => array( 'string', 'null' ),
184 'description' => 'A `H:i:s` formatted time string.',
185 'required' => ! empty( $field['required'] ),
186 );
187 }
188 }
189
190
191 // initialize
192 acf_register_field_type( 'acf_field_time_picker' );
193 endif; // class_exists check
194
195 ?>
196