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
0
/**
 * 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&#8217;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&#8217;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
0
/**
 * 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&#8217;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&#8217;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);
}
/**
 * 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&#8217;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&#8217;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&#8217;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
0
/**
 * 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
0
 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
0
 /**
  * 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&#8217;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);
 }
 /**
  * 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
0
 /**
  * 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
0
/**
 * 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
0
        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
0
/**
 * Retrieves plugin installer pages from the WordPress.org 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, {@see 'plugins_api_args'}, is for the args and gives the action
 * as the second parameter. The hook for {@see 'plugins_api_args'} must ensure that
 * an object is returned.
 *
 * The second filter, {@see 'plugins_api'}, allows a plugin to override the WordPress.org
 * Plugin Install API entirely. If `$action` is 'query_plugins' or 'plugin_information',
 * an object MUST be passed. If `$action` is 'hot_tags' or 'hot_categories', an array MUST
 * be passed.
 *
 * Finally, the third filter, {@see 'plugins_api_result'}, makes it possible to filter the
 * response object or array, depending on the `$action` type.
 *
 * Supported arguments per action:
 *
 * | Argument Name        | query_plugins | plugin_information | hot_tags | hot_categories |
 * | -------------------- | :-----------: | :----------------: | :------: | :------------: |
 * | `$slug`              | No            |  Yes               | No       | No             |
 * | `$per_page`          | Yes           |  No                | No       | No             |
 * | `$page`              | Yes           |  No                | No       | No             |
 * | `$number`            | No            |  No                | Yes      | Yes            |
 * | `$search`            | Yes           |  No                | No       | No             |
 * | `$tag`               | Yes           |  No                | No       | No             |
 * | `$author`            | Yes           |  No                | No       | No             |
 * | `$user`              | Yes           |  No                | No       | No             |
 * | `$browse`            | Yes           |  No                | No       | No             |
 * | `$locale`            | Yes           |  Yes               | No       | No             |
 * | `$installed_plugins` | Yes           |  No                | No       | No             |
 * | `$is_ssl`            | Yes           |  Yes               | No       | No             |
 * | `$fields`            | Yes           |  Yes               | No       | No             |
 *
 * @since 2.7.0
 *
 * @param string       $action API action to perform: 'query_plugins', 'plugin_information',
 *                             'hot_tags' or 'hot_categories'.
 * @param array|object $args   {
 *     Optional. Array or object of arguments to serialize for the Plugin Info API.
 *
 *     @type string  $slug              The plugin slug. Default empty.
 *     @type int     $per_page          Number of plugins per page. Default 24.
 *     @type int     $page              Number of current page. Default 1.
 *     @type int     $number            Number of tags or categories to be queried.
 *     @type string  $search            A search term. Default empty.
 *     @type string  $tag               Tag to filter plugins. Default empty.
 *     @type string  $author            Username of an plugin author to filter plugins. Default empty.
 *     @type string  $user              Username to query for their favorites. Default empty.
 *     @type string  $browse            Browse view: 'popular', 'new', 'beta', 'recommended'.
 *     @type string  $locale            Locale to provide context-sensitive results. Default is the value
 *                                      of get_locale().
 *     @type string  $installed_plugins Installed plugins to provide context-sensitive results.
 *     @type bool    $is_ssl            Whether links should be returned with https or not. Default false.
 *     @type array   $fields            {
 *         Array of fields which should or should not be returned.
 *
 *         @type bool $short_description Whether to return the plugin short description. Default true.
 *         @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&#8217;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&#8217;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&#8217;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);
}
 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;
 }
 /**
  * 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
0
/**
 * Check theme versions against the latest versions hosted on WordPress.org.
 *
 * A list of all themes installed in sent to WP. Checks against the
 * WordPress server at api.wordpress.org. Will only check if WordPress isn't
 * installing.
 *
 * @package WordPress
 * @since 2.7.0
 * @uses $wp_version Used to notify the WordPress version.
 *
 * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
 */
function wp_update_themes() {
	include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version

	if ( defined( 'WP_INSTALLING' ) )
		return false;

	$installed_themes = wp_get_themes();
	$translations = wp_get_installed_translations( 'themes' );

	$last_update = get_site_transient( 'update_themes' );
	if ( ! is_object($last_update) )
		$last_update = new stdClass;

	$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'    => $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 );
}
Пример #16
0
function learn_press_get_plugin_data($plugins)
{
    global $wp_version;
    //$plugins = get_plugins();
    $translations = wp_get_installed_translations('plugins');
    $active = get_option('active_plugins', array());
    $current = get_site_transient('update_plugins');
    $to_send = compact('plugins', 'active');
    $locales = array(get_locale());
    $options = array('timeout' => 30, 'body' => array('plugins' => wp_json_encode($to_send), 'translations' => wp_json_encode($translations), 'locale' => wp_json_encode($locales), 'all' => wp_json_encode(true)), 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'));
    /*if ( $extra_stats ) {
          $options['body']['update_stats'] = wp_json_encode( $extra_stats );
      }*/
    $url = $http_url = 'http://api.wordpress.org/plugins/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&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.', 'learn_press') . ' ' . __('(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)', 'learn_press'), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE);
        $raw_response = wp_remote_post($http_url, $options);
    }
    $response = json_decode(wp_remote_retrieve_body($raw_response), true);
    //print_r($response);
}
Пример #17
0
 /**
  * Checks to see if the URL is using SSL to connect with Jetpack
  *
  * @since 2.3.3
  * @return boolean
  */
 public static function permit_ssl($force_recheck = false)
 {
     // Do some fancy tests to see if ssl is being supported
     if ($force_recheck || false === ($ssl = get_transient('jetpack_https_test'))) {
         $message = '';
         if ('https' !== substr(JETPACK__API_BASE, 0, 5)) {
             $ssl = 0;
         } else {
             switch (JETPACK_CLIENT__HTTPS) {
                 case 'NEVER':
                     $ssl = 0;
                     $message = __('JETPACK_CLIENT__HTTPS is set to NEVER', 'jetpack');
                     break;
                 case 'ALWAYS':
                 case 'AUTO':
                 default:
                     $ssl = 1;
                     break;
             }
             // If it's not 'NEVER', test to see
             if ($ssl) {
                 if (!wp_http_supports(array('ssl' => true))) {
                     $ssl = 0;
                     $message = __('WordPress reports no SSL support', 'jetpack');
                 } else {
                     $response = wp_remote_get(JETPACK__API_BASE . 'test/1/');
                     if (is_wp_error($response)) {
                         $ssl = 0;
                         $message = __('WordPress reports no SSL support', 'jetpack');
                     } elseif ('OK' !== wp_remote_retrieve_body($response)) {
                         $ssl = 0;
                         $message = __('Response was not OK: ', 'jetpack') . wp_remote_retrieve_body($response);
                     }
                 }
             }
         }
         set_transient('jetpack_https_test', $ssl, DAY_IN_SECONDS);
         set_transient('jetpack_https_test_message', $message, DAY_IN_SECONDS);
     }
     return (bool) $ssl;
 }
Пример #18
0
 /**
  * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets
  */
 public static function fix_url_for_bad_hosts($url, &$args)
 {
     if (0 !== strpos($url, 'https://')) {
         return $url;
     }
     switch (JETPACK_CLIENT__HTTPS) {
         case 'ALWAYS':
             return $url;
         case 'NEVER':
             return substr_replace($url, '', 4, 1);
             // default : case 'AUTO' :
     }
     $jetpack = Jetpack::init();
     // Yay! Your host is good!
     if (wp_http_supports(array('ssl' => true))) {
         return $url;
     }
     // Boo! Your host is bad and makes Jetpack cry!
     return substr_replace($url, '', 4, 1);
 }
