Make WordPress Core

Ticket #31294: 31294.3.diff

File 31294.3.diff, 5.1 KB (added by ocean90, 10 years ago)
  • src/wp-admin/customize.php

     
    216216
    217217        $login_url = add_query_arg( array(
    218218                'interim-login' => 1,
    219                 'customize-login' => 1
     219                'customize-login' => 1,
     220                'theme' => $wp_customize->get_stylesheet(),
    220221        ), wp_login_url() );
    221222
    222223        // Prepare Customizer settings to pass to JavaScript.
  • src/wp-admin/js/customize-controls.js

     
    23582358
    23592359                        messenger.targetWindow( iframe[0].contentWindow );
    23602360
    2361                         messenger.bind( 'login', function() {
     2361                        messenger.bind( 'login', function ( params ) {
     2362                                api.trigger( 'nonce-refresh', params.nonce );
     2363
    23622364                                iframe.remove();
    23632365                                messenger.destroy();
    23642366                                delete previewer._login;
     
    25382540                        $.extend( this.nonce, nonce );
    25392541                });
    25402542
     2543                // Refresh the nonces if login sends updated nonces over.
     2544                api.bind( 'nonce-refresh', function( nonce ) {
     2545                        $.extend( api.settings.nonce, nonce );
     2546                        $.extend( api.previewer.nonce, nonce );
     2547                });
     2548
    25412549                // Create Settings
    25422550                $.each( api.settings.settings, function( id, data ) {
    25432551                        api.create( id, id, data.value, {
  • src/wp-admin/js/customize-widgets.js

     
    18981898                sidebar_widgets: api.Widgets.SidebarControl
    18991899        });
    19001900
     1901        // Refresh the nonces if login sends updated nonces over.
     1902        api.bind( 'nonce-refresh', function( nonce ) {
     1903                api.Widgets.data.nonce = nonce['update-widget'];
     1904        });
     1905
    19011906        /**
    19021907         * Init Customizer for widgets.
    19031908         */
  • src/wp-login.php

     
    767767default:
    768768        $secure_cookie = '';
    769769        $customize_login = isset( $_REQUEST['customize-login'] );
    770         if ( $customize_login )
     770        $customize_theme = null;
     771        if ( $customize_login ) {
    771772                wp_enqueue_script( 'customize-base' );
     773                if ( ! empty( $_REQUEST['theme'] ) ) {
     774                        $customize_theme = wp_unslash( $_REQUEST['theme'] );
     775                }
     776        }
    772777
    773778        // If the user wants ssl but the session is not ssl, force a secure cookie.
    774779        if ( !empty($_POST['log']) && !force_ssl_admin() ) {
     
    792797
    793798        $reauth = empty($_REQUEST['reauth']) ? false : true;
    794799
     800        $GLOBALS['_wp_login_logged_in_cookie'] = null;
     801
     802        /**
     803         * Workaround to obtain the LOGGED_IN_COOKIE when wp_signon() is called.
     804         *
     805         * @ignore
     806         * @since 4.2.0
     807         *
     808         * @param string $cookie The logged-in cookie.
     809         */
     810        function _capture_wp_login_logged_in_cookie( $cookie ) {
     811                $GLOBALS['_wp_login_logged_in_cookie'] = $cookie;
     812        }
     813
     814        add_action( 'set_logged_in_cookie', '_capture_wp_login_logged_in_cookie' );
    795815        $user = wp_signon( '', $secure_cookie );
     816        remove_action( 'set_logged_in_cookie', '_capture_wp_login_logged_in_cookie' );
    796817
    797818        if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
    798819                if ( headers_sent() ) {
     
    827848                        /** This action is documented in wp-login.php */
    828849                        do_action( 'login_footer' ); ?>
    829850                        <?php if ( $customize_login ) : ?>
    830                                 <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script>
     851                                <?php
     852                                $theme = wp_get_theme( $customize_theme );
     853                                $messenger_login_params = array(
     854                                        'url' => wp_customize_url(),
     855                                        'channel' => 'login',
     856                                );
     857                                $login_message = array();
     858
     859                                // Update Customizer nonces
     860                                if ( ! $theme->errors() ) {
     861                                        /*
     862                                         * Set the current user and auth cookie so that wp_create_nonce() will succeed;
     863                                         * wp_signon() calls wp_set_auth_cookie() which does not set $_COOKIE, and
     864                                         * wp_create_nonce() calls wp_get_session_token() which calls wp_parse_auth_cookie()
     865                                         * which expects the $_COOKIE to be set.
     866                                         */
     867                                        wp_set_current_user( $user->ID );
     868                                        $_COOKIE[ LOGGED_IN_COOKIE ] = $GLOBALS['_wp_login_logged_in_cookie'];
     869                                        $login_message['nonce'] = array(
     870                                                'save' => wp_create_nonce( 'save-customize_' . $theme->get_stylesheet() ),
     871                                                'preview' => wp_create_nonce( 'preview-customize_' . $theme->get_stylesheet() ),
     872                                                'update-widget' => wp_create_nonce( 'update-widget' ),
     873                                        );
     874                                }
     875
     876                                ?>
     877                                <script type="text/javascript">
     878                                        setTimeout( function () {
     879                                                var messenger = new wp.customize.Messenger( <?php echo wp_json_encode( $messenger_login_params ); ?> );
     880                                                messenger.send( 'login', <?php echo wp_json_encode( $login_message ); ?> );
     881                                        }, 1000 );
     882                                </script>
    831883                        <?php endif; ?>
    832884                        </body></html>
    833885<?php           exit;
     
    924976<?php   } ?>
    925977<?php   if ( $customize_login ) : ?>
    926978                <input type="hidden" name="customize-login" value="1" />
     979                <input type="hidden" name="theme" value="<?php echo esc_attr( $customize_theme ) ?>" />
    927980<?php   endif; ?>
    928981                <input type="hidden" name="testcookie" value="1" />
    929982        </p>