acf_admin_field_group::render_location_value()   F
last analyzed

Complexity

Conditions 35
Paths 54

Size

Total Lines 335

Duplication

Lines 46
Ratio 13.73 %

Importance

Changes 0
Metric Value
cc 35
nc 54
nop 1
dl 46
loc 335
rs 3.3333
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
*  ACF Admin Field Group Class
5
*
6
*  All the logic for editing a field group
7
*
8
*  @class 		acf_admin_field_group
9
*  @package		ACF
10
*  @subpackage	Admin
11
*/
12
13
if( ! class_exists('acf_admin_field_group') ) :
14
15
class acf_admin_field_group {
16
	
17
	
18
	/*
19
	*  __construct
20
	*
21
	*  This function will setup the class functionality
22
	*
23
	*  @type	function
24
	*  @date	5/03/2014
25
	*  @since	5.0.0
26
	*
27
	*  @param	n/a
28
	*  @return	n/a
29
	*/
0 ignored issues
show
Documentation introduced by
The doc-type n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
30
	
31
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
32
		
33
		// actions
34
		add_action('current_screen',									array($this, 'current_screen'));
35
		add_action('save_post',											array($this, 'save_post'), 10, 2);
36
		
37
		
38
		// ajax
39
		add_action('wp_ajax_acf/field_group/render_field_settings',		array($this, 'ajax_render_field_settings'));
40
		add_action('wp_ajax_acf/field_group/render_location_value',		array($this, 'ajax_render_location_value'));
41
		add_action('wp_ajax_acf/field_group/move_field',				array($this, 'ajax_move_field'));
42
		
43
		
44
		// filters
45
		add_filter('post_updated_messages',								array($this, 'post_updated_messages'));
46
		
47
	}
48
	
49
	
50
	/*
51
	*  post_updated_messages
52
	*
53
	*  This function will customize the message shown when editing a field group
54
	*
55
	*  @type	action (post_updated_messages)
56
	*  @date	30/04/2014
57
	*  @since	5.0.0
58
	*
59
	*  @param	$messages (array)
60
	*  @return	$messages
61
	*/
0 ignored issues
show
Documentation introduced by
The doc-type $messages could not be parsed: Unknown type name "$messages" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
62
	
63
	function post_updated_messages( $messages ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
64
		
65
		// append to messages
66
		$messages['acf-field-group'] = array(
67
			0 => '', // Unused. Messages start at index 1.
68
			1 => __('Field group updated.', 'acf'),
69
			2 => __('Field group updated.', 'acf'),
70
			3 => __('Field group deleted.', 'acf'),
71
			4 => __('Field group updated.', 'acf'),
72
			5 => false, // field group does not support revisions
73
			6 => __('Field group published.', 'acf'),
74
			7 => __('Field group saved.', 'acf'),
75
			8 => __('Field group submitted.', 'acf'),
76
			9 => __('Field group scheduled for.', 'acf'),
77
			10 => __('Field group draft updated.', 'acf')
78
		);
79
		
80
		
81
		// return
82
		return $messages;
83
	}
84
	
85
	
86
	/*
87
	*  current_screen
88
	*
89
	*  This function is fired when loading the admin page before HTML has been rendered.
90
	*
91
	*  @type	action (current_screen)
92
	*  @date	21/07/2014
93
	*  @since	5.0.0
94
	*
95
	*  @param	n/a
96
	*  @return	n/a
97
	*/
0 ignored issues
show
Documentation introduced by
The doc-type n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
98
	
99
	function current_screen() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
100
		
101
		// validate screen
102
		if( !acf_is_screen('acf-field-group') ) {
103
		
104
			return;
105
			
106
		}
107
		
108
		
109
		// disable JSON to avoid conflicts between DB and JSON
110
		acf_disable_local();
111
		
112
		
113
		// actions
114
		add_action('admin_enqueue_scripts',		array($this,'admin_enqueue_scripts'), 20);
115
		add_action('admin_head', 				array($this,'admin_head'), 20);
116
		add_action('admin_footer', 				array($this,'admin_footer'), 20);
117
		
118
	}
119
	
120
	
