#38612 closed defect (bug) (fixed)
Infinite refresh loop in Customizer when using the filter 'theme_mod_nav_menu_locations'
Reported by: | Chouby | Owned by: | westonruter |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | Customize | Keywords: | has-patch dev-reviewed commit |
Focuses: | Cc: |
Description
In a multilingual plugin, we need to filter the navigation menu outputted by the theme.
In Polylang, I am thus using the filter theme_mod_nav_menu_locations
to populate the theme locations with the nav menus in the correct language.
Recent changes made to the customizer in WP 4.7 beta1 seem to introduce a backward compatibility issue as using this filter is now causing an infinite refresh loop in the customizer.
Here is a snippet to reproduce:
if ( ! is_admin() ) { add_filter( 'theme_mod_nav_menu_locations', 'pll_theme_mod_nav_menu_locations' ); } function pll_theme_mod_nav_menu_locations( $menus ) { if ( is_array( $menus ) ) { foreach ( $menus as $loc => $menu ) { $menus[ $loc ] = 19; // some existing menu_id } } return $menus; }
Attachments (1)
Change History (16)
#2
@
8 years ago
It indeed works in previous versions of WordPress.
I did not see #37032 before, but I see now that it was opened for WP 4.5 whereas I had no issue with this version.
#3
@
8 years ago
@Chouby ok, I think it may be something to do with the changes done for #27403, but I'm having a hard time pinpointing it. In any case, for an immediate fix while waiting on #37032, I suggest that you modify your code as follows:
<?php function pll_remove_theme_mod_nav_menu_locations_filter() { remove_filter( 'theme_mod_nav_menu_locations', 'pll_theme_mod_nav_menu_locations' ); } if ( ! is_admin() ) { add_filter( 'theme_mod_nav_menu_locations', 'pll_theme_mod_nav_menu_locations' ); // Note that WP_Customize_Manager::customize_preview_settings() is called at wp_footer priority 10. add_action( 'wp_footer', 'pll_remove_theme_mod_nav_menu_locations_filter' ); }
The problem I think is that your filter is interfering with the customizer filters added for nav menus. So it is important to remove your filter before the customizer prints out the setting values so that it doesn't get stuck in that infinite loop.
Try that and let me know how you go.
#4
@
8 years ago
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
#6
@
8 years ago
If anyone else is having this issue the same conflict exists with the latest versions of:
https://wordpress.org/plugins/nav-menu-roles/
https://wordpress.org/plugins/menu-items-visibility-control/
However
https://wordpress.org/plugins/if-menu/
Seems to work.
#7
@
8 years ago
- Keywords needs-patch added
- Milestone set to 4.7
- Resolution duplicate deleted
- Status changed from closed to reopened
@SpencerFinnell I can indeed reproduce issue in the Nav Menu Roles plugin:
- Given Twenty Seventeen activated with starter content imported
- Go to the nav menus admin page
- Set each of the social nav menu's items to only display if user is not logged in.
- Open customizer.
- Infinite refresh ensues.
#9
@
8 years ago
- Keywords has-patch needs-testing added; needs-patch removed
@SpencerFinnell would you give 38612.0.diff a try?
@Chouby This issue wasn't present in WordPress 4.6.1?
Relates to #37032.