Single_template filter from plugins

Hi guys,

I’ve been working for a little while on the new sage9 version of the theme.
I noticed that the current wrapper logic disregards any template coming from external plugins and expects to find any template file within the current theme.
While this is generally ok when developing a theme, it gives some headache when a plugin is injecting a custom preview page template.

I simply changed the filter:

add_filter('template_include', function ($main) {
    if (!is_string($main) || !(string) $main || strpos($main, "plugins") !== false) {
        return $main;
    }
    return template_wrap(new Wrapper(basename($main)));
}, 109);

To exclude templates coming from the plugins folder.

Thought this might be useful for somebody else as well and might be worth taking into consideration for the core wrapper logic.

Cheers,

Nick

2 Likes

I wonder if this is the intended behaviour in Sage 9?

It could be, but doesn’t apply to every single situation. There are projects where you need to have different templates coming from plugins and in that case, changing the wrapper logic like suggested, allows for more flexibility.

I agree. The changes you suggest fixes the problem I was having with Sage 9 and WooCommerce. Thank you!

Will you send a PR to the sage-9 branch for your proposed fix to get the ball rolling with this?

@QWp6t has fixed this on the sage-9 branch.
Templates pulled from plugins work as expected now.