translations_api

The timeline below displays how wordpress function translations_api has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * WordPress Translation Installation Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * 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 array|WP_Error On success an associative array of translations, WP_Error on failure.
 */
function translations_api($type, $args = null)
{
    // Include an unmodified $wp_version.
    require ABSPATH . WPINC . '/version.php';
    if (!in_array($type, array('plugins', 'themes', 'core'), true)) {
        return new WP_Error('invalid_type', __('Invalid translation type.'));
    }
    /**
     * Allows a plugin to override the WordPress.org Translation Installation API entirely.
     *
     * @since 4.0.0
     *
     * @param false|array $result The result array. 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://api.wordpress.org/translations/' . $type . '/1.0/';
        $http_url = $url;
        $ssl = wp_http_supports(array('ssl'));
        if ($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(sprintf(
                /* translators: %s: Support forums URL. */
                __('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/forums/')
            ) . ' ' . __('(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', sprintf(
                /* translators: %s: Support forums URL. */
                __('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/forums/')
            ), $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', sprintf(
                    /* translators: %s: Support forums URL. */
                    __('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/forums/')
                ), wp_remote_retrieve_body($request));
            }
        }
    }
    /**
     * Filters the Translation Installation API response results.
     *
     * @since 4.0.0
     *
     * @param array|WP_Error $res  Response as an associative array 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);
}

WordPress Version: 5.7

/**
 * WordPress Translation Installation Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * 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 an unmodified $wp_version.
    require ABSPATH . WPINC . '/version.php';
    if (!in_array($type, array('plugins', 'themes', 'core'), true)) {
        return new WP_Error('invalid_type', __('Invalid translation type.'));
    }
    /**
     * Allows a plugin to override the WordPress.org Translation Installation API entirely.
     *
     * @since 4.0.0
     *
     * @param false|object $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://api.wordpress.org/translations/' . $type . '/1.0/';
        $http_url = $url;
        $ssl = wp_http_supports(array('ssl'));
        if ($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(sprintf(
                /* translators: %s: Support forums URL. */
                __('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/forums/')
            ) . ' ' . __('(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', sprintf(
                /* translators: %s: Support forums URL. */
                __('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/forums/')
            ), $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', sprintf(
                    /* translators: %s: Support forums URL. */
                    __('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/forums/')
                ), wp_remote_retrieve_body($request));
            }
        }
    }
    /**
     * Filters the Translation Installation API response results.
     *
     * @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);
}

WordPress Version: 5.5

/**
 * WordPress Translation Installation Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * 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 an unmodified $wp_version.
    require ABSPATH . WPINC . '/version.php';
    if (!in_array($type, array('plugins', 'themes', 'core'), true)) {
        return new WP_Error('invalid_type', __('Invalid translation type.'));
    }
    /**
     * Allows a plugin to override the WordPress.org Translation Installation 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://api.wordpress.org/translations/' . $type . '/1.0/';
        $http_url = $url;
        $ssl = wp_http_supports(array('ssl'));
        if ($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(sprintf(
                /* translators: %s: Support forums URL. */
                __('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/forums/')
            ) . ' ' . __('(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', sprintf(
                /* translators: %s: Support forums URL. */
                __('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/forums/')
            ), $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', sprintf(
                    /* translators: %s: Support forums URL. */
                    __('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/forums/')
                ), wp_remote_retrieve_body($request));
            }
        }
    }
    /**
     * Filters the Translation Installation API response results.
     *
     * @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);
}

WordPress Version: 5.4

/**
 * WordPress Translation Installation Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * 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 an unmodified $wp_version.
    require ABSPATH . WPINC . '/version.php';
    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 Installation 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://api.wordpress.org/translations/' . $type . '/1.0/';
        $http_url = $url;
        $ssl = wp_http_supports(array('ssl'));
        if ($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(sprintf(
                /* translators: %s: Support forums URL. */
                __('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/forums/')
            ) . ' ' . __('(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', sprintf(
                /* translators: %s: Support forums URL. */
                __('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/forums/')
            ), $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', sprintf(
                    /* translators: %s: Support forums URL. */
                    __('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/forums/')
                ), wp_remote_retrieve_body($request));
            }
        }
    }
    /**
     * Filters the Translation Installation API response results.
     *
     * @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);
}

WordPress Version: 5.3

/**
 * WordPress Translation Installation Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * 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 Installation 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://api.wordpress.org/translations/' . $type . '/1.0/';
        $http_url = $url;
        $ssl = wp_http_supports(array('ssl'));
        if ($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(sprintf(
                /* translators: %s: Support forums URL. */
                __('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/forums/')
            ) . ' ' . __('(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', sprintf(
                /* translators: %s: Support forums URL. */
                __('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/forums/')
            ), $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', sprintf(
                    /* translators: %s: Support forums URL. */
                    __('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/forums/')
                ), wp_remote_retrieve_body($request));
            }
        }
    }
    /**
     * Filters the Translation Installation API response results.
     *
     * @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);
}

WordPress Version: 4.9

/**
 * WordPress Translation Installation Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * 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 Installation 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(sprintf(
                /* translators: %s: support forums URL */
                __('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, $options);
        }
        if (is_wp_error($request)) {
            $res = new WP_Error('translations_api_failed', sprintf(
                /* translators: %s: support forums URL */
                __('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 = json_decode(wp_remote_retrieve_body($request), true);
            if (!is_object($res) && !is_array($res)) {
                $res = new WP_Error('translations_api_failed', sprintf(
                    /* translators: %s: support forums URL */
                    __('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 Translation Installation API response results.
     *
     * @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);
}

WordPress Version: 4.7

/**
 * WordPress Translation Install Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * 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(sprintf(
                /* translators: %s: support forums URL */
                __('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, $options);
        }
        if (is_wp_error($request)) {
            $res = new WP_Error('translations_api_failed', sprintf(
                /* translators: %s: support forums URL */
                __('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 = json_decode(wp_remote_retrieve_body($request), true);
            if (!is_object($res) && !is_array($res)) {
                $res = new WP_Error('translations_api_failed', sprintf(
                    /* translators: %s: support forums URL */
                    __('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 Translation Install API response results.
     *
     * @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);
}

WordPress Version: 4.6

/**
 * WordPress Translation Install Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * 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));
            }
        }
    }
    /**
     * Filters the Translation Install API response results.
     *
     * @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);
}

WordPress Version: 4.0

/**
 * WordPress Translation Install Administration API
 *
 * @package WordPress
 * @subpackage Administration
 */
/**
 * 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));
            }
        }
    }
    /**
     * Filter the Translation Install API response results.
     *
     * @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);
}