Beispiel #1
0
 public function requestUpdate($queryArgs = array())
 {
     //Query args to append to the URL. Themes can add their own by using a filter callback (see addQueryArgFilter()).
     $queryArgs['installed_version'] = $this->getInstalledVersion();
     $queryArgs = apply_filters(self::$filterPrefix . 'query_args-' . $this->theme, $queryArgs);
     //Various options for the wp_remote_get() call. Themes can filter these, too.
     $options = array('timeout' => 20);
     $options = apply_filters(self::$filterPrefix . 'options-' . $this->theme, $options);
     $url = $this->metadataUrl;
     if (!empty($queryArgs)) {
         $url = add_query_arg($queryArgs, $url);
     }
     //Send the request.
     $result = wp_remote_get($url, $options);
     //Try to parse the response
     $themeUpdate = null;
     $code = wp_remote_retrieve_response_code($result);
     $body = wp_remote_retrieve_body($result);
     if ($code == 200 && !empty($body)) {
         $themeUpdate = ThemeUpdate::fromJson($body);
         //The update should be newer than the currently installed version.
         if ($themeUpdate != null && version_compare($themeUpdate->version, $this->getInstalledVersion(), '<=')) {
             $themeUpdate = null;
         }
     }
     $themeUpdate = apply_filters(self::$filterPrefix . 'result-' . $this->theme, $themeUpdate, $result);
     return $themeUpdate;
 }
Beispiel #2
0
 /**
  * Insert the latest update (if any) into the update list maintained by WP.
  * 
  * @param StdClass $updates Update list.
  * @return array Modified update list.
  */
 public function injectUpdate($updates)
 {
     $state = get_option($this->optionName);
     //Is there an update to insert?
     if (!empty($state) && isset($state->update) && !empty($state->update)) {
         $update = $state->update;
         if (is_string($state->update)) {
             $update = ThemeUpdate::fromJson($state->update);
         }
         $updates->response[$this->theme] = $update->toWpFormat();
     }
     return $updates;
 }