121
	/*
122
	*  admin_enqueue_scripts
123
	*
124
	*  This action is run after post query but before any admin script / head actions. 
125
	*  It is a good place to register all actions.
126
	*
127
	*  @type	action (admin_enqueue_scripts)
128
	*  @date	30/06/2014
129
	*  @since	5.0.0
130
	*
131
	*  @param	n/a
132
	*  @return	n/a
133
	*/
0 ignored issues
show
Documentation introduced by
The doc-type n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
134
	
135
	function admin_enqueue_scripts() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
136
		
137
		// no autosave
138
		wp_dequeue_script('autosave');
139
		
140
		
141
		// custom scripts
142
		wp_enqueue_style('acf-field-group');
143
		wp_enqueue_script('acf-field-group');
144
		
145
		
146
		// 3rd party hook
147
		do_action('acf/field_group/admin_enqueue_scripts');
148
		
149
	}
150
	
151
	
152
	/*
153
	*  admin_head
154
	*
155
	*  This function will setup all functionality for the field group edit page to work
156
	*
157
	*  @type	action (admin_head)
158
	*  @date	23/06/12
159
	*  @since	3.1.8
160
	*
161
	*  @param	$post_id (int)
162
	*  @return	$post_id (int)
163
	*/
0 ignored issues
show
Documentation introduced by
The doc-type $post_id could not be parsed: Unknown type name "$post_id" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
164
	
165
	function admin_head() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
166
		
167
		// global
168
		global $post, $field_group;
169
		
170
		
171
		// set global var
172
		$field_group = acf_get_field_group( $post );
173
		
174
		
175
		// metaboxes
176
		add_meta_box('acf-field-group-fields', __("Fields",'acf'), array($this, 'mb_fields'), 'acf-field-group', 'normal', 'high');
177
		add_meta_box('acf-field-group-locations', __("Location",'acf'), array($this, 'mb_locations'), 'acf-field-group', 'normal', 'high');
178
		add_meta_box('acf-field-group-options', __("Settings",'acf'), array($this, 'mb_options'), 'acf-field-group', 'normal', 'high');
179
		
180
		
181
		// actions
182
		add_action('post_submitbox_misc_actions',	array($this, 'post_submitbox_misc_actions'), 10, 0);
183
		add_action('edit_form_after_title',			array($this, 'edit_form_after_title'), 10, 0);
184
		
185
		
186
		// filters
187
		add_filter('screen_settings',				array($this, 'screen_settings'), 10, 1);
188
		
189
		
190
		// action for 3rd party customisation
191
		do_action('acf/field_group/admin_head');
192
		
193
	}
194
	
195
	
196
	/*
197
	*  admin_footer
198
	*
199
	*  description
200
	*
201
	*  @type	function
202
	*  @date	11/01/2016
203
	*  @since	5.3.2
204
	*
205
	*  @param	$post_id (int)
206
	*  @return	$post_id (int)
207
	*/
0 ignored issues
show
Documentation introduced by
The doc-type $post_id could not be parsed: Unknown type name "$post_id" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
208
	
209
	function admin_footer() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
210
		
211
		// global
212
		global $post;
213
		
214
		
215
		// vars
216
		$l10n = apply_filters('acf/field_group/admin_l10n', array(
217
			'move_to_trash'			=> __("Move to trash. Are you sure?",'acf'),
218
			'checked'				=> __("checked",'acf'),
219
			'no_fields'				=> __("No toggle fields available",'acf'),
220
			'title_is_required'		=> __("Field group title is required",'acf'),
221
			'copy'					=> __("copy",'acf'),
222
			'or'					=> __("or",'acf'),
223
			'fields'				=> __("Fields",'acf'),
224
			'parent_fields'			=> __("Parent fields",'acf'),
225
			'sibling_fields'		=> __("Sibling fields",'acf'),
226
			'move_field'			=> __("Move Custom Field",'acf'),
227
			'move_field_warning'	=> __("This field cannot be moved until its changes have been saved",'acf'),
228
			'null'					=> __("Null",'acf'),
229
			'unload'				=> __('The changes you made will be lost if you navigate away from this page','acf'),
230
			'field_name_start'		=> __('The string "field_" may not be used at the start of a field name','acf'),
231
		));
232
		
233
		$o = array(
234
			'post_id'				=> $post->ID,
235
			'nonce'					=> wp_create_nonce( 'acf_nonce' ),
236
			'admin_url'				=> admin_url(),
237
			'ajaxurl'				=> admin_url( 'admin-ajax.php' ),
238
			'validation'			=> 0,
239
		);
240
		
241
		
242
?>
243
<script type="text/javascript">
244
/* <![CDATA[ */
245
if( typeof acf !== 'undefined' ) {
246
247
	acf.o = <?php echo json_encode($o); ?>;
248
	acf.l10n = <?php echo json_encode($l10n); ?>;
249
	<?php do_action('acf/field_group/admin_footer_js'); ?>
250
	
251
	acf.do_action('prepare');
252
	
253
}
254
/* ]]> */
255
</script>
256
<?php
257
		
258
		
259
		// action for 3rd party customisation
260
		do_action('acf/field_group/admin_footer');
261
		
262
	}
263
	
264
	
265
	/*
266
	*  screen_settings
267
	*
268
	*  description
269
	*
270
	*  @type	function
271
	*  @date	26/01/13
272
	*  @since	3.6.0
273
	*
274
	*  @param	$current (string)
275
	*  @return	$current
276
	*/
0 ignored issues
show
Documentation introduced by
The doc-type $current could not be parsed: Unknown type name "$current" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
277
	
278
	function screen_settings( $html ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
279
		
280
		// vars
281
		$checked = acf_get_user_setting('show_field_keys') ? 'checked="checked"' : '';
282
		
283
		
284
		// append
285
	    $html .= '<div id="acf-append-show-on-screen" class="acf-hidden">';
286
	    $html .= '<label for="acf-field-key-hide"><input id="acf-field-key-hide" type="checkbox" value="1" name="show_field_keys" ' . $checked . ' /> ' . __('Field Keys','acf') . '</label>';
287
		$html .= '</div>';
288
	    
289
	    
290
	    // return
291
	    return $html;
292
	    
293
	}
294
	
295
	
296
	/*
297
	*  post_submitbox_misc_actions
298
	*
299
	*  This function will customize the publish metabox
300
	*
301
	*  @type	function
302
	*  @date	17/07/2015
303
	*  @since	5.2.9
304
	*
305
	*  @param	n/a
306
	*  @return	n/a
307
	*/
0 ignored issues
show
Documentation introduced by
The doc-type n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
308
	
309
	function post_submitbox_misc_actions() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
310
		
311
		// global
312
		global $field_group;
313
		
314
		
315
		// vars
316
		$status = $field_group['active'] ? __("Active",'acf') : __("Disabled",'acf');
317
		
318
?>
319
<script type="text/javascript">
320
(function($) {
321
	
322
	// modify status
323
	$('#post-status-display').html('<?php echo $status; ?>');
324
	
325
	
326
	// remove edit links
327
	$('#misc-publishing-actions a').remove();
328
	
329
	
330
	// remove editables (fixes status text changing on submit)
331
	$('#misc-publishing-actions .hide-if-js').remove();
332
	
333
})(jQuery);	
334
</script>
335
<?php	
336
		
337
	}
338
	
339
	
340
	/*
341
	*  edit_form_after_title
342
	*
343
	*  This action will allow ACF to render metaboxes after the title
344
	*
345
	*  @type	action
346
	*  @date	17/08/13
347
	*
348
	*  @param	n/a
349
	*  @return	n/a
350
	*/
0 ignored issues
show
Documentation introduced by
The doc-type n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
351
	
352
	function edit_form_after_title() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
353
		
354
		?>
355
		<div id="acf-form-data" class="acf-hidden">
356
			<input type="hidden" name="_acfnonce" value="<?php echo wp_create_nonce( 'field_group' ); ?>" />
357
			<input type="hidden" name="_acf_delete_fields" value="0" id="input-delete-fields" />
358
			<?php do_action('acf/field_group/form_data'); ?>
359
		</div>
360
		<?php
361
362
	}
363
	
364
	
365
	/*
366
	*  save_post
367
	*
368
	*  This function will save all the field group data
369
	*
370
	*  @type	function
371
	*  @date	23/06/12
372
	*  @since	1.0.0
373
	*
374
	*  @param	$post_id (int)
375
	*  @return	$post_id (int)
376
	*/
