本文整理汇总了PHP中wp_http_supports函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_http_supports函数的具体用法?PHP wp_http_supports怎么用?PHP wp_http_supports使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_http_supports函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: lsb_health_check
function lsb_health_check()
{
$errors = array();
global $wp_version;
if (version_compare($wp_version, '3.7', '<')) {
$errors[] = sprintf('<p>Live Stream Badger requires WordPress 3.7+. Your version: <span style="color:red">%s</span>.', $wp_version);
}
$php_version = phpversion();
if (version_compare($php_version, '5.3', '<')) {
$errors[] = sprintf('<p>Live Stream Badger requires PHP 5.3+. Your version: <span style="color:red">%s</span>.', $php_version);
}
$ssl_loaded = extension_loaded('openssl') && function_exists('openssl_x509_parse');
if (!$ssl_loaded) {
$errors[] = sprintf('<p>Live Stream Badger requires PHP extension openssl.</p>');
}
if (!wp_http_supports()) {
$errors[] = sprintf('<p>Live Stream Badger requires HTTP transport (curl or streams).</p>');
}
if (!empty($errors)) {
echo '<pre>';
foreach ($errors as $e) {
echo $e;
}
echo '</pre>';
exit;
}
}
示例2: pb_wpapi
/**
* WP API Function
*
* Access information about plugin from the API
*
* @access public
* @param mixed $action
* @param mixed $args (default: null)
* @return string
*/
function pb_wpapi($action, $args = null)
{
if (is_array($args)) {
$args = (object) $args;
}
if (!isset($args->per_page)) {
$args->per_page = 24;
}
// Allows a plugin to override the WordPress.org API entirely.
// Use the filter 'plugins_api_result' to merely add results.
// Please ensure that a object is returned from the following filters.
$args = apply_filters('plugins_api_args', $args, $action);
$res = apply_filters('plugins_api', false, $action, $args);
if (false === $res) {
$url = 'http://api.wordpress.org/plugins/info/1.0/';
if (wp_http_supports(array('ssl'))) {
$url = set_url_scheme($url, 'https');
}
$request = wp_remote_post($url, array('timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))));
if (is_wp_error($request)) {
$res = new WP_Error('plugins_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.'), $request->get_error_message());
} else {
$res = maybe_unserialize(wp_remote_retrieve_body($request));
if (!is_object($res) && !is_array($res)) {
$res = new WP_Error('plugins_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.'), wp_remote_retrieve_body($request));
}
}
} elseif (!is_wp_error($res)) {
$res->external = true;
}
return apply_filters('plugins_api_result', $res, $action, $args);
}
示例3: plugins_api
/**
* Retrieve plugin installer pages from WordPress Plugins API.
*
* It is possible for a plugin to override the Plugin API result with three
* filters. Assume this is for plugins, which can extend on the Plugin Info to
* offer more choices. This is very powerful and must be used with care, when
* overriding the filters.
*
* The first filter, 'plugins_api_args', is for the args and gives the action as
* the second parameter. The hook for 'plugins_api_args' must ensure that an
* object is returned.
*
* The second filter, 'plugins_api', is the result that would be returned.
*
* @since 2.7.0
*
* @param string $action
* @param array|object $args Optional. Arguments to serialize for the Plugin Info API.
* @return object plugins_api response object on success, WP_Error on failure.
*/
function plugins_api($action, $args = null)
{
if (is_array($args)) {
$args = (object) $args;
}
if (!isset($args->per_page)) {
$args->per_page = 24;
}
/**
* Override the Plugin Install API arguments.
*
* Please ensure that an object is returned.
*
* @since 2.7.0
*
* @param object $args Plugin API arguments.
* @param string $action The type of information being requested from the Plugin Install API.
*/
$args = apply_filters('plugins_api_args', $args, $action);
/**
* Allows a plugin to override the WordPress.org Plugin Install API entirely.
*
* Please ensure that an object is returned.
*
* @since 2.7.0
*
* @param bool|object The result object. Default is false.
* @param string $action The type of information being requested from the Plugin Install API.
* @param object $args Plugin API arguments.
*/
$res = apply_filters('plugins_api', false, $action, $args);
if (false === $res) {
$url = 'http://api.wordpress.org/plugins/info/1.0/';
if (wp_http_supports(array('ssl'))) {
$url = set_url_scheme($url, 'https');
}
$request = wp_remote_post($url, array('timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))));
if (is_wp_error($request)) {
$res = new WP_Error('plugins_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.'), $request->get_error_message());
} else {
$res = maybe_unserialize(wp_remote_retrieve_body($request));
if (!is_object($res) && !is_array($res)) {
$res = new WP_Error('plugins_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.'), wp_remote_retrieve_body($request));
}
}
} elseif (!is_wp_error($res)) {
$res->external = true;
}
/**
* Filter the Plugin Install API response results.
*
* @since 2.7.0
*
* @param object|WP_Error $res Response object or WP_Error.
* @param string $action The type of information being requested from the Plugin Install API.
* @param object $args Plugin API arguments.
*/
return apply_filters('plugins_api_result', $res, $action, $args);
}
示例4: translations_api
/**
* Retrieve translations from WordPress Translation API.
*
* @since 4.0.0
*
* @param string $type Type of translations. Accepts 'plugins', 'themes', 'core'.
* @param array|object $args Translation API arguments. Optional.
* @return object|WP_Error On success an object of translations, WP_Error on failure.
*/
function translations_api($type, $args = null)
{
include ABSPATH . WPINC . '/version.php';
// include an unmodified $wp_version
if (!in_array($type, array('plugins', 'themes', 'core'))) {
return new WP_Error('invalid_type', __('Invalid translation type.'));
}
/**
* Allows a plugin to override the WordPress.org Translation Install API entirely.
*
* @since 4.0.0
*
* @param bool|array $result The result object. Default false.
* @param string $type The type of translations being requested.
* @param object $args Translation API arguments.
*/
$res = apply_filters('translations_api', false, $type, $args);
if (false === $res) {
$url = $http_url = 'http://api.wordpress.org/translations/' . $type . '/1.0/';
if ($ssl = wp_http_supports(array('ssl'))) {
$url = set_url_scheme($url, 'https');
}
$options = array('timeout' => 3, 'body' => array('wp_version' => $wp_version, 'locale' => get_locale(), 'version' => $args['version']));
if ('core' !== $type) {
$options['body']['slug'] = $args['slug'];
// Plugin or theme slug
}
$request = wp_remote_post($url, $options);
if ($ssl && is_wp_error($request)) {
trigger_error(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.') . ' ' . __('(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)'), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE);
$request = wp_remote_post($http_url, $options);
}
if (is_wp_error($request)) {
$res = new WP_Error('translations_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.'), $request->get_error_message());
} else {
$res = json_decode(wp_remote_retrieve_body($request), true);
if (!is_object($res) && !is_array($res)) {
$res = new WP_Error('translations_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.'), wp_remote_retrieve_body($request));
}
}
}
/**
<<<<<<< HEAD
* Filters the Translation Install API response results.
=======
* Filter the Translation Install API response results.
>>>>>>> 820e5fa9bcbe2712b79cdb955f67ab1317fff8f6
*
* @since 4.0.0
*
* @param object|WP_Error $res Response object or WP_Error.
* @param string $type The type of translations being requested.
* @param object $args Translation API arguments.
*/
return apply_filters('translations_api_result', $res, $type, $args);
}
示例5: fb_ssl_warning
/**
* Display an admin-facing warning if openSSL is not installed properly
*
* @since 1.0.2
*/
function fb_ssl_warning()
{
$options = get_option('fb_options');
$page = isset($_GET['page']) ? $_GET['page'] : null;
if (!wp_http_supports(array('ssl' => true)) && current_user_can('manage_options')) {
$msg = __('SSL must be enabled on your server for Facebook Social Publisher to work.', 'facebook');
if ($options['social_publisher']['enabled']) {
unset($options['social_publisher']['enabled']);
update_option('fb_options', $options);
$msg .= ' ' . __('As a result, Social Publisher has been disabled.', 'facebook');
}
fb_admin_dialog(__($msg, 'facebook'), true);
}
}
示例6: plugins_api
public static function plugins_api($default, $action, $args)
{
$url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
if ($ssl = wp_http_supports(array('ssl'))) {
$url = set_url_scheme($url, 'https');
}
$args = array('timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args)));
$request = wp_remote_post($url, $args);
if (is_wp_error($request)) {
$url = '';
$name = '';
if (isset($_REQUEST['url'])) {
$url = $_REQUEST['url'];
$name = $_REQUEST['name'];
}
$res = new WP_Error('plugins_api_failed', __('<h3>No Plugin Information Found.</h3> This may be a premium plugin and no other details are available from WordPress.', 'mainwp') . ' ' . ($url == '' ? __('Please visit the Plugin website for more information.', 'mainwp') : __('Please visit the Plugin website for more information: ', 'mainwp') . '<a href="' . rawurldecode($url) . '" target="_blank">' . rawurldecode($name) . '</a>'), $request->get_error_message());
return $res;
}
return $default;
}
示例7: wpr_theme_updates_list
/**
* Updates theme list
*
* @description
*
* @return bool
*/
function wpr_theme_updates_list()
{
include ABSPATH . WPINC . '/version.php';
// include an unmodified $wp_version
//Bounce out if improperly called
if (defined('WP_INSTALLING') || !is_admin()) {
return false;
}
$expiration = 12 * HOUR_IN_SECONDS;
$installed_themes = wp_get_themes();
$last_update = get_site_transient('update_themes');
if (!is_object($last_update)) {
set_site_transient('rollback_themes', time(), $expiration);
}
$themes = $checked = $request = array();
// Put slug of current theme into request.
$request['active'] = get_option('stylesheet');
foreach ($installed_themes as $theme) {
$checked[$theme->get_stylesheet()] = $theme->get('Version');
$themes[$theme->get_stylesheet()] = array('Name' => $theme->get('Name'), 'Title' => $theme->get('Name'), 'Version' => '0.0.0.0.0.0', 'Author' => $theme->get('Author'), 'Author URI' => $theme->get('AuthorURI'), 'Template' => $theme->get_template(), 'Stylesheet' => $theme->get_stylesheet());
}
$request['themes'] = $themes;
$timeout = 3 + (int) (count($themes) / 10);
$options = array('timeout' => $timeout, 'body' => array('themes' => json_encode($request)), 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'));
$url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/';
if ($ssl = wp_http_supports(array('ssl'))) {
$url = set_url_scheme($url, 'https');
}
$raw_response = wp_remote_post($url, $options);
if ($ssl && is_wp_error($raw_response)) {
trigger_error(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.') . ' ' . __('(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)'), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE);
$raw_response = wp_remote_post($http_url, $options);
}
set_site_transient('rollback_themes', time(), $expiration);
if (is_wp_error($raw_response) || 200 != wp_remote_retrieve_response_code($raw_response)) {
return false;
}
$new_update = new stdClass();
$new_update->last_checked = time();
$new_update->checked = $checked;
$response = json_decode(wp_remote_retrieve_body($raw_response), true);
if (is_array($response)) {
$new_update->response = $response['themes'];
}
set_site_transient('rollback_themes', $new_update);
}
示例8: _fetch_plugin_info_from_repository
/**
* Try to fetch plugin's info from .org repository.
*
* @author Vova Feldman (@svovaf)
* @since 1.0.5
*
* @param string $action
* @param object $args
*
* @return bool|mixed
*/
static function _fetch_plugin_info_from_repository($action, $args)
{
$url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
if ($ssl = wp_http_supports(array('ssl'))) {
$url = set_url_scheme($url, 'https');
}
$args = array('timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args)));
$request = wp_remote_post($url, $args);
if (is_wp_error($request)) {
return false;
}
$res = maybe_unserialize(wp_remote_retrieve_body($request));
if (!is_object($res) && !is_array($res)) {
return false;
}
return $res;
}
示例9: http_post
/**
* Make a POST request to the Akismet API.
*
* @param string $request The body of the request.
* @param string $path The path for the request.
* @param string $ip The specific IP address to hit.
* @return array A two-member array consisting of the headers and the response body, both empty in the case of a failure.
*/
public static function http_post($request, $path, $ip = null)
{
$akismet_ua = sprintf('WordPress/%s | Akismet/%s', $GLOBALS['wp_version'], constant('AKISMET_VERSION'));
$akismet_ua = apply_filters('akismet_ua', $akismet_ua);
$content_length = strlen($request);
$api_key = self::get_api_key();
$host = self::API_HOST;
if (!empty($api_key)) {
$host = $api_key . '.' . $host;
}
$http_host = $host;
// use a specific IP if provided
// needed by Akismet_Admin::check_server_connectivity()
if ($ip && long2ip(ip2long($ip))) {
$http_host = $ip;
}
$http_args = array('body' => $request, 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 'Host' => $host, 'User-Agent' => $akismet_ua), 'httpversion' => '1.0', 'timeout' => 15);
$akismet_url = $http_akismet_url = "http://{$http_host}/1.1/{$path}";
/**
* Try SSL first; if that fails, try without it and don't try it again for a while.
*/
$ssl = $ssl_failed = false;
// Check if SSL requests were disabled fewer than X hours ago.
$ssl_disabled = get_option('akismet_ssl_disabled');
if ($ssl_disabled && $ssl_disabled < time() - 60 * 60 * 24) {
// 24 hours
$ssl_disabled = false;
delete_option('akismet_ssl_disabled');
} else {
if ($ssl_disabled) {
do_action('akismet_ssl_disabled');
}
}
if (!$ssl_disabled && function_exists('wp_http_supports') && ($ssl = wp_http_supports(array('ssl')))) {
$akismet_url = set_url_scheme($akismet_url, 'https');
do_action('akismet_https_request_pre');
}
$response = wp_remote_post($akismet_url, $http_args);
Akismet::log(compact('akismet_url', 'http_args', 'response'));
if ($ssl && is_wp_error($response)) {
do_action('akismet_https_request_failure', $response);
// Intermittent connection problems may cause the first HTTPS
// request to fail and subsequent HTTP requests to succeed randomly.
// Retry the HTTPS request once before disabling SSL for a time.
$response = wp_remote_post($akismet_url, $http_args);
Akismet::log(compact('akismet_url', 'http_args', 'response'));
if (is_wp_error($response)) {
$ssl_failed = true;
do_action('akismet_https_request_failure', $response);
do_action('akismet_http_request_pre');
// Try the request again without SSL.
$response = wp_remote_post($http_akismet_url, $http_args);
Akismet::log(compact('http_akismet_url', 'http_args', 'response'));
}
}
if (is_wp_error($response)) {
do_action('akismet_request_failure', $response);
return array('', '');
}
if ($ssl_failed) {
// The request failed when using SSL but succeeded without it. Disable SSL for future requests.
update_option('akismet_ssl_disabled', time());
do_action('akismet_https_disabled');
}
$simplified_response = array($response['headers'], $response['body']);
self::update_alert($simplified_response);
return $simplified_response;
}
示例10: core_upgrade_preamble
/**
* Display upgrade WordPress for downloading latest or upgrading automatically form.
*
* @since 2.7.0
*
* @global string $wp_version
* @global string $required_php_version
* @global string $required_mysql_version
*/
function core_upgrade_preamble()
{
global $wp_version, $required_php_version, $required_mysql_version;
$updates = get_core_updates();
if (!isset($updates[0]->response) || 'latest' == $updates[0]->response) {
echo '<h3>';
_e('You have Project Nami ' . get_projectnami_version() . ' which contains the latest version of WordPress.');
if (wp_http_supports(array('ssl'))) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new WP_Automatic_Updater();
$future_minor_update = (object) array('current' => $wp_version . '.1.next.minor', 'version' => $wp_version . '.1.next.minor', 'php_version' => $required_php_version, 'mysql_version' => $required_mysql_version);
$should_auto_update = $upgrader->should_update('core', $future_minor_update, ABSPATH);
if ($should_auto_update) {
echo ' ' . __('Future security updates will be applied automatically.');
}
}
echo '</h2>';
} else {
echo '<div class="notice notice-warning"><p>';
_e('<strong>Important:</strong> before updating, please back up your database and files.');
echo '</p></div>';
echo '<h3 class="response">';
_e('An updated version of WordPress is available. Please check <a href="http://projectnami.org/download/">the Project Nami Download page</a> for the latest build.');
echo '</h3>';
}
if (isset($updates[0]) && $updates[0]->response == 'development') {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new WP_Automatic_Updater();
if (wp_http_supports('ssl') && $upgrader->should_update('core', $updates[0], ABSPATH)) {
echo '<div class="updated inline"><p>';
echo '<strong>' . __('BETA TESTERS:') . '</strong> ' . __('This site is set up to install updates of future beta versions automatically.');
echo '</p></div>';
}
}
echo '<ul class="core-updates">';
foreach ((array) $updates as $update) {
echo '<li>';
list_core_update($update);
echo '</li>';
}
echo '</ul>';
// Don't show the maintenance mode notice when we are only showing a single re-install option.
if ($updates && (count($updates) > 1 || $updates[0]->response != 'latest')) {
//echo '<p>' . __( 'While your site is being updated, it will be in maintenance mode. As soon as your updates are complete, your site will return to normal.' ) . '</p>';
} elseif (!$updates) {
list($normalized_version) = explode('-', $wp_version);
echo '<p>' . sprintf(__('<a href="%s">Learn more about WordPress %s</a>.'), esc_url(self_admin_url('about.php')), $normalized_version) . '</p>';
}
dismissed_updates();
}
示例11: esc_html_e
esc_html_e('SSL Status', 'akismet');
?>
</th>
<td></td>
<td align="left">
<p>
<?php
if (!function_exists('wp_http_supports')) {
?>
<b><?php
esc_html_e('Disabled.', 'akismet');
?>
</b> <?php
printf(esc_html('Your WordPress installation does not include the function %s; upgrade to the latest version of WordPress.', 'akismet'), '<code>wp_http_supports</code>');
} else {
if (!wp_http_supports(array('ssl'))) {
?>
<b><?php
esc_html_e('Disabled.', 'akismet');
?>
</b> <?php
esc_html_e('Your Web server cannot make SSL requests; contact your Web host and ask them to add support for SSL requests.', 'akismet');
} else {
$ssl_disabled = get_option('akismet_ssl_disabled');
if ($ssl_disabled) {
?>
<b><?php
esc_html_e('Temporarily disabled.', 'akismet');
?>
</b> <?php
esc_html_e('Akismet encountered a problem with a previous SSL request and disabled it temporarily. It will begin using SSL for requests again shortly.', 'akismet');
示例12: plugins_api
//.........这里部分代码省略.........
* @type bool $description Whether to return the plugin full description. Default false.
* @type bool $sections Whether to return the plugin readme sections: description, installation,
* FAQ, screenshots, other notes, and changelog. Default false.
* @type bool $tested Whether to return the 'Compatible up to' value. Default true.
* @type bool $requires Whether to return the required WordPress version. Default true.
* @type bool $rating Whether to return the rating in percent and total number of ratings.
* Default true.
* @type bool $ratings Whether to return the number of rating for each star (1-5). Default true.
* @type bool $downloaded Whether to return the download count. Default true.
* @type bool $downloadlink Whether to return the download link for the package. Default true.
* @type bool $last_updated Whether to return the date of the last update. Default true.
* @type bool $added Whether to return the date when the plugin was added to the wordpress.org
* repository. Default true.
* @type bool $tags Whether to return the assigned tags. Default true.
* @type bool $compatibility Whether to return the WordPress compatibility list. Default true.
* @type bool $homepage Whether to return the plugin homepage link. Default true.
* @type bool $versions Whether to return the list of all available versions. Default false.
* @type bool $donate_link Whether to return the donation link. Default true.
* @type bool $reviews Whether to return the plugin reviews. Default false.
* @type bool $banners Whether to return the banner images links. Default false.
* @type bool $icons Whether to return the icon links. Default false.
* @type bool $active_installs Whether to return the number of active installs. Default false.
* @type bool $group Whether to return the assigned group. Default false.
* @type bool $contributors Whether to return the list of contributors. Default false.
* }
* }
* @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the
* {@link https://developer.wordpress.org/reference/functions/plugins_api/ function reference article}
* for more information on the make-up of possible return values depending on the value of `$action`.
*/
function plugins_api($action, $args = array())
{
if (is_array($args)) {
$args = (object) $args;
}
if (!isset($args->per_page)) {
$args->per_page = 24;
}
if (!isset($args->locale)) {
$args->locale = get_locale();
}
/**
* Filters the WordPress.org Plugin Install API arguments.
*
* Important: An object MUST be returned to this filter.
*
* @since 2.7.0
*
* @param object $args Plugin API arguments.
* @param string $action The type of information being requested from the Plugin Install API.
*/
$args = apply_filters('plugins_api_args', $args, $action);
/**
* Filters the response for the current WordPress.org Plugin Install API request.
*
* Passing a non-false value will effectively short-circuit the WordPress.org API request.
*
* If `$action` is 'query_plugins' or 'plugin_information', an object MUST be passed.
* If `$action` is 'hot_tags' or 'hot_categories', an array should be passed.
*
* @since 2.7.0
*
* @param false|object|array $result The result object or array. Default false.
* @param string $action The type of information being requested from the Plugin Install API.
* @param object $args Plugin API arguments.
*/
$res = apply_filters('plugins_api', false, $action, $args);
if (false === $res) {
$url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
if ($ssl = wp_http_supports(array('ssl'))) {
$url = set_url_scheme($url, 'https');
}
$http_args = array('timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args)));
$request = wp_remote_post($url, $http_args);
if ($ssl && is_wp_error($request)) {
trigger_error(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.') . ' ' . __('(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)'), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE);
$request = wp_remote_post($http_url, $http_args);
}
if (is_wp_error($request)) {
$res = new WP_Error('plugins_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.'), $request->get_error_message());
} else {
$res = maybe_unserialize(wp_remote_retrieve_body($request));
if (!is_object($res) && !is_array($res)) {
$res = new WP_Error('plugins_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.'), wp_remote_retrieve_body($request));
}
}
} elseif (!is_wp_error($res)) {
$res->external = true;
}
/**
* Filters the Plugin Install API response results.
*
* @since 2.7.0
*
* @param object|WP_Error $res Response object or WP_Error.
* @param string $action The type of information being requested from the Plugin Install API.
* @param object $args Plugin API arguments.
*/
return apply_filters('plugins_api_result', $res, $action, $args);
}
示例13: try_get_response_body
private function try_get_response_body($plugin, $second_pass)
{
//Some of this code is lifted from class-wp-upgrader
//Get the WordPress current version to be polite in the API call
include ABSPATH . WPINC . '/version.php';
if (!defined('MINUTE_IN_SECONDS')) {
define('MINUTE_IN_SECONDS', 60);
}
if (!defined('HOUR_IN_SECONDS')) {
define('HOUR_IN_SECONDS', 60 * MINUTE_IN_SECONDS);
}
global $wp_version;
//General options to be passed to wp_remote_get
$options = array('timeout' => HOUR_IN_SECONDS, 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'));
//The URL for the endpoint
$url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
//If we support SSL
//Requires WP 3.2.0
if ($ssl = wp_http_supports(array('ssl'))) {
//Requires WP 3.4.0
$url = set_url_scheme($url, 'https');
}
$plugin_dir = $plugin;
if (strpos($plugin, "/") !== false) {
$plugin_dir = dirname($plugin);
}
//Try to get the response (usually the SSL version)
//Requires WP 2.7.0
$raw_response = wp_remote_get($url . $plugin_dir, $options);
//If we don't have an error and we received a valid response code
//Requires WP 2.7.0
if (!is_wp_error($raw_response) && 200 == wp_remote_retrieve_response_code($raw_response)) {
//Get the actual body
//Requires WP 2.7.0
$body = wp_remote_retrieve_body($raw_response);
//Make sure that it isn't empty and also not an empty serialized object
if ('' != $body && 'N;' != $body) {
//If valid, return that
return $body;
}
}
//The above valid
//If we previously tried an SSL version try without SSL
//Code below same as above block
if ($ssl) {
$raw_response = wp_remote_get($http_url . $plugin, $options);
if (!is_wp_error($raw_response) && 200 == wp_remote_retrieve_response_code($raw_response)) {
$body = wp_remote_retrieve_body($raw_response);
if ('' != $body && 'N;' != $body) {
return $body;
}
}
}
//The above failed
//If we're on a second pass already then there's nothing left to do but bail
if (true === $second_pass) {
return false;
}
//We're still on the first pass, try to get just the name of the directory of the plugin
$parts = explode('/', $plugin);
//Sanity check that we have two parts, a directory and a file name
if (2 === count($parts)) {
//Try this entire function using just the directory name
return $this->try_get_response_body($parts[0], true);
}
//Everything above failed, bail
return false;
}
示例14: get_app_details
/**
* Get application details including app name, namespace, link, and more.
*
* @param string $app_id application identifier. uses appId property if set
* @return array application data response from Facebook API
*/
public function get_app_details($app_id = '')
{
if (!(is_string($app_id) && $app_id)) {
$app_id = $this->getAppId();
if (!$app_id) {
return array();
}
}
$url = $this->getUrl('graph', $app_id);
// switch to HTTP for server configurations not supporting HTTPS
if (substr_compare($url, 'https://', 0, 8) === 0 && !wp_http_supports(array('ssl' => true))) {
$url = 'http://' . substr($url, 8);
}
if (!$url) {
return array();
}
try {
$app_info = self::get_json_url($url);
} catch (WP_FacebookApiException $e) {
return array();
}
if (is_array($app_info) && isset($app_info['id'])) {
return $app_info;
}
return array();
}
示例15: wp_update_themes
//.........这里部分代码省略.........
$checked[ $theme->get_stylesheet() ] = $theme->get('Version');
$themes[ $theme->get_stylesheet() ] = array(
'Name' => $theme->get('Name'),
'Title' => $theme->get('Name'),
'Version' => $theme->get('Version'),
'Author' => $theme->get('Author'),
'Author URI' => $theme->get('AuthorURI'),
'Template' => $theme->get_template(),
'Stylesheet' => $theme->get_stylesheet(),
);
}
// Check for update on a different schedule, depending on the page.
switch ( current_filter() ) {
case 'upgrader_process_complete' :
$timeout = 0;
break;
case 'load-update-core.php' :
$timeout = MINUTE_IN_SECONDS;
break;
case 'load-themes.php' :
case 'load-update.php' :
$timeout = HOUR_IN_SECONDS;
break;
default :
$timeout = 12 * HOUR_IN_SECONDS;
}
$time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked );
if ( $time_not_changed ) {
$theme_changed = false;
foreach ( $checked as $slug => $v ) {
if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) )
$theme_changed = true;
}
if ( isset ( $last_update->response ) && is_array( $last_update->response ) ) {
foreach ( $last_update->response as $slug => $update_details ) {
if ( ! isset($checked[ $slug ]) ) {
$theme_changed = true;
break;
}
}
}
// Bail if we've checked recently and if nothing has changed
if ( ! $theme_changed )
return false;
}
// Update last_checked for current to prevent multiple blocking requests if request hangs
$last_update->last_checked = time();
set_site_transient( 'update_themes', $last_update );
$request['themes'] = $themes;
$locales = array( get_locale() );
/**
* Filter the locales requested for theme translations.
*
* @since 3.7.0
*
* @param array $locales Theme locale. Default is current locale of the site.
*/
$locales = apply_filters( 'themes_update_check_locales', $locales );
$options = array(
'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
'body' => array(
'themes' => json_encode( $request ),
'translations' => json_encode( $translations ),
'locale' => json_encode( $locales ),
),
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
);
$url = 'http://api.wordpress.org/themes/update-check/1.1/';
if ( wp_http_supports( array( 'ssl' ) ) )
$url = set_url_scheme( $url, 'https' );
$raw_response = wp_remote_post( $url, $options );
if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
return false;
$new_update = new stdClass;
$new_update->last_checked = time();
$new_update->checked = $checked;
$response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
if ( is_array( $response ) ) {
$new_update->response = $response['themes'];
$new_update->translations = $response['translations'];
}
set_site_transient( 'update_themes', $new_update );
}