Closed njbarrett closed 7 years ago
Hey @njbarrett
It seems like PHP is trying to call the function add_action()
in Timmy’s namespace (Timmy\add_action()
) instead of the global namespace, where all the functions of WordPress are. Timmy waits for WordPress to be loaded and hooks into the after_setup_theme
action. The easiest solution would of course be to prefix all global functions that Timmy calls with a \
, but I’d like to understand what’s going on. I suspect the problem lies somewhere else.
vendor/
, while WordPress is installed in www/wp/
?I'm having the same issue
Using PHP version 7.1 TImmy is installed in vendor folder in root directory by using bedrock as a custom folder structure with sage9 as a starter theme
Okay. I will install Bedrock and look at this more closely.
Alright. The problem was that Composer loaded init.php
, which automatically initialized Timmy. Usually, when Timmy was installed in a theme, a developer would manually require vendor/autoload.php
in functions.php and Timmy would initialize after WordPress was loaded. With Bedrock, Composer initializes earlier, when WordPress is not loaded yet. The workaround for this is to always initialize Timmy manually.
With the new version 0.12.1 you need to manually initialize Timmy in functions.php of your theme with:
new Timmy\Timmy();
You can add this right after you called new Timber\Timber();
.
Thanks for raising this issue. I think this way Timmy will work in most "special" environments. Initializing Timmy automatically maybe was a good idea when I introduced it. I learnt a lot in the meantime and I think this change is the better way to do it 😊.
I’m closing this for now. In case it shouldn’t work, add your comments here.
Hey guys,
Love your work. I'm having trouble getting Timmy working on my installation. I have installed Timmy and Timber both via Composer, the latest versions of both.
In function.php I have the autoloader set, however it seems Timmy is loaded before the wp functions are available?
Here's the full error: