Completed
Push — master ( bf1080...d99bb1 )
by Md. Mozahidur
04:04
created

acf_admin_field_groups   C

Complexity

Total Complexity 50

Size/Duplication

Total Lines 766
Duplicated Lines 4.44 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 50
lcom 1
cbo 0
dl 34
loc 766
rs 5

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
B current_screen() 0 37 2
A admin_enqueue_scripts() 0 5 1
C check_duplicate() 17 71 7
D check_sync() 17 148 17
B list_table_views() 0 39 2
A trashed_post() 0 14 2
A untrashed_post() 0 14 2
A deleted_post() 0 14 2
A field_group_columns() 0 12 1
A field_group_columns_html() 0 10 1
C render_column() 0 38 7
B admin_footer() 0 103 1
B sync_admin_footer() 0 48 4

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like acf_admin_field_groups often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use acf_admin_field_groups, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 782.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
*  ACF Admin Field Groups Class
5
*
6
*  All the logic for editing a list of field groups
7
*
8
*  @class 		acf_admin_field_groups
9
*  @package		ACF
10
*  @subpackage	Admin
11
*/
12
13
if( ! class_exists('acf_admin_field_groups') ) :
14
15
class acf_admin_field_groups {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
16
	
17
	// vars
18
	var $url = 'edit.php?post_type=acf-field-group',
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $url.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
19
		$sync = array();
20
		
21
	
22
	/*
23
	*  __construct
24
	*
25
	*  This function will setup the class functionality
26
	*
27
	*  @type	function
28
	*  @date	5/03/2014
29
	*  @since	5.0.0
30
	*
31
	*  @param	n/a
32
	*  @return	n/a
33
	*/
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...
34
	
35
	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...
36
	
37
		// actions
38
		add_action('current_screen',		array($this, 'current_screen'));
39
		add_action('trashed_post',			array($this, 'trashed_post'));
40
		add_action('untrashed_post',		array($this, 'untrashed_post'));
41
		add_action('deleted_post',			array($this, 'deleted_post'));
42
		
43
	}
44
	
45
	
46
	/*
47
	*  current_screen
48
	*
49
	*  This function is fired when loading the admin page before HTML has been rendered.
50
	*
51
	*  @type	action (current_screen)
52
	*  @date	21/07/2014
53
	*  @since	5.0.0
54
	*
55
	*  @param	n/a
56
	*  @return	n/a
57
	*/
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...
58
	
59
	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...
60
		
61
		// validate screen
62
		if( !acf_is_screen('edit-acf-field-group') ) {
63
		
64
			return;
65
			
66
		}
67
		
68
69
		// customize post_status
70
		global $wp_post_statuses;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
71
		
72
		
73
		// modify publish post status
74
		$wp_post_statuses['publish']->label_count = _n_noop( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', 'acf' );
75
		
76
		
77
		// reorder trash to end
78
		$wp_post_statuses['trash'] = acf_extract_var( $wp_post_statuses, 'trash' );
79
80
		
81
		// check stuff
82
		$this->check_duplicate();
83
		$this->check_sync();
84
		
85
		
86
		// actions
87
		add_action('admin_enqueue_scripts',							array($this, 'admin_enqueue_scripts'));
88
		add_action('admin_footer',									array($this, 'admin_footer'));
89
		
90
		
91
		// columns
92
		add_filter('manage_edit-acf-field-group_columns',			array($this, 'field_group_columns'), 10, 1);
93
		add_action('manage_acf-field-group_posts_custom_column',	array($this, 'field_group_columns_html'), 10, 2);
94
		
95
	}
96
	
97
	
98
	/*
99
	*  admin_enqueue_scripts
100
	*
101
	*  This function will add the already registered css
102
	*
103
	*  @type	function
104
	*  @date	28/09/13
105
	*  @since	5.0.0
106
	*
107
	*  @param	n/a
108
	*  @return	n/a
109
	*/
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...
110
	
111
	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...
112
		
113
		wp_enqueue_script('acf-input');
114
		
115
	}
116
	
117
	
118
	/*
119
	*  check_duplicate
120
	*
121
	*  This function will check for any $_GET data to duplicate
122
	*
123
	*  @type	function
124
	*  @date	17/10/13
125
	*  @since	5.0.0
126
	*
127
	*  @param	n/a
128
	*  @return	n/a
129
	*/
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...
130
	