0 ignored issues
show
Documentation introduced by
The doc-type $post_id could not be parsed: Unknown type name "$post_id" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
377
	
378
	function save_post( $post_id, $post ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
379
		
380
		// do not save if this is an auto save routine
381
		if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
382
		
383
			return $post_id;
384
			
385
		}
386
		
387
		
388
		// bail early if not acf-field-group
389
		if( $post->post_type !== 'acf-field-group' ) {
390
			
391
			return $post_id;
392
			
393
		}
394
		
395
		
396
		// only save once! WordPress save's a revision as well.
397
		if( wp_is_post_revision($post_id) ) {
398
		
399
	    	return $post_id;
400
	    	
401
        }
402
        
403
        
404
		// verify nonce
405
		if( !acf_verify_nonce('field_group') ) {
406
		
407
			return $post_id;
408
			
409
		}
410
        
411
        
412
        // disable local to avoid conflicts between DB and local
413
		acf_disable_local();
414
		
415
        
416
        // save fields
417
		unset( $_POST['acf_fields']['acfcloneindex'] );
418
		
419
		if( !empty($_POST['acf_fields']) ) {
420
			
421
			foreach( $_POST['acf_fields'] as $field ) {
422
				
423
				// vars
424
				$specific = false;
425
				$save = acf_extract_var( $field, 'save' );
426
				
427
				
428
				// only saved field if has changed
429
				if( $save == 'meta' ) {
430
				
431
					$specific = array(
432
						'menu_order',
433
						'post_parent',
434
					);
435
					
436
				}
437
				
438
				
439
				// set field parent
440
				if( empty($field['parent']) ) {
441
					
442
					$field['parent'] = $post_id;
443
					
444
				}
445
				
446
				
447
				// save field
448
				acf_update_field( $field, $specific );
0 ignored issues
show
Bug introduced by
It seems like $specific defined by array('menu_order', 'post_parent') on line 431 can also be of type array<integer,string,{"0":"string","1":"string"}>; however, acf_update_field() does only seem to accept boolean, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
449
				
450
			}
451
			
452
		}
453
		
454
		
455
		// delete fields
456
        if( $_POST['_acf_delete_fields'] ) {
457
        	
458
	    	$ids = explode('|', $_POST['_acf_delete_fields']);
459
	    	$ids = array_map( 'intval', $ids );
460
	    	
461
			foreach( $ids as $id ) {
462
			
463
				if( $id != 0 ) {
464
				
465
					acf_delete_field( $id );
466
					
467
				}
468
				
469
			}
470
			
471
        }
472
		
473
		
474
		// add args
475
        $_POST['acf_field_group']['ID'] = $post_id;
476
        $_POST['acf_field_group']['title'] = $_POST['post_title'];
477
        
478
        
479
		// save field group
480
        acf_update_field_group( $_POST['acf_field_group'] );
481
		
482
		
483
        // return
484
        return $post_id;
485
	}
486
	
487
	
488
	/*
489
	*  mb_fields
490
	*
491
	*  This function will render the HTML for the medtabox 'acf-field-group-fields'
492
	*
493
	*  @type	function
494
	*  @date	28/09/13
495
	*  @since	5.0.0
496
	*
497
	*  @param	N/A
498
	*  @return	N/A
499
	*/
0 ignored issues
show
Documentation introduced by
The doc-type N/A could not be parsed: Unknown type name "N/A" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
500
	
501
	function mb_fields() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
502
		
503
		// global
504
		global $field_group;
505
		
506
		
507
		// get fields
508
		$view = array(
509
			'fields' => acf_get_fields_by_id( $field_group['ID'] )
510
		);
511
		
512
		
513
		// load view
514
		acf_get_view('field-group-fields', $view);
515
		
516
	}
517
	
518
	
519
	/*
520
	*  mb_options
521
	*
522
	*  This function will render the HTML for the medtabox 'acf-field-group-options'
523
	*
524
	*  @type	function
525
	*  @date	28/09/13
526
	*  @since	5.0.0
527
	*
528
	*  @param	N/A
529
	*  @return	N/A
530
	*/
0 ignored issues
show
Documentation introduced by
The doc-type N/A could not be parsed: Unknown type name "N/A" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
531
	
