acf_settings_addons::html()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
class acf_settings_addons {
4
5
	var $view;
6
7
8
	/*
9
	*  __construct
10
	*
11
	*  Initialize filters, action, variables and includes
12
	*
13
	*  @type	function
14
	*  @date	23/06/12
15
	*  @since	5.0.0
16
	*
17
	*  @param	n/a
18
	*  @return	n/a
19
	*/
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...
20
21
	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...
22
23
		// actions
24
		add_action( 'admin_menu', 				array( $this, 'admin_menu' ) );
25
	}
26
27
28
	/*
29
	*  admin_menu
30
	*
31
	*  This function will add the ACF menu item to the WP admin
32
	*
33
	*  @type	action (admin_menu)
34
	*  @date	28/09/13
35
	*  @since	5.0.0
36
	*
37
	*  @param	n/a
38
	*  @return	n/a
39
	*/
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...
40
41 View Code Duplication
	function admin_menu() {
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...
Duplication introduced by
This method seems to be duplicated in 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...
42
43
		// bail early if no show_admin
44
		if( !acf_get_setting('show_admin') )
45
		{
46
			return;
47
		}
48
49
50
		// add page
51
		$page = add_submenu_page('edit.php?post_type=acf-field-group', __('Add-ons','acf'), __('Add-ons','acf'), acf_get_setting('capability'),'acf-settings-addons', array($this,'html') );
52
53
54
		// actions
55
		add_action('load-' . $page, array($this,'load'));
56
57
	}
58
59
60
	/*
61
	*  load
62
	*
63
	*  description
64
	*
65
	*  @type	function
66
	*  @date	7/01/2014
67
	*  @since	5.0.0
68
	*
69
	*  @param	$post_id (int)
70
	*  @return	$post_id (int)
71
	*/
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...
72
73
	function load() {
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...
74
75
		// vars
76
		$this->view = array(
77
			'json'		=> array(),
78
		);
79
80
81
		// load json
82
        $request = wp_remote_post( 'http://assets.advancedcustomfields.com/add-ons/add-ons.json' );
83
84
        // validate
85
        if( is_wp_error($request) || wp_remote_retrieve_response_code($request) != 200)
86
        {
87
        	acf_add_admin_notice(__('<b>Error</b>. Could not load add-ons list', 'acf'), 'error');
88
        }
89
        else
90
        {
91
	        $this->view['json'] = json_decode( $request['body'], true );
92
        }
93
94
	}
95
96
97
	/*
98
	*  html
99
	*
100
	*  description
101
	*
102
	*  @type	function
103
	*  @date	7/01/2014
104
	*  @since	5.0.0
105
	*
106
	*  @param	$post_id (int)
107
	*  @return	$post_id (int)
108
	*/
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...
109
110
	function 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...
111
112
		// load view
113
		acf_get_view('settings-addons', $this->view);
114
115
	}
116
117
}
118
119
120
// initialize
121
new acf_settings_addons();
122
123
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
124