set_url_scheme

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

WordPress Version: 6.3

/**
 * Sets the scheme for a URL.
 *
 * @since 3.4.0
 * @since 4.4.0 The 'rest' scheme was added.
 *
 * @param string      $url    Absolute URL that includes a scheme
 * @param string|null $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login',
 *                            'login_post', 'admin', 'relative', 'rest', 'rpc', or null. Default null.
 * @return string URL with chosen scheme.
 */
function set_url_scheme($url, $scheme = null)
{
    $orig_scheme = $scheme;
    if (!$scheme) {
        $scheme = is_ssl() ? 'https' : 'http';
    } elseif ('admin' === $scheme || 'login' === $scheme || 'login_post' === $scheme || 'rpc' === $scheme) {
        $scheme = (is_ssl() || force_ssl_admin()) ? 'https' : 'http';
    } elseif ('http' !== $scheme && 'https' !== $scheme && 'relative' !== $scheme) {
        $scheme = is_ssl() ? 'https' : 'http';
    }
    $url = trim($url);
    if (str_starts_with($url, '//')) {
        $url = 'http:' . $url;
    }
    if ('relative' === $scheme) {
        $url = ltrim(preg_replace('#^\w+://[^/]*#', '', $url));
        if ('' !== $url && '/' === $url[0]) {
            $url = '/' . ltrim($url, "/ \t\n\r\x00\v");
        }
    } else {
        $url = preg_replace('#^\w+://#', $scheme . '://', $url);
    }
    /**
     * Filters the resulting URL after setting the scheme.
     *
     * @since 3.4.0
     *
     * @param string      $url         The complete URL including scheme and path.
     * @param string      $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
     * @param string|null $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
     *                                 'login_post', 'admin', 'relative', 'rest', 'rpc', or null.
     */
    return apply_filters('set_url_scheme', $url, $scheme, $orig_scheme);
}

WordPress Version: 5.5

/**
 * Sets the scheme for a URL.
 *
 * @since 3.4.0
 * @since 4.4.0 The 'rest' scheme was added.
 *
 * @param string      $url    Absolute URL that includes a scheme
 * @param string|null $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login',
 *                            'login_post', 'admin', 'relative', 'rest', 'rpc', or null. Default null.
 * @return string URL with chosen scheme.
 */
function set_url_scheme($url, $scheme = null)
{
    $orig_scheme = $scheme;
    if (!$scheme) {
        $scheme = is_ssl() ? 'https' : 'http';
    } elseif ('admin' === $scheme || 'login' === $scheme || 'login_post' === $scheme || 'rpc' === $scheme) {
        $scheme = (is_ssl() || force_ssl_admin()) ? 'https' : 'http';
    } elseif ('http' !== $scheme && 'https' !== $scheme && 'relative' !== $scheme) {
        $scheme = is_ssl() ? 'https' : 'http';
    }
    $url = trim($url);
    if (substr($url, 0, 2) === '//') {
        $url = 'http:' . $url;
    }
    if ('relative' === $scheme) {
        $url = ltrim(preg_replace('#^\w+://[^/]*#', '', $url));
        if ('' !== $url && '/' === $url[0]) {
            $url = '/' . ltrim($url, "/ \t\n\r\x00\v");
        }
    } else {
        $url = preg_replace('#^\w+://#', $scheme . '://', $url);
    }
    /**
     * Filters the resulting URL after setting the scheme.
     *
     * @since 3.4.0
     *
     * @param string      $url         The complete URL including scheme and path.
     * @param string      $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
     * @param string|null $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
     *                                 'login_post', 'admin', 'relative', 'rest', 'rpc', or null.
     */
    return apply_filters('set_url_scheme', $url, $scheme, $orig_scheme);
}

WordPress Version: 5.4

/**
 * Sets the scheme for a URL.
 *
 * @since 3.4.0
 * @since 4.4.0 The 'rest' scheme was added.
 *
 * @param string      $url    Absolute URL that includes a scheme
 * @param string|null $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login',
 *                            'login_post', 'admin', 'relative', 'rest', 'rpc', or null. Default null.
 * @return string $url URL with chosen scheme.
 */
function set_url_scheme($url, $scheme = null)
{
    $orig_scheme = $scheme;
    if (!$scheme) {
        $scheme = is_ssl() ? 'https' : 'http';
    } elseif ('admin' === $scheme || 'login' === $scheme || 'login_post' === $scheme || 'rpc' === $scheme) {
        $scheme = (is_ssl() || force_ssl_admin()) ? 'https' : 'http';
    } elseif ('http' !== $scheme && 'https' !== $scheme && 'relative' !== $scheme) {
        $scheme = is_ssl() ? 'https' : 'http';
    }
    $url = trim($url);
    if (substr($url, 0, 2) === '//') {
        $url = 'http:' . $url;
    }
    if ('relative' == $scheme) {
        $url = ltrim(preg_replace('#^\w+://[^/]*#', '', $url));
        if ('' !== $url && '/' === $url[0]) {
            $url = '/' . ltrim($url, "/ \t\n\r\x00\v");
        }
    } else {
        $url = preg_replace('#^\w+://#', $scheme . '://', $url);
    }
    /**
     * Filters the resulting URL after setting the scheme.
     *
     * @since 3.4.0
     *
     * @param string      $url         The complete URL including scheme and path.
     * @param string      $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
     * @param string|null $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
     *                                 'login_post', 'admin', 'relative', 'rest', 'rpc', or null.
     */
    return apply_filters('set_url_scheme', $url, $scheme, $orig_scheme);
}

WordPress Version: 4.6

/**
 * Sets the scheme for a URL.
 *
 * @since 3.4.0
 * @since 4.4.0 The 'rest' scheme was added.
 *
 * @param string      $url    Absolute URL that includes a scheme
 * @param string|null $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login',
 *                            'login_post', 'admin', 'relative', 'rest', 'rpc', or null. Default null.
 * @return string $url URL with chosen scheme.
 */
function set_url_scheme($url, $scheme = null)
{
    $orig_scheme = $scheme;
    if (!$scheme) {
        $scheme = is_ssl() ? 'https' : 'http';
    } elseif ($scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc') {
        $scheme = (is_ssl() || force_ssl_admin()) ? 'https' : 'http';
    } elseif ($scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative') {
        $scheme = is_ssl() ? 'https' : 'http';
    }
    $url = trim($url);
    if (substr($url, 0, 2) === '//') {
        $url = 'http:' . $url;
    }
    if ('relative' == $scheme) {
        $url = ltrim(preg_replace('#^\w+://[^/]*#', '', $url));
        if ($url !== '' && $url[0] === '/') {
            $url = '/' . ltrim($url, "/ \t\n\r\x00\v");
        }
    } else {
        $url = preg_replace('#^\w+://#', $scheme . '://', $url);
    }
    /**
     * Filters the resulting URL after setting the scheme.
     *
     * @since 3.4.0
     *
     * @param string      $url         The complete URL including scheme and path.
     * @param string      $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
     * @param string|null $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
     *                                 'login_post', 'admin', 'relative', 'rest', 'rpc', or null.
     */
    return apply_filters('set_url_scheme', $url, $scheme, $orig_scheme);
}

WordPress Version: 4.4

/**
 * Sets the scheme for a URL.
 *
 * @since 3.4.0
 * @since 4.4.0 The 'rest' scheme was added.
 *
 * @param string      $url    Absolute url that includes a scheme
 * @param string|null $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login',
 *                            'login_post', 'admin', 'relative', 'rest', 'rpc', or null. Default null.
 * @return string $url URL with chosen scheme.
 */
function set_url_scheme($url, $scheme = null)
{
    $orig_scheme = $scheme;
    if (!$scheme) {
        $scheme = is_ssl() ? 'https' : 'http';
    } elseif ($scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc') {
        $scheme = (is_ssl() || force_ssl_admin()) ? 'https' : 'http';
    } elseif ($scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative') {
        $scheme = is_ssl() ? 'https' : 'http';
    }
    $url = trim($url);
    if (substr($url, 0, 2) === '//') {
        $url = 'http:' . $url;
    }
    if ('relative' == $scheme) {
        $url = ltrim(preg_replace('#^\w+://[^/]*#', '', $url));
        if ($url !== '' && $url[0] === '/') {
            $url = '/' . ltrim($url, "/ \t\n\r\x00\v");
        }
    } else {
        $url = preg_replace('#^\w+://#', $scheme . '://', $url);
    }
    /**
     * Filter the resulting URL after setting the scheme.
     *
     * @since 3.4.0
     *
     * @param string      $url         The complete URL including scheme and path.
     * @param string      $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
     * @param string|null $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
     *                                 'login_post', 'admin', 'relative', 'rest', 'rpc', or null.
     */
    return apply_filters('set_url_scheme', $url, $scheme, $orig_scheme);
}

WordPress Version: 4.3

/**
 * Set the scheme for a URL
 *
 * @since 3.4.0
 *
 * @param string $url    Absolute url that includes a scheme
 * @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
 * @return string $url URL with chosen scheme.
 */
function set_url_scheme($url, $scheme = null)
{
    $orig_scheme = $scheme;
    if (!$scheme) {
        $scheme = is_ssl() ? 'https' : 'http';
    } elseif ($scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc') {
        $scheme = (is_ssl() || force_ssl_admin()) ? 'https' : 'http';
    } elseif ($scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative') {
        $scheme = is_ssl() ? 'https' : 'http';
    }
    $url = trim($url);
    if (substr($url, 0, 2) === '//') {
        $url = 'http:' . $url;
    }
    if ('relative' == $scheme) {
        $url = ltrim(preg_replace('#^\w+://[^/]*#', '', $url));
        if ($url !== '' && $url[0] === '/') {
            $url = '/' . ltrim($url, "/ \t\n\r\x00\v");
        }
    } else {
        $url = preg_replace('#^\w+://#', $scheme . '://', $url);
    }
    /**
     * Filter the resulting URL after setting the scheme.
     *
     * @since 3.4.0
     *
     * @param string $url         The complete URL including scheme and path.
     * @param string $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
     * @param string $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
     *                            'login_post', 'admin', 'rpc', or 'relative'.
     */
    return apply_filters('set_url_scheme', $url, $scheme, $orig_scheme);
}

