Make WordPress Core


Ignore:
Timestamp:
07/08/2015 09:29:53 PM (10 years ago)
Author:
westonruter
Message:

Customizer: Remove additional wrapper element around wp_nav_menu() which broke some theme designs.

Also includes these related changes:

  • Export oldContainer and newContainer among the customize-preview-menu-refreshed event params for themes to be able to more easily re-initialize the DOM elements.
  • Improve performance for partial refresh by only sending settings related to the menu being previewed.
  • Fix previewing of menu assigned to Custom Menu by exporting a menu term_id as opposed to an object, as the former is more stable for comparing in in args hashes.
  • Do full refresh of preview when nav menu unassigned so that the layout can be updated.
  • Harden conditions for when partial refresh is eligible for a wp_nav_menu() instance.

Fixes #32841.

File:
1 edited

Legend:

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

    r33131 r33138  
    769769            &&
    770770            ( empty( $args['walker'] ) || is_string( $args['walker'] ) )
     771            &&
     772            (
     773                ! empty( $args['theme_location'] )
     774                ||
     775                ( ! empty( $args['menu'] ) && ( is_numeric( $args['menu'] ) || is_object( $args['menu'] ) ) )
     776            )
    771777        );
    772778        $args['can_partial_refresh'] = $can_partial_refresh;
     
    779785        }
    780786
     787        // Replace object menu arg with a term_id menu arg, as this exports better to JS and is easier to compare hashes.
     788        if ( ! empty( $hashed_args['menu'] ) && is_object( $hashed_args['menu'] ) ) {
     789            $hashed_args['menu'] = $hashed_args['menu']->term_id;
     790        }
     791
    781792        ksort( $hashed_args );
    782793        $hashed_args['args_hash'] = $this->hash_nav_menu_args( $hashed_args );
     
    799810    public function filter_wp_nav_menu( $nav_menu_content, $args ) {
    800811        if ( ! empty( $args->can_partial_refresh ) && ! empty( $args->instance_number ) ) {
    801             $nav_menu_content = sprintf(
    802                 '<div id="partial-refresh-menu-container-%1$d" class="partial-refresh-menu-container" data-instance-number="%1$d">%2$s</div>',
    803                 $args->instance_number,
    804                 $nav_menu_content
     812            $nav_menu_content = preg_replace(
     813                '/(?<=class=")/',
     814                sprintf( 'partial-refreshable-nav-menu partial-refreshable-nav-menu-%1$d ', $args->instance_number ),
     815                $nav_menu_content,
     816                1 // Only update the class on the first element found, the menu container.
    805817            );
    806818        }
Note: See TracChangeset for help on using the changeset viewer.