532
	function mb_options() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
533
		
534
		// global
535
		global $field_group;
536
		
537
		
538
		// field key (leave in for compatibility)
539
		if( !acf_is_field_group_key( $field_group['key']) ) {
540
			
541
			$field_group['key'] = uniqid('group_');
542
			
543
		}
544
		
545
		
546
		// don't use view because we need access to $this context
547
		include( acf_get_path('admin/views/field-group-options.php') );
548
		
549
	}
550
	
551
	
552
	/*
553
	*  mb_locations
554
	*
555
	*  This function will render the HTML for the medtabox 'acf-field-group-locations'
556
	*
557
	*  @type	function
558
	*  @date	28/09/13
559
	*  @since	5.0.0
560
	*
561
	*  @param	N/A
562
	*  @return	N/A
563
	*/
0 ignored issues
show
Documentation introduced by
The doc-type N/A could not be parsed: Unknown type name "N/A" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
564
	
565
	function mb_locations() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
566
		
567
		// global
568
		global $field_group;
569
		
570
		
571
		// UI needs at lease 1 location rule
572
		if( empty($field_group['location']) ) {
573
			
574
			$field_group['location'] = array(
575
				
576
				// group 0
577
				array(
578
					
579
					// rule 0
580
					array(
581
						'param'		=>	'post_type',
582
						'operator'	=>	'==',
583
						'value'		=>	'post',
584
					)
585
				)
586
				
587
			);
588
		}
589
		
590
		
591
		// don't use view because we need access to $this context
592
		include( acf_get_path('admin/views/field-group-locations.php') );
593
		
594
	}
595
	
596
	
597
	/*
598
	*  render_location_value
599
	*
600
	*  This function will render out an input containing location rule values for the given args
601
	*
602
	*  @type	function
603
	*  @date	30/09/13
604
	*  @since	5.0.0
605
	*
606
	*  @param	$options (array)
607
	*  @return	N/A
608
	*/
0 ignored issues
show
Documentation introduced by
The doc-type N/A could not be parsed: Unknown type name "N/A" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
609
	
