예제 #1
0
 public function testReturnsResultOfPassingWpDataToFactoryCreate()
 {
     $wpData = ['response' => ['code' => 201]];
     $this->wpHttp->get('uri', [])->willReturn($wpData);
     $this->factory->create($wpData)->shouldBeCalled();
     $this->request->get('uri');
 }
 /**
  * @param string|array $address
  */
 public function provide_coordinates_for_address($address)
 {
     if (is_array($address)) {
         $address = implode(', ', array_filter(array_map('trim', $address)));
     }
     $address = trim($address);
     if ($location = $this->get_resolved($address)) {
         return $location;
     }
     $base_request_url = trailingslashit($this->get_google_api_base()) . $this->get_google_api_json_format();
     $url = esc_url(add_query_arg(array('address' => $address), $base_request_url));
     $response = $this->http->get($url);
     if (is_wp_error($response)) {
         return false;
     }
     $decoded = json_decode($response['body'], true);
     if (empty($decoded['status']) || 'OK' !== $decoded['status']) {
         return false;
     }
     if (empty($decoded['results'][0]['place_id']) || empty($decoded['results'][0]['geometry']['location']['lat']) || empty($decoded['results'][0]['geometry']['location']['lng'])) {
         return false;
     }
     $location = $decoded['results'][0]['geometry']['location'];
     $updated_transient = array_merge($this->get_transient(), array($address => $location));
     set_transient(self::$transient_name, $updated_transient);
     $this->transient = $updated_transient;
     return $location;
 }
예제 #3
0
 /**
  * Gets an instagram feed
  *
  * @param string $username Username
  * @param integer $limit Number of images to return
  * @return array
  */
 protected function getFeed($username = null, $limit = 5)
 {
     if (empty($username)) {
         return array();
     }
     $results = get_transient('InstagramWidget::getFeed');
     if ($results === false) {
         $request = new WP_Http();
         $response = $request->get("http://ink361.com/feed/user/{$username}");
         $results = array();
         if (!is_a($response, 'WP_Error')) {
             try {
                 $resultsXml = new SimpleXMLElement($response['body']);
                 foreach ($resultsXml->channel[0]->item as $node) {
                     // ink361 sends <a href="ink361.com"><img src="image.jpg"></a>
                     try {
                         $imageNode = new DOMDocument();
                         $imageNode->loadHTML($node->description);
                         $img = $imageNode->getElementsByTagName('img');
                         $results[] = $img->item(0)->getAttribute('src');
                         if (count($results) == $limit) {
                             break;
                         }
                     } catch (Exception $e) {
                     }
                 }
                 set_transient('InstagramWidget::getFeed', $results, HOUR_IN_SECONDS);
             } catch (Exception $e) {
             }
         }
     }
     return $results;
 }
