WordPress.org

Make WordPress Core

Ticket #17048: patch17048_draft.diff

File patch17048_draft.diff, 20.7 KB (added by edwardw, 3 years ago)

Proof-of-concept draft patch for root-relative URLs (not final)

  • wp-login.php

     
    216216        $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n"; 
    217217        $message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n"; 
    218218        $message .= __('To reset your password, visit the following address:') . "\r\n\r\n"; 
    219         $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n"; 
     219        $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login', 'absolute') . ">\r\n"; 
    220220 
    221221        if ( is_multisite() ) 
    222222                $blogname = $GLOBALS['current_site']->site_name; 
  • wp-includes/feed-rss2.php

     
    5050                <content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded> 
    5151        <?php endif; ?> 
    5252<?php endif; ?> 
    53                 <wfw:commentRss><?php echo esc_url( get_post_comments_feed_link(null, 'rss2') ); ?></wfw:commentRss> 
     53                <wfw:commentRss><?php echo esc_url( get_post_comments_feed_link(null, 'rss2', 'absolute') ); ?></wfw:commentRss> 
    5454                <slash:comments><?php echo get_comments_number(); ?></slash:comments> 
    5555<?php rss_enclosure(); ?> 
    5656        <?php do_action('rss2_item'); ?> 
  • wp-includes/default-constants.php

     
    8080 */ 
    8181function wp_plugin_directory_constants( ) { 
    8282        if ( !defined('WP_CONTENT_URL') ) 
    83                 define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); // full url - WP_CONTENT_DIR is defined further up 
     83                define( 'WP_CONTENT_URL', get_site_url(null, '', null, 'root_relative') . '/wp-content'); // full url - WP_CONTENT_DIR is defined further up 
    8484 
    8585        /** 
    8686         * Allows for the plugins directory to be moved from the default location. 
  • wp-includes/comment-template.php

     
    467467 * 
    468468 * @param object|string|int $comment Comment to retrieve. 
    469469 * @param array $args Optional args. 
     470 * @param string $type Type of link - either 'absolute' or 'root_relative' (default). 
    470471 * @return string The permalink to the given comment. 
    471472 */ 
    472 function get_comment_link( $comment = null, $args = array() ) { 
     473function get_comment_link( $comment = null, $args = array(), $type = 'root_relative' ) { 
    473474        global $wp_rewrite, $in_comment_loop; 
    474475 
    475476        $comment = get_comment($comment); 
     
    497498                        $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args ); 
    498499 
    499500                if ( $wp_rewrite->using_permalinks() ) 
    500                         $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' ); 
     501                        $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID, false, $type ) ) . 'comment-page-' . $args['page'], 'comment' ); 
    501502                else 
    502                         $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) ); 
     503                        $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID, false, $type ) ); 
    503504        } else { 
    504                 $link = get_permalink( $comment->comment_post_ID ); 
     505                $link = get_permalink( $comment->comment_post_ID, false, $type ); 
    505506        } 
    506507 
    507508        return apply_filters( 'get_comment_link', $link . '#comment-' . $comment->comment_ID, $comment, $args ); 
     
    513514 * @since 1.5.0 
    514515 * 
    515516 * @param int $post_id Optional post id 
     517 * @param string $type Type of link - 'absolute' or 'root_relative' (default) 
    516518 * @return string The link to the comments 
    517519 */ 
    518 function get_comments_link($post_id = 0) { 
    519         return get_permalink($post_id) . '#comments'; 
     520function get_comments_link($post_id = 0, $type = 'root_relative') { 
     521        return get_permalink($post_id, false, $type) . '#comments'; 
    520522} 
    521523 
    522524/** 
  • wp-includes/link-template.php

     
    7575 * 
    7676 * @param int $id Optional. Post ID. 
    7777 * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name. 
     78 * @param string $type Optional. Either 'absolute' or 'root_relative'. Defaults to 'root_relative'. 
    7879 * @return string 
    7980 */ 
    80 function get_permalink($id = 0, $leavename = false) { 
     81function get_permalink($id = 0, $leavename = false, $type = 'root_relative') { 
    8182        $rewritecode = array( 
    8283                '%year%', 
    8384                '%monthnum%', 
     
    155156                        $author, 
    156157                        $post->post_name, 
    157158                ); 
    158                 $permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) ); 
     159                $permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink), null, $type ); 
    159160                $permalink = user_trailingslashit($permalink, 'single'); 
    160161        } else { // if they're not using the fancy permalink option 
    161                 $permalink = home_url('?p=' . $post->ID); 
     162                $permalink = home_url('?p=' . $post->ID, null, $type); 
    162163        } 
    163164        return apply_filters('post_link', $permalink, $post, $leavename); 
    164165} 
     
    463464 * 
    464465 * @param int $post_id Optional. Post ID. 
    465466 * @param string $feed Optional. Feed type. 
     467 * @param string $type Optional. Either 'absolute' or 'root_relative'. Defaults to root_relative. 
    466468 * @return string 
    467469 */ 
    468 function get_post_comments_feed_link($post_id = 0, $feed = '') { 
     470function get_post_comments_feed_link($post_id = 0, $feed = '', $type = 'root_relative') { 
    469471        $post_id = absint( $post_id ); 
    470472 
    471473        if ( ! $post_id ) 
     
    485487                        $url .= "/$feed"; 
    486488                $url = user_trailingslashit($url, 'single_feed'); 
    487489        } else { 
    488                 $type = get_post_field('post_type', $post_id); 
    489                 if ( 'page' == $type ) 
    490                         $url = home_url("?feed=$feed&amp;page_id=$post_id"); 
     490                $post_type = get_post_field('post_type', $post_id); 
     491                if ( 'page' == $post_type ) 
     492                        $url = home_url("?feed=$feed&amp;page_id=$post_id", null, $type); 
    491493                else 
    492                         $url = home_url("?feed=$feed&amp;p=$post_id"); 
     494                        $url = home_url("?feed=$feed&amp;p=$post_id", null, $type); 
    493495        } 
    494496 
    495497        return apply_filters('post_comments_feed_link', $url); 
     
    19441946 * 
    19451947 * @uses get_home_url() 
    19461948 * 
    1947  * @param  string $path   (optional) Path relative to the home url. 
    1948  * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http','https' 
     1949 * @param string $path   (optional) Path relative to the home url. 
     1950 * @param string $scheme (optional) Scheme to give the home url context. Currently 'http','https' 
     1951 * @param string $type Optional. Type of link - either 'absolute' or 'root_relative'. Defaults to root_relative. 
    19491952 * @return string Home url link with optional path appended. 
    19501953*/ 
    1951 function home_url( $path = '', $scheme = null ) { 
    1952         return get_home_url(null, $path, $scheme); 
     1954function home_url( $path = '', $scheme = null, $type = 'root_relative' ) { 
     1955        return get_home_url(null, $path, $scheme, $type); 
    19531956} 
    19541957 
    19551958/** 
     
    19671970 * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http','https' 
    19681971 * @return string Home url link with optional path appended. 
    19691972*/ 
    1970 function get_home_url( $blog_id = null, $path = '', $scheme = null ) { 
     1973function get_home_url( $blog_id = null, $path = '', $scheme = null, $type = 'root_relative' ) { 
    19711974        $orig_scheme = $scheme; 
    19721975 
    19731976        if ( !in_array( $scheme, array( 'http', 'https' ) ) ) 
     
    19801983 
    19811984        if ( 'http' != $scheme ) 
    19821985                $url = str_replace( 'http://', "$scheme://", $url ); 
     1986                 
     1987        if ( $type == 'root_relative' ) { 
     1988                $url_parts = parse_url($url); 
     1989                $url = $url_parts['path'] . (array_key_exists('query',$url_parts) ? '?'.$url_parts['query'] : ''); 
     1990        } 
    19831991 
    19841992        if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) 
    19851993                $url .= '/' . ltrim( $path, '/' ); 
     
    20012009 * 
    20022010 * @param string $path Optional. Path relative to the site url. 
    20032011 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'. 
     2012 * @param string $type Optional. Type of link - either 'absolute' or 'root_relative'. Defaults to root_relative. 
    20042013 * @return string Site url link with optional path appended. 
    20052014*/ 
    2006 function site_url( $path = '', $scheme = null ) { 
    2007         return get_site_url(null, $path, $scheme); 
     2015function site_url( $path = '', $scheme = null, $type = 'root_relative' ) { 
     2016        return get_site_url(null, $path, $scheme, $type); 
    20082017} 
    20092018 
    20102019/** 
     
    20202029 * @param int $blog_id (optional) Blog ID. Defaults to current blog. 
    20212030 * @param string $path Optional. Path relative to the site url. 
    20222031 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'. 
     2032 * @param string $type Optional. Type of link - either 'absolute' or 'root_relative'. Defaults to root_relative. 
    20232033 * @return string Site url link with optional path appended. 
    20242034*/ 
    2025 function get_site_url( $blog_id = null, $path = '', $scheme = null ) { 
     2035function get_site_url( $blog_id = null, $path = '', $scheme = null, $type = 'root_relative' ) { 
    20262036        // should the list of allowed schemes be maintained elsewhere? 
    20272037        $orig_scheme = $scheme; 
    20282038        if ( !in_array( $scheme, array( 'http', 'https' ) ) ) { 
     
    20442054        if ( 'http' != $scheme ) 
    20452055                $url = str_replace( 'http://', "{$scheme}://", $url ); 
    20462056 
     2057        if ( $type == 'root_relative' ) { 
     2058                $url_parts = parse_url($url); 
     2059                $url = $url_parts['path'] . (array_key_exists('query',$url_parts) ? '?'.$url_parts['query'] : ''); 
     2060        } 
     2061 
    20472062        if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) 
    20482063                $url .= '/' . ltrim( $path, '/' ); 
    20492064 
     
    21182133 
    21192134        if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) 
    21202135                $url .= '/' . ltrim($path, '/'); 
    2121  
     2136         
    21222137        return apply_filters('content_url', $url, $path); 
    21232138} 
    21242139 
     
    21732188 * 
    21742189 * @param string $path Optional. Path relative to the site url. 
    21752190 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http','https', 'login', 'login_post', or 'admin'. 
     2191 * @param string $type Optional. Either 'absolute' or 'root_relative'. Defaults to 'root_relative'. 
    21762192 * @return string Site url link with optional path appended. 
    21772193*/ 
    2178 function network_site_url( $path = '', $scheme = null ) { 
     2194function network_site_url( $path = '', $scheme = null, $type = 'root_relative' ) { 
    21792195        global $current_site; 
    21802196 
    21812197        if ( !is_multisite() ) 
    2182                 return site_url($path, $scheme); 
     2198                return site_url($path, $scheme, $type); 
    21832199 
    21842200        $orig_scheme = $scheme; 
    21852201        if ( !in_array($scheme, array('http', 'https')) ) { 
     
    21982214        if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) 
    21992215                $url .= ltrim($path, '/'); 
    22002216 
     2217        if ( $type == 'root_relative' ) { 
     2218                $url_parts = parse_url($url); 
     2219                $url = $url_parts['path'] . (array_key_exists('query',$url_parts) ? '?'.$url_parts['query'] : ''); 
     2220        } 
     2221 
    22012222        return apply_filters('network_site_url', $url, $path, $orig_scheme); 
    22022223} 
    22032224 
     
    22132234 * 
    22142235 * @param  string $path   (optional) Path relative to the home url. 
    22152236 * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http','https' 
     2237 * @param  string $type   (optional) Type of URL. Either 'absolute' or (default)'root_relative' 
    22162238 * @return string Home url link with optional path appended. 
    22172239*/ 
    2218 function network_home_url( $path = '', $scheme = null ) { 
     2240function network_home_url( $path = '', $scheme = null, $type = 'root_relative' ) { 
    22192241        global $current_site; 
    22202242 
    22212243        if ( !is_multisite() ) 
    2222                 return home_url($path, $scheme); 
     2244                return home_url($path, $scheme, $type); 
    22232245 
    22242246        $orig_scheme = $scheme; 
    22252247 
     
    22312253        if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) 
    22322254                $url .= ltrim( $path, '/' ); 
    22332255 
     2256        if ( $type == 'root_relative' ) { 
     2257                $url_parts = parse_url($url); 
     2258                $url = $url_parts['path'] . (array_key_exists('query',$url_parts) ? '?'.$url_parts['query'] : ''); 
     2259        } 
     2260 
    22342261        return apply_filters( 'network_home_url', $url, $path, $orig_scheme); 
    22352262} 
    22362263 
  • wp-includes/feed-rss2-comments.php

     
    2626                        printf(ent2ncr(__('Comments for %s')), get_bloginfo_rss( 'name' ) . get_wp_title_rss()); 
    2727        ?></title> 
    2828        <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" /> 
    29         <link><?php (is_single()) ? the_permalink_rss() : bloginfo_rss("url") ?></link> 
     29        <link><?php if(is_single()) { the_permalink_rss(); } else { echo home_url('',null,'absolute'); } ?></link> 
    3030        <description><?php bloginfo_rss("description") ?></description> 
    3131        <lastBuildDate><?php echo mysql2date('r', get_lastcommentmodified('GMT')); ?></lastBuildDate> 
    3232        <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod> 
     
    4747                                printf(ent2ncr(__('By: %s')), get_comment_author_rss()); 
    4848                        } 
    4949                ?></title> 
    50                 <link><?php comment_link() ?></link> 
     50                <link><?php comment_link('absolute') ?></link> 
    5151                <dc:creator><?php echo get_comment_author_rss() ?></dc:creator> 
    5252                <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true, false), false); ?></pubDate> 
    5353                <guid isPermaLink="false"><?php comment_guid() ?></guid> 
  • wp-includes/general-template.php

     
    229229 * 
    230230 * @param string $redirect Path to redirect to on login. 
    231231 * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false. 
     232 * @param string $type Absolute or relative url - 'absolute' or 'root_relative' (default). 
    232233 * @return string A log in url 
    233234 */ 
    234 function wp_login_url($redirect = '', $force_reauth = false) { 
    235         $login_url = site_url('wp-login.php', 'login'); 
     235function wp_login_url($redirect = '', $force_reauth = false, $type = 'root_relative') { 
     236        $login_url = site_url('wp-login.php', 'login', $type); 
    236237 
    237238        if ( !empty($redirect) ) 
    238239                $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url); 
  • wp-includes/canonical.php

     
    287287                $redirect = @parse_url($redirect_url); 
    288288 
    289289        // www.example.com vs example.com 
    290         $user_home = @parse_url(home_url()); 
     290        $user_home = @parse_url(home_url('',null,'absolute')); 
    291291        if ( !empty($user_home['host']) ) 
    292292                $redirect['host'] = $user_home['host']; 
    293293        if ( empty($user_home['path']) ) 
  • wp-includes/pluggable.php

     
    12401240 
    12411241        $message  = sprintf(__('Username: %s'), $user_login) . "\r\n"; 
    12421242        $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n"; 
    1243         $message .= wp_login_url() . "\r\n"; 
     1243        $message .= wp_login_url('',false,'absolute') . "\r\n"; 
    12441244 
    12451245        wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message); 
    12461246 
  • wp-includes/feed.php

     
    187187 * @uses apply_filters() Call 'the_permalink_rss' on the post permalink 
    188188 */ 
    189189function the_permalink_rss() { 
    190         echo esc_url( apply_filters('the_permalink_rss', get_permalink() )); 
     190        echo esc_url( apply_filters('the_permalink_rss', get_permalink(0,false,'absolute') )); 
    191191} 
    192192 
    193193/** 
     
    197197 * @return none 
    198198 */ 
    199199function comments_link_feed() { 
    200         echo esc_url( get_comments_link() ); 
     200        echo esc_url( get_comments_link(0,'absolute') ); 
    201201} 
    202202 
    203203/** 
     
    236236 * Display the link to the comments. 
    237237 * 
    238238 * @since 1.5.0 
     239 * @param $type Optional. Type of link - either 'absolute' or 'root_relative' (default) 
    239240 */ 
    240 function comment_link() { 
    241         echo esc_url( get_comment_link() ); 
     241function comment_link($type = 'root_relative') { 
     242        echo esc_url( get_comment_link(null, Array(), $type) ); 
    242243} 
    243244 
    244245/** 
     
    486487 * @since 2.5 
    487488 */ 
    488489function self_link() { 
    489         $host = @parse_url(home_url()); 
    490         $host = $host['host']; 
     490        $host_array = @parse_url(home_url('',null,'absolute')); 
     491        $host = $host_array['host']; 
    491492        echo esc_url( 
    492493                'http' 
    493494                . ( (isset($_SERVER['https']) && $_SERVER['https'] == 'on') ? 's' : '' ) . '://' 
    494495                . $host 
     496                . ( (array_key_exists('port',$host_array)) ? ':'.strval($host_array['port']) : '') 
    495497                . stripslashes($_SERVER['REQUEST_URI']) 
    496498                ); 
    497499} 
  • xmlrpc.php

     
    3838    <engineLink>http://wordpress.org/</engineLink> 
    3939    <homePageLink><?php bloginfo_rss('url') ?></homePageLink> 
    4040    <apis> 
    41       <api name="WordPress" blogID="1" preferred="true" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" /> 
    42       <api name="Movable Type" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" /> 
    43       <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" /> 
    44       <api name="Blogger" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" /> 
    45       <api name="Atom" blogID="" preferred="false" apiLink="<?php echo site_url('wp-app.php/service', 'rpc') ?>" /> 
     41      <api name="WordPress" blogID="1" preferred="true" apiLink="<?php echo site_url('xmlrpc.php', 'rpc', 'absolute') ?>" /> 
     42      <api name="Movable Type" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc', 'absolute') ?>" /> 
     43      <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc', 'absolute') ?>" /> 
     44      <api name="Blogger" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc', 'absolute') ?>" /> 
     45      <api name="Atom" blogID="" preferred="false" apiLink="<?php echo site_url('wp-app.php/service', 'rpc', 'absolute') ?>" /> 
    4646    </apis> 
    4747  </service> 
    4848</rsd> 
  • wp-admin/includes/ms.php

     
    237237        $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content ); 
    238238        $content = str_replace( '###EMAIL###', $value, $content ); 
    239239        $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content ); 
    240         $content = str_replace( '###SITEURL###', network_home_url(), $content ); 
     240        $content = str_replace( '###SITEURL###', network_home_url('',null,'absolute'), $content ); 
    241241 
    242242        wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), get_option( 'blogname' ) ), $content ); 
    243243} 
     
    290290                $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content ); 
    291291                $content = str_replace( '###EMAIL###', $_POST['email'], $content); 
    292292                $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content ); 
    293                 $content = str_replace( '###SITEURL###', network_home_url(), $content ); 
     293                $content = str_replace( '###SITEURL###', network_home_url('',null,'absolute'), $content ); 
    294294 
    295295                wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), get_option( 'blogname' ) ), $content ); 
    296296                $_POST['email'] = $current_user->user_email; 
  • wp-admin/user-new.php

     
    7373                        $newuser_key = substr( md5( $user_id ), 0, 5 ); 
    7474                        add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) ); 
    7575                        $message = __("Hi,\n\nYou have been invited to join '%s' at\n%s with the role of %s.\nPlease click the following link to confirm the invite:\n%s\n"); 
    76                         wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ),  sprintf($message, get_option('blogname'), site_url(), $_REQUEST[ 'role' ], site_url("/newbloguser/$newuser_key/"))); 
     76                        wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ),  sprintf($message, get_option('blogname'), site_url('',null,'absolute'), $_REQUEST[ 'role' ], site_url("/newbloguser/$newuser_key/",null,'absolute'))); 
    7777                        $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' ); 
    7878                } 
    7979        }