610
	function render_location_value( $options ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
611
		
612
		// vars
613
		$options = wp_parse_args( $options, array(
614
			'group_id'	=> 0,
615
			'rule_id'	=> 0,
616
			'value'		=> null,
617
			'param'		=> null,
618
		));
619
		
620
		
621
		// vars
622
		$choices = array();
623
		
624
		
625
		// some case's have the same outcome
626
		if( $options['param'] == "page_parent" ) {
627
		
628
			$options['param'] = "page";
629
			
630
		}
631
632
		
633
		switch( $options['param'] ) {
634
			
635
			
636
			/*
637
			*  Post
638
			*/
639
			
640
			case "post_type" :
641
				
642
				// all post types except attachment
643
				$exclude = array('attachment');
644
				$choices = acf_get_post_types( $exclude );
645
				$choices = acf_get_pretty_post_types( $choices );
646
647
				break;
648
				
649
				
650
			case "post" :
651
				
652
				// get post types
653
				$exclude = array('page', 'attachment');
654
				$post_types = acf_get_post_types( $exclude );
655
				
656
						
657
				// get posts grouped by post type
658
				$groups = acf_get_grouped_posts(array(
659
					'post_type' => $post_types
660
				));
661
				
662
				
663 View Code Duplication
				if( !empty($groups) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
664
			
665
					foreach( array_keys($groups) as $group_title ) {
666
						
667
						// vars
668
						$posts = acf_extract_var( $groups, $group_title );
669
						
670
						
671
						// override post data
672
						foreach( array_keys($posts) as $post_id ) {
673
							
674
							// update
675
							$posts[ $post_id ] = acf_get_post_title( $posts[ $post_id ] );
676
							
677
						};
678
						
679
						
680
						// append to $choices
681
						$choices[ $group_title ] = $posts;
682
						
683
					}
684
					
685
				}
686
				
687
				break;
688
			
689
			
690
			case "post_category" :
691
				
692
				$terms = acf_get_taxonomy_terms( 'category' );
0 ignored issues
show
Documentation introduced by
'category' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
693
				
694
				if( !empty($terms) ) {
695
					
696
					$choices = array_pop($terms);
697
					
698
				}
699
				
700
				break;
701
			
702
			
703
			case "post_format" :
704
				
705
				$choices = get_post_format_strings();
706
								
707
				break;
708
			
709
			
710
			case "post_status" :
711
				
712
				global $wp_post_statuses;
713
				
714
				if( !empty($wp_post_statuses) ) {
715
					
716
					foreach( $wp_post_statuses as $status ) {
717
						
718
						$choices[ $status->name ] = $status->label;
719
						
720
					}
721
					
722
				}
723
								
724
				break;
725
			
726
			
727
			case "post_taxonomy" :
728
				
729
				$choices = acf_get_taxonomy_terms();
730
				
731
				// unset post_format
732
				if( isset($choices['post_format']) ) {
733
				
734
					unset( $choices['post_format']) ;
735
					
736
				}
737
							
738
				break;
739
			
740
			
741
			/*
742
			*  Page
743
			*/
744
			
745
			case "page" :
746
				
747
				
748
				// get posts grouped by post type
749
				$groups = acf_get_grouped_posts(array(
750
					'post_type' => 'page'
751
				));
752
				
753
				
754 View Code Duplication
				if( !empty($groups) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
755
			
756
					foreach( array_keys($groups) as $group_title ) {
757
						
758
						// vars
759
						$posts = acf_extract_var( $groups, $group_title );
760
						
761
						
762
						// override post data
763
						foreach( array_keys($posts) as $post_id ) {
764
							
765
							// update
766
							$posts[ $post_id ] = acf_get_post_title( $posts[ $post_id ] );
767
							
768
						};
769
						
770
						
771
						// append to $choices
772
						$choices = $posts;
773
						
774
					}
775
					
776
				}
777
				
778
				
779
				break;
780
				
781
			
782
			case "page_type" :
783
				
784
				$choices = array(
785
					'front_page'	=>	__("Front Page",'acf'),
786
					'posts_page'	=>	__("Posts Page",'acf'),
787
					'top_level'		=>	__("Top Level Page (no parent)",'acf'),
788
					'parent'		=>	__("Parent Page (has children)",'acf'),
789
					'child'			=>	__("Child Page (has parent)",'acf'),
790
				);
791
								
792
				break;
793
			
794
			
795
			case "page_parent" :
796
				
797
				// refer to "page"
798
				
799
				break;
800
			
801
			
802
			case "page_template" :
803
				
804
				$choices = array(
805
					'default'	=>	__("Default Template",'acf'),
806
				);
807
				
808
				$templates = get_page_templates();
809
				
810
				foreach( $templates as $k => $v ) {
811
				
812
					$choices[ $v ] = $k;
813
					
814
				}
815
				
816
				break;
817
				
818
			
819
			/*
820
			*  User
821
			*/
822
			
823
			case "current_user" :
824
				
825
				// viewing
826
				$choices = array(
827
					'logged_in'		=> __('Logged in', 'acf'),
828
					'viewing_front'	=> __('Viewing front end', 'acf'),
829
					'viewing_back'	=> __('Viewing back end', 'acf')
830
				);
831
								
832
				break;
833
			
834
			case "current_user_role" :
835
				
836
				// global
837
				global $wp_roles;
838
				
839
				
840
				// specific roles
841
				$choices = $wp_roles->get_names();
842
				
843
				
844
				// multi-site
845
				if( is_multisite() ) {
846
					
847
					$choices = array_merge(array(
848
						'super_admin' => __('Super Admin', 'acf')
849
					), $choices);
850
					
851
				}
852
				
853
				break;
854
			
855
			case "user_role" :
856
				
857
				global $wp_roles;
858
				
859
				$choices = array_merge( array('all' => __('All', 'acf')), $wp_roles->get_names() );
860
			
861
				break;
862
				
863
				
864
			case "user_form" :
865
				
866
				$choices = array(
867
					'all' 		=> __('All', 'acf'),
868
					'edit' 		=> __('Add / Edit', 'acf'),
869
					'register' 	=> __('Register', 'acf')
870
				);
871
			
872
				break;
873
				
874
			
875
			/*
876
			*  Forms
877
			*/
878
			
879
			case "attachment" :
880
				
881
				$choices = array('all' => __('All', 'acf'));
882
			
883
				break;
884
				
885
				
886
			case "taxonomy" :
887
				
888
				$choices = array_merge( array('all' => __('All', 'acf')), acf_get_taxonomies() );
889
				
890
								
891
				// unset post_format
892
				if( isset($choices['post_format']) ) {
893
				
894
					unset( $choices['post_format']);
895
					
896
				}
897
							
898
				break;
899
				
900
				
901
			case "comment" :
902
				
903
				$choices = array('all' => __('All', 'acf'));
904
			
905
				break;
906
			
907
			
908
			case "widget" :
909
				
910
				global $wp_widget_factory;
911
				
912
				$choices = array(
913
					'all' 		=> __('All', 'acf'),
914
				);
915
				
916
				
917
				if( !empty( $wp_widget_factory->widgets ) ) {
918
					
919
					foreach( $wp_widget_factory->widgets as $widget ) {
920
					
921
						$choices[ $widget->id_base ] = $widget->name;
922
						
923
					}
924
					
925
				}
926
								
927
				break;
928
		}
929
		
930
		
931
		// allow custom location rules
932
		$choices = apply_filters( 'acf/location/rule_values/' . $options['param'], $choices );
933
							
934
		
935
		// create field
936
		acf_render_field(array(
0 ignored issues
show
Documentation introduced by
array('type' => 'select'... 'choices' => $choices) is of type array<string,?,{"type":"...ue":"?","choices":"?"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
937
			'type'		=> 'select',
938
			'prefix'	=> "acf_field_group[location][{$options['group_id']}][{$options['rule_id']}]",
939
			'name'		=> 'value',
940
			'value'		=> $options['value'],
941
			'choices'	=> $choices,
942
		));
943
		
944
	}
945
	
946
	
947
	/*
948
	*  ajax_render_location_value
949
	*
950
	*  This function can be accessed via an AJAX action and will return the result from the render_location_value function
951
	*
952
	*  @type	function (ajax)
953
	*  @date	30/09/13
954
	*  @since	5.0.0
955
	*
956
	*  @param	n/a
957
	*  @return	n/a
958
	*/
0 ignored issues
show
Documentation introduced by
The doc-type n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
959
	
960
	function ajax_render_location_value() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
961
		
962
		// validate
963
		if( !acf_verify_ajax() ) {
964
		
965
			die();
966
			
967
		}
968
		
969
		
970
		// call function
971
		$this->render_location_value( $_POST );
972
		
973
		
974
		// die
975
		die();
976
								
977
	}
