| @@ -56,23 +56,17 @@ | ||
| 56 | 56 | * |
| 57 | 57 | * @return mixed |
| 58 | 58 | */ |
| 59 | 59 | public function add_auth_headers( $args, $url ) { |
| 60 | - // only act on download request's | |
| 61 | 60 | if( strpos( $url, $this->api->url ) !== 0 || strpos( $url, 'download' ) === false ) { |
| 62 | 61 | return $args; |
| 63 | 62 | } |
| 64 | 63 | |
| 65 | - // only add if activation key not empty | |
| 66 | - if( empty( $this->license->activation_key ) ) { | |
| 67 | - return $args; | |
| 68 | - } | |
| 69 | - | |
| 70 | 64 | if( empty( $args['headers'] ) ) { |
| 71 | 65 | $args['headers'] = array(); |
| 72 | 66 | } |
| 73 | 67 | |
| 74 | - $args['headers']['Authorization'] = 'Bearer ' . urlencode( $this->license->activation_key ); | |
| 68 | + $args['headers']['Authorization'] = 'Bearer ' . urlencode( $this->license->key ); | |
| 75 | 69 | return $args; |
| 76 | 70 | } |
| 77 | 71 | |
| 78 | 72 | /** |
| @@ -137,23 +131,15 @@ | ||
| 137 | 131 | protected function fetch_updates() { |
| 138 | 132 | |
| 139 | 133 | if( is_array( $this->available_updates ) ) { |
| 140 | 134 | return $this->available_updates; |
| 141 | - } | |
| 135 | + } | |
| 142 | 136 | |
| 143 | - // don't try if we failed a request recently. | |
| 144 | - $failed_at = get_transient( 'boxzilla_request_failed' ); | |
| 145 | - if( ! empty( $failed_at ) && ( (strtotime('now') - 300) < $failed_at ) ) { | |
| 146 | - return array(); | |
| 147 | - } | |
| 148 | - | |
| 149 | 137 | // fetch remote info |
| 150 | 138 | try { |
| 151 | 139 | $remote_plugins = $this->api->get_plugins( $this->extensions ); |
| 152 | 140 | } catch( API_Exception $e ) { |
| 153 | - // set flag for 5 minutes | |
| 154 | - set_transient( 'boxzilla_request_failed', strtotime('now'), 300 ); | |
| 155 | - return array(); | |
| 141 | + return array(); | |
| 156 | 142 | } |
| 157 | 143 | |
| 158 | 144 | // filter remote plugins, we only want the ones with an update available |
| 159 | 145 | $this->available_updates = $this->filter_remote_plugins( $remote_plugins ); |
| @@ -182,9 +168,9 @@ | ||
| 182 | 168 | } |
| 183 | 169 | ); |
| 184 | 170 | |
| 185 | 171 | // plugin found and local plugin version not same as remote version? |
| 186 | - if( ! $local_plugin || version_compare( $local_plugin->version(), $remote_plugin->new_version, '>=' ) ) { | |
| 172 | + if( ! $local_plugin || version_compare( $local_plugin->version(), $remote_plugin->version, '>=' ) ) { | |
| 187 | 173 | continue; |
| 188 | 174 | } |
| 189 | 175 | |
| 190 | 176 | // add some dynamic data |
| @@ -215,8 +201,9 @@ | ||
| 215 | 201 | * |
| 216 | 202 | * @return mixed |
| 217 | 203 | */ |
| 218 | 204 | protected function format_response( Plugin $plugin, $response ) { |
| 205 | + $response->new_version = $response->version; | |
| 219 | 206 | $response->slug = dirname( $plugin->slug() ); |
| 220 | 207 | $response->plugin = $plugin->slug(); |
| 221 | 208 | |
| 222 | 209 | // add some notices if license is inactive |
| @@ -223,9 +210,12 @@ | ||
| 223 | 210 | if( ! $this->license->activated ) { |
| 224 | 211 | $response->upgrade_notice = sprintf( 'You will need to <a href="%s">activate your license</a> to install this plugin update.', admin_url( 'edit.php?post_type=boxzilla-box&page=boxzilla-settings' ) ); |
| 225 | 212 | $response->sections->changelog = '<p>' . sprintf( 'You will need to <a href="%s" target="_top">activate your license</a> to install this plugin update.', admin_url( 'edit.php?post_type=boxzilla-box&page=boxzilla-settings' ) ) . '</p>' . $response->sections->changelog; |
| 226 | 213 | $response->package = null; |
| 227 | - } | |
| 214 | + } else { | |
| 215 | + // add activation key to download URL | |
| 216 | + $response->package = add_query_arg( array( 'key' => $this->license->activation_key ), $response->package ); | |
| 217 | + } | |
| 228 | 218 | |
| 229 | 219 | // cast subkey objects to array as that is what WP expects |
| 230 | 220 | $response->sections = get_object_vars( $response->sections ); |
| 231 | 221 | $response->banners = get_object_vars( $response->banners ); |
| @@ -232,5 +222,5 @@ | ||
| 232 | 222 | |
| 233 | 223 | return $response; |
| 234 | 224 | } |
| 235 | 225 | |
| 236 | -} | |
| 226 | +} | |