A small pro tip for devs who are using WordPress Sage9/10 for theme development. I saw many devs doesn't realize that when you are creating View composer and doing stuff inside it, like calling internal functions or executing SQL, for example:
get_bloginfo('name', 'display')
It will be executed as many times as blade files are involved, for example:
protected static $views = [
'*',
];
Will execute get_bloginfo()
for all blade files.
You should make use of singleton for this, inside ThemeServiceProvider.php
register method add:
$this->app->singleton(App::class);
Where App::class is view composer class, from now on, service container will not load this class if it's already loaded.
Top comments (0)