WordPress Version: 4.0

/**
 * Set the scheme for a URL
 *
 * @since 3.4.0
 *
 * @param string $url Absolute url that includes a scheme
 * @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
 * @return string $url URL with chosen scheme.
 */
function set_url_scheme($url, $scheme = null)
{
    $orig_scheme = $scheme;
    if (!$scheme) {
        $scheme = is_ssl() ? 'https' : 'http';
    } elseif ($scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc') {
        $scheme = (is_ssl() || force_ssl_admin()) ? 'https' : 'http';
    } elseif ($scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative') {
        $scheme = is_ssl() ? 'https' : 'http';
    }
    $url = trim($url);
    if (substr($url, 0, 2) === '//') {
        $url = 'http:' . $url;
    }
    if ('relative' == $scheme) {
        $url = ltrim(preg_replace('#^\w+://[^/]*#', '', $url));
        if ($url !== '' && $url[0] === '/') {
            $url = '/' . ltrim($url, "/ \t\n\r\x00\v");
        }
    } else {
        $url = preg_replace('#^\w+://#', $scheme . '://', $url);
    }
    /**
     * Filter the resulting URL after setting the scheme.
     *
     * @since 3.4.0
     *
     * @param string $url         The complete URL including scheme and path.
     * @param string $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
     * @param string $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
     *                            'login_post', 'admin', 'rpc', or 'relative'.
     */
    return apply_filters('set_url_scheme', $url, $scheme, $orig_scheme);
}

WordPress Version: 3.9

/**
 * Set the scheme for a URL
 *
 * @since 3.4.0
 *
 * @param string $url Absolute url that includes a scheme
 * @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
 * @return string $url URL with chosen scheme.
 */
function set_url_scheme($url, $scheme = null)
{
    $orig_scheme = $scheme;
    if (!in_array($scheme, array('http', 'https', 'relative'))) {
        if (('login_post' == $scheme || 'rpc' == $scheme) && (force_ssl_login() || force_ssl_admin())) {
            $scheme = 'https';
        } elseif ('login' == $scheme && force_ssl_admin()) {
            $scheme = 'https';
        } elseif ('admin' == $scheme && force_ssl_admin()) {
            $scheme = 'https';
        } else {
            $scheme = is_ssl() ? 'https' : 'http';
        }
    }
    $url = trim($url);
    if (substr($url, 0, 2) === '//') {
        $url = 'http:' . $url;
    }
    if ('relative' == $scheme) {
        $url = ltrim(preg_replace('#^\w+://[^/]*#', '', $url));
        if ($url !== '' && $url[0] === '/') {
            $url = '/' . ltrim($url, "/ \t\n\r\x00\v");
        }
    } else {
        $url = preg_replace('#^\w+://#', $scheme . '://', $url);
    }
    /**
     * Filter the resulting URL after setting the scheme.
     *
     * @since 3.4.0
     *
     * @param string $url         The complete URL including scheme and path.
     * @param string $scheme      Scheme applied to the URL. One of 'http', 'https', or 'relative'.
     * @param string $orig_scheme Scheme requested for the URL. One of 'http', 'https', 'login',
     *                            'login_post', 'admin', 'rpc', or 'relative'.
     */
    return apply_filters('set_url_scheme', $url, $scheme, $orig_scheme);
}

WordPress Version: 3.7

/**
 * Set the scheme for a URL
 *
 * @since 3.4.0
 *
 * @param string $url Absolute url that includes a scheme
 * @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
 * @return string $url URL with chosen scheme.
 */
function set_url_scheme($url, $scheme = null)
{
    $orig_scheme = $scheme;
    if (!in_array($scheme, array('http', 'https', 'relative'))) {
        if (('login_post' == $scheme || 'rpc' == $scheme) && (force_ssl_login() || force_ssl_admin())) {
            $scheme = 'https';
        } elseif ('login' == $scheme && force_ssl_admin()) {
            $scheme = 'https';
        } elseif ('admin' == $scheme && force_ssl_admin()) {
            $scheme = 'https';
        } else {
            $scheme = is_ssl() ? 'https' : 'http';
        }
    }
    $url = trim($url);
    if (substr($url, 0, 2) === '//') {
        $url = 'http:' . $url;
    }
    if ('relative' == $scheme) {
        $url = ltrim(preg_replace('#^\w+://[^/]*#', '', $url));
        if ($url !== '' && $url[0] === '/') {
            $url = '/' . ltrim($url, "/ \t\n\r\x00\v");
        }
    } else {
        $url = preg_replace('#^\w+://#', $scheme . '://', $url);
    }
    return apply_filters('set_url_scheme', $url, $scheme, $orig_scheme);
}