131
	function check_duplicate() {
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...
Coding Style introduced by
check_duplicate uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
132
		
133
		// message
134 View Code Duplication
		if( $ids = acf_maybe_get($_GET, 'acfduplicatecomplete') ) {
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...
135
			
136
			// explode
137
			$ids = explode(',', $ids);
138
			$total = count($ids);
139
			
140
			if( $total == 1 ) {
141
				
142
				acf_add_admin_notice( sprintf(__('Field group duplicated. %s', 'acf'), '<a href="' . get_edit_post_link($ids[0]) . '">' . get_the_title($ids[0]) . '</a>') );
143
				
144
			} else {
145
				
146
				acf_add_admin_notice( sprintf(_n( '%s field group duplicated.', '%s field groups duplicated.', $total, 'acf' ), $total) );
147
				
148
			}
149
			
150
		}
151
		
152
		
153
		// import field group
154
		if( $id = acf_maybe_get($_GET, 'acfduplicate') ) {
155
			
156
			// validate
157
			check_admin_referer('bulk-posts');
158
			
159
			
160
			// duplicate
161
			$field_group = acf_duplicate_field_group( $id );
162
			
163
			
164
			// redirect
165
			wp_redirect( admin_url( $this->url . '&acfduplicatecomplete=' . $field_group['ID'] ) );
166
			exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method check_duplicate() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
167
			
168
		} elseif( acf_maybe_get($_GET, 'action2') === 'acfduplicate' ) {
169
		
170
			// validate
171
			check_admin_referer('bulk-posts');
172
				
173
			
174
			// get ids
175
			$ids = acf_maybe_get($_GET, 'post');
176
			
177
			if( !empty($ids) ) {
178
				
179
				// vars
180
				$new_ids = array();
181
				
182
				foreach( $ids as $id ) {
183
					
184
					// duplicate
185
					$field_group = acf_duplicate_field_group( $id );
186
					
187
					
188
					// increase counter
189
					$new_ids[] = $field_group['ID'];
190
					
191
				}
192
				
193
				
194
				// redirect
195
				wp_redirect( admin_url( $this->url . '&acfduplicatecomplete=' . implode(',', $new_ids)) );
196
				exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method check_duplicate() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
197
			}
198
		
199
		}
200
		
201
	}
202
	
203
	
204
	/*
205
	*  check_sync
206
	*
207
	*  This function will check for any $_GET data to sync
208
	*
209
	*  @type	function
210
	*  @date	9/12/2014
211
	*  @since	5.1.5
212
	*
213
	*  @param	n/a
214
	*  @return	n/a
215
	*/
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...
216
	
217
	function check_sync() {
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...
Coding Style introduced by
check_sync uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
218
		
219
		// message
220 View Code Duplication
		if( $ids = acf_maybe_get($_GET, 'acfsynccomplete') ) {
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...
221
			
222
			// explode
223
			$ids = explode(',', $ids);
224
			$total = count($ids);
225
			
226
			if( $total == 1 ) {
227
				
228
				acf_add_admin_notice( sprintf(__('Field group synchronised. %s', 'acf'), '<a href="' . get_edit_post_link($ids[0]) . '">' . get_the_title($ids[0]) . '</a>') );
229
				
230
			} else {
231
				
232
				acf_add_admin_notice( sprintf(_n( '%s field group synchronised.', '%s field groups synchronised.', $total, 'acf' ), $total) );
233
				
234
			}
235
			
236
		}
237
		
238
		
239
		// vars
240
		$groups = acf_get_field_groups();
241
		
242
		
243
		// bail early if no field groups
244
		if( empty($groups) ) {
245
			
246
			return;
247
			
248
		}
249
		
250
		
251
		// find JSON field groups which have not yet been imported
252
		foreach( $groups as $group ) {
253
			
254
			// vars
255
			$local = acf_maybe_get($group, 'local', false);
256
			$modified = acf_maybe_get($group, 'modified', 0);
257
			$private = acf_maybe_get($group, 'private', false);
258
			
259
			
260
			// ignore DB / PHP / private field groups
261
			if( $local !== 'json' || $private ) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
262
				
263
				// do nothing
264
				
265
			} elseif( !$group['ID'] ) {
266
				
267
				$this->sync[ $group['key'] ] = $group;
268
				
269
			} elseif( $modified && $modified > get_post_modified_time('U', true, $group['ID'], true) ) {
270
				
271
				$this->sync[ $group['key'] ]  = $group;
272
				
273
			}
274
						
275
		}
