@@ -101,8 +101,9 @@ discard block |
||
| 101 | 101 | 'readme', |
| 102 | 102 | ); |
| 103 | 103 | foreach ($required_config_params as $required_param) { |
| 104 | - if (empty($this->config[$required_param])) |
|
| 105 | - $this->missing_config[] = $required_param; |
|
| 104 | + if (empty($this->config[$required_param])) { |
|
| 105 | + $this->missing_config[] = $required_param; |
|
| 106 | + } |
|
| 106 | 107 | } |
| 107 | 108 | return (empty($this->missing_config)); |
| 108 | 109 | } |
@@ -122,23 +123,31 @@ discard block |
||
| 122 | 123 | $zip_url = add_query_arg(array('access_token' => $this->config['access_token']), $zip_url); |
| 123 | 124 | $this->config['zip_url'] = $zip_url; |
| 124 | 125 | } |
| 125 | - if (!isset($this->config['new_version'])) |
|
| 126 | - $this->config['new_version'] = $this->get_new_version(); |
|
| 127 | - if (!isset($this->config['last_updated'])) |
|
| 128 | - $this->config['last_updated'] = $this->get_date(); |
|
| 129 | - if (!isset($this->config['description'])) |
|
| 130 | - $this->config['description'] = $this->get_description(); |
|
| 126 | + if (!isset($this->config['new_version'])) { |
|
| 127 | + $this->config['new_version'] = $this->get_new_version(); |
|
| 128 | + } |
|
| 129 | + if (!isset($this->config['last_updated'])) { |
|
| 130 | + $this->config['last_updated'] = $this->get_date(); |
|
| 131 | + } |
|
| 132 | + if (!isset($this->config['description'])) { |
|
| 133 | + $this->config['description'] = $this->get_description(); |
|
| 134 | + } |
|
| 131 | 135 | $plugin_data = $this->get_plugin_data(); |
| 132 | - if (!isset($this->config['plugin_name'])) |
|
| 133 | - $this->config['plugin_name'] = $plugin_data['Name']; |
|
| 134 | - if (!isset($this->config['version'])) |
|
| 135 | - $this->config['version'] = $plugin_data['Version']; |
|
| 136 | - if (!isset($this->config['author'])) |
|
| 137 | - $this->config['author'] = $plugin_data['Author']; |
|
| 138 | - if (!isset($this->config['homepage'])) |
|
| 139 | - $this->config['homepage'] = $plugin_data['PluginURI']; |
|
| 140 | - if (!isset($this->config['readme'])) |
|
| 141 | - $this->config['readme'] = 'README.md'; |
|
| 136 | + if (!isset($this->config['plugin_name'])) { |
|
| 137 | + $this->config['plugin_name'] = $plugin_data['Name']; |
|
| 138 | + } |
|
| 139 | + if (!isset($this->config['version'])) { |
|
| 140 | + $this->config['version'] = $plugin_data['Version']; |
|
| 141 | + } |
|
| 142 | + if (!isset($this->config['author'])) { |
|
| 143 | + $this->config['author'] = $plugin_data['Author']; |
|
| 144 | + } |
|
| 145 | + if (!isset($this->config['homepage'])) { |
|
| 146 | + $this->config['homepage'] = $plugin_data['PluginURI']; |
|
| 147 | + } |
|
| 148 | + if (!isset($this->config['readme'])) { |
|
| 149 | + $this->config['readme'] = 'README.md'; |
|
| 150 | + } |
|
| 142 | 151 | } |
| 143 | 152 | |
| 144 | 153 | /** |
@@ -152,32 +161,38 @@ discard block |
||
| 152 | 161 | $version = get_site_transient(md5($this->config['slug']) . '_new_version'); |
| 153 | 162 | if ($this->overrule_transients() || (!isset($version) || !$version || '' == $version)) { |
| 154 | 163 | $raw_response = $this->remote_get(trailingslashit($this->config['raw_url']) . basename($this->config['slug'])); |
| 155 | - if (is_wp_error($raw_response)) |
|
| 156 | - $version = false; |
|
| 164 | + if (is_wp_error($raw_response)) { |
|
| 165 | + $version = false; |
|
| 166 | + } |
|
| 157 | 167 | if (is_array($raw_response)) { |
| 158 | - if (!empty($raw_response['body'])) |
|
| 159 | - preg_match('/.*Version\:\s*(.*)$/mi', $raw_response['body'], $matches); |
|
| 168 | + if (!empty($raw_response['body'])) { |
|
| 169 | + preg_match('/.*Version\:\s*(.*)$/mi', $raw_response['body'], $matches); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + if (empty($matches[1])) { |
|
| 173 | + $version = false; |
|
| 174 | + } else { |
|
| 175 | + $version = $matches[1]; |
|
| 160 | 176 | } |
| 161 | - if (empty($matches[1])) |
|
| 162 | - $version = false; |
|
| 163 | - else |
|
| 164 | - $version = $matches[1]; |
|
| 165 | 177 | // back compat for older readme version handling |
| 166 | 178 | // only done when there is no version found in file name |
| 167 | 179 | if (false === $version) { |
| 168 | 180 | $raw_response = $this->remote_get(trailingslashit($this->config['raw_url']) . $this->config['readme']); |
| 169 | - if (is_wp_error($raw_response)) |
|
| 170 | - return $version; |
|
| 181 | + if (is_wp_error($raw_response)) { |
|
| 182 | + return $version; |
|
| 183 | + } |
|
| 171 | 184 | preg_match('#^\s*`*~Current Version\:\s*([^~]*)~#im', $raw_response['body'], $__version); |
| 172 | 185 | if (isset($__version[1])) { |
| 173 | 186 | $version_readme = $__version[1]; |
| 174 | - if (-1 == version_compare($version, $version_readme)) |
|
| 175 | - $version = $version_readme; |
|
| 187 | + if (-1 == version_compare($version, $version_readme)) { |
|
| 188 | + $version = $version_readme; |
|
| 189 | + } |
|
| 176 | 190 | } |
| 177 | 191 | } |
| 178 | 192 | // refresh every 6 hours |
| 179 | - if (false !== $version) |
|
| 180 | - set_site_transient(md5($this->config['slug']) . '_new_version', $version, 60 * 60 * 6); |
|
| 193 | + if (false !== $version) { |
|
| 194 | + set_site_transient(md5($this->config['slug']) . '_new_version', $version, 60 * 60 * 6); |
|
| 195 | + } |
|
| 181 | 196 | } |
| 182 | 197 | return $version; |
| 183 | 198 | } |
@@ -202,8 +217,9 @@ discard block |
||
| 202 | 217 | */ |
| 203 | 218 | public function remote_get($query) |
| 204 | 219 | { |
| 205 | - if (!empty($this->config['access_token'])) |
|
| 206 | - $query = add_query_arg(array('access_token' => $this->config['access_token']), $query); |
|
| 220 | + if (!empty($this->config['access_token'])) { |
|
| 221 | + $query = add_query_arg(array('access_token' => $this->config['access_token']), $query); |
|
| 222 | + } |
|
| 207 | 223 | $raw_response = wp_remote_get($query, array( |
| 208 | 224 | 'sslverify' => $this->config['sslverify'] |
| 209 | 225 | )); |
@@ -236,8 +252,9 @@ discard block |
||
| 236 | 252 | $github_data = get_site_transient(md5($this->config['slug']) . '_github_data'); |
| 237 | 253 | if ($this->overrule_transients() || (!isset($github_data) || !$github_data || '' == $github_data)) { |
| 238 | 254 | $github_data = $this->remote_get($this->config['api_url']); |
| 239 | - if (is_wp_error($github_data)) |
|
| 240 | - return false; |
|
| 255 | + if (is_wp_error($github_data)) { |
|
| 256 | + return false; |
|
| 257 | + } |
|
| 241 | 258 | $github_data = json_decode($github_data['body']); |
| 242 | 259 | // refresh every 6 hours |
| 243 | 260 | set_site_transient(md5($this->config['slug']) . '_github_data', $github_data, 60 * 60 * 6); |
@@ -294,8 +311,9 @@ discard block |
||
| 294 | 311 | */ |
| 295 | 312 | public function http_request_sslverify($args, $url) |
| 296 | 313 | { |
| 297 | - if ($this->config['zip_url'] == $url) |
|
| 298 | - $args['sslverify'] = $this->config['sslverify']; |
|
| 314 | + if ($this->config['zip_url'] == $url) { |
|
| 315 | + $args['sslverify'] = $this->config['sslverify']; |
|
| 316 | + } |
|
| 299 | 317 | return $args; |
| 300 | 318 | } |
| 301 | 319 | |
@@ -312,8 +330,9 @@ discard block |
||
| 312 | 330 | { |
| 313 | 331 | // Check if the transient contains the 'checked' information |
| 314 | 332 | // If not, just return its value without hacking it |
| 315 | - if (empty($transient->checked)) |
|
| 316 | - return $transient; |
|
| 333 | + if (empty($transient->checked)) { |
|
| 334 | + return $transient; |
|
| 335 | + } |
|
| 317 | 336 | // check the version and decide if it's new |
| 318 | 337 | $update = version_compare($this->config['new_version'], $this->config['version']); |
| 319 | 338 | if (1 === $update) { |
@@ -323,8 +342,9 @@ discard block |
||
| 323 | 342 | $response->url = add_query_arg(array('access_token' => $this->config['access_token']), $this->config['github_url']); |
| 324 | 343 | $response->package = $this->config['zip_url']; |
| 325 | 344 | // If response is false, don't alter the transient |
| 326 | - if (false !== $response) |
|
| 327 | - $transient->response[$this->config['slug']] = $response; |
|
| 345 | + if (false !== $response) { |
|
| 346 | + $transient->response[$this->config['slug']] = $response; |
|
| 347 | + } |
|
| 328 | 348 | } |
| 329 | 349 | return $transient; |
| 330 | 350 | } |
@@ -343,8 +363,9 @@ discard block |
||
| 343 | 363 | public function get_plugin_info($false, $action, $response) |
| 344 | 364 | { |
| 345 | 365 | // Check if this call API is for the right plugin |
| 346 | - if (!isset($response->slug) || $response->slug != $this->config['slug']) |
|
| 347 | - return false; |
|
| 366 | + if (!isset($response->slug) || $response->slug != $this->config['slug']) { |
|
| 367 | + return false; |
|
| 368 | + } |
|
| 348 | 369 | $response->slug = $this->config['slug']; |
| 349 | 370 | $response->plugin_name = $this->config['plugin_name']; |
| 350 | 371 | $response->version = $this->config['new_version']; |