Make WordPress Core

Changeset 21136


Ignore:
Timestamp:
06/26/2012 06:53:45 PM (14 years ago)
Author:
nacin
Message:

Refresh nonces in the customizer. props koopersmith. see #20876 for 3.4.

Location:
branches/3.4
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/3.4/wp-admin/customize.php

    r21069 r21136  
    88 */
    99
     10define( 'IFRAME_REQUEST', true );
     11
    1012require_once( './admin.php' );
    1113if ( ! current_user_can( 'edit_theme_options' ) )
     
    6668<div class="wp-full-overlay expanded">
    6769        <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
    68                 <?php wp_nonce_field( 'customize_controls-' . $wp_customize->get_stylesheet() ); ?>
    6970                <div id="customize-header-actions" class="wp-full-overlay-header">
    7071                        <?php
     
    176177                'settings' => array(),
    177178                'controls' => array(),
     179                'nonce'    => array(
     180                        'save'    => wp_create_nonce( 'save-customize_' . $wp_customize->get_stylesheet() ),
     181                        'preview' => wp_create_nonce( 'preview-customize_' . $wp_customize->get_stylesheet() )
     182                ),
    178183        );
    179184
  • branches/3.4/wp-admin/js/customize-controls.dev.js

    r21071 r21136  
    295295                        deferred.promise( this );
    296296
    297                         this.previewer = params.previewer;
     297                        this.container = params.container;
     298                        this.signature = params.signature;
    298299
    299300                        $.extend( params, { channel: api.PreviewFrame.uuid() });
     
    339340                        this.request.done( function( response ) {
    340341                                var location = self.request.getResponseHeader('Location'),
    341                                         signature = 'WP_CUSTOMIZER_SIGNATURE',
     342                                        signature = self.signature,
    342343                                        index;
    343344
     
    372373
    373374                                // Create the iframe and inject the html content.
    374                                 self.iframe = $('<iframe />').appendTo( self.previewer.container );
     375                                self.iframe = $('<iframe />').appendTo( self.container );
    375376
    376377                                // Bind load event after the iframe has been added to the page;
     
    417418
    418419                                iframe = $('<iframe src="' + self.previewUrl() + '" />').hide();
    419                                 iframe.appendTo( self.previewer.container );
     420                                iframe.appendTo( self.container );
    420421                                iframe.load( function() {
    421422                                        self.triedLogin = true;
     
    498499                        this.container   = api.ensure( params.container );
    499500                        this.allowedUrls = params.allowedUrls;
     501                        this.signature   = params.signature;
    500502
    501503                        params.url = window.location.href;
     
    571573                                previewUrl: this.previewUrl(),
    572574                                query:      this.query() || {},
    573                                 previewer:  this
     575                                container:  this.container,
     576                                signature:  this.signature
    574577                        });
    575578
     
    584587                                        self.targetWindow( this.targetWindow() );
    585588                                        self.channel( this.channel() );
     589
     590                                        self.send( 'active' );
    586591                                });
    587592
     
    684689                        form:        '#customize-controls',
    685690                        previewUrl:  api.settings.url.preview,
    686                         allowedUrls: api.settings.url.allowed
     691                        allowedUrls: api.settings.url.allowed,
     692                        signature:   'WP_CUSTOMIZER_SIGNATURE'
    687693                }, {
     694
     695                        nonce: api.settings.nonce,
     696
    688697                        query: function() {
    689698                                return {
    690699                                        wp_customize: 'on',
    691700                                        theme:        api.settings.theme.stylesheet,
    692                                         customized:   JSON.stringify( api.get() )
     701                                        customized:   JSON.stringify( api.get() ),
     702                                        nonce:        this.nonce.preview
    693703                                };
    694704                        },
    695 
    696                         nonce: $('#_wpnonce').val(),
    697705
    698706                        save: function() {
     
    700708                                        query = $.extend( this.query(), {
    701709                                                action: 'customize_save',
    702                                                 nonce:  this.nonce
     710                                                nonce:  this.nonce.save
    703711                                        }),
    704712                                        request = $.post( api.settings.url.ajax, query );
     
    733741                        }
    734742                });
     743
     744                // Refresh the nonces if the preview sends updated nonces over.
     745                previewer.bind( 'nonce', function( nonce ) {
     746                        $.extend( this.nonce, nonce );
     747                });
    735748
    736749                $.each( api.settings.settings, function( id, data ) {
  • branches/3.4/wp-includes/class-wp-customize-manager.php

    r21070 r21136  
    1818        protected $controls = array();
    1919
     20        protected $nonce_tick;
     21
    2022        protected $customized;
    2123
     
    309311         */
    310312        public function customize_preview_init() {
     313                $this->nonce_tick = check_ajax_referer( 'preview-customize_' . $this->get_stylesheet(), 'nonce' );
     314
    311315                $this->prepare_controls();
    312316
     
    363367                );
    364368
     369                if ( 2 == $this->nonce_tick ) {
     370                        $settings['nonce'] = array(
     371                                'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ),
     372                                'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() )
     373                        );
     374                }
     375
    365376                foreach ( $this->settings as $id => $setting ) {
    366377                        $settings['values'][ $id ] = $setting->js_value();
     
    469480                        die;
    470481
    471                 check_ajax_referer( 'customize_controls-' . $this->get_stylesheet(), 'nonce' );
     482                check_ajax_referer( 'save-customize_' . $this->get_stylesheet(), 'nonce' );
    472483
    473484                // Do we have to switch themes?
  • branches/3.4/wp-includes/js/customize-preview.dev.js

    r21054 r21136  
    8989                        });
    9090                        preview.send( 'synced' );
    91                 })
     91                });
     92
     93                preview.bind( 'active', function() {
     94                        if ( api.settings.nonce )
     95                                preview.send( 'nonce', api.settings.nonce );
     96                });
    9297
    9398                preview.send( 'ready' );
  • branches/3.4/wp-login.php

    r21031 r21136  
    4040 */
    4141function login_header($title = 'Log In', $message = '', $wp_error = '') {
    42         global $error, $interim_login, $current_site, $customize_login;
     42        global $error, $interim_login, $current_site;
    4343
    4444        // Don't index any of these forms
     
    6868                <meta name="viewport" content="width=320; initial-scale=0.9; maximum-scale=1.0; user-scalable=0;" /><?php
    6969        }
    70 
    71         if ( $customize_login )
    72                 wp_enqueue_script( 'customize-base' );
    7370
    7471        do_action( 'login_enqueue_scripts' );
     
    569566        $interim_login = isset($_REQUEST['interim-login']);
    570567        $customize_login = isset( $_REQUEST['customize-login'] );
     568        if ( $customize_login )
     569                wp_enqueue_script( 'customize-base' );
    571570
    572571        // If the user wants ssl but the session is not ssl, force a secure cookie.
     
    605604                if ( $interim_login ) {
    606605                        $message = '<p class="message">' . __('You have logged in successfully.') . '</p>';
    607                         login_header( '', $message );
    608 
    609                         if ( ! $customize_login ) : ?>
    610                                 <script type="text/javascript">setTimeout( function(){window.close()}, 8000);</script>
    611                                 <p class="alignright">
    612                                 <input type="button" class="button-primary" value="<?php esc_attr_e('Close'); ?>" onclick="window.close()" /></p>
    613 <?php           endif;
    614 
    615                         ?></div><?php
    616 
    617                         do_action('login_footer');
    618 
    619                         if ( $customize_login ) : ?>
     606                        login_header( '', $message ); ?>
     607
     608                        <?php if ( ! $customize_login ) : ?>
     609                        <script type="text/javascript">setTimeout( function(){window.close()}, 8000);</script>
     610                        <p class="alignright">
     611                        <input type="button" class="button-primary" value="<?php esc_attr_e('Close'); ?>" onclick="window.close()" /></p>
     612                        <?php endif; ?>
     613                        </div>
     614                        <?php do_action( 'login_footer' ); ?>
     615                        <?php if ( $customize_login ) : ?>
    620616                                <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script>
    621 <?php           endif; ?>
     617                        <?php endif; ?>
    622618                        </body></html>
    623619<?php           exit;
Note: See TracChangeset for help on using the changeset viewer.