276
		
277
		
278
		// bail if no sync needed
279
		if( empty($this->sync) ) {
280
			
281
			return;
282
			
283
		}
284
	
285
		
286
		// import field group
287
		if( $key = acf_maybe_get($_GET, 'acfsync') ) {
288
			
289
			// disable JSON
290
			// - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance
291
			acf_update_setting('json', false);
292
			
293
			
294
			// validate
295
			check_admin_referer('bulk-posts');
296
			
297
			
298
			// append fields
299
			if( acf_have_local_fields( $key ) ) {
300
				
301
				$this->sync[ $key ]['fields'] = acf_get_local_fields( $key );
302
				
303
			}
304
			
305
			
306
			// import
307
			$field_group = acf_import_field_group( $this->sync[ $key ] );
308
			
309
			
310
			// redirect
311
			wp_redirect( admin_url( $this->url . '&acfsynccomplete=' . $field_group['ID'] ) );
312
			exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method check_sync() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
313
			
314
		} elseif( acf_maybe_get($_GET, 'action2') === 'acfsync' ) {
315
			
316
			// validate
317
			check_admin_referer('bulk-posts');
318
				
319
			
320
			// get ids
321
			$keys = acf_maybe_get($_GET, 'post');
322
			
323
			if( !empty($keys) ) {
324
				
325
				// disable JSON
326
				// - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance
327
				acf_update_setting('json', false);
328
				
329
				// vars
330
				$new_ids = array();
331
				
332
				foreach( $keys as $key ) {
333
					
334
					// append fields
335
					if( acf_have_local_fields( $key ) ) {
336
						
337
						$this->sync[ $key ]['fields'] = acf_get_local_fields( $key );
338
						
339
					}
340
					
341
					
342
					// import
343
					$field_group = acf_import_field_group( $this->sync[ $key ] );
344
										
345
					
346
					// append
347
					$new_ids[] = $field_group['ID'];
348
					
349
				}
350
				
351
				
352
				// redirect
353
				wp_redirect( admin_url( $this->url . '&acfsynccomplete=' . implode(',', $new_ids)) );
354
				exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method check_sync() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
355
				
356
			}
357
		
358
		}
359
		
360
		
361
		// filters
362
		add_filter('views_edit-acf-field-group', array($this, 'list_table_views'));
363
		
364
	}
365
	
366
	
367
	/*
368
	*  list_table_views
369
	*
370
	*  This function will add an extra link for JSON in the field group list table
371
	*
372
	*  @type	function
373
	*  @date	3/12/2014
374
	*  @since	5.1.5
375
	*
376
	*  @param	$views (array)
377
	*  @return	$views
378
	*/
0 ignored issues
show
Documentation introduced by
The doc-type $views could not be parsed: Unknown type name "$views" 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...
379
	
380
	function list_table_views( $views ) {
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...
Coding Style introduced by
list_table_views uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
381
		
382
		// vars
383
		$class = '';
384
		$total = count($this->sync);
385
		
386
		// active
387
		if( acf_maybe_get($_GET, 'post_status') === 'sync' ) {
388
			
389
			// actions
390
			add_action('admin_footer', array($this, 'sync_admin_footer'), 5);
391
			
392
			
393
			// set active class
394
			$class = ' class="current"';
395
			
396
			
397
			// global
398
			global $wp_list_table;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
399
			
400
			
401
			// update pagination
402
			$wp_list_table->set_pagination_args( array(
403
				'total_items' => $total,
404
				'total_pages' => 1,
405
				'per_page' => $total
406
			));
407
			
408
		}
409
		
410
		
411
		// add view
412
		$views['json'] = '<a' . $class . ' href="' . admin_url($this->url . '&post_status=sync') . '">' . __('Sync available', 'acf') . ' <span class="count">(' . $total . ')</span></a>';
413
		
414
		
415
		// return
416
		return $views;
417
		
418
	}
419
	
420
	