978
	
979
	
980
	/*
981
	*  ajax_render_field_settings
982
	*
983
	*  This function will return HTML containing the field's settings based on it's new type
984
	*
985
	*  @type	function (ajax)
986
	*  @date	30/09/13
987
	*  @since	5.0.0
988
	*
989
	*  @param	n/a
990
	*  @return	n/a
991
	*/
0 ignored issues
show
Documentation introduced by
The doc-type n/a could not be parsed: Unknown type name "n/a" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
992
	
993
	function ajax_render_field_settings() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
994
		
995
		// vars
996
		$options = array(
997
			'nonce'			=> '',
998
			'parent'		=> 0,
999
			'field_group'	=> 0,
1000
			'prefix'		=> '',
1001
			'type'			=> '',
1002
		);
1003
		
1004
		
1005
		// load post options
1006
		$options = wp_parse_args($_POST, $options);
1007
		
1008
		
1009
		// verify nonce
1010
		if( !wp_verify_nonce($options['nonce'], 'acf_nonce') ) {
1011
		
1012
			die(0);
1013
			
1014
		}
1015
		
1016
		
1017
		// required
1018
		if( !$options['type'] ) {
1019
		
1020
			die(0);
1021
			
1022
		}
1023
		
1024
				
1025
		// render options
1026
		$field = acf_get_valid_field(array(
0 ignored issues
show
Documentation introduced by
array('type' => $options...options['field_group']) is of type array<string,?,{"type":"..."?","field_group":"?"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1027
			'type'			=> $options['type'],
1028
			'name'			=> 'temp',
1029
			'prefix'		=> $options['prefix'],
1030
			'parent'		=> $options['parent'],
1031
			'field_group'	=> $options['field_group'],
1032
		));
1033
		
1034
		
1035
		// render
1036
		do_action("acf/render_field_settings/type={$field['type']}", $field);
1037
		
1038
		
1039
		// die
1040
		die();
1041
								
1042
	}
