Make WordPress Core

Changeset 20828


Ignore:
Timestamp:
05/18/2012 08:04:59 PM (12 years ago)
Author:
ryan
Message:

Introduce set_url_scheme(). Includes get_site_url() logic for determining when to use http vs. https. Use this to rerite urls to obey is_ssl(). Props jkudish. fixes #18017

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/link-template.php

    r20685 r20828  
    21992199
    22002200/**
     2201 * Set the scheme for a URL
     2202 *
     2203 * @since 3.4.0
     2204 *
     2205 * @param string $url Absolute url that includes a scheme
     2206 * @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
     2207 * @return string $url URL with chosen scheme.
     2208 */
     2209function set_url_scheme( $url, $scheme = null ) {
     2210    $orig_scheme = $scheme;
     2211    if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
     2212        if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
     2213            $scheme = 'https';
     2214        elseif ( ( 'login' == $scheme ) && force_ssl_admin() )
     2215            $scheme = 'https';
     2216        elseif ( ( 'admin' == $scheme ) && force_ssl_admin() )
     2217            $scheme = 'https';
     2218        else
     2219            $scheme = ( is_ssl() ? 'https' : 'http' );
     2220    }
     2221
     2222    if ( 'relative' == $scheme )
     2223        $url = preg_replace( '#^.+://[^/]*#', '', $url );
     2224    else
     2225        $url = preg_replace( '#^.+://#', $scheme . '://', $url );
     2226
     2227    return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme );
     2228}
     2229
     2230/**
    22012231 * Get the URL to the user's dashboard.
    22022232 *
Note: See TracChangeset for help on using the changeset viewer.