Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Menu throws Fatal Error #168

Open
MrFortnite1111 opened this issue Nov 5, 2024 · 13 comments
Open

[BUG] Menu throws Fatal Error #168

MrFortnite1111 opened this issue Nov 5, 2024 · 13 comments

Comments

@MrFortnite1111
Copy link

Expected Behavior

No Fatal Error

Actual behavior

Fatal error: Uncaught InvalidArgumentException: Expected an instance of Timber\CoreInterface or WP_Term, got stdClass in /var/www/html/wordpress/wp-content/themes/hampteraptor/vendor/timber/timber/src/Factory/MenuFactory.php:172 Stack trace: #0 /var/www/html/wordpress/wp-content/themes/hampteraptor/vendor/timber/timber/src/Factory/MenuFactory.php(76): Timber\Factory\MenuFactory->from_object(Object(stdClass), Array) timber/timber#1 /var/www/html/wordpress/wp-content/themes/hampteraptor/vendor/timber/timber/src/Factory/MenuFactory.php(33): Timber\Factory\MenuFactory->from_nav_menu_terms(Array) timber/timber#2 /var/www/html/wordpress/wp-content/themes/hampteraptor/vendor/timber/timber/src/Timber.php(995): Timber\Factory\MenuFactory->from(NULL, Array) timber/timber#3 /var/www/html/wordpress/wp-content/themes/hampteraptor/src/StarterSite.php(44): Timber\Timber::get_menu() timber/timber#4 /var/www/html/wordpress/wp-includes/class-wp-hook.php(324): StarterSite->add_to_context(Array) timber/timber#5 /var/www/html/wordpress/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) timber/timber#6 /var/www/html/wordpress/wp-content/themes/hampteraptor/vendor/timber/timber/src/Timber.php(1315): apply_filters('timber/context', Array) timber/timber#7 /var/www/html/wordpress/wp-content/themes/hampteraptor/vendor/timber/timber/src/Timber.php(1206): Timber\Timber::context_global() timber/timber#8 /var/www/html/wordpress/wp-content/themes/hampteraptor/page.php(24): Timber\Timber::context() timber/timber#9 /var/www/html/wordpress/wp-includes/template-loader.php(106): include('/var/www/html/w...') timber/timber#10 /var/www/html/wordpress/wp-blog-header.php(19): require_once('/var/www/html/w...') timber/timber#11 /var/www/html/wordpress/index.php(17): require('/var/www/html/w...') timber/timber#12 {main} thrown in /var/www/html/wordpress/wp-content/themes/hampteraptor/vendor/timber/timber/src/Factory/MenuFactory.php on line 172

Steps to reproduce behavior

Any time I create a menu it throws this fatal error.

Notes

No response

What version of Timber are you using?

2.x-dev

What version of WordPress are you using?

6.6.2

What version of PHP are you using?

8.1

How did you install Timber?

Installed or updated Timber through Composer

@gchtr
Copy link
Member

gchtr commented Nov 6, 2024

Can you show us the code for how you create your menu?

@MrFortnite1111
Copy link
Author

I'm using the starter Timber theme and stock Wordpress. I'm customizing my Wordpress site and adding a menu, which causes the error to occure.

@Levdbas
Copy link
Member

Levdbas commented Nov 8, 2024

Hi @MrFortnite1111 ,

I tried to reproduce your issue but are not able to do so with Timber 2.3.0, and the development version of timber starter.

I created a menu which does get loaded normally. Have you created any menu locations or done any code changes in your theme?

@MrFortnite1111
Copy link
Author

I have not made any code changes, but I have made menu locations such as draft/sample pages. No matter what menu location I would add to the menu, it would still give me the fatal error.

@Levdbas
Copy link
Member

Levdbas commented Nov 11, 2024

Can you share a minimal git repo and steps on how to configure the database to recreate this specific issue? Without it we can't do much unfortunately. The functionality you mentioned @MrFortnite1111 is covered by unit tests, so the basic functionality is fully tested. Can be that you have a unique situation but we need something on how to test this.

@MrFortnite1111
Copy link
Author

Hey, so my professor helped me with the issue today and we figured something in the database was corrupted. We exported the code over to a new database and the issue wasn't there anymore. Regardless, thanks for the help along the way to solve the issue.

@Levdbas
Copy link
Member

Levdbas commented Nov 13, 2024

So you used Timber at school @MrFortnite1111, that is so nice to hear! Also glad that you were able to solve this issue with some help. Database related issues are always the hardest to debug in WordPress, but luckily don't happen that often. I had one yesterday as well with a website that took me a few hours as well to get running again.

Either way, good luck with your project!

@webdobe
Copy link

webdobe commented Dec 5, 2024

We are still running into this issue throughout the class. Based on what I can see is causing it is when the students are adding a new menu item or deleting the default menu and adding a new menu. It starts getting into this error. Only want to fix it is completely delete the menu from the Customize section of wordpress. But then it holds on to it somehow in wordpress. I believe it may be a wordpress bug right now not saving the menu data correctly in the "Customize" panel.

@Levdbas
Copy link
Member

Levdbas commented Dec 6, 2024

Hi @webdobe , welcome!

It might be the case that an empty menu causes issues in $context['menu'] = Timber::get_menu(); from the StarterSite class.

Normally you would use Timber::get_menu() in combination with a WordPress menu location. like so Timber::get_menu('primary_location'). Could you try and register a menu location and then setting that menu location in that method that I mentioned?

@Levdbas
Copy link
Member

Levdbas commented Dec 6, 2024

@timber/rangers , it seems that using Timber::get_menu(); without any parameters can cause this issue. Obvious fix would be twofold:

  • update starter theme to include a menu location and pass that to get_menu.
  • In the long run always expect the first paremeter to be set in a Timber::get_menu(); call? It does not make sense to get a menu at random?

I can take care of the first one in the starter theme, the second one will probably be a breaking change and thus can be addressed in Timber 3.x, if agreed I can put that on the board.

@webdobe
Copy link

webdobe commented Dec 6, 2024

@Levdbas thank you, that is what I observed as well while debugging the issue. I think short term we can just set the get_menu like you mentioned. I think it would be worth mentioning in the docs. Especially if someone starts developing with Timber on an existing wordpress database where they have modified the menus.

@Levdbas Levdbas reopened this Dec 9, 2024
@Levdbas Levdbas transferred this issue from timber/timber Dec 28, 2024
@Levdbas
Copy link
Member

Levdbas commented Dec 28, 2024

Moved the issue to the starter theme. The changes to fix this are in place, we just need to do some final checks on the code and release a new version if we don't want to iterate on this further for now.

@gchtr , after the holidays, shall we take a look at this?

@gchtr
Copy link
Member

gchtr commented Jan 3, 2025

@Levdbas Sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants