Fix for broken customizer
-
This plugin is no longer maintained or available for download, but I still think it’s a useful plugin and a fairly small one that did its job well until the WordPress theme customizer broke in 2015.
The plugin throws the following exception:
[28-Dec-2018 18:54:20 UTC] PHP Fatal error: Uncaught Exception: Illegal widget setting ID: nav_menu_item[559-navception1] in ./wp-includes/customize/class-wp-customize-nav-menu-item-setting.php:171 Stack trace: #0 ./wp-includes/class-wp-customize-nav-menus.php(692): WP_Customize_Nav_Menu_Item_Setting->__construct(Object(WP_Customize_Manager), ‘nav_menu_item[5…’, Array) #1 ./wp-includes/class-wp-hook.php(286): WP_Customize_Nav_Menus->customize_register(Object(WP_Customize_Manager)) #2 ./wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #3 ./wp-includes/plugin.php(453): WP_Hook->do_action(Array) #4 ./wp-includes/class-wp-customize-manager.php(926): do_action(‘customize_regis…’, Object(WP_Customize_Manager)) #5 ./wp-includes/class-wp-hook.php(286): WP_Customize_Manager->wp_loaded(”) #6 ./wp-includes/class-wp-hook.php(310): WP_Hook-> in ./wp-includes/customize/class-wp-customize-nav-menu-item-setting.php on line 171
After digging through the code a bit, here’s what I found:
On June 16, 2015, WordPress introduced regex checking of menu item IDs. The regex is looking for ‘/^nav_menu_item\[(?P<id>-?\d+)\]$/’ which breaks Navception because Navception adds a ‘-navception’ suffix to the menu item IDs. WP is looking for an id like “nav_menu_item[123]”, but Navception’s IDs look like “nav_menu_item[123-navception1]” This causes WordPress to throw the Illegal widget setting ID exception in class-wp-customize-nav-menu-item-setting.php.
Removing the “-navception” suffix appears to fix the problem. Add this to Line 106:
$args['navception_suffix_prefix'] = "";
Non-Navception menu IDs: nav_menu_item[123]
Navception menu IDs: nav_menu_item[123-navception1]
Updated Navception menu IDs: nav_menu_item[1231]Note the trailing 1. This number will increment for every Naception menu you include on your site.
DISCLAIMER: I have not tested this fix in every scenario and it might not work in your situation. I’m not responsible for whatever may happen. I recommend NOT using an unsupported and unmaintained WP plugin, especially a broken one, but if you absolutely must, you can try this fix at your own risk!
- The topic ‘Fix for broken customizer’ is closed to new replies.