Make WordPress Core

Opened 2 months ago

Last modified 2 months ago

#47139 new defect (bug)

function wp_logout_url urlencode causes issues in items wrap nav walker.

Reported by: BackuPs Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Menus Keywords:
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 (2)

#1 @BackuPs
2 months ago

To add more details to this.

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

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. https://developer.wordpress.org/reference/functions/wp_nav_menu/

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 2 months ago by BackuPs (previous) (diff)

#2 @SergeyBiryukov
2 months ago

  • Component changed from General to Menus
Note: See TracTickets for help on using tickets.