v1.8.9 of Paid Memberships Pro includes the new function
pmpro_loadTemplate that we use when loading any of the plugin-generated pages or system-generated emails. Having a central function to load these templates makes it easier to add templates of your own or filter PMPro to load templates from a different location.
Overriding PMPro Page Templates
Paid Memberships Pro generates frontend page content via the shortcodes pmpro_account, pmpro_billing, pmpro_cancel, pmpro_checkout. pmpro_confirmation, pmpro_invoice, and pmpro_levels. If you cannot accomplish your customization needs via hooks and filters or a custom stylesheet/CSS and need finer control over the HTML code generated, then you might want to override the template files for these pages.
By default, Paid Memberships Pro will look in your active theme (and parent theme if applicable) for a directory named “paid-memberships-pro/pages”. You can then copy files from /wp-content/plugins/paid-memberships-pro/pages/ into that folder and tweak the files to your needs. PMPro will load your modified version of the template instead of the default one that is bundled with Paid Memberships Pro.
This way you can edit those files without breaking your changes when you upgrade Paid Memberships Pro later. There still made be additions or changes to our default templates that you will want to or need to change in your custom templates, but you’ll have less work to do than if you “hacked the core” PMPro plugin.
NEW: Loading Custom Page Templates From a Plugin Instead of Your Theme
Before PMPro v1.8.9, if you wanted to load a custom page template from somewhere outside your theme’s /paid-memberships-pro/ directory you had to create a separate filter and callback for each template you wanted to override. If you were editing multiple templates, you would have a lot of similar code filling up your customizations plugin.
Since v1.8.9, you can use the new pmpro_pages_custom_template_path filter to tell PMPro to check a specific directory for ALL page templates. If the template is found, it will be used. If it’s not found, PMPro will continue to look in the theme and default pages folder.
So if you have a plugin pmpro-customizations.php with a folder “pages” in it, you can tell PMPro to use templates from that pages folder using code like this:
Creating your own page templates.
Now if you are building a PMPro addon and want to allow users to be able to override your template by placing their own versions in the /paid-memberships-pro/pages/ directory of their theme, you can use pmpro_loadTemplate. Here is an example that will load your own template file. We’ll be updating our addons to work the same way.
Which emails can I modify?
NEW: Loading Custom Email Templates From a Plugin Instead of Your Theme
However, sometimes you need to programatically update email templates. Similar to filtering page templates, you can use the pmpro_email_custom_template_path filter like this:
You can also create your own email templates and load them using pmpro_loadTemplate(‘name’, NULL, ’email’); which will try to load email templates from /wp-content/themes/your-theme/paid-memberships-pro/email/name.html.
Note that we use “email” without an S for our email folder but “pages” with an S for the pages folder.
We’re going to be adding some extra helper functionality around creating new email templates and integrating them with the Email Templates Admin Editor so users can easily override the email templates your addons use. When we get that done, we’ll post to the blog here. In the meantime, we can help in the member forums.