Make WordPress Core


Ignore:
Timestamp:
03/09/2016 12:08:51 AM (9 years ago)
Author:
westonruter
Message:

Customize: Fix regressions and harden implementation of selective refresh for nav menus.

  • Request full refresh if there are nav menu instances that lack partials for a changed setting.
  • Restore WP_Customize_Nav_Menus::$preview_nav_menu_instance_args and WP_Customize_Nav_Menus::export_preview_data() from 4.3, and keeping a tally of all wp_nav_menu() calls regardless of whether they can use selective refresh.
  • Ensure that all instances of wp_nav_menu() are tallied, regardless of whether they are made during the initial preview call or during subsequent partial renderings. Export nav_menu_instance_args with each partial rendering response just as they are returned when rendering the preview as a whole.
  • Fix issues with Custom Menu widget where nav menu items would fail to render when switching between menus when a menu lacked items to begin with.
  • Make sure the fallback behavior is invoked when the partial is no longer associated with a menu.
  • Do fallback behavior to refresh preview when all menu items are removed from a menu.

Follows [36586].
See #27355.
Fixes #35362.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/nav-menus.php

    r36782 r36889  
    618618        do_action( 'customize_register', $this->wp_customize );
    619619        $menus = $this->wp_customize->nav_menus;
     620        $menu_id = wp_create_nav_menu( 'Foo' );
    620621
    621622        $results = $menus->filter_wp_nav_menu_args( array(
     
    623624            'fallback_cb'     => 'wp_page_menu',
    624625            'walker'          => '',
    625             'menu'            => wp_create_nav_menu( 'Foo' ),
     626            'menu'            => $menu_id,
    626627            'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    627628        ) );
    628629        $this->assertArrayHasKey( 'customize_preview_nav_menus_args', $results );
     630        $this->assertTrue( $results['can_partial_refresh'] );
    629631
    630632        $results = $menus->filter_wp_nav_menu_args( array(
     
    634636            'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    635637        ) );
    636         $this->assertArrayNotHasKey( 'customize_preview_nav_menus_args', $results );
     638        $this->assertFalse( $results['can_partial_refresh'] );
     639        $this->assertArrayHasKey( 'customize_preview_nav_menus_args', $results );
    637640        $this->assertEquals( 'wp_page_menu', $results['fallback_cb'] );
    638641
     
    645648            'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    646649        ) );
     650        $this->assertTrue( $results['can_partial_refresh'] );
    647651        $this->assertArrayHasKey( 'customize_preview_nav_menus_args', $results );
    648652        $this->assertEquals( $nav_menu_term->term_id, $results['customize_preview_nav_menus_args']['menu'] );
     653
     654        $results = $menus->filter_wp_nav_menu_args( array(
     655            'echo'            => true,
     656            'fallback_cb'     => 'wp_page_menu',
     657            'walker'          => '',
     658            'menu'            => $menu_id,
     659            'container'       => 'div',
     660            'items_wrap'      => '%3$s',
     661        ) );
     662        $this->assertTrue( $results['can_partial_refresh'] );
     663
     664        $results = $menus->filter_wp_nav_menu_args( array(
     665            'echo'            => true,
     666            'fallback_cb'     => 'wp_page_menu',
     667            'walker'          => '',
     668            'menu'            => $menu_id,
     669            'container'       => false,
     670            'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
     671        ) );
     672        $this->assertTrue( $results['can_partial_refresh'] );
     673
     674        $results = $menus->filter_wp_nav_menu_args( array(
     675            'echo'            => true,
     676            'fallback_cb'     => 'wp_page_menu',
     677            'walker'          => '',
     678            'menu'            => $menu_id,
     679            'container'       => false,
     680            'items_wrap'      => '%3$s',
     681        ) );
     682        $this->assertFalse( $results['can_partial_refresh'] );
    649683    }
    650684
     
    692726
    693727    /**
     728     * Test WP_Customize_Nav_Menus::export_preview_data() method.
     729     *
     730     * @see WP_Customize_Nav_Menus::export_preview_data()
     731     */
     732    function test_export_preview_data() {
     733        ob_start();
     734        $this->wp_customize->nav_menus->export_preview_data();
     735        $html = ob_get_clean();
     736        $this->assertTrue( (bool) preg_match( '/_wpCustomizePreviewNavMenusExports = ({.+})/s', $html, $matches ) );
     737        $exported_data = json_decode( $matches[1], true );
     738        $this->assertArrayHasKey( 'navMenuInstanceArgs', $exported_data );
     739    }
     740
     741    /**
    694742     * Test WP_Customize_Nav_Menus::render_nav_menu_partial() method.
    695743     *
Note: See TracChangeset for help on using the changeset viewer.