Skip to content

Instantly share code, notes, and snippets.

@grok
Last active August 29, 2015 13:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save grok/10508187 to your computer and use it in GitHub Desktop.
Encountering what appears to be a core bug with the core WordPress Walker_Nav_Menu being extended within PHP 5.4.24 WordPress V3.8.2
<?php
class My_Walker extends Walker_Nav_Menu {
}
?>
<?php
echo '##### COMMENSE MY WALKER #####' . "\n";
wp_nav_menu(
array(
'walker' => new My_Walker()
)
);
echo '##### COMPLETE MY WALKER #####';
echo "\n\n";
echo '##### COMMENSE CORE WALKER #####' . "\n";
wp_nav_menu();
echo '##### COMPLETE CORE WALKER #####';
?>
<?php get_header(); ?>
##### COMMENSE MY WALKER #####
<br />
<b>Notice</b>: Trying to get property of non-object in <b>/wp-includes/nav-menu-template.php</b> on line <b>148</b><br />
<br />
<b>Notice</b>: Trying to get property of non-object in <b>/wp-includes/nav-menu-template.php</b> on line <b>151</b><br />
<br />
<b>Notice</b>: Trying to get property of non-object in <b>/wp-includes/nav-menu-template.php</b> on line <b>151</b><br />
<br />
<b>Notice</b>: Trying to get property of non-object in <b>/wp-includes/nav-menu-template.php</b> on line <b>153</b><br />
<div class="menu"><ul><li id="menu-item-2" class="menu-item-2"><a></a></li></ul></div>
##### COMPLETE MY WALKER #####
##### COMMENSE CORE WALKER #####
<div class="menu"><ul><li class="page_item page-item-2"><a href="/?page_id=2">Sample Page</a></li></ul></div>
##### COMPLETE CORE WALKER #####
@grok
Copy link
Author

grok commented Apr 11, 2014

PHP 5.4.24
WordPress. Version 3.8.2

@grok
Copy link
Author

grok commented Apr 11, 2014

Solution seems to be to take references to $args and instead of doing $arg->value switch it to $arg['value']

@grok
Copy link
Author

grok commented Apr 11, 2014

Current Solutions

Until ticket #24587 is resolved, this can be fixed by redeclaring the functions from core in my extended class and just changing to arrays or typecasting.

If you go to nav-menu-template.php and just copy out the code for Walker_Nav_Menu into your walker and change $args->whatever to $args['whatever'] -- this should fix it.

I know this is C&P and a shit way to go about it - but it's a known bug and all we can do at the moment.

This is actually only a problem up until you create a menu in the back end, give it an item, and assign it to the menu location.

@JoshKoberstein
Copy link

"This is actually only a problem up until you create a menu in the back end, give it an item, and assign it to the menu location."

What happens if you...

wp_nav_menu(array('walker' => new My_Walker(), 'fallback_cb' => false)); 

@grok
Copy link
Author

grok commented Apr 21, 2014

@JoshKoberstein are you speaking towards AFTER you have created a menu entry and have >= 1 menu item in it?

This problem only manifests if you write the code and no menu exists in the system as far as I can tell.

P.S. I'm including @ notation with your name so that when they get that working it should display properly :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment