WordPress.org

Make WordPress Core

Ticket #23225: 23225.2.patch

File 23225.2.patch, 1.8 KB (added by westonruter, 5 years ago)

https://github.com/xwpco/wordpress-develop/commit/1c972d16bd3a50f6a64161bcbacc535447aaee74 https://github.com/xwpco/wordpress-develop/pull/30

  • src/wp-includes/class-wp-customize-manager.php

    diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
    index c658198..a762134 100644
    final class WP_Customize_Manager { 
    424424                add_action( 'wp_head', array( $this, 'customize_preview_base' ) );
    425425                add_action( 'wp_head', array( $this, 'customize_preview_html5' ) );
    426426                add_action( 'wp_footer', array( $this, 'customize_preview_settings' ), 20 );
     427                add_action( 'wp_footer', array( $this, 'customize_preview_base_hash_url_fix' ), 30 );
    427428                add_action( 'shutdown', array( $this, 'customize_preview_signature' ), 1000 );
    428429                add_filter( 'wp_die_handler', array( $this, 'remove_preview_signature' ) );
    429430
    final class WP_Customize_Manager { 
    461462         * @since 3.4.0
    462463         */
    463464        public function customize_preview_base() {
    464                 ?><base href="<?php echo home_url( '/' ); ?>" /><?php
     465                // Note: we cannot just pass $_SERVER[REQUEST_URI] directly to home_url() because of subdirectory installs
     466                $host = parse_url( home_url(), PHP_URL_HOST );
     467                $base_href = '//' . $host . wp_unslash( $_SERVER['REQUEST_URI'] );
     468                ?><base href="<?php echo esc_url( $base_href ); ?>" /><?php
    465469        }
    466470
    467471        /**
    final class WP_Customize_Manager { 
    516520        }
    517521
    518522        /**
     523         * Print script to allow hash URLs to work as expected
     524         *
     525         * @since 4.1
     526         */
     527        public function customize_preview_base_hash_url_fix() {
     528                wp_print_scripts( array( 'jquery' ) );
     529                ?><script>
     530                (function( $ ){
     531                        var base = $( 'head > base[href]:last' ),
     532                                baseUrl = base.prop( 'href' ).replace( /#.*/, '' );
     533                        $( 'a[href^="#"]' ).attr( 'href', function ( i, hash ) {
     534                                return baseUrl + hash;
     535                        } );
     536                })( jQuery );
     537                </script><?php
     538        }
     539
     540        /**
    519541         * Prints a signature so we can ensure the customizer was properly executed.
    520542         *
    521543         * @since 3.4.0