Make WordPress Core


Ignore:
Timestamp:
06/08/2012 07:22:11 PM (14 years ago)
Author:
ryan
Message:

Customizer: Gravefully handle cookie expipration. Prompt for log in in the preview. Props ocean90, koopersmith, nacin. fixes #20876

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-customize-manager.php

    r21027 r21031  
    3232        require( ABSPATH . WPINC . '/class-wp-customize-control.php' );
    3333
     34        add_filter( 'wp_die_handler', array( $this, 'wp_die_handler' ) );
     35
    3436        add_action( 'setup_theme',  array( $this, 'setup_theme' ) );
    3537        add_action( 'wp_loaded',    array( $this, 'wp_loaded' ) );
     
    5355    }
    5456
    55     /**
    56      * Start preview and customize theme.
    57      *
    58      * Check if customize query variable exist. Init filters to filter the current theme.
     57    /**
     58     * Return true if it's an AJAX request.
     59     *
     60     * @since 3.4.0
     61     */
     62    public function doing_ajax() {
     63        return isset( $_POST['customized'] ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX );
     64    }
     65
     66    /**
     67     * Custom wp_die wrapper. Returns either the standard message for UI
     68     * or the AJAX message.
     69     *
     70     * @param  mixed $ajax_message AJAX return
     71     * @param  mixed $message      UI message
     72     *
     73     * @since 3.4.0
     74     */
     75    private function wp_die( $ajax_message, $message ) {
     76        if ( $this->doing_ajax() )
     77            wp_die( $ajax_message );
     78
     79        wp_die( $message );
     80    }
     81
     82    /**
     83     * Return the AJAX wp_die() handler if it's a customized request.
     84     *
     85     * @since 3.4.0
     86     */
     87    public function wp_die_handler() {
     88        if ( $this->doing_ajax() )
     89            return '_ajax_wp_die_handler';
     90
     91        return '_default_wp_die_handler';
     92    }
     93    /**
     94    * Start preview and customize theme.
     95    *
     96    * Check if customize query variable exist. Init filters to filter the current theme.
    5997     *
    6098     * @since 3.4.0
    6199     */
    62100    public function setup_theme() {
    63         if ( is_admin() && ! defined( 'DOING_AJAX' ) )
    64             auth_redirect();
     101        if ( is_admin() && ! $this->doing_ajax() )
     102            auth_redirect();
     103        elseif ( $this->doing_ajax() && ! is_user_logged_in())
     104            wp_die( 0 );
    65105
    66106        send_origin_headers();
     
    72112        // You can't preview a theme if it doesn't exist, or if it is not allowed (unless active).
    73113        if ( ! $this->theme->exists() )
    74             wp_die( __( 'Cheatin’ uh?' ) );
     114            $this->wp_die( -1, __( 'Cheatin’ uh?' ) );
    75115
    76116        if ( $this->theme->get_stylesheet() != get_stylesheet() && ( ! $this->theme()->is_allowed() || ! current_user_can( 'switch_themes' ) ) )
    77             wp_die( __( 'Cheatin’ uh?' ) );
     117            $this->wp_die( -1, __( 'Cheatin’ uh?' ) );
    78118
    79119        if ( ! current_user_can( 'edit_theme_options' ) )
    80             wp_die( __( 'Cheatin’ uh?' ) );
     120            $this->wp_die( -1, __( 'Cheatin’ uh?' ) );
    81121
    82122        $this->start_previewing_theme();
Note: See TracChangeset for help on using the changeset viewer.