Version Description
- feat: Implement new field datetime picker
- feat: Add filters for related posts fields with name and post types
Download this release
Release Info
Developer | Mirucon |
Plugin | Smart Custom Fields |
Version | 4.1.0 |
Comparing to | |
See all releases |
Code changes from version 4.0.2 to 4.1.0
classes/fields/class.field-datetime-picker.php
ADDED
@@ -0,0 +1,370 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class file for Smart_Custom_Fields_Field_Datetime_picker.
|
4 |
+
*
|
5 |
+
* @author Toshihiro Kanai <i@miruc.co>
|
6 |
+
* @package Smart_Custom_Fields
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class Smart_Custom_Fields_Field_Datetime_Picker.
|
11 |
+
*
|
12 |
+
* @since 4.x
|
13 |
+
*/
|
14 |
+
class Smart_Custom_Fields_Field_Datetime_Picker extends Smart_Custom_Fields_Field_Base {
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Set the required items
|
18 |
+
*
|
19 |
+
* @return array
|
20 |
+
*/
|
21 |
+
protected function init() {
|
22 |
+
add_action(
|
23 |
+
SCF_Config::PREFIX . 'before-editor-enqueue-scripts',
|
24 |
+
array( $this, 'editor_enqueue_scripts' )
|
25 |
+
);
|
26 |
+
add_action(
|
27 |
+
SCF_Config::PREFIX . 'before-settings-enqueue-scripts',
|
28 |
+
array( $this, 'settings_enqueue_scripts' )
|
29 |
+
);
|
30 |
+
return array(
|
31 |
+
'type' => 'datetime_picker',
|
32 |
+
'display-name' => __( 'Datetime picker', 'smart-custom-fields' ),
|
33 |
+
'optgroup' => 'other-fields',
|
34 |
+
);
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Set the non required items
|
39 |
+
*
|
40 |
+
* @return array
|
41 |
+
*/
|
42 |
+
protected function options() {
|
43 |
+
return array(
|
44 |
+
'date_format' => '',
|
45 |
+
'max_date' => '',
|
46 |
+
'min_date' => '',
|
47 |
+
'time_24hr' => '',
|
48 |
+
'default' => '',
|
49 |
+
'instruction' => '',
|
50 |
+
'notes' => '',
|
51 |
+
);
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Loading resources for editor
|
56 |
+
*/
|
57 |
+
public function editor_enqueue_scripts() {
|
58 |
+
wp_enqueue_style(
|
59 |
+
'flatpickr-style',
|
60 |
+
'//cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css',
|
61 |
+
array()
|
62 |
+
);
|
63 |
+
wp_enqueue_script(
|
64 |
+
'flatpickr-script',
|
65 |
+
'//cdn.jsdelivr.net/npm/flatpickr',
|
66 |
+
array(),
|
67 |
+
true,
|
68 |
+
true
|
69 |
+
);
|
70 |
+
wp_enqueue_script(
|
71 |
+
SCF_Config::PREFIX . 'flatpickr-script',
|
72 |
+
plugins_url( '../../js/settings-datetime-picker.js', __FILE__ ),
|
73 |
+
array( 'flatpickr-script' ),
|
74 |
+
false,
|
75 |
+
true
|
76 |
+
);
|
77 |
+
$locale = $this->get_locale_name();
|
78 |
+
if ( $locale ) {
|
79 |
+
wp_enqueue_script(
|
80 |
+
"flatpickr-lang-${locale}",
|
81 |
+
"//npmcdn.com/flatpickr/dist/l10n/${locale}.js",
|
82 |
+
array(),
|
83 |
+
false,
|
84 |
+
true
|
85 |
+
);
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Loading resources for editor for custom field settings page
|
91 |
+
*/
|
92 |
+
public function settings_enqueue_scripts() {
|
93 |
+
wp_enqueue_style(
|
94 |
+
'flatpickr-style',
|
95 |
+
'//cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css',
|
96 |
+
array()
|
97 |
+
);
|
98 |
+
wp_enqueue_script(
|
99 |
+
'flatpickr-script',
|
100 |
+
'//cdn.jsdelivr.net/npm/flatpickr',
|
101 |
+
array(),
|
102 |
+
false,
|
103 |
+
true
|
104 |
+
);
|
105 |
+
wp_enqueue_script(
|
106 |
+
SCF_Config::PREFIX . 'flatpickr-script',
|
107 |
+
plugins_url( '../../js/settings-datetime-picker.js', __FILE__ ),
|
108 |
+
array( 'flatpickr-script' ),
|
109 |
+
false,
|
110 |
+
true
|
111 |
+
);
|
112 |
+
$locale = $this->get_locale_name();
|
113 |
+
if ( $locale ) {
|
114 |
+
wp_enqueue_script(
|
115 |
+
"flatpickr-lang-${locale}",
|
116 |
+
"//npmcdn.com/flatpickr/dist/l10n/${locale}.js",
|
117 |
+
array(),
|
118 |
+
false,
|
119 |
+
true
|
120 |
+
);
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Get the field
|
126 |
+
*
|
127 |
+
* @param int $index Index number.
|
128 |
+
* @param string $value Value.
|
129 |
+
* @return string HTML content.
|
130 |
+
*/
|
131 |
+
public function get_field( $index, $value ) {
|
132 |
+
$name = $this->get_field_name_in_editor( $index );
|
133 |
+
$disabled = $this->get_disable_attribute( $index );
|
134 |
+
$data_js = $this->get_data_js();
|
135 |
+
|
136 |
+
return '<input
|
137 |
+
type="text"
|
138 |
+
name="' . esc_attr( $name ) . '"
|
139 |
+
value="' . esc_attr( $value ) . '"
|
140 |
+
class="' . esc_attr( SCF_Config::PREFIX . 'datetime_picker' ) . '"
|
141 |
+
data-js=\'' . $data_js . '\'
|
142 |
+
' . disabled( true, $disabled, false ) . '/>';
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Displaying the option fields in custom field settings page
|
147 |
+
*
|
148 |
+
* @param int $group_key Group key.
|
149 |
+
* @param int $field_key Field key.
|
150 |
+
*/
|
151 |
+
public function display_field_options( $group_key, $field_key ) {
|
152 |
+
$this->display_label_option( $group_key, $field_key );
|
153 |
+
$this->display_name_option( $group_key, $field_key );
|
154 |
+
?>
|
155 |
+
<tr>
|
156 |
+
<th><?php esc_html_e( 'Date Format', 'smart-custom-fields' ); ?></th>
|
157 |
+
<td>
|
158 |
+
<input type="text"
|
159 |
+
name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'date_format' ) ); ?>"
|
160 |
+
class="widefat"
|
161 |
+
value="<?php echo esc_attr( $this->get( 'date_format' ) ); ?>"
|
162 |
+
/><br />
|
163 |
+
<span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
|
164 |
+
<?php esc_html_e( 'e.g. Y-m-d', 'smart-custom-fields' ); ?>
|
165 |
+
<?php
|
166 |
+
printf(
|
167 |
+
/* translators: 1: Opening of a tag, 2: Closing a tag. */
|
168 |
+
esc_html__( '%1$sSee here%2$s for more information.', 'smart-custom-fields' ),
|
169 |
+
'<a href="https://flatpickr.js.org/options/" target="_blank">',
|
170 |
+
'</a>'
|
171 |
+
);
|
172 |
+
esc_html_e(
|
173 |
+
'This datetime picker currently does not include the timezone support, therefore you need to include some information on the instruction field below to enforce everyone to use the same timezone. The value returned by this field is always a plain text of date string.',
|
174 |
+
'smart-custom-fields'
|
175 |
+
);
|
176 |
+
?>
|
177 |
+
</span>
|
178 |
+
</td>
|
179 |
+
</tr>
|
180 |
+
<tr>
|
181 |
+
<th><?php esc_html_e( 'Max Date', 'smart-custom-fields' ); ?></th>
|
182 |
+
<td>
|
183 |
+
<input type="text"
|
184 |
+
name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'max_date' ) ); ?>"
|
185 |
+
class="widefat"
|
186 |
+
value="<?php echo esc_attr( $this->get( 'max_date' ) ); ?>"
|
187 |
+
/><br />
|
188 |
+
<span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
|
189 |
+
<?php esc_html_e( 'String or Date.', 'smart-custom-fields' ); ?>
|
190 |
+
<?php
|
191 |
+
printf(
|
192 |
+
/* translators: 1: Opening of a tag, 2: Closing a tag. */
|
193 |
+
esc_html__( '%1$sSee here%2$s for more information.', 'smart-custom-fields' ),
|
194 |
+
'<a href="https://flatpickr.js.org/examples/#mindate-and-maxdate" target="_blank">',
|
195 |
+
'</a>'
|
196 |
+
);
|
197 |
+
?>
|
198 |
+
</span>
|
199 |
+
</td>
|
200 |
+
</tr>
|
201 |
+
<tr>
|
202 |
+
<th><?php esc_html_e( 'Min Date', 'smart-custom-fields' ); ?></th>
|
203 |
+
<td>
|
204 |
+
<input type="text"
|
205 |
+
name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'min_date' ) ); ?>"
|
206 |
+
class="widefat"
|
207 |
+
value="<?php echo esc_attr( $this->get( 'min_date' ) ); ?>"
|
208 |
+
/><br />
|
209 |
+
<span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
|
210 |
+
<?php esc_html_e( 'String or Date.', 'smart-custom-fields' ); ?>
|
211 |
+
<?php
|
212 |
+
printf(
|
213 |
+
/* translators: 1: Opening of a tag, 2: Closing a tag. */
|
214 |
+
esc_html__( '%1$sSee here%2$s for more information.', 'smart-custom-fields' ),
|
215 |
+
'<a href="https://flatpickr.js.org/examples/#mindate-and-maxdate" target="_blank">',
|
216 |
+
'</a>'
|
217 |
+
);
|
218 |
+
?>
|
219 |
+
</span>
|
220 |
+
</td>
|
221 |
+
</tr>
|
222 |
+
<tr>
|
223 |
+
<th><?php esc_html_e( '24 Hour', 'smart-custom-fields' ); ?></th>
|
224 |
+
<td>
|
225 |
+
<input type="text"
|
226 |
+
name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'time_24hr' ) ); ?>"
|
227 |
+
class="widefat"
|
228 |
+
value="<?php echo esc_attr( $this->get( 'time_24hr' ) ); ?>"
|
229 |
+
/><br />
|
230 |
+
<span class="<?php echo esc_attr( SCF_Config::PREFIX ); ?>notes">
|
231 |
+
<?php esc_html_e( 'Use 24 hour or not. Provide boolean value, true or false (Default false).', 'smart-custom-fields' ); ?>
|
232 |
+
</span>
|
233 |
+
</td>
|
234 |
+
</tr>
|
235 |
+
<tr>
|
236 |
+
<th><?php esc_html_e( 'Instruction', 'smart-custom-fields' ); ?></th>
|
237 |
+
<td>
|
238 |
+
<textarea name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'instruction' ) ); ?>"
|
239 |
+
class="widefat" rows="5"><?php echo esc_attr( $this->get( 'instruction' ) ); ?></textarea>
|
240 |
+
</td>
|
241 |
+
</tr>
|
242 |
+
<tr>
|
243 |
+
<th><?php esc_html_e( 'Notes', 'smart-custom-fields' ); ?></th>
|
244 |
+
<td>
|
245 |
+
<input type="text"
|
246 |
+
name="<?php echo esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'notes' ) ); ?>"
|
247 |
+
class="widefat"
|
248 |
+
value="<?php echo esc_attr( $this->get( 'notes' ) ); ?>"
|
249 |
+
/>
|
250 |
+
</td>
|
251 |
+
</tr>
|
252 |
+
<?php
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* Return content of data-js to pass data to front-end.
|
257 |
+
*
|
258 |
+
* @return false|mixed|string
|
259 |
+
*/
|
260 |
+
private function get_data_js() {
|
261 |
+
$data = array();
|
262 |
+
|
263 |
+
if ( $this->get_locale_name() ) {
|
264 |
+
$data['locale'] = $this->get_locale_name();
|
265 |
+
}
|
266 |
+
|
267 |
+
if ( $this->get( 'date_format' ) ) {
|
268 |
+
$data['dateFormat'] = $this->get( 'date_format' );
|
269 |
+
}
|
270 |
+
|
271 |
+
if ( $this->get( 'max_date' ) ) {
|
272 |
+
$data['maxDate'] = $this->get( 'max_date' );
|
273 |
+
}
|
274 |
+
|
275 |
+
if ( $this->get( 'min_date' ) ) {
|
276 |
+
$data['minDate'] = $this->get( 'min_date' );
|
277 |
+
}
|
278 |
+
|
279 |
+
if ( $this->get( 'time_24hr' ) ) {
|
280 |
+
$data['time_24hr'] = $this->get( 'time_24hr' );
|
281 |
+
}
|
282 |
+
|
283 |
+
$data = apply_filters( SCF_Config::PREFIX . 'datetime_picker_data', $data );
|
284 |
+
|
285 |
+
return json_encode( $data );
|
286 |
+
}
|
287 |
+
|
288 |
+
/**
|
289 |
+
* Return locale name for flatpickr.
|
290 |
+
*
|
291 |
+
* @return false|string $locale
|
292 |
+
*/
|
293 |
+
private function get_locale_name() {
|
294 |
+
|
295 |
+
/**
|
296 |
+
* The locale list is hardcoded here. Because of this, when flatpickr adds support for new language it's required to update the list.
|
297 |
+
*
|
298 |
+
* The list is from: https://github.com/flatpickr/flatpickr/blob/master/src/l10n/index.ts
|
299 |
+
* Or at https://github.com/flatpickr/flatpickr/tree/master/src/l10n ,
|
300 |
+
* run the following script and copy the result:
|
301 |
+
* const list = document.querySelectorAll('.files .content > span > a'); const items = []; for (const item of list) { items.push(item.innerHTML.split('.')[0]) }; console.log(items)
|
302 |
+
*/
|
303 |
+
$supported_locales = array(
|
304 |
+
'ar',
|
305 |
+
'at',
|
306 |
+
'be',
|
307 |
+
'bg',
|
308 |
+
'bn',
|
309 |
+
'cat',
|
310 |
+
'cs',
|
311 |
+
'cy',
|
312 |
+
'da',
|
313 |
+
'de',
|
314 |
+
'eo',
|
315 |
+
'es',
|
316 |
+
'et',
|
317 |
+
'fa',
|
318 |
+
'fi',
|
319 |
+
'fo',
|
320 |
+
'fr',
|
321 |
+
'gr',
|
322 |
+
'he',
|
323 |
+
'hi',
|
324 |
+
'hr',
|
325 |
+
'hu',
|
326 |
+
'id',
|
327 |
+
'it',
|
328 |
+
'ja',
|
329 |
+
'km',
|
330 |
+
'ko',
|
331 |
+
'kz',
|
332 |
+
'lt',
|
333 |
+
'lv',
|
334 |
+
'mk',
|
335 |
+
'mn',
|
336 |
+
'ms',
|
337 |
+
'my',
|
338 |
+
'nl',
|
339 |
+
'no',
|
340 |
+
'pa',
|
341 |
+
'pl',
|
342 |
+
'pt',
|
343 |
+
'ro',
|
344 |
+
'ru',
|
345 |
+
'si',
|
346 |
+
'sk',
|
347 |
+
'sl',
|
348 |
+
'sq',
|
349 |
+
'sr',
|
350 |
+
'sv',
|
351 |
+
'th',
|
352 |
+
'tr',
|
353 |
+
'uk',
|
354 |
+
'vn',
|
355 |
+
'zh',
|
356 |
+
);
|
357 |
+
|
358 |
+
$wp_locale = get_locale();
|
359 |
+
if ( strpos( $wp_locale, '_' ) ) {
|
360 |
+
$user_lang = explode( $wp_locale, '_' )[0];
|
361 |
+
} else {
|
362 |
+
$user_lang = $wp_locale;
|
363 |
+
}
|
364 |
+
|
365 |
+
if ( in_array( $user_lang, $supported_locales, true ) ) {
|
366 |
+
return $user_lang;
|
367 |
+
}
|
368 |
+
return false;
|
369 |
+
}
|
370 |
+
}
|
classes/fields/class.field-related-posts.php
CHANGED
@@ -76,7 +76,6 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
|
|
76 |
public function relational_posts_search() {
|
77 |
check_ajax_referer( SCF_Config::NAME . '-relation-post-types', 'nonce' );
|
78 |
$_posts = array();
|
79 |
-
$args = array();
|
80 |
if ( isset( $_POST['post_types'] ) ) {
|
81 |
$post_type = explode( ',', $_POST['post_types'] );
|
82 |
$args = array(
|
@@ -89,8 +88,8 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
|
|
89 |
|
90 |
if ( isset( $_POST['click_count'] ) ) {
|
91 |
$posts_per_page = get_option( 'posts_per_page' );
|
92 |
-
$offset
|
93 |
-
$args
|
94 |
$args,
|
95 |
array(
|
96 |
'offset' => $offset,
|
@@ -107,6 +106,18 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
|
|
107 |
)
|
108 |
);
|
109 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
$_posts = get_posts( $args );
|
111 |
}
|
112 |
header( 'Content-Type: application/json; charset=utf-8' );
|
@@ -134,14 +145,26 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
|
|
134 |
}
|
135 |
$posts_per_page = get_option( 'posts_per_page' );
|
136 |
|
137 |
-
|
138 |
-
$choices_posts = get_posts( array(
|
139 |
'post_type' => $post_type,
|
140 |
'order' => 'ASC',
|
141 |
'orderby' => 'ID',
|
142 |
'posts_per_page' => $posts_per_page,
|
143 |
'post_status' => 'any',
|
144 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
$choices_li = array();
|
146 |
foreach ( $choices_posts as $_post ) {
|
147 |
$post_title = get_the_title( $_post->ID );
|
@@ -199,6 +222,7 @@ class Smart_Custom_Fields_Field_Related_Posts extends Smart_Custom_Fields_Field_
|
|
199 |
<ul>%s</ul>
|
200 |
<p class="load-relation-items load-relation-post-types %s">%s</p>
|
201 |
<input type="hidden" name="%s" %s />
|
|
|
202 |
%s
|
203 |
</div>
|
204 |
</div>
|
76 |
public function relational_posts_search() {
|
77 |
check_ajax_referer( SCF_Config::NAME . '-relation-post-types', 'nonce' );
|
78 |
$_posts = array();
|
|
|
79 |
if ( isset( $_POST['post_types'] ) ) {
|
80 |
$post_type = explode( ',', $_POST['post_types'] );
|
81 |
$args = array(
|
88 |
|
89 |
if ( isset( $_POST['click_count'] ) ) {
|
90 |
$posts_per_page = get_option( 'posts_per_page' );
|
91 |
+
$offset = $_POST['click_count'] * $posts_per_page;
|
92 |
+
$args = array_merge(
|
93 |
$args,
|
94 |
array(
|
95 |
'offset' => $offset,
|
106 |
)
|
107 |
);
|
108 |
}
|
109 |
+
|
110 |
+
$field_name = sanitize_text_field( $_POST['field_name'] );
|
111 |
+
/**
|
112 |
+
* This filter will be always applied when it queries posts in related posts field.
|
113 |
+
*/
|
114 |
+
$args = apply_filters( SCF_Config::PREFIX . 'custom_related_posts_args', $args, $field_name, $post_type );
|
115 |
+
|
116 |
+
/**
|
117 |
+
* This filter will only be applied when getting posts via ajax call, therefore it won't be applied for the first load.
|
118 |
+
*/
|
119 |
+
$args = apply_filters( SCF_Config::PREFIX . 'custom_related_posts_args_ajax_call', $args, $field_name, $post_type );
|
120 |
+
|
121 |
$_posts = get_posts( $args );
|
122 |
}
|
123 |
header( 'Content-Type: application/json; charset=utf-8' );
|
145 |
}
|
146 |
$posts_per_page = get_option( 'posts_per_page' );
|
147 |
|
148 |
+
$args = array(
|
|
|
149 |
'post_type' => $post_type,
|
150 |
'order' => 'ASC',
|
151 |
'orderby' => 'ID',
|
152 |
'posts_per_page' => $posts_per_page,
|
153 |
'post_status' => 'any',
|
154 |
+
);
|
155 |
+
|
156 |
+
/**
|
157 |
+
* This filter will be always applied when it queries posts in related posts field.
|
158 |
+
*/
|
159 |
+
$args = apply_filters( SCF_Config::PREFIX . 'custom_related_posts_args', $args, $name, $post_type );
|
160 |
+
/**
|
161 |
+
* This filter will only be applied in the first load, therefore it won't be applied when getting posts via ajax call.
|
162 |
+
*/
|
163 |
+
$args = apply_filters( SCF_Config::PREFIX . 'custom_related_posts_args_first_load', $args, $name, $post_type );
|
164 |
+
|
165 |
+
// Get posts to show in the first load.
|
166 |
+
$choices_posts = get_posts( $args );
|
167 |
+
|
168 |
$choices_li = array();
|
169 |
foreach ( $choices_posts as $_post ) {
|
170 |
$post_title = get_the_title( $_post->ID );
|
222 |
<ul>%s</ul>
|
223 |
<p class="load-relation-items load-relation-post-types %s">%s</p>
|
224 |
<input type="hidden" name="%s" %s />
|
225 |
+
<input type="hidden" id="smart-cf-field-name-data" data-js="' . $name . '" />
|
226 |
%s
|
227 |
</div>
|
228 |
</div>
|
js/editor-relation-post-types.js
CHANGED
@@ -65,11 +65,18 @@ jQuery( function( $ ) {
|
|
65 |
var btn_load_text = btn_load.text();
|
66 |
btn_load.text( 'Now loading...' );
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
args = $.extend( args, {
|
69 |
action : smart_cf_relation_post_types.action,
|
70 |
nonce : smart_cf_relation_post_types.nonce,
|
71 |
click_count: click_count,
|
72 |
-
post_types : post_types
|
|
|
73 |
} );
|
74 |
$.post(
|
75 |
smart_cf_relation_post_types.endpoint,
|
65 |
var btn_load_text = btn_load.text();
|
66 |
btn_load.text( 'Now loading...' );
|
67 |
|
68 |
+
var nameEl = document.getElementById('smart-cf-field-name-data');
|
69 |
+
var name = '';
|
70 |
+
if (nameEl) {
|
71 |
+
name = nameEl.getAttribute('data-js');
|
72 |
+
}
|
73 |
+
|
74 |
args = $.extend( args, {
|
75 |
action : smart_cf_relation_post_types.action,
|
76 |
nonce : smart_cf_relation_post_types.nonce,
|
77 |
click_count: click_count,
|
78 |
+
post_types : post_types,
|
79 |
+
field_name: name
|
80 |
} );
|
81 |
$.post(
|
82 |
smart_cf_relation_post_types.endpoint,
|
js/settings-datetime-picker.js
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
window.addEventListener('DOMContentLoaded', function() {
|
2 |
+
var el = document.querySelector('.smart-cf-datetime_picker');
|
3 |
+
|
4 |
+
if (el) {
|
5 |
+
var data = el.getAttribute('data-js');
|
6 |
+
data = JSON.parse(data);
|
7 |
+
data['enableTime'] = true;
|
8 |
+
}
|
9 |
+
|
10 |
+
flatpickr('.smart-cf-datetime_picker', data);
|
11 |
+
});
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== Smart Custom Fields ===
|
2 |
-
Contributors: inc2734, toro_unit, mimosafa, hideokamoto, hisako-isaka, kurudrive, hanamura, justinticktock, designhehe, mayukojpn, hogetan, robssanches
|
3 |
Donate link: http://www.amazon.co.jp/registry/wishlist/39ANKRNSTNW40
|
4 |
Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
|
5 |
Requires at least: 3.9
|
6 |
Tested up to: 4.9.8
|
7 |
-
Stable tag: 4.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -36,6 +36,7 @@ https://www.youtube.com/watch?v=WxPZurn0yvI
|
|
36 |
* Related Terms
|
37 |
* Color picker
|
38 |
* Date picker
|
|
|
39 |
* Boolean
|
40 |
* Message
|
41 |
|
@@ -128,6 +129,10 @@ You can translate this plugin into your language by using [GlotPress](https://tr
|
|
128 |
|
129 |
== Changelog ==
|
130 |
|
|
|
|
|
|
|
|
|
131 |
= 4.0.2 =
|
132 |
* Some updates by [@robssanches](https://github.com/robssanches)
|
133 |
|
1 |
=== Smart Custom Fields ===
|
2 |
+
Contributors: inc2734, toro_unit, mimosafa, hideokamoto, hisako-isaka, kurudrive, hanamura, justinticktock, designhehe, mayukojpn, hogetan, robssanches, mirucon
|
3 |
Donate link: http://www.amazon.co.jp/registry/wishlist/39ANKRNSTNW40
|
4 |
Tags: plugin, custom field, custom, field, meta, meta field, repeat, repeatable
|
5 |
Requires at least: 3.9
|
6 |
Tested up to: 4.9.8
|
7 |
+
Stable tag: 4.1.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
36 |
* Related Terms
|
37 |
* Color picker
|
38 |
* Date picker
|
39 |
+
* Datetime picker
|
40 |
* Boolean
|
41 |
* Message
|
42 |
|
129 |
|
130 |
== Changelog ==
|
131 |
|
132 |
+
= 4.1.0 =
|
133 |
+
* feat: Implement new field datetime picker
|
134 |
+
* feat: Add filters for related posts fields with name and post types
|
135 |
+
|
136 |
= 4.0.2 =
|
137 |
* Some updates by [@robssanches](https://github.com/robssanches)
|
138 |
|
smart-custom-fields.php
CHANGED
@@ -3,11 +3,9 @@
|
|
3 |
* Plugin name: Smart Custom Fields
|
4 |
* Plugin URI: https://github.com/inc2734/smart-custom-fields/
|
5 |
* Description: Smart Custom Fields is a simple plugin that management custom fields.
|
6 |
-
* Version: 4.0
|
7 |
* Author: inc2734
|
8 |
* Author URI: https://2inc.org
|
9 |
-
* Created: October 9, 2014
|
10 |
-
* Modified: August 12, 2018
|
11 |
* Text Domain: smart-custom-fields
|
12 |
* Domain Path: /languages
|
13 |
* License: GPLv2 or later
|
3 |
* Plugin name: Smart Custom Fields
|
4 |
* Plugin URI: https://github.com/inc2734/smart-custom-fields/
|
5 |
* Description: Smart Custom Fields is a simple plugin that management custom fields.
|
6 |
+
* Version: 4.1.0
|
7 |
* Author: inc2734
|
8 |
* Author URI: https://2inc.org
|
|
|
|
|
9 |
* Text Domain: smart-custom-fields
|
10 |
* Domain Path: /languages
|
11 |
* License: GPLv2 or later
|