421
	/*
422
	*  trashed_post
423
	*
424
	*  This function is run when a post object is sent to the trash
425
	*
426
	*  @type	action (trashed_post)
427
	*  @date	8/01/2014
428
	*  @since	5.0.0
429
	*
430
	*  @param	$post_id (int)
431
	*  @return	n/a
432
	*/
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...
433
	
434
	function trashed_post( $post_id ) {
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...
435
		
436
		// validate post type
437
		if( get_post_type($post_id) != 'acf-field-group' ) {
438
		
439
			return;
440
		
441
		}
442
		
443
		
444
		// trash field group
445
		acf_trash_field_group( $post_id );
446
		
447
	}
448
	
449
	
450
	/*
451
	*  untrashed_post
452
	*
453
	*  This function is run when a post object is restored from the trash
454
	*
455
	*  @type	action (untrashed_post)
456
	*  @date	8/01/2014
457
	*  @since	5.0.0
458
	*
459
	*  @param	$post_id (int)
460
	*  @return	n/a
461
	*/
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...
462
	
463
	function untrashed_post( $post_id ) {
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...
464
		
465
		// validate post type
466
		if( get_post_type($post_id) != 'acf-field-group' ) {
467
		
468
			return;
469
			
470
		}
471
		
472
		
473
		// trash field group
474
		acf_untrash_field_group( $post_id );
475
		
476
	}
477
	
478
	
479
	/*
480
	*  deleted_post
481
	*
482
	*  This function is run when a post object is deleted from the trash
483
	*
484
	*  @type	action (deleted_post)
485
	*  @date	8/01/2014
486
	*  @since	5.0.0
487
	*
488
	*  @param	$post_id (int)
489
	*  @return	n/a
490
	*/
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...
491
	
492
	function deleted_post( $post_id ) {
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...
493
		
494
		// validate post type
495
		if( get_post_type($post_id) != 'acf-field-group' ) {
496
		
497
			return;
498
			
499
		}
500
		
501
		
502
		// trash field group
503
		acf_delete_field_group( $post_id );
504
		
505
	}
506
	
507
	
508
	/*
509
	*  field_group_columns
510
	*
511
	*  This function will customize the columns for the field group table
512
	*
513
	*  @type	filter (manage_edit-acf-field-group_columns)
514
	*  @date	28/09/13
515
	*  @since	5.0.0
516
	*
517
	*  @param	$columns (array)
518
	*  @return	$columns (array)
519
	*/
0 ignored issues
show
Documentation introduced by
The doc-type $columns could not be parsed: Unknown type name "$columns" 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...
520
	
521
	function field_group_columns( $columns ) {
0 ignored issues
show
Unused Code introduced by
The parameter $columns is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
522
		
523
		return array(
524
			'cb'	 				=> '<input type="checkbox" />',
525
			'title' 				=> __('Title', 'acf'),
526
			'acf-fg-description'	=> __('Description', 'acf'),
527
			'acf-fg-status' 		=> '<i class="acf-icon -dot-3 small acf-js-tooltip" title="' . __('Status', 'acf') . '"></i>',
528
			'acf-fg-count' 			=> __('Fields', 'acf'),
529
			
530
		);
531
		
532
	}
533
	
534
	
535
	/*
536
	*  field_group_columns_html
537
	*
538
	*  This function will render the HTML for each table cell
539
	*
540
	*  @type	action (manage_acf-field-group_posts_custom_column)
541
	*  @date	28/09/13
542
	*  @since	5.0.0
543
	*
544
	*  @param	$column (string)
545
	*  @param	$post_id (int)
546
	*  @return	n/a
547
	*/
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...
548
	
549
	function field_group_columns_html( $column, $post_id ) {
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...
550
		
551
		// vars
552
		$field_group = acf_get_field_group( $post_id );
553
		
554
		
555
		// render
556
		$this->render_column( $column, $field_group );
557
	    
558
	}
559
	