예제 #4
0
 private function from_remote()
 {
     $data = array();
     $url = 'https://api.wpengine.com/1.2/?method=disk-usage&account_name=' . PWP_NAME . '&wpe_apikey=' . WPE_APIKEY . '&blog_id=all';
     $http = new WP_Http();
     $msg = $http->get($url);
     if (!is_a($msg, 'WP_Error') && isset($msg['body'])) {
         $data = json_decode($msg['body'], TRUE);
     }
     return $data;
 }
 /**
  * {@inheritdoc}
  * @internal
  */
 public function _download_framework($version, $wp_filesystem_download_directory)
 {
     /** @var WP_Filesystem_Base $wp_filesystem */
     global $wp_filesystem;
     $user_slash_repo = fw()->manifest->get($this->manifest_key);
     $http = new WP_Http();
     $response = $http->get('https://api.github.com/repos/' . $user_slash_repo . '/releases');
     unset($http);
     if (wp_remote_retrieve_response_code($response) !== 200) {
         return new WP_Error('fw_ext_update_github_framework_download_releases_failed', __('Failed to access Github repository releases.', 'fw'));
     }
     $releases = json_decode($response['body'], true);
     unset($response);
     if (empty($releases)) {
         return new WP_Error('fw_ext_update_github_framework_download_no_releases', __('Github repository has no releases.', 'fw'));
     }
     $release = false;
     foreach ($releases as $_release) {
         if ($_release['tag_name'] === $version) {
             $release = $_release;
         }
     }
     if (empty($release)) {
         return new WP_Error('fw_ext_update_github_framework_download_not_existing_release', sprintf(__('Requested version (release) for download does not exists "%s".', 'fw'), $version));
     }
     $http = new WP_Http();
     $response = $http->request($release['zipball_url'], array('timeout' => $this->download_timeout));
     unset($http);
     if (wp_remote_retrieve_response_code($response) !== 200) {
         return new WP_Error('fw_ext_update_github_framework_download_failed', __('Failed to download framework zip.', 'fw'));
     }
     $zip_path = $wp_filesystem_download_directory . '/temp.zip';
     // save zip to file
     $wp_filesystem->put_contents($zip_path, $response['body']);
     unset($response);
     unzip_file(FW_WP_Filesystem::filesystem_path_to_real_path($zip_path), $wp_filesystem_download_directory);
     // remove zip file
     $wp_filesystem->delete($zip_path, false, 'f');
     $unzipped_dir = $wp_filesystem->dirlist($wp_filesystem_download_directory);
     $unzipped_dir = $wp_filesystem_download_directory . '/' . key($unzipped_dir);
     return $unzipped_dir;
 }
 /**
  * Download an extension
  *
  * global $wp_filesystem; must me initialized
  *
  * @param string $extension_name
  * @param array $data Extension data from the "available extensions" array
  * @return string|WP_Error WP Filesystem path to the downloaded directory
  */
 private function download($extension_name, $data)
 {
     $wp_error_id = 'fw_extension_download';
     if (empty($data['download'])) {
         return new WP_Error($wp_error_id, sprintf(__('Extension "%s" has no download sources.', 'fw'), $this->get_extension_title($extension_name)));
     }
     /** @var WP_Filesystem_Base $wp_filesystem */
     global $wp_filesystem;
     $wp_fs_tmp_dir = FW_WP_Filesystem::real_path_to_filesystem_path($this->get_tmp_dir());
     if ($wp_filesystem->exists($wp_fs_tmp_dir)) {
         // just in case it already exists, clear everything, it may contain old files
         if (!$wp_filesystem->rmdir($wp_fs_tmp_dir, true)) {
             return new WP_Error($wp_error_id, sprintf(__('Cannot remove temporary directory: %s', 'fw'), $wp_fs_tmp_dir));
         }
     }
     if (!FW_WP_Filesystem::mkdir_recursive($wp_fs_tmp_dir)) {
         return new WP_Error($wp_error_id, sprintf(__('Cannot create temporary directory: %s', 'fw'), $wp_fs_tmp_dir));
     }
     foreach ($data['download'] as $source => $source_data) {
         switch ($source) {
             case 'github':
                 if (empty($source_data['user_repo'])) {
                     return new WP_Error($wp_error_id, sprintf(__('"%s" extension github source "user_repo" parameter is required', 'fw'), $this->get_extension_title($extension_name)));
                 }
                 $transient_name = 'fw_ext_mngr_gh_dl';
                 $transient_ttl = HOUR_IN_SECONDS;
                 $cache = get_site_transient($transient_name);
                 if ($cache === false) {
                     $cache = array();
                 }
                 if (isset($cache[$source_data['user_repo']])) {
                     $download_link = $cache[$source_data['user_repo']]['zipball_url'];
                 } else {
                     $http = new WP_Http();
                     $response = $http->get(apply_filters('fw_github_api_url', 'https://api.github.com') . '/repos/' . $source_data['user_repo'] . '/releases/latest');
                     unset($http);
                     $response_code = intval(wp_remote_retrieve_response_code($response));
                     if ($response_code !== 200) {
                         if ($response_code === 403) {
                             $json_response = json_decode($response['body'], true);
                             if ($json_response) {
                                 return new WP_Error($wp_error_id, __('Github error:', 'fw') . ' ' . $json_response['message']);
                             }
                         } elseif ($response_code) {
                             return new WP_Error($wp_error_id, sprintf(__('Failed to access Github repository "%s" releases. (Response code: %d)', 'fw'), $source_data['user_repo'], $response_code));
                         } elseif (is_wp_error($response)) {
                             return new WP_Error($wp_error_id, sprintf(__('Failed to access Github repository "%s" releases. (%s)', 'fw'), $source_data['user_repo'], $response->get_error_message()));
                         } else {
                             return new WP_Error($wp_error_id, sprintf(__('Failed to access Github repository "%s" releases.', 'fw'), $source_data['user_repo']));
                         }
                     }
                     $release = json_decode($response['body'], true);
                     unset($response);
                     if (empty($release)) {
                         return new WP_Error($wp_error_id, sprintf(__('"%s" extension github repository "%s" has no releases.', 'fw'), $this->get_extension_title($extension_name), $source_data['user_repo']));
                     }
                     $cache[$source_data['user_repo']] = array('zipball_url' => 'https://github.com/' . $source_data['user_repo'] . '/archive/' . $release['tag_name'] . '.zip', 'tag_name' => $release['tag_name']);
                     set_site_transient($transient_name, $cache, $transient_ttl);
                     $download_link = $cache[$source_data['user_repo']]['zipball_url'];
                     unset($release);
                 }
                 $http = new WP_Http();
                 $response = $http->request($download_link, array('timeout' => $this->download_timeout));
                 unset($http);
                 if (($response_code = intval(wp_remote_retrieve_response_code($response))) !== 200) {
                     if ($response_code) {
                         return new WP_Error($wp_error_id, sprintf(__('Cannot download the "%s" extension zip. (Response code: %d)', 'fw'), $this->get_extension_title($extension_name), $response_code));
                     } elseif (is_wp_error($response)) {
                         return new WP_Error($wp_error_id, sprintf(__('Cannot download the "%s" extension zip. %s', 'fw'), $this->get_extension_title($extension_name), $response->get_error_message()));
                     } else {
                         return new WP_Error($wp_error_id, sprintf(__('Cannot download the "%s" extension zip.', 'fw'), $this->get_extension_title($extension_name)));
                     }
                 }
                 $zip_path = $wp_fs_tmp_dir . '/temp.zip';
                 // save zip to file
                 if (!$wp_filesystem->put_contents($zip_path, $response['body'])) {
                     return new WP_Error($wp_error_id, sprintf(__('Cannot save the "%s" extension zip.', 'fw'), $this->get_extension_title($extension_name)));
                 }
                 unset($response);
                 $unzip_result = unzip_file(FW_WP_Filesystem::filesystem_path_to_real_path($zip_path), $wp_fs_tmp_dir);
                 if (is_wp_error($unzip_result)) {
                     return $unzip_result;
                 }
                 // remove zip file
                 if (!$wp_filesystem->delete($zip_path, false, 'f')) {
                     return new WP_Error($wp_error_id, sprintf(__('Cannot remove the "%s" extension downloaded zip.', 'fw'), $this->get_extension_title($extension_name)));
                 }
                 $unzipped_dir_files = $wp_filesystem->dirlist($wp_fs_tmp_dir);
                 if (!$unzipped_dir_files) {
                     return new WP_Error($wp_error_id, __('Cannot access the unzipped directory files.', 'fw'));
                 }
                 /**
                  * get first found directory
                  * (if everything worked well, there should be only one directory)
                  */
                 foreach ($unzipped_dir_files as $file) {
                     if ($file['type'] == 'd') {
                         return $wp_fs_tmp_dir . '/' . $file['name'];
                     }
                 }
                 return new WP_Error($wp_error_id, sprintf(__('The unzipped "%s" extension directory not found.', 'fw'), $this->get_extension_title($extension_name)));
                 break;
             default:
                 return new WP_Error($wp_error_id, sprintf(__('Unknown "%s" extension download source "%s"', 'fw'), $this->get_extension_title($extension_name), $source));
         }
     }
 }