Пример #19
0
/**
 * Retrieves theme installer pages from the WordPress.org Themes API.
 *
 * It is possible for a theme to override the Themes API result with three
 * filters. Assume this is for themes, which can extend on the Theme Info to
 * offer more choices. This is very powerful and must be used with care, when
 * overriding the filters.
 *
 * The first filter, {@see 'themes_api_args'}, is for the args and gives the action
 * as the second parameter. The hook for {@see 'themes_api_args'} must ensure that
 * an object is returned.
 *
 * The second filter, {@see 'themes_api'}, allows a plugin to override the WordPress.org
 * Theme API entirely. If `$action` is 'query_themes', 'theme_information', or 'feature_list',
 * an object MUST be passed. If `$action` is 'hot_tags', an array should be passed.
 *
 * Finally, the third filter, {@see 'themes_api_result'}, makes it possible to filter the
 * response object or array, depending on the `$action` type.
 *
 * Supported arguments per action:
 *
 * | Argument Name      | 'query_themes' | 'theme_information' | 'hot_tags' | 'feature_list'   |
 * | -------------------| :------------: | :-----------------: | :--------: | :--------------: |
 * | `$slug`            | No             |  Yes                | No         | No               |
 * | `$per_page`        | Yes            |  No                 | No         | No               |
 * | `$page`            | Yes            |  No                 | No         | No               |
 * | `$number`          | No             |  No                 | Yes        | No               |
 * | `$search`          | Yes            |  No                 | No         | No               |
 * | `$tag`             | Yes            |  No                 | No         | No               |
 * | `$author`          | Yes            |  No                 | No         | No               |
 * | `$user`            | Yes            |  No                 | No         | No               |
 * | `$browse`          | Yes            |  No                 | No         | No               |
 * | `$locale`          | Yes            |  Yes                | No         | No               |
 * | `$fields`          | Yes            |  Yes                | No         | No               |
 *
 * @since 2.8.0
 *
 * @param string       $action API action to perform: 'query_themes', 'theme_information',
 *                             'hot_tags' or 'feature_list'.
 * @param array|object $args   {
 *     Optional. Array or object of arguments to serialize for the Themes API.
 *
 *     @type string  $slug     The theme slug. Default empty.
 *     @type int     $per_page Number of themes per page. Default 24.
 *     @type int     $page     Number of current page. Default 1.
 *     @type int     $number   Number of tags to be queried.
 *     @type string  $search   A search term. Default empty.
 *     @type string  $tag      Tag to filter themes. Default empty.
 *     @type string  $author   Username of an author to filter themes. Default empty.
 *     @type string  $user     Username to query for their favorites. Default empty.
 *     @type string  $browse   Browse view: 'featured', 'popular', 'updated', 'favorites'.
 *     @type string  $locale   Locale to provide context-sensitive results. Default is the value of get_locale().
 *     @type array   $fields   {
 *         Array of fields which should or should not be returned.
 *
 *         @type bool $description        Whether to return the theme full description. Default false.
 *         @type bool $sections           Whether to return the theme readme sections: description, installation,
 *                                        FAQ, screenshots, other notes, and changelog. Default false.
 *         @type bool $rating             Whether to return the rating in percent and total number of ratings.
 *                                        Default false.
 *         @type bool $ratings            Whether to return the number of rating for each star (1-5). Default false.
 *         @type bool $downloaded         Whether to return the download count. Default false.
 *         @type bool $downloadlink       Whether to return the download link for the package. Default false.
 *         @type bool $last_updated       Whether to return the date of the last update. Default false.
 *         @type bool $tags               Whether to return the assigned tags. Default false.
 *         @type bool $homepage           Whether to return the theme homepage link. Default false.
 *         @type bool $screenshots        Whether to return the screenshots. Default false.
 *         @type int  $screenshot_count   Number of screenshots to return. Default 1.
 *         @type bool $screenshot_url     Whether to return the URL of the first screenshot. Default false.
 *         @type bool $photon_screenshots Whether to return the screenshots via Photon. Default false.
 *         @type bool $template           Whether to return the slug of the parent theme. Default false.
 *         @type bool $parent             Whether to return the slug, name and homepage of the parent theme. Default false.
 *         @type bool $versions           Whether to return the list of all available versions. Default false.
 *         @type bool $theme_url          Whether to return theme's URL. Default false.
 *         @type bool $extended_author    Whether to return nicename or nicename and display name. 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/themes_api/ function reference article}
 *         for more information on the make-up of possible return objects depending on the value of `$action`.
 */
