WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/18/2016 08:04:36 PM (5 years ago)
Author:
westonruter
Message:

Customize: Implement customized state persistence with changesets.

Includes infrastructure developed in the Customize Snapshots feature plugin.

See https://make.wordpress.org/core/2016/10/12/customize-changesets-technical-design-decisions/

Props westonruter, valendesigns, utkarshpatel, stubgo, lgedeon, ocean90, ryankienstra, mihai2u, dlh, aaroncampbell, jonathanbardo, jorbin.
See #28721.
See #31089.
Fixes #30937.
Fixes #31517.
Fixes #30028.
Fixes #23225.
Fixes #34142.
Fixes #36485.

File:
1 edited

Legend:

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

    r38794 r38810  
    4949        $this->manager         = $manager;
    5050
    51         // Skip useless hooks when the user can't manage nav menus anyway.
     51        // See https://github.com/xwp/wp-customize-snapshots/blob/962586659688a5b1fd9ae93618b7ce2d4e7a421c/php/class-customize-snapshot-manager.php#L469-L499
     52        add_action( 'customize_register', array( $this, 'customize_register' ), 11 );
     53        add_filter( 'customize_dynamic_setting_args', array( $this, 'filter_dynamic_setting_args' ), 10, 2 );
     54        add_filter( 'customize_dynamic_setting_class', array( $this, 'filter_dynamic_setting_class' ), 10, 3 );
     55
     56        // Skip remaining hooks when the user can't manage nav menus anyway.
    5257        if ( ! current_user_can( 'edit_theme_options' ) ) {
    5358            return;
     
    5964        add_action( 'wp_ajax_customize-nav-menus-insert-auto-draft', array( $this, 'ajax_insert_auto_draft_post' ) );
    6065        add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    61         add_action( 'customize_register', array( $this, 'customize_register' ), 11 );
    62         add_filter( 'customize_dynamic_setting_args', array( $this, 'filter_dynamic_setting_args' ), 10, 2 );
    63         add_filter( 'customize_dynamic_setting_class', array( $this, 'filter_dynamic_setting_class' ), 10, 3 );
    6466        add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_templates' ) );
    6567        add_action( 'customize_controls_print_footer_scripts', array( $this, 'available_items_template' ) );
     
    487489    public function customize_register() {
    488490
     491        /*
     492         * Preview settings for nav menus early so that the sections and controls will be added properly.
     493         * See https://github.com/xwp/wp-customize-snapshots/blob/962586659688a5b1fd9ae93618b7ce2d4e7a421c/php/class-customize-snapshot-manager.php#L506-L543
     494         */
     495        $nav_menus_setting_ids = array();
     496        foreach ( array_keys( $this->manager->unsanitized_post_values() ) as $setting_id ) {
     497            if ( preg_match( '/^(nav_menu_locations|nav_menu|nav_menu_item)\[/', $setting_id ) ) {
     498                $nav_menus_setting_ids[] = $setting_id;
     499            }
     500        }
     501        foreach ( $nav_menus_setting_ids as $setting_id ) {
     502            $setting = $this->manager->get_setting( $setting_id );
     503            if ( $setting ) {
     504                $setting->preview();
     505            }
     506        }
     507
    489508        // Require JS-rendered control types.
    490509        $this->manager->register_panel_type( 'WP_Customize_Nav_Menus_Panel' );
Note: See TracChangeset for help on using the changeset viewer.