In our code recipe blog posts and through our support team, we often show you how to modify your Paid Memberships Pro site’s default behavior with custom code. But how do you actually apply these code snippets once you’ve got them in hand?
This tutorial explains how to safely add custom code to adjust your membership site functionality via two methods:
- Using the Code Snippets plugin available for free in the WordPress repository (preferred for beginners).
- Creating a custom plugin to hold all of your PMPro customizations (for advanced developers).
Table of contents
- Why do I need to add custom code?
- Why can’t I just edit my theme?
- Learn How to Copy and Paste Custom PHP Recipes
- Two Methods to Add Custom Code to PMPro
- How to Add Globals or Constants in wp-config.php
- How to Troubleshoot Broken Customizations
- More Ways to Customize: Designing with CSS
- Final Thoughts: Membership Site Customization Techniques
Why do I need to add custom code?
Paid Memberships Pro is open source software for membership sites built on WordPress.
PMPro is built in such a way so that developers and non-developers alike can create amazingly robust and complex membership platforms without the need for custom code.
When you have a unique feature or requirement that the base PMPro platform does not support, you will need to consider using custom code. We provide examples of these code snippets throughout our site, that show you how to extend Paid Memberships Pro without editing any core plugin files.
Why can’t I just edit my theme?
Directly editing your theme’s functions.php file can be tempting for quick fixes, but it’s risky.
Unless you are the sole author of your theme, there is a 100% chance that changes you make in your theme will be lost when the theme gets updated.
Changes can also be lost if you switch your theme in the future.
Both of these cases will cause you to lose all of your custom functionality, which you may not be able to recover without a current theme backup.
Using the Code Snippets plugin or a custom plugin just for your site ensures that your modifications are preserved independently of theme changes.
In addition, storing all of your customizations in these safer tools helps you, your developers, and our support team know exactly where the custom code is located as it relates to your Paid Memberships Pro setup.
Learn How to Copy and Paste Custom PHP Recipes
Before you begin working with custom code, please read through our documentation on how to copy and paste custom PHP recipes.
This guide is useful for beginner to intermediate level WordPress users who may not be very familiar with PHP and code. We cover how to safely use the code recipes we provide in this site, as well as steps to take if you mistakenly break your website.
Two Methods to Add Custom Code to PMPro
Method 1: Use the Code Snippets Plugin
The Code Snippets plugin by Shea Bunge provides a simple user interface to add PHP code snippets (or what we call “recipes”) on your site. The plugin is available for free download in the WordPress.org plugin repository.
If you’re new to WordPress or just not comfortable using FTP / SFTP to access your site’s files, this is our recommended method to add custom code to your membership site.
Once you install the plugin, navigate to Code Snippets > Add New to create a new customization in your site. Check out this companion guide on using the Code Snippets plugin for the complete instructions.
Method 2: Create a Plugin for PMPro Customizations
A customizations plugin is a specific type of plugin designed just for your site. You can use this plugin to store custom PHP code snippets that alter or enhance the functionality of your site.
A customization plugin protects your changes from being lost during theme updates, unlike direct modifications to the theme’s functions.php file.
This is an advanced developer’s preferred method to safely customize WordPress, your theme, and your plugins base functionality.
To help kickstart your customization process, we offer a blank plugin template. Or, you can manually create a plugin for your site.
Using the Blank Customizations Plugin
- Download a Blank Plugin Template: Start by downloading this blank customizations plugin template. This template is a basic scaffold that contains the minimal file structure and code required for WordPress to recognize it as a plugin.
- Upload to WordPress: Log into your WordPress site and navigate to Plugins > Add New > Upload Plugin. Choose the .zip file of your blank plugin template and upload it.
- Activate the Plugin: Once uploaded, you can activate the plugin directly from the Plugins page. This blank plugin now serves as a container for your custom PHP code.
Note: You’ll still need FTP/SFTP access to your WordPress site’s server and files to safely add and edit your customizations plugin files. We do not recommend using the Plugin File Editor within WordPress to add and edit custom code.
Manually Create a Customizations Plugin
First, connect to your web server via SFTP or FTP.
SFTP or FTP (File Transfer Protocol or Secure File Transfer Protocol) is a standard network protocol used to transfer files from your local computer to a remote server, or vice versa, over the Internet.
To use FTP, you need an FTP client, software that connects to your web server with SFTP account details from your host. Your web host should be able to provide you with FTP or SFTP credentials.
If you don’t know how to use FTP, refer to this WordPress Developer Resource on FTP clients. You can also refer to your web host’s FAQs and guides.
To use FTP, you must have:
- FTP or SFTP address: The address of your server provided by the hosting company.
- Username and Password: Credentials to access your server.
- Port number: Often provided by your host if it differs from the default (FTP typically uses port 21, while SFTP uses port 22).
- Root directory: The path to the directory where your website files are stored, which may also be provided by your host.
While many of our Add Ons can be installed directly via your WordPress Dashboard, the customizations plugin is one instance where knowing how to use FTP to “upload” or “edit” files on your web server is very important.
Next, create the customizations plugin.
- Create a plugin folder: Navigate to the wp-content/plugins directory of your WordPress installation. Create a new folder here for your plugin, typically named after your plugin or its functionality (e.g., pmpro-customizations).
- Create the main plugin file: Inside the plugin folder you created, make a new PHP file. This file should have the same name as your plugin folder (e.g., pmpro-customizations.php).
- Add required WordPress plugin headers: Open your plugin file in a text editor and paste this block of code into the file. These header requirements are essential for WordPress to identify and display your plugin in the admin dashboard.
- Add Custom Code: Below the header, you can begin adding your PHP code for the customizations or functionality you wish to implement. If you are building a heavily customized membership site, consider adding a subfolder with individual .php files that you then include in the main plugin file. This will help your code stay organized.
- Upload via FTP: Save your plugin file and use your FTP client to upload the plugin folder (containing your PHP file) to the wp-content/plugins directory on your web server.
- Activate the Plugin: Finally, navigate to the Plugins page in the WordPress admin. Here you’ll see your new plugin in the list and can activate it to enable the custom functionality on your site.
Creating a custom plugin manually offers full control over its contents and structure, ideal for those comfortable with SFTP and file management.
This approach ensures that your custom code is organized, theme-agnostic, can be instantly disabled for testing purposes, and is easily accessible for future updates.
Video: Set Up a Paid Memberships Pro Customizations Plugin
The video below demonstrates how to follow these steps to create a plugin for customizations to your WordPress membership site.
How to Edit Your Customizations Plugin
- Launch your FTP Client and connect to the server. Once connected, navigate to the wp-content/plugins/pmpro-customizations folder.
- Find the pmpro-customizations.php file within the folder. This is the main file of your custom plugin where your custom PHP code resides. Download a copy of the most recent version of the file to your local computer.
- Open the downloaded pmpro-customizations.php file in your preferred text editor.
- Scroll to the bottom of the file or the appropriate section where you wish to add new code or make changes. This could be code snippets (or “recipes”) provided by support forums or your own custom PHP code.
- After making your changes, save the file.
- Return to your FTP client with the connection to your server still active.
- Navigate back to the wp-content/plugins/pmpro-customizations/ folder on your server.
- Upload the updated pmpro-customizations.php file from your local computer to the server folder.
- You may be prompted to overwrite the existing file on the server; confirm that you want to proceed with the upload.
After uploading the updated plugin file:
- Check for Errors: Visit your WordPress site to ensure that the changes you made are working as expected and have not introduced any errors or issues.
- Reactivate Plugin if Necessary: If you had deactivated the plugin before making changes, navigate to Plugins in the WordPress admin. Click “Activate” to reactivate your customizations plugin.
- Backup Regularly: Always keep backups of your custom plugin files before making significant changes, ensuring you can restore a previous version if needed. For heavily customized sites, consider using a private GitHub repository to maintain your custom code.
How to Add Globals or Constants in wp-config.php
Just like PHP, global variables and constants are another way you can customize the behavior of WordPress and your plugins. Constants are specifically used to define settings that affect the entire website.
To add or modify these settings, you must use SFTP to edit your WordPress site’s wp-config.php file. This file, located in the WordPress installation’s root directory, includes database connection details and security keys.
Some of the PMPro Add Ons use constants or globals that must be defined in your WordPress site’s wp-config.php file.
The default WordPress wp-config.pnp file contains loads of critical information for your WordPress site. To be safe, place new constants immediately below the WP_DEBUG constant.
Add each constant on a new line and end each line with a semicolon. For example:
define( 'PMPROIO_CODES', 1 );
How to Troubleshoot Broken Customizations
If an update to your Code Snippets or in your customizations plugin introduces a bug or white screen, you can use the steps below to recover your website. These steps show you how to identify where the bug was introduced and how to fix it.
Note: The Code Snippets plugin has built-in code checking logic. It is very unlikely that custom snippets will introduce a fatal error or white screen. But, it is possible that custom code could error and you could lose access to the WordPress admin.
If this happens, use the steps in the second section below on Troubleshooting Your Customizations Plugin to deactivate the Code Snippets plugin via SFTP.
Troubleshooting the Code Snippets Plugin
Use these steps if you still have access to your site’s WordPress admin.
- Deactivate all snippets: In the WordPress admin, navigate to Snippets. Deactivate all snippets to see if this resolves the issue. If your site returns to normal functionality, one or more snippets are the cause of the problem.
- Reactivate snippets one by one: Reactivate each snippet individually and check your site’s functionality after activating each one. This process helps identify the specific snippet causing the issue.
- Review the problematic snippet: Once you identify the snippet causing the problem, review its code. Look for syntax errors, compatibility issues with your WordPress version or theme, or conflicts with other plugins.
- Test in a staging environment: If possible, test the problematic snippet in a staging environment. This prevents further issues on your live site and allows you to troubleshoot more freely.
- Seek assistance if needed: If you’re unable to resolve the issue by reviewing the code, consider seeking assistance. Our support team guides you in resolving conflicts with your theme, plugins, payment gateway, and host. Provide them with the snippet code and details about the issue.
Troubleshooting Your Customizations Plugin
- Connect to your server via SFTP: Once connected, navigate to the wp-content/plugins directory. This folder contains all the plugins installed on your WordPress site.
- Rename the folder: This change effectively deactivates the plugin because WordPress can no longer find the plugin’s folder under its expected name. Use a name like pmpro-customizations-off to indicate it has been deactivated.
- Check your site’s functionality: Open a web browser and go to your WordPress site’s URL. Without the problematic plugin active, your site should load correctly. You may also check the WordPress Plugins screen to confirm that the plugin has been deactivated.
- Make corrections: Using a text editor, open the plugin file(s) where you added or changed code. Correct any errors or problematic code snippets.
- Test the changes: If possible, test your changes on a local development environment to prevent further issues on your live site.
- Update the plugin files: Replace the plugin file with your updated version.
- Rename the folder: Once you are sure the files are repaired, rename the plugin folder back to its original name, pmpro-customizations.
- Reactivate the plugin: In the WordPress admin, navigate to Plugins and reactivate your custom plugin.
More Ways to Customize: Designing with CSS
For visual customizations, view our separate guide for applying custom CSS. These steps will help you ensure that your site’s appearance aligns with your branding and design preferences, without affecting the underlying functionality.
Final Thoughts: Membership Site Customization Techniques
Whether you’re making minor tweaks or major overhauls, the ability to customize your PMPro site gives you complete freedom to design the exact membership site your business needs.
This tutorial provided two reliable methods for adding custom code—using the Code Snippets plugin for beginners and creating a custom plugin for advanced developers. Both of these approaches will ensure the customizations remain in place, even if you change your theme or need to update your plugins.
With this foundational knowledge, you should feel 100% confident to use the code recipes here on our site to extend PMPro. Not only do you have the steps to add code safely, you also have the skills to disable your custom code in the case of a fatal error or white screen.
Remember to always back up your site and test customizations in a staging environment to ensure the best results for your live site.
Join our free community of membership site creators.
PMPro offers a community Slack space for members, and you’re invited. Learn more about the community’s free benefits and get a link to join Slack now.
Free Course: Membership Site Development—The Basics
Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.