diff --git a/js/customize-nav-menus-posts-extensions.js b/js/customize-nav-menus-posts-extensions.js index b815206..be64671 100644 --- a/js/customize-nav-menus-posts-extensions.js +++ b/js/customize-nav-menus-posts-extensions.js @@ -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. @@ -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; diff --git a/php/class-wp-customize-posts.php b/php/class-wp-customize-posts.php index 74990d9..40ca97c 100644 --- a/php/class-wp-customize-posts.php +++ b/php/class-wp-customize-posts.php @@ -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; } @@ -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() { @@ -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() { diff --git a/tests/php/test-class-wp-customize-posts.php b/tests/php/test-class-wp-customize-posts.php index b8adbc3..6e3844f 100644 --- a/tests/php/test-class-wp-customize-posts.php +++ b/tests/php/test-class-wp-customize-posts.php @@ -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. *