api-pro.php ➔ acf_pro_get_view()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php 
2
3
/*
4
*  acf_pro_get_view
5
*
6
*  This function will load in a file from the 'admin/views' folder and allow variables to be passed through
7
*
8
*  @type	function
9
*  @date	28/09/13
10
*  @since	5.0.0
11
*
12
*  @param	$view_name (string)
13
*  @param	$args (array)
14
*  @return	n/a
15
*/
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...
16
17
function acf_pro_get_view( $view_name = '', $args = array() ) {
18
	
19
	// vars
20
	$path = acf_get_path("pro/admin/views/{$view_name}.php");
21
	
22
	
23
	if( file_exists($path) ) {
24
		
25
		include( $path );
26
		
27
	}
28
	
29
}
30
31
32
/*
33
*  acf_pro_get_remote_url
34
*
35
*  description
36
*
37
*  @type	function
38
*  @date	16/01/2014
39
*  @since	5.0.0
40
*
41
*  @param	$post_id (int)
42
*  @return	$post_id (int)
43
*/
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...
44
45
function acf_pro_get_remote_url( $action = '', $args = array() ) {
46
	
47
	// defaults
48
	$args['a'] = $action;
49
	$args['p'] = 'pro';
50
	
51
	
52
	// vars
53
	$url = "http://connect.advancedcustomfields.com/index.php?" . build_query($args);
54
	
55
	
56
	// return
57
	return $url;
58
	
59
}
60
61
62
/*
63
*  acf_pro_get_remote_response
64
*
65
*  description
66
*
67
*  @type	function
68
*  @date	16/01/2014
69
*  @since	5.0.0
70
*
71
*  @param	$post_id (int)
72
*  @return	$post_id (int)
73
*/
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...
74
75
function acf_pro_get_remote_response( $action = '', $post = array() ) {
76
	
77
	// vars
78
	$url = acf_pro_get_remote_url( $action );
79
	
80
	
81
	// connect
82
	$request = wp_remote_post( $url, array(
83
		'body' => $post
84
	));
85
	
86
	
87
	// return body
88
    if( !is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) {
89
    	
90
        return $request['body'];
91
    
92
    }
93
    
94
    
95
    // return
96
    return 0;
97
    
98
}
99
100
101
/*
102
*  acf_pro_is_update_available
103
*
104
*  This function will return true if an update is available
105
*
106
*  @type	function
107
*  @date	14/05/2014
108
*  @since	5.0.0
109
*
110
*  @param	n/a
111
*  @return	(boolean)
112
*/
113
114
function acf_pro_is_update_available() {
115
	
116
	// vars
117
	$info = acf_pro_get_remote_info();
118
	$version = acf_get_setting('version');
119
	 
120
	
121
	// return false if no info
122
	if( empty($info['version']) ) {
123
		
124
		return false;
125
		
126
	}
127
	
128
    
129
    // return false if the external version is '<=' the current version
130
	if( version_compare($info['version'], $version, '<=') ) {
131
		
132
    	return false;
133
    
134
    }
135
    
136
	
137
	// return
138
	return true;
139
	
140
}
141
142
143
/*
144
*  acf_pro_get_remote_info
145
*
146
*  This function will return remote plugin data
147
*
148
*  @type	function
149
*  @date	16/01/2014
150
*  @since	5.0.0
151
*
152
*  @param	n/a
153
*  @return	(mixed)
154
*/
155
156
function acf_pro_get_remote_info() {
157
	
158
	// clear transient if force check is enabled
159
	if( !empty($_GET['force-check']) ) {
160
		
161
		// only allow transient to be deleted once per page load
162
		if( empty($_GET['acf-ignore-force-check']) ) {
163
			
164
			delete_transient( 'acf_pro_get_remote_info' );
165
			
166
		}
167
		
168
		
169
		// update $_GET
170
		$_GET['acf-ignore-force-check'] = true;
171
		
172
	}
173
	
174
	
175
	// get transient
176
	$transient = get_transient( 'acf_pro_get_remote_info' );
177
178
	if( $transient !== false ) {
179
	
180
		return $transient;
181
	
182
	}
183
184
	
185
	// vars
186
	$info = acf_pro_get_remote_response('get-info');
187
	$timeout = 12 * HOUR_IN_SECONDS;
188
	
189
	
190
    // decode
191
    if( !empty($info) ) {
192
    	
193
		$info = json_decode($info, true);
194
		
195
		// fake info version
196
        //$info['version'] = '6.0.0';
197
        
198
    } else {
199
	    
200
	    $info = 0; // allow transient to be returned, but empty to validate
201
	    $timeout = 2 * HOUR_IN_SECONDS;
202
	    
203
    }
204
        
205
        
206
	// update transient
207
	set_transient('acf_pro_get_remote_info', $info, $timeout );
208
	
209
	
210
	// return
211
	return $info;
212
}
213
214
215
function acf_pro_is_license_active() {
216
	
217
	// vars
218
	$data = acf_pro_get_license( true );
219
	$url = home_url();
220
	
221
	if( !empty($data['url']) && !empty($data['key']) && $data['url'] == $url ) {
222
		
223
		return true;
224
		
225
	}
226
	
227
	
228
	return false;
229
	
230
}
231
232
function acf_pro_get_license( $all = false ) {
233
	
234
	// get option
235
	$data = get_option('acf_pro_license');
236
	
237
	
238
	// decode
239
	$data = base64_decode($data);
240
	
241
	
242
	// attempt deserialize
243
	if( is_serialized( $data ) )
244
	{
245
		$data = maybe_unserialize($data);
246
		
247
		// $all
248
		if( !$all )
249
		{
250
			$data = $data['key'];
251
		}
252
		
253
		return $data;
254
	}
255
	
256
	
257
	// return
258
	return false;
259
}
260
261
262
263
function acf_pro_update_license( $license ) {
264
	
265
	$save = array(
266
		'key'	=> $license,
267
		'url'	=> home_url()
268
	);
269
	
270
	
271
	$save = maybe_serialize($save);
272
	$save = base64_encode($save);
273
	
274
	
275
	return update_option('acf_pro_license', $save);
276
	
277
}
278
279
?>
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...
280