WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/02/2017 03:36:18 AM (20 months ago)
Author:
westonruter
Message:

Customize: Add infrastructure for trashing/reverting of unpublished changes; introduce full-screen OverlayNotification for trashing and theme install/preview.

  • Introduce a new wp.customize.previewer.trash() JS API to trash the current changeset, along with logic to WP_Customize_Manager to handle deleting changeset drafts.
  • Add trashing to wp.customize.state which is then used to update the UI.
  • UI for trashing is pending design feedback. One possibility is to add a new trash button to Publish Settings section that invokes wp.customize.previewer.trash().
  • Improve logic for managing the visibility and disabled states for publish buttons.
  • Prevent attempting requestChangesetUpdate while processing and bump processing while doing save.
  • Update changeset_date state only if sent in save response.
  • Merge ThemesSection#loadThemePreview() into ThemesPanel#loadThemePreview().
  • Remove unused autosaved state.
  • Start autosaving and prompting at beforeunload after a change first happens. This is key for theme previews since even if a user did not make any changes, there were still dirty settings which would get stored in an auto-draft unexpectedly.
  • Allow Notification to accept additional classes to be added to container.
  • Introduce OverlayNotification and use for theme installing, previewing, and trashing. Such overlay notifications take over the entire window.

Props westonruter, celloexpressions.
See #37661, #39896, #21666, #35210.

File:
1 edited

