PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 3.2.3
Nested Pages v3.2.3
3.3.1 3.2.15 3.2.14 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.2 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.3.1 1.6.3.2 1.6.4 1.6.5 1.6.5.1 1.6.5.2 1.6.6 1.6.7 1.6.8 1.7.0 1.7.1 2.0.1 2.0.2 2.0.3 2.0.4 3.0.1 3.0.10 3.0.11 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.21 3.1.22 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7
wp-nested-pages / app / Entities / PostType / PostTypeCustomFields.php
wp-nested-pages / app / Entities / PostType Last commit date
PostTypeCustomFields.php 7 years ago PostTypeRepository.php 3 years ago RegisterPostTypes.php 8 years ago
PostTypeCustomFields.php
88 lines
1 <?php
2 namespace NestedPages\Entities\PostType;
3
4 /**
5 * Enables the filtering of custom fields in the quick edit interface
6 * Basic field types currently supported : text|date|select
7 *
8 * Filter should return an array of fields
9 *
10 * Example:
11 * $fields = [
12 [
13 'key' => 'custom_field',
14 'label' => __('Custom Field', 'text-domain'),
15 'type' => 'date', // date|text|select
16 'format' => 'm/d/Y', // Required for date
17 'required' => false,
18 'validation_message' => __('A deadline is required.'),
19 'choices' => [] // For select type
20 ]
21 ];
22 */
23 class PostTypeCustomFields
24 {
25 public function outputFields($post_type, $column = 'left')
26 {
27 $fields = apply_filters('nestedpages_quickedit_custom_fields', [], $post_type, $column);
28 if ( empty($fields) ) return;
29 $out = '';
30 foreach ( $fields as $field ){
31 $method = $field['type'] . 'Field';
32 if ( method_exists($this, $method) ) $out .= $this->$method($field);
33 }
34 return $out;
35 }
36
37 public function dateField($field)
38 {
39 $out = '<div class="form-control np-datepicker-container">';
40 $out .= '<label>' . $field['label'] . '</label>';
41 $out .= '<div class="datetime"><input type="text" data-datepicker-format="' . $field['format_datepicker'] . '" name="np_custom_' . $field['key'] . '" class="np_datepicker full" value="" data-np-custom-field="' . $field['key'] . '" /></div>';
42 $out .= '</div>';
43 return $out;
44 }
45
46 public function textField($field)
47 {
48 $out = '<div class="form-control">';
49 $out .= '<label>' . $field['label'] . '</label>';
50 $out .= '<input type="text" name="np_custom_' . $field['key'] . '" value="" data-np-custom-field="' . $field['key'] . '" />';
51 $out .= '</div>';
52 return $out;
53 }
54
55 public function selectField($field)
56 {
57 $out = '<div class="form-control">';
58 $out .= '<label>' . $field['label'] . '</label>';
59 $out .= '<select name="np_custom_' . $field['key'] . '" value="" data-np-custom-field="' . $field['key'] . '">';
60 foreach ( $field['choices'] as $key => $label ){
61 $out .= '<option value="' . $key . '">' . $label . '</option>';
62 }
63 $out .= '</select>';
64 $out .= '</div>';
65 return $out;
66 }
67
68 /**
69 * Output the data attributes for the post in quick edit for initial population
70 */
71 public function dataAttributes($post, $post_type)
72 {
73 $custom_fields_left = apply_filters('nestedpages_quickedit_custom_fields', [], $post_type, $column = 'left');
74 $custom_fields_right = apply_filters('nestedpages_quickedit_custom_fields', [], $post_type, $column = 'right');
75 $custom_fields = array_merge($custom_fields_left, $custom_fields_right);
76 $out = '';
77 if ( empty($custom_fields) ) return $out;
78 foreach ( $custom_fields as $field ) :
79 $custom_value = ( isset($post->meta[$field['key']]) ) ? $post->meta[$field['key']] : null;
80 if ( $custom_value ) :
81 $value = $custom_value[0];
82 if ( $field['type'] == 'date' && $field['format_save'] && $value !== '' ) $value = date($field['format_save'], strtotime($value));
83 $out .= ' data-npcustom-' . $field['key'] . '="' . $value . '"';
84 endif;
85 endforeach;
86 return $out;
87 }
88 }