function ml_check_pb_keys()
{
    $headers = array('X-PUSHBOTS-APPID' => get_option('ml_pb_app_id'), 'X-PUSHBOTS-SECRET' => get_option('ml_pb_secret_key'), 'Content-Type' => 'application/json', 'Content-Length' => 0);
    $url = 'https://api.pushbots.com/analytics';
    $request = new WP_Http();
    $result = $request->get($url, array('timeout' => 10, 'headers' => $headers, 'sslverify' => false));
    return isset($result['response']['code']) && $result['response']['code'] == 200;
}
예제 #8
0
function fpp_acquire_page_access_token($page_id, $profile_access_token)
{
    $request = new WP_Http();
    $api_url = 'https://graph.facebook.com/me/accounts?access_token=' . urlencode($profile_access_token);
    $response = $request->get($api_url, array('timeout' => FPP_REQUEST_TIMEOUT, 'sslverify' => fpp_get_ssl_verify()));
    if (array_key_exists('errors', $response)) {
        throw new FacebookUnreachableException(!empty($response->errors) ? array_pop(array_pop($response->errors)) : '');
    }
    $json_response = json_decode($response['body']);
    if (!is_object($json_response) || !property_exists($json_response, 'data')) {
        throw new FacebookUnexpectedErrorException(__('Can\'t access Facebook user account information.', FPP_TEXT_DOMAIN));
    }
    foreach ($json_response->data as $account) {
        if ($account->id == $page_id) {
            if (!property_exists($account, 'access_token')) {
                throw new FacebookUnexpectedErrorException(__('Some or all access permissions for your page are missing.', FPP_TEXT_DOMAIN));
            }
            $page_access_token = $account->access_token;
            break;
        }
    }
    if (!isset($page_access_token)) {
        throw new FacebookErrorException(__('Your Facebook user account data contains no page with the given ID. You have to be administrator of the given page.', FPP_TEXT_DOMAIN));
    }
    return $page_access_token;
}
 public function run()
 {
     if (!$this->is_config_update_disabled()) {
         $response = $this->http->get(ICL_REMOTE_WPML_CONFIG_FILES_INDEX . 'wpml-config/config-index.json');
         if (!is_wp_error($response) && $response['response']['code'] == 200) {
             $arr = json_decode($response['body']);
             if (isset($arr->plugins) && isset($arr->themes)) {
                 update_option('wpml_config_index', $arr);
                 update_option('wpml_config_index_updated', time());
                 $config_files = maybe_unserialize(get_option('wpml_config_files_arr'));
                 $config_files_for_themes = array();
                 $deleted_configs_for_themes = array();
                 $config_files_for_plugins = array();
                 $deleted_configs_for_plugins = array();
                 if ($config_files) {
                     if (isset($config_files->themes)) {
                         $config_files_for_themes = $config_files->themes;
                         $deleted_configs_for_themes = $config_files->themes;
                     }
                     if (isset($config_files->plugins)) {
                         $config_files_for_plugins = $config_files->plugins;
                         $deleted_configs_for_plugins = $config_files->plugins;
                     }
                 }
                 foreach ($arr->themes as $theme) {
                     if ($this->sitepress->get_wp_api()->get_theme_name() == $theme->name && (!isset($config_files_for_themes[$theme->name]) || md5($config_files_for_themes[$theme->name]) != $theme->hash)) {
                         $response = $this->http->get(ICL_REMOTE_WPML_CONFIG_FILES_INDEX . $theme->path);
                         if ($response['response']['code'] == 200) {
                             $config_files_for_themes[$theme->name] = $response['body'];
                         }
                     }
                 }
                 foreach ($deleted_configs_for_themes as $key => $deleted_config) {
                     unset($config_files_for_themes[$key]);
                 }
                 $active_plugins = $this->sitepress->get_wp_api()->get_plugins();
                 $active_plugins_names = array();
                 foreach ($active_plugins as $active_plugin) {
                     $active_plugins_names[] = $active_plugin['Name'];
                 }
                 foreach ($arr->plugins as $plugin) {
                     if (in_array($plugin->name, $active_plugins_names) && (!isset($config_files_for_plugins[$plugin->name]) || md5($config_files_for_plugins[$plugin->name]) != $plugin->hash)) {
                         $response = $this->http->get(ICL_REMOTE_WPML_CONFIG_FILES_INDEX . $plugin->path);
                         if (!is_wp_error($response) && $response['response']['code'] == 200) {
                             $config_files_for_plugins[$plugin->name] = $response['body'];
                         }
                     }
                 }
                 foreach ($deleted_configs_for_plugins as $key => $deleted_config) {
                     unset($config_files_for_plugins[$key]);
                 }
                 if (!isset($config_files) || !$config_files) {
                     $config_files = new stdClass();
                 }
                 $config_files->themes = $config_files_for_themes;
                 $config_files->plugins = $config_files_for_plugins;
                 update_option('wpml_config_files_arr', $config_files);
                 return true;
             }
         }
     }
     return false;
 }
예제 #10
0
 function update_wpml_config_index_event()
 {
     $wp_http_class = new WP_Http();
     $response = $wp_http_class->get(ICL_REMOTE_WPML_CONFIG_FILES_INDEX . 'wpml-config/config-index.json');
     if (!is_wp_error($response) && $response['response']['code'] == 200) {
         $arr = json_decode($response['body']);
         if (isset($arr->plugins) && isset($arr->themes)) {
             update_option('wpml_config_index', $arr);
             update_option('wpml_config_index_updated', time());
             $config_files_arr = maybe_unserialize(get_option('wpml_config_files_arr'));
             if ($config_files_arr) {
                 $config_files_themes_arr = $config_files_arr->themes;
                 $config_files_plugins_arr = $config_files_arr->plugins;
             } else {
                 $config_files_themes_arr = array();
                 $config_files_plugins_arr = array();
             }
             $wp_http_class = new WP_Http();
             $theme_data = wp_get_theme();
             foreach ($arr->themes as $theme) {
                 if ($theme_data->get('Name') == $theme->name && (!isset($config_files_themes_arr[$theme->name]) || md5($config_files_themes_arr[$theme->name]) != $theme->hash)) {
                     $response = $wp_http_class->get(ICL_REMOTE_WPML_CONFIG_FILES_INDEX . $theme->path);
                     if ($response['response']['code'] == 200) {
                         $config_files_themes_arr[$theme->name] = $response['body'];
                     }
                 }
             }
             if (!function_exists('get_plugins')) {
                 require_once ABSPATH . 'wp-admin/includes/plugin.php';
             }
             $active_plugins = get_plugins();
             foreach ($active_plugins as $active_plugin) {
                 $active_plugins_names[] = $active_plugin['Name'];
             }
             foreach ($arr->plugins as $plugin) {
                 if (in_array($plugin->name, $active_plugins_names) && (!isset($config_files_plugins_arr[$plugin->name]) || md5($config_files_plugins_arr[$plugin->name]) != $plugin->hash)) {
                     $response = $wp_http_class->get(ICL_REMOTE_WPML_CONFIG_FILES_INDEX . $plugin->path);
                     if (!is_wp_error($response) && $response['response']['code'] == 200) {
                         $config_files_plugins_arr[$plugin->name] = $response['body'];
                     }
                 }
             }
             if (!isset($config_files_arr) || !$config_files_arr) {
                 $config_files_arr = new stdClass();
             }
             $config_files_arr->themes = $config_files_themes_arr;
             $config_files_arr->plugins = $config_files_plugins_arr;
             update_option('wpml_config_files_arr', $config_files_arr);
             return true;
         }
     }
     return false;
 }
