Make WordPress Core

Opened 5 years ago

Last modified 5 years ago

#47139 reviewing defect (bug)

function wp_logout_url urlencode causes issues in items wrap nav walker.

Reported by: backups's profile BackuPs Owned by: audrasjb's profile audrasjb
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Menus Keywords: reporter-feedback
Focuses: Cc:



The function wp_logout_url returns a encoded logout url. This used to work before without any issues.

string(128) "http://wprtdev.tst/wp-login.php?action=logout&_wpnonce=72f1be58e4&redirect_to=http%3A%2F%2Fwprtdev.tst%2F%3Floggedout%3Dtrue"

But if you parse this url as a list element in the menu walker you get a warning and error

<b>Warning</b>:  sprintf(): Too few arguments in <b>/var/docs/wprtdev.tst/public/wp-includes/nav-menu-template.php</b> on line <b>261</b><br />

because the walker uses %3$s for the items wrap and the encoded url has %3Afor : and %3F for ?

It is not possible to add a logout url into the items wrap like this

'items_wrap'=>'<ul id="%1$s" class="%2$s">%3$s<li id="woo-menu-logon-main" class="menu-item menu-item-type-post_type"><a href="http://wprtdev.tst/wp-login.php?action=logout&amp;_wpnonce=72f1be58e4&amp;redirect_to=http%3A%2F%2Fwprtdev.tst%2Fblog%3Floggedout%3Dtrue" title="Logout from shop" itemprop="url"><i class="wooicon icon icon-exit"></i>Logout</a></li>',

How to fix this?

Thank you !

Change History (4)

#1 @BackuPs
5 years ago

To add more details to this.

Your own coding example adds a extra list element this way at

wp_nav_menu( array(
    'theme_location' => 'primary',
    'items_wrap'     => '<ul><li id="item-id"><?php __( 'Menu:', 'textdomain' ); ?></li>%3$s</ul>'
) );

To be found here.

However if you add a extra menu item with a url that url cannot be encoded because the sprintf() function uses identifiers and a encoded url has codes that look like a identifier.

So sprintf also acting on %3F and the other ones in the encoded url causing the sprintf function to fail

How to work around this?

Last edited 5 years ago by BackuPs (previous) (diff)

#2 @SergeyBiryukov
5 years ago

  • Component changed from General to Menus

#3 @audrasjb
5 years ago

  • Keywords reporter-feedback added
  • Owner set to audrasjb
  • Status changed from new to reviewing

Hi @BackuPs thanks for the ticket and sorry for the delay,

Could you provide an example of the code used to generate your menu? so we could try to reproduce the issue.


#4 @BackuPs
5 years ago


The example is in my initial report of the issue.

Just try the following. But try this


// now call 

                return wp_nav_menu( array(
                                                'theme_location' => 'top-menu',
                                                'container' => 'nav',
                                                'container_id' => 'navigation',
                                                'container_class' => 'jqueryslidemenu',
                                                'menu_id' => 'top-bar-menu',   
                                                'fallback_cb' => '',
                                                'items_wrap'=>'<ul id="%1$s" class="%2$s">%3$s<li id="woo-menu-logon-xxxx" class="menu-item menu-item-type-post_type"><a href="'.$logout_url.'" title="Logout from shop">Logout</a></li></ul>',

Note: Change the theme_location to the correct menu location !

Note: See TracTickets for help on using tickets.