Make WordPress Core

Ticket #20876: 20876.diff

File 20876.diff, 11.8 KB (added by nacin, 14 years ago)
  • wp-login.php

     
    8282        $login_header_url   = apply_filters( 'login_headerurl',   $login_header_url   );
    8383        $login_header_title = apply_filters( 'login_headertitle', $login_header_title );
    8484
     85        // Don't allow interim logins to navigate away from the page.
     86        if ( $interim_login )
     87                $login_header_url = '#';
     88
    8589        ?>
    8690        </head>
    8791        <body class="login<?php if ( wp_is_mobile() ) echo ' mobile'; ?>">
     
    126130 * @param string $input_id Which input to auto-focus
    127131 */
    128132function login_footer($input_id = '') {
    129         ?>
     133        global $interim_login;
     134
     135        // Don't allow interim logins to navigate away from the page.
     136        if ( ! $interim_login ): ?>
    130137        <p id="backtoblog"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php esc_attr_e( 'Are you lost?' ); ?>"><?php printf( __( '&larr; Back to %s' ), get_bloginfo( 'title', 'display' ) ); ?></a></p>
     138        <?php endif; ?>
     139
    131140        </div>
    132141
    133142        <?php if ( !empty($input_id) ) : ?>
     
    555564default:
    556565        $secure_cookie = '';
    557566        $interim_login = isset($_REQUEST['interim-login']);
     567        $customize_login = isset( $_REQUEST['customize-login'] );
     568        if ( $customize_login )
     569                wp_enqueue_script( 'customize-base' );
    558570
    559571        // If the user wants ssl but the session is not ssl, force a secure cookie.
    560572        if ( !empty($_POST['log']) && !force_ssl_admin() ) {
     
    592604                if ( $interim_login ) {
    593605                        $message = '<p class="message">' . __('You have logged in successfully.') . '</p>';
    594606                        login_header( '', $message ); ?>
     607
     608                        <?php if ( ! $customize_login ) : ?>
    595609                        <script type="text/javascript">setTimeout( function(){window.close()}, 8000);</script>
    596610                        <p class="alignright">
    597611                        <input type="button" class="button-primary" value="<?php esc_attr_e('Close'); ?>" onclick="window.close()" /></p>
    598                         </div></body></html>
     612                        <?php endif; ?>
     613                        </div>
     614                        <?php do_action( 'login_footer' ); ?>
     615                        <?php if ( $customize_login ) : ?>
     616                                <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script>
     617                        <?php endif; ?>
     618                        </body></html>
    599619<?php           exit;
    600620                }
    601621
     
    666686<?php   } else { ?>
    667687                <input type="hidden" name="redirect_to" value="<?php echo esc_attr($redirect_to); ?>" />
    668688<?php   } ?>
     689<?php   if ( $customize_login ) : ?>
     690                <input type="hidden" name="customize-login" value="1" />
     691<?php   endif; ?>
    669692                <input type="hidden" name="testcookie" value="1" />
    670693        </p>
    671694</form>
  • wp-includes/class-wp-customize-manager.php

     
    1717        protected $sections = array();
    1818        protected $controls = array();
    1919
     20        protected $nonce_tick;
     21
    2022        protected $customized;
    2123
    2224        private $_post_values;
     
    3133                require( ABSPATH . WPINC . '/class-wp-customize-section.php' );
    3234                require( ABSPATH . WPINC . '/class-wp-customize-control.php' );
    3335
     36                add_filter( 'wp_die_handler', array( $this, 'wp_die_handler' ) );
     37
    3438                add_action( 'setup_theme',  array( $this, 'setup_theme' ) );
    3539                add_action( 'wp_loaded',    array( $this, 'wp_loaded' ) );
    3640
     
    5357        }
    5458
    5559        /**
     60         * Return true if it's an AJAX request.
     61         *
     62         * @since 3.4.0
     63         */
     64        public function doing_ajax() {
     65                return isset( $_POST['customized'] ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX );
     66        }
     67
     68        /**
     69         * Custom wp_die wrapper. Returns either the standard message for UI
     70         * or the AJAX message.
     71         *
     72         * @param  mixed $ajax_message AJAX return
     73         * @param  mixed $message      UI message
     74         *
     75         * @since 3.4.0
     76         */
     77        private function wp_die( $ajax_message, $message ) {
     78                if ( $this->doing_ajax() )
     79                        wp_die( $ajax_message );
     80
     81                wp_die( $message );
     82        }
     83
     84        /**
     85         * Return the AJAX wp_die() handler if it's a customized request.
     86         *
     87         * @since 3.4.0
     88         */
     89        public function wp_die_handler() {
     90                if ( $this->doing_ajax() )
     91                        return '_ajax_wp_die_handler';
     92
     93                return '_default_wp_die_handler';
     94        }
     95
     96        /**
    5697         * Start preview and customize theme.
    5798         *
    5899         * Check if customize query variable exist. Init filters to filter the current theme.
     
    60101         * @since 3.4.0
    61102         */
    62103        public function setup_theme() {
    63                 if ( is_admin() && ! defined( 'DOING_AJAX' ) )
    64                         auth_redirect();
     104                if ( is_admin() && ! $this->doing_ajax() )
     105                    auth_redirect();
     106                elseif ( $this->doing_ajax() && ! is_user_logged_in() )
     107                    wp_die( 0 );
    65108
    66109                send_origin_headers();
    67110
     
    71114
    72115                // You can't preview a theme if it doesn't exist, or if it is not allowed (unless active).
    73116                if ( ! $this->theme->exists() )
    74                         wp_die( __( 'Cheatin&#8217; uh?' ) );
     117                        $this->wp_die( -1, __( 'Cheatin&#8217; uh?' ) );
    75118
    76119                if ( $this->theme->get_stylesheet() != get_stylesheet() && ( ! $this->theme()->is_allowed() || ! current_user_can( 'switch_themes' ) ) )
    77                         wp_die( __( 'Cheatin&#8217; uh?' ) );
     120                        $this->wp_die( -1, __( 'Cheatin&#8217; uh?' ) );
    78121
    79122                if ( ! current_user_can( 'edit_theme_options' ) )
    80                         wp_die( __( 'Cheatin&#8217; uh?' ) );
     123                        $this->wp_die( -1, __( 'Cheatin&#8217; uh?' ) );
    81124
     125                if ( $this->doing_ajax() && ! defined( 'DOING_AJAX' ) ) // Fire on previews.
     126                        $this->nonce_tick = check_ajax_referer( 'customize_preview-' . $this->get_stylesheet(), 'nonce' );
     127
    82128                $this->start_previewing_theme();
    83129                show_admin_bar( false );
    84130        }
     
    300346                        'backgroundImageHasDefault' => current_theme_supports( 'custom-background', 'default-image' ),
    301347                );
    302348
     349                if ( 2 == $this->nonce_tick ) {
     350                        $settings['customize-controls-nonce'] = wp_create_nonce( 'customize-controls-' . $this->get_stylesheet() );
     351                        $settings['customize-preview-nonce'] = wp_create_nonce( 'customize_preview-' . $this->get_stylesheet() );
     352                }
     353
    303354                foreach ( $this->settings as $id => $setting ) {
    304355                        $settings['values'][ $id ] = $setting->js_value();
    305356                }
     
    9491000                return '#' . $unhashed;
    9501001
    9511002        return $color;
    952 }
    953  No newline at end of file
     1003}
  • wp-includes/script-loader.php

     
    305305                'saved'     => __( 'Saved' ),
    306306                'cancel'    => __( 'Cancel' ),
    307307                'close'     => __( 'Close' ),
     308                'cheatin'   => __( 'Cheatin&#8217; uh?' ),
    308309        ) );
    309310
    310311        if ( is_admin() ) {
  • wp-admin/customize.php

     
    77 * @since 3.4.0
    88 */
    99
     10define( 'IFRAME_REQUEST', true );
     11
    1012require_once( './admin.php' );
    1113if ( ! current_user_can( 'edit_theme_options' ) )
    1214        wp_die( __( 'Cheatin&#8217; uh?' ) );
     
    5759<body class="<?php echo esc_attr( $body_class ); ?>">
    5860<div class="wp-full-overlay expanded">
    5961        <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
    60                 <?php wp_nonce_field( 'customize_controls-' . $wp_customize->get_stylesheet() ); ?>
     62                <?php wp_nonce_field( 'customize_controls-' . $wp_customize->get_stylesheet(), 'customize-controls-nonce', false ); ?>
     63                <?php wp_nonce_field( 'customize_preview-' . $wp_customize->get_stylesheet(), 'customize-preview-nonce', false ); ?>
    6164                <div id="customize-header-actions" class="wp-full-overlay-header">
    6265                        <?php
    6366                                $save_text = $wp_customize->is_theme_active() ? __( 'Save &amp; Publish' ) : __( 'Save &amp; Activate' );
     
    140143                'TB_iframe'      => 'true'
    141144        ), home_url( '/' ) );
    142145
     146        $login_url = add_query_arg( array(
     147                'interim-login' => 1,
     148                'customize-login' => 1
     149        ), wp_login_url() );
     150
    143151        $settings = array(
    144152                'theme'    => array(
    145153                        'stylesheet' => $wp_customize->get_stylesheet(),
     
    153161                        'allowed'       => array_map( 'esc_url', $allowed_urls ),
    154162                        'isCrossDomain' => $cross_domain,
    155163                        'fallback'      => $fallback_url,
     164                        'login'         => $login_url,
    156165                ),
    157166                'browser'  => array(
    158167                        'mobile' => wp_is_mobile(),
  • wp-admin/js/customize-controls.dev.js

     
    334334                                        return;
    335335                                }
    336336
     337                                // Check if the user is not logged in.
     338                                if ( '0' === response ) {
     339                                        deferred.rejectWith( self, [ 'logged out' ] );
     340                                        return;
     341                                }
     342
     343                                // Check for cheaters.
     344                                if ( '-1' === response ) {
     345                                        deferred.rejectWith( self, [ 'cheatin' ] );
     346                                        return;
     347                                }
     348
    337349                                // Check for a signature in the request.
    338350                                index = response.lastIndexOf( signature );
    339351                                if ( -1 === index || index < response.lastIndexOf('</html>') ) {
     
    541553                        this.loading.fail( function( reason, location ) {
    542554                                if ( 'redirect' === reason && location )
    543555                                        self.url( location );
     556
     557                                if ( 'logged out' === reason ) {
     558                                        if ( self.iframe ) {
     559                                                self.iframe.destroy();
     560                                                delete self.iframe;
     561                                        }
     562
     563                                        self.login().done( self.refresh );
     564                                }
     565
     566                                if ( 'cheatin' === reason )
     567                                        self.cheatin();
    544568                        });
     569                },
     570
     571                login: function() {
     572                        var previewer = this,
     573                                deferred, messenger, iframe;
     574
     575                        if ( this._login )
     576                                return this._login;
     577
     578                        deferred = $.Deferred();
     579                        this._login = deferred.promise();
     580
     581                        messenger = new api.Messenger({
     582                                channel: 'login',
     583                                url:     api.settings.url.login
     584                        });
     585
     586                        iframe = $('<iframe src="' + api.settings.url.login + '" />').appendTo( this.container );
     587
     588                        messenger.targetWindow( iframe[0].contentWindow );
     589
     590                        messenger.bind( 'login', function() {
     591                                iframe.remove();
     592                                messenger.destroy();
     593                                delete previewer._login;
     594                                deferred.resolve();
     595                        });
     596
     597                        return this._login;
     598                },
     599
     600                cheatin: function() {
     601                        $( document.body ).empty().addClass('cheatin').append( '<p>' + api.l10n.cheatin + '</p>' );
    545602                }
    546603        });
    547604
     
    587644                        url:         api.settings.url.preview,
    588645                        allowedUrls: api.settings.url.allowed
    589646                }, {
     647
     648                        p_nonce: $('#customize-preview-nonce').val(),
     649                        c_nonce: $('#customize-controls-nonce').val(),
     650
    590651                        query: function() {
    591652                                return {
    592653                                        wp_customize: 'on',
    593654                                        theme:        api.settings.theme.stylesheet,
    594                                         customized:   JSON.stringify( api.get() )
     655                                        customized:   JSON.stringify( api.get() ),
     656                                        nonce:        this.p_nonce
     657                                       
    595658                                };
    596659                        },
    597660
    598                         nonce: $('#_wpnonce').val(),
    599 
    600661                        save: function() {
    601                                 var query = $.extend( this.query(), {
     662                                var self  = this,
     663                                        query = $.extend( this.query(), {
    602664                                                action: 'customize_save',
    603                                                 nonce:  this.nonce
     665                                                nonce:  this.c_nonce
    604666                                        }),
    605667                                        request = $.post( api.settings.url.ajax, query );
    606668
     
    612674                                        body.removeClass('saving');
    613675                                });
    614676
    615                                 request.done( function() {
     677                                request.done( function( response ) {
     678                                        // Check if the user is logged out.
     679                                        if ( '0' === response ) {
     680                                                self.iframe.iframe.hide();
     681                                                self.login().done( function() {
     682                                                        self.save();
     683                                                        self.iframe.iframe.show();
     684                                                });
     685                                                return;
     686                                        }
     687
     688                                        // Check for cheaters.
     689                                        if ( '-1' === response ) {
     690                                                self.cheatin();
     691                                                return;
     692                                        }
     693
    616694                                        api.trigger( 'saved' );
    617695                                });
    618696                        }
  • wp-admin/css/customize-controls.dev.css

     
    514514        -webkit-overflow-scrolling: touch;
    515515}
    516516
     517/**
     518 * Handle cheaters.
     519 */
     520body.cheatin {
     521        min-width: 0;
     522        background: #f9f9f9;
     523        padding: 50px;
     524}
     525
     526body.cheatin p {
     527        max-width: 700px;
     528        margin: 0 auto;
     529        padding: 2em;
     530        font-size: 14px;
     531
     532        background: #fff;
     533        border: 1px solid #dfdfdf;
     534
     535        -webkit-border-radius: 3px;
     536        border-radius:         3px;
     537}
     538 No newline at end of file