560
	function render_column( $column, $field_group ) {
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...
561
		
562
		// description
563
		if( $column == 'acf-fg-description' ) {
564
			
565
			if( $field_group['description'] ) {
566
				
567
				echo '<span class="acf-description">' . $field_group['description'] . '</span>';
568
				
569
			}
570
        
571
        // status
572
	    } elseif( $column == 'acf-fg-status' ) {
573
			
574
			if( isset($this->sync[ $field_group['key'] ]) ) {
575
				
576
				echo '<i class="acf-icon -sync grey small acf-js-tooltip" title="' . __('Sync available', 'acf') .'"></i> ';
577
				
578
			}
579
			
580
			if( $field_group['active'] ) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
581
				
582
				//echo '<i class="acf-icon -check small acf-js-tooltip" title="' . __('Active', 'acf') .'"></i> ';
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
583
				
584
			} else {
585
				
586
				echo '<i class="acf-icon -minus yellow small acf-js-tooltip" title="' . __('Disabled', 'acf') . '"></i> ';
587
				
588
			}
589
	    
590
        // fields
591
	    } elseif( $column == 'acf-fg-count' ) {
592
			
593
			echo acf_get_field_count( $field_group );
594
        
595
        }
596
		
597
	}
598
	
599
	
600
	/*
601
	*  admin_footer
602
	*
603
	*  This function will render extra HTML onto the page
604
	*
605
	*  @type	action (admin_footer)
606
	*  @date	23/06/12
607
	*  @since	3.1.8
608
	*
609
	*  @param	n/a
610
	*  @return	n/a
611
	*/
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...
612
	
613
	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...
614
		
615
		// vars
616
		$www = 'http://www.advancedcustomfields.com/resources/';
617
		
618
?><script type="text/html" id="tmpl-acf-column-2">
619
<div class="acf-column-2">
620
	<div class="acf-box">
621
		<div class="inner">
622
			<h2><?php echo acf_get_setting('name'); ?> <?php echo acf_get_setting('version'); ?></h2>
623
624
			<h3><?php _e("Changelog",'acf'); ?></h3>
625
			<p><?php _e("See what's new in",'acf'); ?> <a href="<?php echo admin_url('edit.php?post_type=acf-field-group&page=acf-settings-info&tab=changelog'); ?>"><?php _e("version",'acf'); ?> <?php echo acf_get_setting('version'); ?></a>
626
			
627
			<h3><?php _e("Resources",'acf'); ?></h3>
628
			<ul>
629
				<li><a href="<?php echo $www; ?>#getting-started" target="_blank"><?php _e("Getting Started",'acf'); ?></a></li>
630
				<li><a href="<?php echo $www; ?>#updates" target="_blank"><?php _e("Updates",'acf'); ?></a></li>
631
				<li><a href="<?php echo $www; ?>#field-types" target="_blank"><?php _e("Field Types",'acf'); ?></a></li>
632
				<li><a href="<?php echo $www; ?>#functions" target="_blank"><?php _e("Functions",'acf'); ?></a></li>
633
				<li><a href="<?php echo $www; ?>#actions" target="_blank"><?php _e("Actions",'acf'); ?></a></li>
634
				<li><a href="<?php echo $www; ?>#filters" target="_blank"><?php _e("Filters",'acf'); ?></a></li>
635
				<li><a href="<?php echo $www; ?>#how-to" target="_blank"><?php _e("'How to' guides",'acf'); ?></a></li>
636
				<li><a href="<?php echo $www; ?>#tutorials" target="_blank"><?php _e("Tutorials",'acf'); ?></a></li>
637
			</ul>
638
		</div>
639
		<div class="footer footer-blue">
640
			<ul class="acf-hl">
641
				<li><?php _e("Created by",'acf'); ?> Elliot Condon</li>
642
			</ul>
643
		</div>
644
	</div>
645
</div>
646
<div class="acf-clear"></div>
647
</script>
648
<script type="text/javascript">
649
(function($){
650
	
651
	// wrap
652
	$('#wpbody .wrap').attr('id', 'acf-field-group-wrap');
653
	
654
	
655
	// wrap form
656
	$('#posts-filter').wrap('<div class="acf-columns-2" />');
657
	
658
	
659
	// add column main
660
	$('#posts-filter').addClass('acf-column-1');
661
	
662
	
663
	// add column side
664
	$('#posts-filter').after( $('#tmpl-acf-column-2').html() );
665
	
666
	
667
	// modify row actions
668
	$('#the-list tr').each(function(){
669
		
670
		// vars
671
		var $tr = $(this),
672
			id = $tr.attr('id'),
673
			description = $tr.find('.column-acf-fg-description').html();
674
		
675
		
676
		// replace Quick Edit with Duplicate (sync page has no id attribute)
677
		if( id ) {
678
			
679
			// vars
680
			var post_id	= id.replace('post-', '');
681
			
682
			
683
			// create el
684
			var $span = $('<span class="acf-duplicate-field-group"><a title="<?php _e('Duplicate this item', 'acf'); ?>" href="<?php echo admin_url($this->url . '&acfduplicate='); ?>' + post_id + '&_wpnonce=<?php echo wp_create_nonce('bulk-posts'); ?>"><?php _e('Duplicate', 'acf'); ?></a> | </span>');
685
			
686
			
687
			// replace
688
			$tr.find('.column-title .row-actions .inline').replaceWith( $span );
689
			
690
		}
691
		
692
		
693
		// add description to title
694
		$tr.find('.column-title .row-title').after( description );
695
		
696
	});
697
	
698
	
699
	// modify bulk actions
700
	$('#bulk-action-selector-bottom option[value="edit"]').attr('value','acfduplicate').text('<?php _e( 'Duplicate', 'acf' ); ?>');
701
	
702
	
703
	// clean up table
704
	$('#adv-settings label[for="acf-fg-description-hide"]').remove();
705
	
706
	
707
	// mobile compatibility
708
	var status = $('.acf-icon.-dot-3').first().attr('title');
709
	$('td.column-acf-fg-status').attr('data-colname', status);
710
	
711
})(jQuery);
712
</script>
713
<?php
714
		
715
	}
716
	
717
	
718
	/*
719
	*  sync_admin_footer
720
	*
721
	*  This function will render extra HTML onto the page
722
	*
723
	*  @type	action (admin_footer)
724
	*  @date	23/06/12
725
	*  @since	3.1.8
726
	*
727
	*  @param	n/a
728
	*  @return	n/a
729
	*/
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...
730
	
731
	function sync_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...
732
		
733
		// vars
734
		$i = -1;
735
		$columns = array(
736
			'acf-fg-description',
737
			'acf-fg-status',
738
			'acf-fg-count'
739
		);
740
		
741
?>
742
<script type="text/html" id="tmpl-acf-json-tbody">
743
<?php foreach( $this->sync as $field_group ): $i++; ?>
744
	<tr <?php if($i%2 == 0): ?>class="alternate"<?php endif; ?>>
745
		<th class="check-column" scope="row">
746
			<label for="cb-select-<?php echo $field_group['key']; ?>" class="screen-reader-text"><?php printf( __( 'Select %s', 'acf' ), $field_group['title'] ); ?></label>
747
			<input type="checkbox" value="<?php echo $field_group['key']; ?>" name="post[]" id="cb-select-<?php echo $field_group['key']; ?>">
748
		</th>
749
		<td class="post-title page-title column-title">
750
			<strong>
751
				<span class="row-title"><?php echo $field_group['title']; ?></span><span class="acf-description"><?php echo $field_group['key']; ?>.json</span>
752
			</strong>
753
			<div class="row-actions">
754
				<span class="import"><a title="<?php echo esc_attr( __('Synchronise field group', 'acf') ); ?>" href="<?php echo admin_url($this->url . '&post_status=sync&acfsync=' . $field_group['key'] . '&_wpnonce=' . wp_create_nonce('bulk-posts')); ?>"><?php _e( 'Sync', 'acf' ); ?></a></span>
755
			</div>
756
		</td>
757
		<?php foreach( $columns as $column ): ?>
758
			<td class="column-<?php echo $column; ?>"><?php $this->render_column( $column, $field_group ); ?></td>
759
		<?php endforeach; ?>
760
	</tr>
761
<?php endforeach; ?>
762
</script>
763
<script type="text/javascript">
764
(function($){
765
	
766
	// update table HTML
767
	$('#the-list').html( $('#tmpl-acf-json-tbody').html() );
768
	
769
	
770
	// modify bulk actions
771
	$('#bulk-action-selector-bottom option[value="edit"]').attr('value','acfsync').text('<?php _e('Sync', 'acf'); ?>');
772
	$('#bulk-action-selector-bottom option[value="trash"]').remove();
773
		
774
})(jQuery);
775
</script>
776
<?php
777
		
778
	}
779
			
780
}
781
782
new acf_admin_field_groups();
783
784
endif;
785
786
?>
787