Roots Discourse

Best Practice for Standard WordPress Plugin with Partial Template in Sage

Alright, so I’ve previously developed a plugin that allows me to communicate with the Stripe API to do some membership/purchase related things on my WordPress site. I’m fairly new to sage so I’m just wondering what the best practice is to get a partial template (loaded from a plugin) to fit most themes.

So my plugin creates a custom post type called ‘membership’ to store data from Stripe and then I have a filter added to look for single post types with type of ‘membership’ to load a Partial template into WordPress. Lets call this template single-membership.php.

Normally I would just call template_get_part(‘template_part’); to get the relevant pieces of the theme I needed. Something like:

single-membership.php

<?php
get_template_part('header');
include('main-content-file-membership.php');
get_template_part('footer';)
?>

However, with Sage, since it uses Blade, I get an error like this:

Theme without header.php is <strong>deprecated</strong> since version 3.0.0 with no alternative available. Please include a header.php template in your theme. in C:\dev\sites\palmtree.studios.local\bedrock\web\wp\wp-includes\functions.php on line 3984

Maybe I’m not thinking about this correctly, I just want the plugin template to fit most themes. I realize every theme is different, but I was hoping to at least get some nav elements and wp_head loaded with the footer just for some basic styling and cohesiveness across the site.

Any advice is much appreciated.

AFAIK there is no universal way of achieving it across all the themes.

The idea in the method you have presented will work in “the most” of the themes as you mentioned (but I would rather use get_footer and get_header).
To put it simply -> Roots/Sage is not one of “the most” due to its very customized nature and the way its rendered.

For sure, thanks for the info. I wasn’t sure if there was a built-in way to handle this. I think I’ll just end up making a custom Blade template for ‘membership’ post type and add a filter that will override the one packaged with the plugin.

Thanks again!