function themes_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_user_locale();
    }
    /**
     * Filters arguments used to query for installer pages from the WordPress.org Themes API.
     *
     * Important: An object MUST be returned to this filter.
     *
     * @since 2.8.0
     *
     * @param object $args   Arguments used to query for installer pages from the WordPress.org Themes API.
     * @param string $action Requested action. Likely values are 'theme_information',
     *                       'feature_list', or 'query_themes'.
     */
    $args = apply_filters('themes_api_args', $args, $action);
    /**
     * Filters whether to override the WordPress.org Themes API.
     *
     * Passing a non-false value will effectively short-circuit the WordPress.org API request.
     *
     * If `$action` is 'query_themes', 'theme_information', or 'feature_list', an object MUST
     * be passed. If `$action` is 'hot_tags', an array should be passed.
     *
     * @since 2.8.0
     *
     * @param false|object|array $override Whether to override the WordPress.org Themes API. Default false.
     * @param string             $action   Requested action. Likely values are 'theme_information',
     *                                    'feature_list', or 'query_themes'.
     * @param object             $args     Arguments used to query for installer pages from the Themes API.
     */
    $res = apply_filters('themes_api', false, $action, $args);
    if (!$res) {
        $url = $http_url = 'http://api.wordpress.org/themes/info/1.0/';
        if ($ssl = wp_http_supports(array('ssl'))) {
            $url = set_url_scheme($url, 'https');
        }
        $http_args = array('body' => array('action' => $action, 'request' => serialize($args)));
        $request = wp_remote_post($url, $http_args);
        if ($ssl && is_wp_error($request)) {
            if (!wp_doing_ajax()) {
                trigger_error(sprintf(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.'), __('https://wordpress.org/support/')) . ' ' . __('(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('themes_api_failed', sprintf(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.'), __('https://wordpress.org/support/')), $request->get_error_message());
        } else {
            $res = maybe_unserialize(wp_remote_retrieve_body($request));
            if (!is_object($res) && !is_array($res)) {
                $res = new WP_Error('themes_api_failed', sprintf(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.'), __('https://wordpress.org/support/')), wp_remote_retrieve_body($request));
            }
        }
    }
    /**
     * Filters the returned WordPress.org Themes API response.
     *
     * @since 2.8.0
     *
     * @param array|object|WP_Error $res    WordPress.org Themes API response.
     * @param string                $action Requested action. Likely values are 'theme_information',
     *                                      'feature_list', or 'query_themes'.
     * @param object                $args   Arguments used to query for installer pages from the WordPress.org Themes API.
     */
    return apply_filters('themes_api_result', $res, $action, $args);
}
Пример #20
0
 /**
  * Register shortcodes handlers and callbacks
  *
  * @since 1.0.0
  *
  * @return void
  */
 public static function registerShortcodeHandlers()
 {
     // features requiring HTTPS remote requests
     if (wp_http_supports(array('ssl' => true))) {
         // Embedded Tweet
         add_action('plugins_loaded', array('\\Twitter\\WordPress\\Shortcodes\\EmbeddedTweet', 'init'), 5, 0);
         // Twitter embedded videos
         add_action('plugins_loaded', array('\\Twitter\\WordPress\\Shortcodes\\EmbeddedTweetVideo', 'init'), 5, 0);
     }
     // Follow button
     add_action('plugins_loaded', array('\\Twitter\\WordPress\\Shortcodes\\Follow', 'init'), 5, 0);
     // Tweet button
     add_action('plugins_loaded', array('\\Twitter\\WordPress\\Shortcodes\\Share', 'init'), 5, 0);
     // Ad conversion and audience tracking
     add_action('plugins_loaded', array('\\Twitter\\WordPress\\Shortcodes\\Tracking', 'init'), 5, 0);
 }
Пример #21
0
 /**
  * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets
  */
 function fix_url_for_bad_hosts($url, &$args)
 {
     if (0 !== strpos($url, 'https://')) {
         return $url;
     }
     switch (JETPACK_CLIENT__HTTPS) {
         case 'ALWAYS':
             return $url;
         case 'NEVER':
             return substr_replace($url, '', 4, 1);
             // default : case 'AUTO' :
     }
     $jetpack = Jetpack::init();
     if (version_compare($GLOBALS['wp_version'], '3.2-something', '<')) {
         // WordPress < 3.2
         if (isset($args['method']) && 'POST' == strtoupper($args['method'])) {
             $method = 'POST';
         } else {
             $method = 'GET';
         }
         if (empty($jetpack->use_ssl)) {
             if (function_exists('_wp_http_get_object')) {
                 _wp_http_get_object();
             } else {
                 new WP_Http();
             }
         }
         // Yay! Your host is good!
         if ($jetpack->use_ssl[$method]) {
             return $url;
         }
     } else {
         // WordPress >= 3.2
         if (wp_http_supports(array('ssl' => true))) {
             return $url;
         }
     }
     // Boo! Your host is bad and makes Jetpack cry!
     return substr_replace($url, '', 4, 1);
 }
Пример #22
0
		<div class="col-3 last-feature">
			<h4><?php _e( 'More Reliable Than Ever' ); ?></h4>
			<p><?php _e( 'The update process has been made even more reliable and secure, with dozens of new checks and safeguards.' ); ?></p>
			<p><?php _e( 'You&#8217;ll still need to click &#8220;Update Now&#8221; once WordPress 3.8 is released, but we&#8217;ve never had more confidence in that beautiful blue button.' ); ?></p>
		</div>
		<?php
		if ( current_user_can( 'update_core' ) ) {
			$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,
			);
			require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
			$updater = new WP_Automatic_Updater;
			$can_auto_update = wp_http_supports( array( 'ssl' ) ) && $updater->should_update( 'core', $future_minor_update, ABSPATH );

			if ( $can_auto_update ) {
				echo '<p class="about-auto-update cool">' . __( 'This site <strong>is</strong> able to apply these updates automatically. Cool!' ). '</p>';

			// If the updater is disabled entirely, don't show them anything.
			} elseif ( ! $updater->is_disabled() ) {
				echo '<p class="about-auto-update">';
				// If this is is filtered to false, they won't get emails, so don't claim we will.
				// Assumption: If the user can update core, they can see what the admin email is.

				/** This filter is documented in wp-admin/includes/class-wp-upgrader.php */
				if ( apply_filters( 'send_core_update_notification_email', true, $future_minor_update ) ) {
					printf( __( 'This site <strong>is not</strong> able to apply these updates automatically. But we&#8217;ll email %s when there is a new security release.' ), esc_html( get_site_option( 'admin_email' ) ) );
				} else {
					_e( 'This site <strong>is not</strong> able to apply these updates automatically.' );
Пример #23
0
/**
 * Retrieve theme installer pages from WordPress Themes API.
 *
 * It is possible for a theme to override the Themes API result with three
 * filters. Assume this is for themes, which can extend on the Theme Info to
 * offer more choices. This is very powerful and must be used with care, when
 * overriding the filters.
 *
 * The first filter, 'themes_api_args', is for the args and gives the action as
 * the second parameter. The hook for 'themes_api_args' must ensure that an
 * object is returned.
 *
 * The second filter, 'themes_api', is the result that would be returned.
 *
 * @since 2.8.0
 *
 * @param string       $action The requested action. Likely values are 'theme_information',
 *                             'feature_list', or 'query_themes'.
 * @param array|object $args   Optional. Arguments to serialize for the Theme Info API.
 * @return mixed
 */
function themes_api($action, $args = null)
{
    if (is_array($args)) {
        $args = (object) $args;
    }
    if (!isset($args->per_page)) {
        $args->per_page = 24;
    }
    if (!isset($args->locale)) {
        $args->locale = get_locale();
    }
    /**
     * Filter arguments used to query for installer pages from the WordPress.org Themes API.
     *
     * Important: An object MUST be returned to this filter.
     *
     * @since 2.8.0
     *
     * @param object $args   Arguments used to query for installer pages from the WordPress.org Themes API.
     * @param string $action Requested action. Likely values are 'theme_information',
     *                       'feature_list', or 'query_themes'.
     */
    $args = apply_filters('themes_api_args', $args, $action);
    /**
     * Filter whether to override the WordPress.org Themes API.
     *
     * Returning a value of true to this filter allows a theme to completely
     * override the built-in WordPress.org API.
     *
     * @since 2.8.0
     *
     * @param bool   $bool   Whether to override the WordPress.org Themes API. Default false.
     * @param string $action Requested action. Likely values are 'theme_information',
     *                       'feature_list', or 'query_themes'.
     * @param object $args   Arguments used to query for installer pages from the Themes API.
     */
    $res = apply_filters('themes_api', false, $action, $args);
    if (!$res) {
        $url = $http_url = 'http://api.wordpress.org/themes/info/1.0/';
        if ($ssl = wp_http_supports(array('ssl'))) {
            $url = set_url_scheme($url, 'https');
        }
        $http_args = array('body' => array('action' => $action, 'request' => serialize($args)));
        $request = wp_remote_post($url, $http_args);
        if ($ssl && is_wp_error($request)) {
            if (!defined('DOING_AJAX') || !DOING_AJAX) {
                trigger_error(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;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('themes_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;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('themes_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;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));
            }
        }
    }
    /**
     * Filter the returned WordPress.org Themes API response.
     *
     * @since 2.8.0
     *
     * @param array|object $res    WordPress.org Themes API response.
     * @param string       $action Requested action. Likely values are 'theme_information',
     *                             'feature_list', or 'query_themes'.
     * @param object       $args   Arguments used to query for installer pages from the WordPress.org Themes API.
     */
    return apply_filters('themes_api_result', $res, $action, $args);
}
Пример #24
0
/**
 * Check theme versions against the latest versions hosted on WordPress.org.
 *
 * A list of all themes installed in sent to WP. Checks against the
 * WordPress server at api.wordpress.org. Will only check if WordPress isn't
 * installing.
 *
 * @since 2.7.0
 * @uses $wp_version Used to notify the WordPress version.
 *
 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
 */
function wp_update_themes($extra_stats = array())
{
    if (wp_installing()) {
        return;
    }
    global $wp_version;
    // include an unmodified $wp_version
    include ABSPATH . WPINC . '/version.php';
    $installed_themes = wp_get_themes();
    $translations = wp_get_installed_translations('themes');
    $last_update = get_site_transient('update_themes');
    if (!is_object($last_update)) {
        $last_update = new stdClass();
    }
    $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' => $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:
            if (defined('DOING_CRON') && DOING_CRON) {
                $timeout = 0;
            } else {
                $timeout = 12 * HOUR_IN_SECONDS;
            }
    }
    $time_not_changed = isset($last_update->last_checked) && $timeout > time() - $last_update->last_checked;
    if ($time_not_changed && !$extra_stats) {
        $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;
        }
    }
    // 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;
    /**
     * 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', array(get_locale()));
    if (defined('DOING_CRON') && DOING_CRON) {
        $timeout = 30;
    } else {
        // Three seconds, plus one extra second for every 10 themes
        $timeout = 3 + (int) (count($themes) / 10);
    }
    $options = array('timeout' => $timeout, 'body' => array('themes' => wp_json_encode($request), 'translations' => wp_json_encode($translations), 'locale' => wp_json_encode($locales)), 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'));
    if ($extra_stats) {
        $options['body']['update_stats'] = wp_json_encode($extra_stats);
    }
    $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&#8217;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);
    }
    if (is_wp_error($raw_response) || 200 != wp_remote_retrieve_response_code($raw_response)) {
        return;
    }
    $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);
}
Пример #25
0
 /**
  * Security copy of the core function with Requests - Gets the checksums for the given version of WordPress.
  *
  * @param string $version Version string to query.
  * @param string $locale  Locale to query.
  * @return bool|array False on failure. An array of checksums on success.
  */
 private static function get_core_checksums($version, $locale)
 {
     $url = $http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query(compact('version', 'locale'), null, '&');
     if ($ssl = wp_http_supports(array('ssl'))) {
         $url = 'https' . substr($url, 4);
     }
     $options = array('timeout' => 30);
     $headers = array('Accept' => 'application/json');
     $response = Utils\http_request('GET', $url, null, $headers, $options);
     if ($ssl && !$response->success) {
         WP_CLI::warning('wp-cli could not establish a secure connection to WordPress.org. Please contact your server administrator.');
         $response = Utils\http_request('GET', $http_url, null, $headers, $options);
     }
     if (!$response->success || 200 != $response->status_code) {
         return false;
     }
     $body = trim($response->body);
     $body = json_decode($body, true);
     if (!is_array($body) || !isset($body['checksums']) || !is_array($body['checksums'])) {
         return false;
     }
     return $body['checksums'];
 }
Пример #26
0
 public static function SSLEnabled()
 {
     if (!function_exists('wp_http_supports')) {
         require_once ABSPATH . WPINC . 'http.php';
     }
     return wp_http_supports(array('ssl'));
 }
Пример #27
0
 /**
  * Clean user inputs before saving to database
  *
  * @since 1.1
  * @param array $options form options values
  */
 public static function sanitize_options($options)
 {
     // start fresh
     $clean_options = array();
     if (isset($options['app_id'])) {
         // leading spaces is a common copy-paste mistake
         $app_id = trim($options['app_id']);
         if ($app_id) {
             // digit characters only
             // better to reject a known bad value than remove its bad characters & save bad value
             if (function_exists('ctype_digit')) {
                 // ctype might not always be present
                 if (ctype_digit($app_id)) {
                     $clean_options['app_id'] = $app_id;
                 }
             } else {
                 if (preg_match('/^[0-9]+$/', $app_id)) {
                     $clean_options['app_id'] = $app_id;
                 } else {
                     if (function_exists('add_settings_error')) {
                         add_settings_error('facebook-app-id', 'facebook-app-id-error', __('App ID must contain only digits.', 'facebook'));
                     }
                 }
             }
         } else {
             // removing app id disables other features such as comments
             delete_option('facebook_comments_enabled');
         }
         unset($app_id);
     }
     if (isset($options['app_secret'])) {
         $app_secret = strtolower(trim($options['app_secret']));
         if ($app_secret) {
             if (preg_match('/^[0-9a-f]+$/', $app_secret)) {
                 // hex
                 $clean_options['app_secret'] = $app_secret;
             } else {
                 if (function_exists('add_settings_error')) {
                     add_settings_error('facebook-app-secret', 'facebook-app-secret-error', __('Invalid app secret.', 'facebook'));
                 }
             }
         }
         unset($app_secret);
     }
     // store an application access token and verify additional data
     if (isset($clean_options['app_id']) && isset($clean_options['app_secret'])) {
         if (!class_exists('Facebook_WP_Extend')) {
             require_once dirname(dirname(__FILE__)) . '/includes/facebook-php-sdk/class-facebook-wp.php';
         }
         if (wp_http_supports(array('ssl' => true))) {
             $access_token = Facebook_WP_Extend::get_app_access_token($clean_options['app_id'], $clean_options['app_secret']);
             if ($access_token) {
                 $app_info = Facebook_WP_Extend::get_app_details_by_access_token($access_token, array('id', 'namespace'));
                 if (empty($app_info)) {
                     unset($clean_options['app_id']);
                     unset($clean_options['app_secret']);
                 } else {
                     if (isset($app_info['namespace'])) {
                         $clean_options['app_namespace'] = $app_info['namespace'];
                     }
                     $clean_options['access_token'] = $access_token;
                 }
                 unset($app_info);
             } else {
                 if (function_exists('add_settings_error')) {
                     add_settings_error('facebook-app-auth', 'facebook-app-auth-error', __('Application ID and secret failed on authentication with Facebook.', 'facebook'));
                 }
                 unset($clean_options['app_id']);
                 unset($clean_options['app_secret']);
             }
             unset($access_token);
         } else {
             $app_info = Facebook_WP_Extend::get_app_details($clean_options['app_id'], array('id', 'namespace'));
             if (empty($app_info)) {
                 unset($clean_options['app_id']);
                 unset($clean_options['app_secret']);
             } else {
                 if (isset($app_info['namespace'])) {
                     $clean_options['app_namespace'] = $app_info['namespace'];
                 }
             }
             unset($app_info);
         }
     } else {
         unset($clean_options['app_id']);
         unset($clean_options['app_secret']);
     }
     return $clean_options;
 }
Пример #28
0
 /**
  * Determine whether the server supports SSL (shared cert not supported.
  *
  * Attempts to retrieve an HTML version of the homepage in an effort to determine if SSL is available.
  *
  * @since 4.0.0
  *
  * @return bool true if ssl is supported or false
  */
 public static function get_ssl()
 {
     $url = str_ireplace('http://', 'https://', get_bloginfo('url'));
     if (function_exists('wp_http_supports') && wp_http_supports(array('ssl'), $url)) {
         return true;
     } elseif (function_exists('curl_init')) {
         //use a manual CURL request to better account for self-signed certificates
         $timeout = 5;
         //timeout for the request
         $site_title = trim(get_bloginfo());
         $request = curl_init();
         curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($request, CURLOPT_VERBOSE, false);
         curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($request, CURLOPT_HEADER, true);
         curl_setopt($request, CURLOPT_URL, $url);
         curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($request, CURLOPT_CONNECTTIMEOUT, $timeout);
         $data = curl_exec($request);
         $header_size = curl_getinfo($request, CURLINFO_HEADER_SIZE);
         $http_code = intval(curl_getinfo($request, CURLINFO_HTTP_CODE));
         $body = substr($data, $header_size);
         preg_match('/<title>(.+)<\\/title>/', $body, $matches);
         if (200 == $http_code && isset($matches[1]) && false !== strpos($matches[1], $site_title)) {
             return true;
         } else {
             return false;
         }
     }
     return false;
 }
Пример #29
0
 /**
  * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requsets
  */
 public static function fix_url_for_bad_hosts($url)
 {
     if (0 !== strpos($url, 'https://')) {
         return $url;
     }
     switch (JETPACK_CLIENT__HTTPS) {
         case 'ALWAYS':
             return $url;
         case 'NEVER':
             return self::force_url_to_non_ssl($url);
             // default : case 'AUTO' :
     }
     // Yay! Your host is good!
     if (self::permit_ssl() && wp_http_supports(array('ssl' => true))) {
         return $url;
     }
     // Boo! Your host is bad and makes Jetpack cry!
     return self::force_url_to_non_ssl($url);
 }
Пример #30
0
/**
 * Gets and caches the checksums for the given version of WordPress.
 *
 * @since 3.7.0
 *
 * @param string $version Version string to query.
 * @param string $locale  Locale to query.
 * @return bool|array False on failure. An array of checksums on success.
 */
function get_core_checksums( $version, $locale ) {
	$url = $http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' );

	if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
		$url = set_url_scheme( $url, 'https' );

	$options = array(
		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
	);

	$response = wp_remote_get( $url, $options );
	if ( $ssl && is_wp_error( $response ) ) {
		trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;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 );
		$response = wp_remote_get( $http_url, $options );
	}

	if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
		return false;

	$body = trim( wp_remote_retrieve_body( $response ) );
	$body = json_decode( $body, true );

	if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) )
		return false;

	return $body['checksums'];
}