Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Disable polyfill for nav menu item loading/searching fix landing in 4.7 #315

Merged
merged 1 commit into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion js/customize-nav-menus-posts-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ wp.customize.Posts.NavMenusExtensions = (function( api, $ ) {
/**
* Rewrite Ajax requests to inject Customizer state.
*
* @todo Remove this once 4.7 is the minimum requirement.
*
* @param {object} options Options.
* @param {string} options.type Type.
* @param {string} options.url URL.
Expand Down Expand Up @@ -248,7 +250,11 @@ wp.customize.Posts.NavMenusExtensions = (function( api, $ ) {
api.control.each( component.extendNavMenuItemOriginalObjectReference );
api.control.bind( 'add', component.extendNavMenuItemOriginalObjectReference );
api.bind( 'change', component.watchPostSettingChanges );
$.ajaxPrefilter( component.ajaxPrefilterAvailableNavMenuItemRequests );

// Feature detect WP 4.7, only prefilter available item requests if WP<4.7.
if ( ! api.requestChangesetUpdate ) {
$.ajaxPrefilter( component.ajaxPrefilterAvailableNavMenuItemRequests );
}
} );

return component;
Expand Down
9 changes: 7 additions & 2 deletions php/class-wp-customize-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,17 @@ public function __construct( WP_Customize_Manager $manager ) {
}

/**
* Replace core's load and search ajax handlers with forked versions that apply customized state.
* Replace core's load and search ajax handlers with forked versions that apply customized state (only pre-4.7).
*
* @todo Remove this once 4.7 is the minimum requirement.
* @codeCoverageIgnore
*
* @see WP_Customize_Nav_Menus::ajax_load_available_items()
* @see WP_Customize_Nav_Menus::ajax_search_available_items()
* @param WP_Customize_Manager $wp_customize Manager.
*/
public function replace_nav_menus_ajax_handlers( $wp_customize ) {
if ( ! isset( $wp_customize->nav_menus ) ) {
if ( ! isset( $wp_customize->nav_menus ) || version_compare( strtok( get_bloginfo( 'version' ), '-' ), '4.7', '>=' ) ) {
return;
}

Expand Down Expand Up @@ -1486,6 +1489,7 @@ public function get_select2_item_result( $post ) {
*
* Forked from https://github.com/xwp/wordpress-develop/blob/2515aab6739ea0d2f065eea08ae429889a018fb3/src/wp-includes/class-wp-customize-nav-menus.php#L88-L115
*
* @todo Remove this once 4.7 is the minimum requirement.
* @codeCoverageIgnore
*/
public function ajax_load_available_items() {
Expand Down Expand Up @@ -1526,6 +1530,7 @@ public function ajax_load_available_items() {
*
* Forked from https://github.com/xwp/wordpress-develop/blob/2515aab6739ea0d2f065eea08ae429889a018fb3/src/wp-includes/class-wp-customize-nav-menus.php#L228-L258
*
* @todo Remove this once 4.7 is the minimum requirement.
* @codeCoverageIgnore
*/
public function ajax_search_available_items() {
Expand Down
20 changes: 0 additions & 20 deletions tests/php/test-class-wp-customize-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,6 @@ public function test_construct() {
$this->assertInstanceOf( 'WP_Customize_Posts_Preview', $posts->preview );
}

/**
* Test replace_nav_menus_ajax_handlers.
*
* @covers WP_Customize_Posts::replace_nav_menus_ajax_handlers()
*/
public function test_replace_nav_menus_ajax_handlers() {
$handlers = array(
'wp_ajax_load-available-menu-items-customizer' => 'ajax_load_available_items',
'wp_ajax_search-available-menu-items-customizer' => 'ajax_search_available_items',
);
foreach ( $handlers as $action => $method_name ) {
$this->assertEquals( 10, has_action( $action, array( $this->wp_customize->nav_menus, $method_name ) ) );
}
$this->posts->replace_nav_menus_ajax_handlers( $this->wp_customize );
foreach ( $handlers as $action => $method_name ) {
$this->assertFalse( has_action( $action, array( $this->wp_customize->nav_menus, $method_name ) ) );
$this->assertEquals( 10, has_action( $action, array( $this->posts, $method_name ) ) );
}
}

/**
* Test add_customize_nonce.
*
Expand Down