[wp-trac] [WordPress Trac] #45733: Identical nav menu names cause prevent Customizer from loading

WordPress Trac noreply at wordpress.org
Fri Dec 21 16:24:55 UTC 2018


#45733: Identical nav menu names cause prevent Customizer from loading
--------------------------+-----------------------------
 Reporter:  brianburton   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Customize     |    Version:  5.0.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 **Description of Problem**

 When my theme is installed it performs a setup process to create menus
 required by the theme.  I discovered that if the labels of the nav
 "anchors" and the nav menus are identical, it will cause an error and
 prevent the customizer from loading.

 **Sample Code**
 {{{#!php
 register_nav_menus( array(
         'super'   => esc_html__( 'Super Navigation', 'textdomain' )
 ) );

 $superId = wp_create_nav_menu( 'Super Navigation' );

 set_theme_mod( 'nav_menu_locations', array(
         'super'   => $superId
 ) );
 }}}

 When I open the Customizer on the front end, the only thing visible is an
 empty customizer window and the preview remains blank.

 [[Image(https://i.imgur.com/6qr9wYq.jpg)]]

 Checking the PHP error logs I discovered this:

 {{{
 PHP Catchable fatal error:  Object of class WP_Error could not be
 converted to string in \wordpress\wp-includes\general-template.php on line
 4277
 }}}

 **Workaround**

 The workaround is to give the nav "anchors" and nav menus unique names.

 **Solution**

 I'm not familiar enough with WP core development to know which solution
 would be best, however I would recommend one of the following:

 1. Make the following change to the !__checked_selected_helper() function
 in general-template.php (tested as working):
 {{{#!php
 function __checked_selected_helper( $helper, $current, $echo, $type ) {
         if (is_wp_error($helper))
                 return;

         if ( (string) $helper === (string) $current )
 }}}

 2. Have wp_create_nav_menu() return an instance of WP_Error if it is
 called with an existing label (preferred).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45733>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list