예제 #11
0
function ml_registered_devices_count()
{
    $request = new WP_Http();
    $headers = array('X-PUSHBOTS-APPID' => get_option('ml_pb_app_id'), 'X-PUSHBOTS-SECRET' => get_option('ml_pb_secret_key'), 'platform' => 0);
    $url = MOBILOUD_PB_URL . '/deviceToken/count';
    $result = $request->get($url, array('timeout' => 10, 'headers' => $headers, 'sslverify' => false));
    $iosCount = null;
    if ($result instanceof WP_Error) {
        $iosCount = null;
    } elseif (isset($result['body'])) {
        $responseJson = json_decode($result['body']);
        $iosCount = isset($responseJson->count) ? $responseJson->count : 0;
    }
    $request = new WP_Http();
    $headers = array('X-PUSHBOTS-APPID' => get_option('ml_pb_app_id'), 'X-PUSHBOTS-SECRET' => get_option('ml_pb_secret_key'), 'platform' => 1);
    $url = MOBILOUD_PB_URL . '/deviceToken/count';
    $result = $request->get($url, array('timeout' => 10, 'headers' => $headers, 'sslverify' => false));
    $androidCount = null;
    if ($result instanceof WP_Error) {
        $androidCount = null;
    } elseif (isset($result['body'])) {
        $responseJson = json_decode($result['body']);
        $androidCount = isset($responseJson->count) ? $responseJson->count : 0;
    }
    return array('ios' => $iosCount, 'android' => $androidCount);
}
예제 #12
0
function nospamuser_check($type, $data)
{
    $settings = bb_get_option('nospamuser-settings');
    if (!$settings) {
        bb_update_option('nospamuser-settings', $settings = array('days' => 30, 'min_occur' => 5, 'max_occur' => 10, 'api_key' => '', 'recaptcha_mode' => 'aggressive', 'recapthca_pub' => '', 'recaptcha_priv' => '', 'stats_public' => 0));
    }
    if (!is_array($result = bb_get_transient('nospamuser-' . $type . '-' . md5($data)))) {
        $wp_http = new WP_Http();
        $response = $wp_http->get('http://www.stopforumspam.com/api?' . urlencode($type) . '=' . urlencode($data), array('user-agent' => apply_filters('http_headers_useragent', backpress_get_option('wp_http_version')) . NOSPAMUSER_AGENT));
        $response = $response['body'];
        if (strpos($response, '<response success="true">') === false) {
            return;
        }
        if (strpos($response, '<appears>no</appears>') !== false) {
            $result = array(0, 0);
        } else {
            preg_match('/<lastseen>([^<>]+)<\\/lastseen>/', $response, $matches);
            $result = array((int) substr($response, strpos($response, '<frequency>') + 11), strtotime($matches[1]));
        }
        bb_set_transient('nospamuser-' . $type . '-' . md5($data), $result, 604800);
    }
    if ($result == array(0, 0)) {
        // Even if the settings are set incorrectly, non-spammers shouldn't be blocked.
        return;
    }
    if ($result[0] >= $settings['min_occur'] && $result[1] >= time() - $settings['days'] * 86400 || $result[0] >= $settings['max_occur'] && $settings['recaptcha_mode'] == 'aggressive') {
        if ($result[0] >= $settings['max_occur'] && $settings['recaptcha_mode'] == 'adaptive') {
            nospamuser_block($type, $data, true);
        } elseif ($settings['recaptcha_mode'] == 'aggressive' || !$settings['recaptcha_pub'] || !$settings['recaptcha_priv']) {
            nospamuser_block($type, $data, true);
        } else {
            nospamuser_block($type, $data, false);
        }
    }
}
 /**
  * @param string $user_slash_repo Github 'user/repo'
  * @param string $version Requested version to download
  * @param string $wp_filesystem_download_directory Allocated temporary empty directory
  * @param string $title Used in messages
  *
  * @return string|WP_Error Path to the downloaded directory
  */
 private function download($user_slash_repo, $version, $wp_filesystem_download_directory, $title)
 {
     $http = new WP_Http();
     $response = $http->get($this->get_github_api_url('/repos/' . $user_slash_repo . '/releases/tags/' . $version));
     unset($http);
     $response_code = intval(wp_remote_retrieve_response_code($response));
     if ($response_code !== 200) {
         if ($response_code === 403) {
             $json_response = json_decode($response['body'], true);
             if ($json_response) {
                 return new WP_Error('fw_ext_update_github_download_releases_failed', __('Github error:', 'fw') . ' ' . $json_response['message']);
             }
         }
         if ($response_code) {
             return new WP_Error('fw_ext_update_github_download_releases_failed', sprintf(__('Failed to access Github repository "%s" releases. (Response code: %d)', 'fw'), $user_slash_repo, $response_code));
         } else {
             return new WP_Error('fw_ext_update_github_download_releases_failed', sprintf(__('Failed to access Github repository "%s" releases.', 'fw'), $user_slash_repo));
         }
     }
     $release = json_decode($response['body'], true);
     unset($response);
     if (empty($release)) {
         return new WP_Error('fw_ext_update_github_download_no_release', sprintf(__('%s github repository "%s" does not have the "%s" release.', 'fw'), $title, $user_slash_repo, $version));
     }
     $http = new WP_Http();
     $response = $http->request('https://github.com/' . $user_slash_repo . '/archive/' . $release['tag_name'] . '.zip', array('timeout' => $this->download_timeout));
     unset($http);
     if (intval(wp_remote_retrieve_response_code($response)) !== 200) {
         return new WP_Error('fw_ext_update_github_download_failed', sprintf(__('Cannot download %s zip.', 'fw'), $title));
     }
     /** @var WP_Filesystem_Base $wp_filesystem */
     global $wp_filesystem;
     $zip_path = $wp_filesystem_download_directory . '/temp.zip';
     // save zip to file
     if (!$wp_filesystem->put_contents($zip_path, $response['body'])) {
         return new WP_Error('fw_ext_update_github_save_download_failed', sprintf(__('Cannot save %s zip.', 'fw'), $title));
     }
     unset($response);
     $unzip_result = unzip_file(FW_WP_Filesystem::filesystem_path_to_real_path($zip_path), $wp_filesystem_download_directory);
     if (is_wp_error($unzip_result)) {
         return $unzip_result;
     }
     // remove zip file
     if (!$wp_filesystem->delete($zip_path, false, 'f')) {
         return new WP_Error('fw_ext_update_github_remove_downloaded_zip_failed', sprintf(__('Cannot remove %s zip.', 'fw'), $title));
     }
     $unzipped_dir_files = $wp_filesystem->dirlist($wp_filesystem_download_directory);
     if (!$unzipped_dir_files) {
         return new WP_Error('fw_ext_update_github_unzipped_dir_fail', __('Cannot access the unzipped directory files.', 'fw'));
     }
     /**
      * get first found directory
      * (if everything worked well, there should be only one directory)
      */
     foreach ($unzipped_dir_files as $file) {
         if ($file['type'] == 'd') {
             return $wp_filesystem_download_directory . '/' . $file['name'];
         }
     }
     return new WP_Error('fw_ext_update_github_unzipped_dir_not_found', sprintf(__('The unzipped %s directory not found.', 'fw'), $title));
 }
