-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacf-remote-update.php
executable file
·147 lines (105 loc) · 2.45 KB
/
acf-remote-update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/*
* acf_remote_update
*
* @description: Handles all plugin updates
* @since: 3.6
* @created: 2/02/13
*/
class acf_remote_update
{
var $settings;
/*
* Constructor
*
* @description:
* @since 1.0.0
* @created: 23/06/12
*/
function __construct( $options )
{
// Add slug
$options['slug'] = current( explode('/', $options['basename']) );
// devine settins
$this->settings = $options;
// update
add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'));
add_filter('plugins_api', array($this, 'check_info'), 10, 3);
}
/*
* get_remote
*
* @description:
* @since: 3.6
* @created: 31/01/13
*/
function get_remote()
{
// vars
$info = false;
// Get the remote info
$request = wp_remote_post( $this->settings['remote'] );
if( !is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200)
{
$info = @unserialize($request['body']);
$info->slug = $this->settings['slug'];
}
return $info;
}
/*
* check_update
*
* @description:
* @since: 3.6
* @created: 31/01/13
*/
function check_update( $transient )
{
if( empty($transient->checked) )
{
return $transient;
}
// vars
$info = $this->get_remote();
// validate
if( !$info )
{
return $transient;
}
// compare versions
if( version_compare($info->version, $this->settings['version'], '<=') )
{
return $transient;
}
// create new object for update
$obj = new stdClass();
$obj->slug = $info->slug;
$obj->new_version = $info->version;
$obj->url = $info->homepage;
$obj->package = $info->download_link;
// add to transient
$transient->response[ $this->settings['basename'] ] = $obj;
return $transient;
}
/*
* check_info
*
* @description:
* @since: 3.6
* @created: 31/01/13
*/
function check_info( $false, $action, $arg )
{
// validate
if( !isset($arg->slug) || $arg->slug != $this->settings['slug'] )
{
return $false;
}
if( $action == 'plugin_information' )
{
$false = $this->get_remote();
}
return $false;
}
}
?>