Legend:

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

    r41648 r41667  
    375375        remove_action( 'admin_init', '_maybe_update_themes' );
    376376
    377         add_action( 'wp_ajax_customize_save',           array( $this, 'save' ) );
    378         add_action( 'wp_ajax_customize_refresh_nonces', array( $this, 'refresh_nonces' ) );
    379         add_action( 'wp_ajax_customize-load-themes',    array( $this, 'load_themes_ajax' ) );
    380         add_action( 'wp_ajax_dismiss_customize_changeset_autosave', array( $this, 'handle_dismiss_changeset_autosave_request' ) );
     377        add_action( 'wp_ajax_customize_save',             array( $this, 'save' ) );
     378        add_action( 'wp_ajax_customize_trash',            array( $this, 'handle_changeset_trash_request' ) );
     379        add_action( 'wp_ajax_customize_refresh_nonces',   array( $this, 'refresh_nonces' ) );
     380        add_action( 'wp_ajax_customize_load_themes',      array( $this, 'handle_load_themes_request' ) );
     381        add_action( 'wp_ajax_customize_dismiss_autosave', array( $this, 'handle_dismiss_autosave_request' ) );
    381382
    382383        add_action( 'customize_register',                 array( $this, 'register_controls' ) );
     
    28312832
    28322833    /**
     2834     * Handle request to trash a changeset.
     2835     *
     2836     * @since 4.9.0
     2837     */
     2838    public function handle_changeset_trash_request() {
     2839        if ( ! is_user_logged_in() ) {
     2840            wp_send_json_error( 'unauthenticated' );
     2841        }
     2842
     2843        if ( ! $this->is_preview() ) {
     2844            wp_send_json_error( 'not_preview' );
     2845        }
     2846
     2847        if ( ! check_ajax_referer( 'trash_customize_changeset', 'nonce', false ) ) {
     2848            wp_send_json_error( array(
     2849                'code' => 'invalid_nonce',
     2850                'message' => __( 'There was an authentication problem. Please reload and try again.' ),
     2851            ) );
     2852        }
     2853
     2854        $changeset_post_id = $this->changeset_post_id();
     2855
     2856        if ( ! $changeset_post_id ) {
     2857            wp_send_json_error( array(
     2858                'message' => __( 'No changes saved yet, so there is nothing to trash.' ),
     2859                'code' => 'non_existent_changeset',
     2860            ) );
     2861            return;
     2862        }
     2863
     2864        if ( $changeset_post_id && ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->delete_post, $changeset_post_id ) ) {
     2865            wp_send_json_error( array(
     2866                'code' => 'changeset_trash_unauthorized',
     2867                'message' => __( 'Unable to trash changes.' ),
     2868            ) );
     2869        }
     2870
     2871        if ( 'trash' === get_post_status( $changeset_post_id ) ) {
     2872            wp_send_json_error( array(
     2873                'message' => __( 'Changes have already been trashed.' ),
     2874                'code' => 'changeset_already_trashed',
     2875            ) );
     2876            return;
     2877        }
     2878
     2879        $r = wp_trash_post( $changeset_post_id );
     2880        if ( ! ( $r instanceof WP_Post ) ) {
     2881            wp_send_json_error( array(
     2882                'code' => 'changeset_trash_failure',
     2883                'message' => __( 'Unable to trash changes.' ),
     2884            ) );
     2885        }
     2886
     2887        wp_send_json_success( array(
     2888            'message' => __( 'Changes trashed successfully.' ),
     2889        ) );
     2890    }
     2891
     2892    /**
    28332893     * Re-map 'edit_post' meta cap for a customize_changeset post to be the same as 'customize' maps.
    28342894     *
     
    31033163     * @since 4.9.0
    31043164     */
    3105     public function handle_dismiss_changeset_autosave_request() {
     3165    public function handle_dismiss_autosave_request() {
    31063166        if ( ! $this->is_preview() ) {
    31073167            wp_send_json_error( 'not_preview', 400 );
    31083168        }
    31093169
    3110         if ( ! check_ajax_referer( 'dismiss_customize_changeset_autosave', 'nonce', false ) ) {
     3170        if ( ! check_ajax_referer( 'customize_dismiss_autosave', 'nonce', false ) ) {
    31113171            wp_send_json_error( 'invalid_nonce', 403 );
    31123172        }
     
    35443604        ?>
    35453605        <script type="text/html" id="tmpl-customize-notification">
    3546             <li class="notice notice-{{ data.type || 'info' }} {{ data.alt ? 'notice-alt' : '' }} {{ data.dismissible ? 'is-dismissible' : '' }}" data-code="{{ data.code }}" data-type="{{ data.type }}">
    3547                 {{{ data.message || data.code }}}
     3606            <li class="notice notice-{{ data.type || 'info' }} {{ data.alt ? 'notice-alt' : '' }} {{ data.dismissible ? 'is-dismissible' : '' }} {{ data.classes || '' }}" data-code="{{ data.code }}" data-type="{{ data.type }}">
     3607                <div class="notification-message">{{{ data.message || data.code }}}</div>
    35483608                <# if ( data.dismissible ) { #>
    35493609                    <button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php _e( 'Dismiss' ); ?></span></button>
     
    35773637            </div>
    35783638        </script>
     3639        <script type="text/html" id="tmpl-customize-trash-changeset-control">
     3640            <button type="button" class="button-link button-link-delete"><?php _e( 'Trash unpublished changes' ); ?></button>
     3641        </script>
    35793642        <?php
    35803643    }
     
    39023965            'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ),
    39033966            'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ),
    3904             'switch-themes' => wp_create_nonce( 'switch-themes' ),
    3905             'dismiss_autosave' => wp_create_nonce( 'dismiss_customize_changeset_autosave' ),
     3967            'switch_themes' => wp_create_nonce( 'switch_themes' ),
     3968            'dismiss_autosave' => wp_create_nonce( 'customize_dismiss_autosave' ),
     3969            'trash' => wp_create_nonce( 'trash_customize_changeset' ),
    39063970        );
    39073971
     
    41604224        $this->add_control( 'changeset_status', array(
    41614225            'section' => 'publish_settings',
     4226            'priority' => 10,
    41624227            'settings' => array(),
    41634228            'type' => 'radio',
     
    41744239        $this->add_control( new WP_Customize_Date_Time_Control( $this, 'changeset_scheduled_date', array(
    41754240            'section' => 'publish_settings',
     4241            'priority' => 20,
    41764242            'settings' => array(),
    41774243            'type' => 'date_time',
     
    47244790     * @since 4.9.0
    47254791     */
    4726     public function load_themes_ajax() {
    4727         check_ajax_referer( 'switch-themes', 'switch-themes-nonce' );
     4792    public function handle_load_themes_request() {
     4793        check_ajax_referer( 'switch_themes', 'nonce' );
    47284794
    47294795        if ( ! current_user_can( 'switch_themes' ) ) {
Note: See TracChangeset for help on using the changeset viewer.