예제 #14
0
function opensso_get_name($ssotoken)
{
    $url = OPENSSO_ATTRIBUTES . '?subjectid=' . urlencode($ssotoken);
    $http = new WP_Http();
    $response = $http->get($url, array('headers' => $headers));
    if ($response['response']['code'] != 200) {
        return null;
    }
    // Need to parse name/value pairs, to get value for WordPress username attribute
    $lines = explode("\n", $response['body']);
    reset($lines);
    foreach ($lines as $line) {
        if ($line == 'userdetails.attribute.name=' . OPENSSO_WORDPRESS_USERNAME_ATTRIBUTE) {
            // 'current' line holds attribute value
            // 28 points to character after 'userdetails.attribute.value='
            $name = substr(current($lines), 28);
            break;
        }
    }
    return $name;
}
예제 #15
0
    if ($current_state != $new_state) {
        $this->set_rand_enabled($new_state);
        $message = "ORDER BY RAND() support is now <b>" . ($new_state ? 'enabled' : 'disabled') . "</b>.";
    }
    // HTML post-processing
    $result = $this->set_regex_html_post_process_text($fv_regex_html_post_process);
    if ($result !== TRUE) {
        $error = "<b>Error in HTML replacement regex:</b><br>{$result}<br>(Maybe you forgot the beginning and ending characters?)";
    }
}
// Fix file permissions
if (wpe_param('file-perms')) {
    check_admin_referer(PWP_NAME . '-config');
    $url = "https://api.wpengine.com/1.2/?method=file-permissions&account_name=" . PWP_NAME . "&wpe_apikey=" . WPE_APIKEY;
    $http = new WP_Http();
    $msg = $http->get($url);
    if (is_a($msg, 'WP_Error')) {
        return false;
    }
    if (!isset($msg['body'])) {
        return false;
    }
    $data = json_decode($msg['body'], true);
    $message = @$data['message'];
}
// Process purging all caches
if (wpe_param('purge-all')) {
    check_admin_referer(PWP_NAME . '-config');
    // check_admin_referer(PWP_NAME.'-config');		DO NOT CHECK because it's OK to just hit it from anywhere, and in fact we do.
    WpeCommon::purge_memcached();
    WpeCommon::clear_maxcdn_cache();
예제 #16
0
/**
 * Gets last tweet from specified account
 *
 * Based on script developed by Joost de Valk, which used Snoopy class to connect to twitter.com
 * Replaced Snoopy with WP_Http object to request URL, and added regular expression to format urls in 
 * tweet's body.
 * 
 *
 * Since CALS News 1.0
 * @uses WP_Http (replaces Snoopy)
 * @print $output (twitter html)
 * @link http://yoast.com/display-latest-tweet/ 
 * @link http://stackoverflow.com/questions/1959062/how-to-add-anchor-tag-to-a-url-from-text-input
 * 
*/
function cals_get_last_tweet()
{
    //require_once(ABSPATH . 'wp-includes/class-snoopy.php');
    require_once ABSPATH . 'wp-includes/class-http.php';
    $twitterid = "uwmadisoncals";
    $tweet = get_option("lasttweet");
    //$url  = "http://twitter.com/statuses/user_timeline/uwmadisoncals.json?count=5";
    $url = "https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=" . $twitterid . "&count=10";
    if ($tweet['lastcheck'] < mktime() - 2700) {
        $http = new WP_Http();
        $result = $http->get($url);
        global $current_user;
        if (!is_admin() && current_user_can('level_10') && $current_user->user_login == "amnemec") {
            //print_r ($result);
            //include('../../plugins/ecals_submissions_form/ecals_submission_form.php');
        }
        if (!is_object($result)) {
            //check if an WP_error object was returned... if so, display error message below
            $twitterdata = json_decode($result['body'], true);
            $i = 0;
            while ($twitterdata[$i]['in_reply_to_user_id'] != '') {
                $i++;
            }
            //add anchor tag to urls found in tweet's text (i.e. "http://bit.ly/b54pIs")
            $pattern = '#\\b(([\\w-]+://?|www[.])[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|/)))#';
            $replace = '<a href="' . strtolower('\\1') . '">\\1</a>';
            $output = preg_replace($pattern, $replace, $twitterdata[$i]["text"]);
            //add anchor tag to twitter handles found in tweet's text (i.e. "@uwmadison")
            $pattern = '/\\@([a-zA-Z0-9_]+)/';
            $replace = '<a href="http://twitter.com/' . strtolower('\\1') . '">@\\1</a>';
            $output = preg_replace($pattern, $replace, $output);
            //add anchor tag to hashtags found in tweet's text (i.e. "#uw2014")
            $pattern = '/(^|\\s)#(\\w+)/';
            $replace = ' <a href="http://twitter.com/search?q=%23' . strtolower('\\2') . '">#\\2</a>';
            $output = preg_replace($pattern, $replace, $output);
            $tweet['lastcheck'] = mktime();
            $tweet['datemonth'] = date('M');
            $tweet['dateday'] = date('d');
            $tweet['dateyear'] = date('Y');
            $tweet['data'] = $output;
            $tweet['rawdata'] = $twitterdata;
            $tweet['followers'] = $twitterdata[0]['user']['followers_count'];
            $date_month = date('M');
            $date_day = date('d');
            $date_year = date('Y');
            update_option('lasttweet', $tweet);
        } else {
            echo "Twitter API not responding.";
        }
    } else {
        $output = $tweet['data'];
        $dateoutput = $tweet['rawdata'][0]['created_at'];
        $rawtext = $tweet['rawdata'][0]['text'];
        $date_month = substr($dateoutput, 4, 3);
        $date_day = substr($dateoutput, 8, 2);
        $date_year = substr($dateoutput, 26, 4);
        if ($output == '') {
            $output = $rawtext;
        }
    }
    if ($date_month == "Jan") {
        $date_month = "January";
        $date_month_hidden = "01";
    } else {
        if ($date_month == "Feb") {
            $date_month = "February";
            $date_month_hidden = "02";
        } else {
            if ($date_month == "Mar") {
                $date_month = "March";
                $date_month_hidden = "03";
            } else {
                if ($date_month == "Apr") {
                    $date_month = "April";
                    $date_month_hidden = "04";
                } else {
                    if ($date_month == "May") {
                        $date_month = "May";
                        $date_month_hidden = "05";
                    } else {
                        if ($date_month == "Jun") {
                            $date_month = "June";
                            $date_month_hidden = "06";
                        } else {
                            if ($date_month == "Jul") {
                                $date_month = "July";
                                $date_month_hidden = "07";
                            } else {
                                if ($date_month == "Aug") {
                                    $date_month = "August";
                                    $date_month_hidden = "08";
                                } else {
                                    if ($date_month == "Sep") {
                                        $date_month = "September";
                                        $date_month_hidden = "09";
                                    } else {
                                        if ($date_month == "Oct") {
                                            $date_month = "October";
                                            $date_month_hidden = "10";
                                        } else {
                                            if ($date_month == "Nov") {
                                                $date_month = "November";
                                                $date_month_hidden = "11";
                                            } else {
                                                if ($date_month == "Dec") {
                                                    $date_month = "December";
                                                    $date_month_hidden = "12";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($date_day == "01") {
        $date_day_formatted = "1";
    } else {
        if ($date_day == "02") {
            $date_day_formatted = "2";
        } else {
            if ($date_day == "03") {
                $date_day_formatted = "3";
            } else {
                if ($date_day == "04") {
                    $date_day_formatted = "4";
                } else {
                    if ($date_day == "05") {
                        $date_day_formatted = "5";
                    } else {
                        if ($date_day == "06") {
                            $date_day_formatted = "6";
                        } else {
                            if ($date_day == "07") {
                                $date_day_formatted = "7";
                            } else {
                                if ($date_day == "08") {
                                    $date_day_formatted = "8";
                                } else {
                                    if ($date_day == "09") {
                                        $date_day_formatted = "9";
                                    } else {
                                        $date_day_formatted = $date_day;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    echo '<div class="newsItem social twitter">
    	
    		<div class="previousa">
    		<div class="additionalContent" style="min-height: 130px;"><img src="http://beta.cals.wisc.edu/wp-content/themes/CALSv1_0/images/twitter-bg-' . rand(1, 3) . '.jpg" alt=" " /></div>
    		<div class="text">
    			<div class="glyph"><div class="symbol"></div></div>
    			<div class="titleheading">
    			<h3>' . $output . '</h3>
    			</div>
    			<div class="excerpt">
    			
    			
    			
    			
			
    			
    			</div>
    			<div class="dateheading">
    			' . $date_month . ' ' . $date_day_formatted . ', ' . $date_year . '
    			</div>
    			<div class="hiddendate">-' . $date_year . '' . $date_month_hidden . '' . $date_day . '</div>
					
					<span class="number">10</span>
    		</div>
    		
    		<a href="http://twitter.com/uwmadisoncals/" title="Follow UWMadisonCALS on Twitter" class="highlight">Follow UWMadisonCALS on Twitter</a>
    		
    		
    		</div>
    </div>';
}
예제 #17
0
        
        a:target {
                background-color: yellow;
        }
        </style>
</head>
<body>
        <h1>Facebook Page Publish - Fault Diagnosis</h1>
        <p>In order for the plugin to work, every test should return a positive response. Errors are mostly due to server limitations or misconfiguration. If you observe an error, try the compatibility options on the plugin settings page and/or post your test results in the <a href="http://wordpress.org/tags/facebook-page-publish">forum</a>.</p>
        <h2>Check if your server can connect to Facebook</h2>
        <p>Sends a https request to Facebook to detect possible connection errors. Expects a code 400 / Bad request response.</p>
        <?php 
require_once dirname(__FILE__) . '/../../../wp-load.php';
$request = new WP_Http();
$api_url = 'https://graph.facebook.com/oauth/access_token?client_id=fake-id&client_secret=fake-id&redirect_uri=http://fake-uri.com';
$response = $request->get($api_url);
if (array_key_exists('errors', $response)) {
    echo '<h3 style="color:red">There seems to be a problem</h3>';
    echo '<p>Try enabling the compatibility options of the plugin</p>';
} else {
    echo '<h3 style="color:green">Everything looks fine</h3>';
}
echo '<pre style="font-size:8pt">';
print_r($response);
echo '</pre>';
?>

        
        <h2>Check if the SSL module is loaded</h2>
        <p>Facebook requires secure https transmissions. Therefore your webserver has to support SSL. Not all hoster, especially freehoster, offer this service.</p>
        <?php 
예제 #18
0
 public function ensure_standard_settings()
 {
     global $wpdb, $memcached_servers;
     // Compute some values
     $blog_url = home_url();
     $sitename = "unknown: " . __FILE__;
     if (preg_match("#^/nas/wp/www/[^/]+/([^/]+)/#", __FILE__, $match)) {
         $sitename = $match[1];
     }
     echo "Ensuring: {$sitename} - {$blog_url}\n";
     add_filter('http_request_timeout', function () {
         return 30;
     }, 1);
     // some sites take FOREVER
     $http = new WP_Http();
     $url = 'https://api.wpengine.com/1.2/?method=site&account_name=' . PWP_NAME . '&wpe_apikey=' . WPE_APIKEY;
     $msg = $http->get($url);
     if (!$msg || is_a($msg, 'WP_Error') || !isset($msg['body'])) {
         echo "### FAIL: Couldn't load site configuration! (from " . __FILE__ . ")\n";
         echo $url . "\n";
         echo "Server Response:\n";
         var_export($msg);
         return;
     }
     $config = json_decode($msg['body'], TRUE);
     if (!$config || !is_array($config)) {
         echo "### FAIL: Couldn't decode site configuration! (from " . __FILE__ . ")\n";
         echo $url . "\n";
         echo "Server Response:\n";
         var_export($msg);
         return;
     }
     $is_pod = WPE_CLUSTER_TYPE == "pod";
     $cluster_id = WPE_CLUSTER_ID;
     $is_bpod = defined('WPE_BPOD') && WPE_BPOD;
     $lbmaster = $is_pod ? "localhost" : "lbmaster-{$cluster_id}";
     $dbmaster = $is_pod ? "localhost" : "dbmaster-{$cluster_id}";
     $is_high_traffic = el($config, 'high_traffic', false) || $is_pod;
     $all_varnish = true;
     // not having this has bit us before, and having it for small sites is fine.
     // If site has hyper db in place, turn of w3tc dbcache
     $hyperdb = el($config, 'hyperdb');
     if ($is_pod) {
         $hyperdb = false;
     }
     if ($hyperdb) {
         $dbcache_enabled = false;
     } else {
         $dbcache_enabled = true;
     }
     // List of user-agent patterns where we shouldn't use the page cache.
     $no_cache_user_agents = array("X-WPE-Rewrite");
     // List of cookie-patterns where we shouldn't use the page cache.
     $no_cache_cookies = array("wptouch_switch_cookie");
     $is_nfs = !$is_pod;
     $allow_file_locking = !$is_nfs;
     // Should we allow W3TC Page Cache?
     // If we're sending all traffic to Varnish, then no it's just overlap.
     $pgcache_enabled = !$all_varnish;
     // Should we allow W3TC Object Cache?
     // It takes a *lot* more memory in memcached, but can significantly speed up a site.
     if (isset($config['use_object_cache'])) {
         $allowed_objectcache = $config['use_object_cache'];
     } else {
         $allowed_objectcache = ($is_high_traffic || $is_pod) && !$is_bpod;
     }
     // used to be slow on a pod, but now with unix sockets for memcached it's fast!
     // Should we cache database queries for logged-in users?
     // Normally no, but for high-admin sites it does help and might be worth the risk.
     $cache_database_for_logged_in = $is_high_traffic || $allowed_objectcache || el($config, 'cache_database_for_logged_in', false);
     if ($is_pod) {
         $cache_database_for_logged_in = false;
     }
     // How long to allow files to be cached before they're considered "stale" and should
     // be reaped by a cron task.  This is extra slow on NFS, so keep it short so we do
     // not have to sift through too many files.  Maybe this should be in memcached!
     $file_cache_seconds = $is_nfs ? 600 : 60 * 60;
     $memcached_file_ttl = $is_pod ? 24 * 60 * 60 : 60 * 60 * 2;
     // if in memcached we can leave around far longer than on disk
     // Which server should be used for database-related or file-related memcached?
     $file_memcached_server = $is_pod ? "unix:///tmp/memcached.sock" : ($cluster_id == 1 ? "localhost:11211" : "{$dbmaster}:11211");
     $db_memcached_server = $file_memcached_server;
     $obj_memcached_server = $file_memcached_server;
     // Should we use the memcached-based file cache or the disk-based?  Disk-based means
     // flushing only affects one blog, but memory-based is much faster to process.
     $pgcache_in_memcached = $is_pod ? false : true;
     $pgcache_cache_queries = $pgcache_in_memcached;
     // NetDNA CDN zone for this site
     // $cdn_domain = $this->get_cdn_domain( el( $config, 'netdna', array( ) ), $blog_url );
     // Ensure WPEngine standard account.
     echo "Ensuring the WPEngine account...\n";
     $wpe_user_id = username_exists('wpengine');
     // get existing ID
     $wpe_user = array('user_login' => 'wpengine', 'user_pass' => md5(mt_rand() . mt_rand() . mt_rand() . mt_rand() . time() . gethostname() . WPE_APIKEY), 'user_email' => '*****@*****.**', 'user_url' => 'http://wpengine.com', 'role' => 'administrator', 'user_nicename' => 'wpengine', 'description' => 'This is the "wpengine" admin user that our staff uses to gain access to your admin area to provide support and troubleshooting. It can only be accessed by a button in our secure log that auto generates a password and dumps that password after the staff member has logged in. We have taken extreme measures to ensure that our own user is not going to be misused to harm any of our clients sites.');
     if (!$wpe_user_id) {
         $wpe_user_id = wp_insert_user($wpe_user);
         // creates; returns new user ID
     } else {
         $wpe_user['ID'] = $wpe_user_id;
         wp_update_user($wpe_user);
     }
     if ($wpe_user_id) {
         // could be we tried to create it but failed; then don't run this code
         // Set the request variable because some plugins keyed on it during profile_update hook.
         $_REQUEST['user_id'] = $wpe_user_id;
         // Impersonate as the wpengine user.
         if (function_exists('wp_set_current_user')) {
             wp_set_current_user($wpe_user_id);
         }
     }
     // Make Multisite wpengine admin a Super Admin
     if ($wpe_user_id && function_exists('is_multisite') && is_multisite()) {
         require_once ABSPATH . '/wp-admin/includes/ms.php';
         grant_super_admin($wpe_user_id);
     }
     // Empty caches
     echo "Emptying all caches...\n";
     $this->empty_all_caches();
     // Deactivate plugins we don't support.
     echo "Deactivating plugins: hello, migration, cachers...\n";
     $plugins = array("hello.php", "wpengine-migrate/plugin.php", "wp-file-cache/file-cache.php", "wp-super-cache/wp-cache.php", "hyper-cache/plugin.php", "db-cache-reloaded/db-module.php", "db-cache-reloaded/db-cache-reloaded.php", "no-revisions/norevisions.php", "wp-phpmyadmin/wp-phpmyadmin.php", "wpengine-common/plugin.php");
     $plugins[] = "w3-total-cache/w3-total-cache.php";
     if (false == el($config, 'profiler')) {
         $plugins[] = "wpe-profiler/wpe-profiler.php";
     }
     // Check if the plugin is active.  If so, deactivate it and turn on the other plugin
     $required_plugins = array();
     // If plugin is activated, turn it off and turn on the other one instead.
     $disable_sitemap = false;
     // This plugin is not in the repo anymore, but that doesn't mean that people won't bring it over from another host.
     if (is_plugin_active('google-xml-sitemaps-with-multisite-support/sitemap.php')) {
         echo "Turning off 'google-xml-sitemaps-with-multisite-support/sitemap.php' ";
         $plugins[] = 'google-xml-sitemaps-with-multisite-support/sitemap.php';
         $disable_sitemap = true;
     }
     if ($disable_sitemap) {
         echo " ... Turning on 'bwp-google-xml-sitemaps/bwp-simple-gxs.php'\n";
         // BWP sitemap installer uses wp_rewrite, but when this function runs, it's not instantiated yet in wp-settings.php
         global $wp_rewrite;
         if (NULL == $wp_rewrite) {
             $wp_rewrite = new WP_Rewrite();
         }
         // Remove sitemap files
         $remove_file = array('sitemap.xml', 'sitemap.xml.gz');
         foreach ($remove_file as $file) {
             if (file_exists(ABSPATH . "/{$file}")) {
                 echo "Remove {$file}\n";
                 unlink(ABSPATH . "/{$file}");
             }
         }
     }
     deactivate_plugins($plugins);
     //look for plugins that WP Engine Api needs to know about
     include_once __DIR__ . '/class.plugins.php';
     PluginsConfig::sniff();
     // Activate all the plugins we require.  If already activated this won't do anything.
     if (el($config, 'profiler')) {
         $required_plugins[] = "wpe-profiler/wpe-profiler.php";
     }
     foreach ($required_plugins as $path) {
         echo "Activating {$path}...\n";
         $result = activate_plugin($path);
         if ($result) {
             die("Error activating {$path}: {$result}\n");
         }
     }
     // Display info about Runkit
     $have_runkit = extension_loaded('runkit');
     $have_preamble = el($config, 'use_preamble');
     echo "Have Runkit: " . ($have_runkit ? "yes" : "no") . "; Have preamble: " . ($have_preamble ? "yes" : "no") . "\n";
     // If first-run, do some extra config
     if (wpe_param('first-run')) {
         $this->ensure_account_user();
     }
     // Clean-up
     echo "Emptying all caches...\n";
     $this->empty_all_caches();
     echo "Done!\n";
 }
 /**
  * @param array $opts {user_repo: 'ThemeFuse/Unyson'}
  * @param string $zip_path
  *
  * @return WP_Error
  */
 public function download(array $opts, $zip_path)
 {
     $wp_error_id = 'fw_ext_github_download_source';
     $theme_ext_requirements = fw()->theme->manifest->get('requirements/extensions');
     /** @var WP_Filesystem_Base $wp_filesystem */
     global $wp_filesystem;
     $extension_name = $opts['extension_name'];
     $extension_title = $opts['extension_title'];
     if (empty($opts['user_repo'])) {
         return new WP_Error($wp_error_id, sprintf(__('"%s" extension github source "user_repo" parameter is required', 'fw'), $extension_title));
     }
     $transient_name = 'fw_ext_mngr_gh_dl';
     $transient_ttl = HOUR_IN_SECONDS;
     $cache = get_site_transient($transient_name);
     if ($cache === false) {
         $cache = array();
     }
     if (isset($cache[$opts['user_repo']])) {
         $download_link = $cache[$opts['user_repo']]['zipball_url'];
     } else {
         $http = new WP_Http();
         if (isset($theme_ext_requirements[$extension_name]) && isset($theme_ext_requirements[$extension_name]['max_version'])) {
             $tag = 'tags/v' . $theme_ext_requirements[$extension_name]['max_version'];
         } else {
             $tag = 'latest';
         }
         $response = $http->get(apply_filters('fw_github_api_url', 'https://api.github.com') . '/repos/' . $opts['user_repo'] . '/releases/' . $tag);
         unset($http);
         $response_code = intval(wp_remote_retrieve_response_code($response));
         if ($response_code !== 200) {
             if ($response_code === 403) {
                 if ($json_response = json_decode($response['body'], true)) {
                     return new WP_Error($wp_error_id, __('Github error:', 'fw') . ' ' . $json_response['message']);
                 } else {
                     return new WP_Error($wp_error_id, sprintf(__('Failed to access Github repository "%s" releases. (Response code: %d)', 'fw'), $opts['user_repo'], $response_code));
                 }
             } elseif ($response_code) {
                 return new WP_Error($wp_error_id, sprintf(__('Failed to access Github repository "%s" releases. (Response code: %d)', 'fw'), $opts['user_repo'], $response_code));
             } elseif (is_wp_error($response)) {
                 return new WP_Error($wp_error_id, sprintf(__('Failed to access Github repository "%s" releases. (%s)', 'fw'), $opts['user_repo'], $response->get_error_message()));
             } else {
                 return new WP_Error($wp_error_id, sprintf(__('Failed to access Github repository "%s" releases.', 'fw'), $opts['user_repo']));
             }
         }
         $release = json_decode($response['body'], true);
         unset($response);
         if (empty($release)) {
             return new WP_Error($wp_error_id, sprintf(__('"%s" extension github repository "%s" has no releases.', 'fw'), $extension_title, $opts['user_repo']));
         }
         $cache[$opts['user_repo']] = array('zipball_url' => 'https://github.com/' . $opts['user_repo'] . '/archive/' . $release['tag_name'] . '.zip', 'tag_name' => $release['tag_name']);
         set_site_transient($transient_name, $cache, $transient_ttl);
         $download_link = $cache[$opts['user_repo']]['zipball_url'];
         unset($release);
     }
     $http = new WP_Http();
     $response = $http->request($download_link, array('timeout' => $this->download_timeout));
     unset($http);
     if (($response_code = intval(wp_remote_retrieve_response_code($response))) !== 200) {
         if ($response_code) {
             return new WP_Error($wp_error_id, sprintf(__('Cannot download the "%s" extension zip. (Response code: %d)', 'fw'), $extension_title, $response_code));
         } elseif (is_wp_error($response)) {
             return new WP_Error($wp_error_id, sprintf(__('Cannot download the "%s" extension zip. %s', 'fw'), $extension_title, $response->get_error_message()));
         } else {
             return new WP_Error($wp_error_id, sprintf(__('Cannot download the "%s" extension zip.', 'fw'), $extension_title));
         }
     }
     // save zip to file
     if (!$wp_filesystem->put_contents($zip_path, $response['body'])) {
         return new WP_Error($wp_error_id, sprintf(__('Cannot save the "%s" extension zip.', 'fw'), $extension_title));
     }
     unset($response);
 }