1043
	
1044
	/*
1045
	*  ajax_move_field
1046
	*
1047
	*  description
1048
	*
1049
	*  @type	function
1050
	*  @date	20/01/2014
1051
	*  @since	5.0.0
1052
	*
1053
	*  @param	$post_id (int)
1054
	*  @return	$post_id (int)
1055
	*/
0 ignored issues
show
Documentation introduced by
The doc-type $post_id could not be parsed: Unknown type name "$post_id" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
1056
	
1057
	function ajax_move_field() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1058
		
1059
		// disable JSON to avoid conflicts between DB and JSON
1060
		acf_disable_local();
1061
		
1062
		
1063
		$args = acf_parse_args($_POST, array(
1064
			'nonce'				=> '',
1065
			'field_id'			=> 0,
1066
			'field_group_id'	=> 0
1067
		));
1068
		
1069
		
1070
		// verify nonce
1071
		if( ! wp_verify_nonce($args['nonce'], 'acf_nonce') ) {
1072
		
1073
			die();
1074
			
1075
		}
1076
		
1077
		
1078
		// confirm?
1079
		if( $args['field_id'] && $args['field_group_id'] ) {
1080
			
1081
			// vars 
1082
			$field = acf_get_field($args['field_id']);
1083
			$field_group = acf_get_field_group($args['field_group_id']);
1084
			
1085
			
1086
			// update parent
1087
			$field['parent'] = $field_group['ID'];
1088
			
1089
			
1090
			// remove conditional logic
1091
			$field['conditional_logic'] = 0;
1092
			
1093
			
1094
			// update field
1095
			acf_update_field($field);
0 ignored issues
show
Documentation introduced by
$field is of type array<string,?,{"conditional_logic":"integer"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1096
			
1097
			$v1 = $field['label'];
1098
			$v2 = '<a href="' . admin_url("post.php?post={$field_group['ID']}&action=edit") . '" target="_blank">' . $field_group['title'] . '</a>';
1099
			
1100
			echo '<p><strong>' . __('Move Complete.', 'acf') . '</strong></p>';
1101
			echo '<p>' . sprintf( __('The %s field can now be found in the %s field group', 'acf'), $v1, $v2 ). '</p>';
1102
			
1103
			echo '<a href="#" class="acf-button blue acf-close-popup">' . __("Close Window",'acf') . '</a>';
1104
			
1105
			die();
1106
			
1107
		}
1108
		
1109
		
1110
		// get all field groups
1111
		$field_groups = acf_get_field_groups();
1112
		$choices = array();
1113
		
1114
		
1115
		if( !empty($field_groups) ) {
1116
			
1117
			foreach( $field_groups as $field_group ) {
1118
				
1119
				if( $field_group['ID'] ) {
1120
					
1121
					$choices[ $field_group['ID'] ] = $field_group['title'];
1122
					
1123
				}
1124
				
1125
			}
1126
			
1127
		}
1128
		
1129
		
1130
		// render options
1131
		$field = acf_get_valid_field(array(
0 ignored issues
show
Documentation introduced by
array('type' => 'select'... 'choices' => $choices) is of type array<string,string|arra...ng","choices":"array"}>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1132
			'type'		=> 'select',
1133
			'name'		=> 'acf_field_group',
1134
			'choices'	=> $choices
1135
		));
1136
		
1137
		
1138
		echo '<p>' . __('Please select the destination for this field', 'acf') . '</p>';
1139
		
1140
		echo '<form id="acf-move-field-form">';
1141
		
1142
			// render
1143
			acf_render_field_wrap( $field );
1144
			
1145
			echo '<button type="submit" class="acf-button blue">' . __("Move Field",'acf') . '</button>';
1146
			
1147
		echo '</form>';
1148
		
1149
		
1150
		// die
1151
		die();
1152
		
1153
	}
1154
	
1155
}
1156
1157
// initialize
1158
new acf_admin_field_group();
1159
1160
endif;
1161
1162
?>
1163