PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.8
Advanced Custom Fields: Extended v0.8
0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.9 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1 0.9.1.1 0.9.2 0.9.2.1 0.9.2.2 0.9.2.3 0.9.2.4 trunk 0.5 0.5.1 0.5.2 0.5.2.1 0.5.2.3 0.5.5 0.5.5.1 0.5.8 0.5.8.1 0.6 0.6.0.1 0.6.0.2 0.6.1 0.6.3 0.6.5 0.6.7 0.6.7.2 0.7 0.7.0.3 0.7.5 0.7.5.5 0.7.8 0.7.9 0.7.9.3 0.7.9.4 0.7.9.9.8 0.7.9.9.9 0.8 0.8.1 0.8.2 0.8.3 0.8.3.1 0.8.4 0.8.4.1 0.8.4.5 0.8.4.6 0.8.5 0.8.5.5
acf-extended / includes / fields / field-forms.php
acf-extended / includes / fields Last commit date
field-advanced-link.php 6 years ago field-button.php 6 years ago field-clone.php 6 years ago field-column.php 6 years ago field-dynamic-message.php 6 years ago field-file.php 6 years ago field-flexible-content.php 6 years ago field-forms.php 6 years ago field-group.php 6 years ago field-hidden.php 6 years ago field-image.php 6 years ago field-post-statuses.php 6 years ago field-post-types.php 6 years ago field-recaptcha.php 6 years ago field-repeater.php 6 years ago field-select.php 6 years ago field-slug.php 6 years ago field-taxonomies.php 6 years ago field-taxonomy-terms.php 6 years ago field-textarea.php 6 years ago field-user-roles.php 6 years ago
field-forms.php
376 lines
1 <?php
2
3 if(!defined('ABSPATH'))
4 exit;
5
6 class acfe_field_forms extends acf_field{
7
8 function __construct(){
9
10 $this->name = 'acfe_forms';
11 $this->label = __('Forms', 'acfe');
12 $this->category = 'relational';
13 $this->defaults = array(
14 'post_type' => array(),
15 'field_type' => 'checkbox',
16 'multiple' => 0,
17 'allow_null' => 0,
18 'choices' => array(),
19 'default_value' => '',
20 'ui' => 0,
21 'ajax' => 0,
22 'placeholder' => '',
23 'layout' => '',
24 'toggle' => 0,
25 'allow_custom' => 0,
26 'return_format' => 'name',
27 );
28
29 parent::__construct();
30
31 }
32
33 function prepare_field($field){
34
35 $field['choices'] = acfe_get_pretty_forms($field['forms']);
36
37 // Set Field Type
38 $field['type'] = $field['field_type'];
39
40 return $field;
41
42 }
43
44 function render_field_settings($field){
45
46 if(isset($field['default_value']))
47 $field['default_value'] = acf_encode_choices($field['default_value'], false);
48
49 // Allow Form
50 acf_render_field_setting($field, array(
51 'label' => __('Allow Forms','acf'),
52 'instructions' => '',
53 'type' => 'select',
54 'name' => 'forms',
55 'choices' => acfe_get_pretty_forms(),
56 'multiple' => 1,
57 'ui' => 1,
58 'allow_null' => 1,
59 'placeholder' => __("All forms",'acf'),
60 ));
61
62 // field_type
63 acf_render_field_setting($field, array(
64 'label' => __('Appearance','acf'),
65 'instructions' => __('Select the appearance of this field', 'acf'),
66 'type' => 'select',
67 'name' => 'field_type',
68 'optgroup' => true,
69 'choices' => array(
70 'checkbox' => __('Checkbox', 'acf'),
71 'radio' => __('Radio Buttons', 'acf'),
72 'select' => _x('Select', 'noun', 'acf')
73 )
74 ));
75
76 // default_value
77 acf_render_field_setting($field, array(
78 'label' => __('Default Value','acf'),
79 'instructions' => __('Enter each default value on a new line','acf'),
80 'name' => 'default_value',
81 'type' => 'textarea',
82 ));
83
84 // return_format
85 acf_render_field_setting($field, array(
86 'label' => __('Return Value', 'acf'),
87 'instructions' => '',
88 'type' => 'radio',
89 'name' => 'return_format',
90 'choices' => array(
91 'id' => __('Form ID', 'acfe'),
92 'name' => __('Form name', 'acfe')
93 ),
94 'layout' => 'horizontal',
95 ));
96
97 // Select + Radio: allow_null
98 acf_render_field_setting($field, array(
99 'label' => __('Allow Null?','acf'),
100 'instructions' => '',
101 'name' => 'allow_null',
102 'type' => 'true_false',
103 'ui' => 1,
104 'conditions' => array(
105 array(
106 array(
107 'field' => 'field_type',
108 'operator' => '==',
109 'value' => 'select',
110 ),
111 ),
112 array(
113 array(
114 'field' => 'field_type',
115 'operator' => '==',
116 'value' => 'radio',
117 ),
118 ),
119 )
120 ));
121
122 // placeholder
123 acf_render_field_setting($field, array(
124 'label' => __('Placeholder Text','acf'),
125 'instructions' => __('Appears within the input','acf'),
126 'type' => 'text',
127 'name' => 'placeholder',
128 'placeholder' => _x('Select', 'verb', 'acf'),
129 'conditional_logic' => array(
130 array(
131 array(
132 'field' => 'field_type',
133 'operator' => '==',
134 'value' => 'select',
135 ),
136 array(
137 'field' => 'allow_null',
138 'operator' => '==',
139 'value' => '1',
140 ),
141
142 )
143 )
144 ));
145
146 // Select: multiple
147 acf_render_field_setting($field, array(
148 'label' => __('Select multiple values?','acf'),
149 'instructions' => '',
150 'name' => 'multiple',
151 'type' => 'true_false',
152 'ui' => 1,
153 'conditions' => array(
154 array(
155 array(
156 'field' => 'field_type',
157 'operator' => '==',
158 'value' => 'select',
159 ),
160 ),
161 )
162 ));
163
164 // Select: ui
165 acf_render_field_setting($field, array(
166 'label' => __('Stylised UI','acf'),
167 'instructions' => '',
168 'name' => 'ui',
169 'type' => 'true_false',
170 'ui' => 1,
171 'conditions' => array(
172 array(
173 array(
174 'field' => 'field_type',
175 'operator' => '==',
176 'value' => 'select',
177 ),
178 ),
179 )
180 ));
181
182
183 // Select: ajax
184 acf_render_field_setting($field, array(
185 'label' => __('Use AJAX to lazy load choices?','acf'),
186 'instructions' => '',
187 'name' => 'ajax',
188 'type' => 'true_false',
189 'ui' => 1,
190 'conditions' => array(
191 array(
192 array(
193 'field' => 'field_type',
194 'operator' => '==',
195 'value' => 'select',
196 ),
197 array(
198 'field' => 'ui',
199 'operator' => '==',
200 'value' => 1,
201 ),
202 ),
203 )
204 ));
205
206 // Radio: other_choice
207 acf_render_field_setting($field, array(
208 'label' => __('Other','acf'),
209 'instructions' => '',
210 'name' => 'other_choice',
211 'type' => 'true_false',
212 'ui' => 1,
213 'message' => __("Add 'other' choice to allow for custom values", 'acf'),
214 'conditions' => array(
215 array(
216 array(
217 'field' => 'field_type',
218 'operator' => '==',
219 'value' => 'radio',
220 ),
221 ),
222 )
223 ));
224
225
226 // Radio: save_other_choice
227 acf_render_field_setting($field, array(
228 'label' => __('Save Other','acf'),
229 'instructions' => '',
230 'name' => 'save_other_choice',
231 'type' => 'true_false',
232 'ui' => 1,
233 'message' => __("Save 'other' values to the field's choices", 'acf'),
234 'conditions' => array(
235 array(
236 array(
237 'field' => 'field_type',
238 'operator' => '==',
239 'value' => 'radio',
240 ),
241 array(
242 'field' => 'other_choice',
243 'operator' => '==',
244 'value' => 1,
245 ),
246 ),
247 )
248 ));
249
250 // Checkbox: layout
251 acf_render_field_setting($field, array(
252 'label' => __('Layout','acf'),
253 'instructions' => '',
254 'type' => 'radio',
255 'name' => 'layout',
256 'layout' => 'horizontal',
257 'choices' => array(
258 'vertical' => __("Vertical",'acf'),
259 'horizontal' => __("Horizontal",'acf')
260 ),
261 'conditions' => array(
262 array(
263 array(
264 'field' => 'field_type',
265 'operator' => '==',
266 'value' => 'checkbox',
267 ),
268 ),
269 array(
270 array(
271 'field' => 'field_type',
272 'operator' => '==',
273 'value' => 'radio',
274 ),
275 ),
276 )
277 ));
278
279 // Checkbox: toggle
280 acf_render_field_setting($field, array(
281 'label' => __('Toggle','acf'),
282 'instructions' => __('Prepend an extra checkbox to toggle all choices','acf'),
283 'name' => 'toggle',
284 'type' => 'true_false',
285 'ui' => 1,
286 'conditions' => array(
287 array(
288 array(
289 'field' => 'field_type',
290 'operator' => '==',
291 'value' => 'checkbox',
292 ),
293 ),
294 )
295 ));
296
297 // Checkbox: other_choice
298 acf_render_field_setting($field, array(
299 'label' => __('Allow Custom','acf'),
300 'instructions' => '',
301 'name' => 'allow_custom',
302 'type' => 'true_false',
303 'ui' => 1,
304 'message' => __("Allow 'custom' values to be added", 'acf'),
305 'conditions' => array(
306 array(
307 array(
308 'field' => 'field_type',
309 'operator' => '==',
310 'value' => 'checkbox',
311 ),
312 ),
313 )
314 ));
315
316
317 // Checkbox: save_other_choice
318 acf_render_field_setting($field, array(
319 'label' => __('Save Custom','acf'),
320 'instructions' => '',
321 'name' => 'save_custom',
322 'type' => 'true_false',
323 'ui' => 1,
324 'message' => __("Save 'custom' values to the field's choices", 'acf'),
325 'conditions' => array(
326 array(
327 array(
328 'field' => 'field_type',
329 'operator' => '==',
330 'value' => 'checkbox',
331 ),
332 array(
333 'field' => 'allow_custom',
334 'operator' => '==',
335 'value' => 1,
336 ),
337 ),
338 )
339 ));
340
341 }
342
343
344 function format_value($value, $post_id, $field){
345
346 // Return: name
347 if($field['return_format'] === 'name'){
348
349 // array
350 if(acf_is_array($value)){
351
352 foreach($value as $i => $v){
353
354 $form_name = get_field('acfe_form_name', $v);
355
356 $value[$i] = $form_name;
357
358 }
359
360 // string
361 }else{
362
363 $value = get_field('acfe_form_name', $value);
364
365 }
366
367 }
368
369 // return
370 return $value;
371
372 }
373
374 }
375
376 new acfe_field_forms();