If you’re using the Member Network Sites Add On, the code recipe below demonstrates (at a high level) how you can limit allowed plugins and themes based on the membership level purchased.

Table of contents
The Code Recipe
Save the code recipe below as a .php file and upload it to the ‘wp-content/mu-plugins’ folder. Update the pmpro_plugins_per_level
and pmpro_themes_per_levels
globals in the plugin.
<?php | |
/* | |
Plugin Name: PMPro Limit Available Plugins and Themes | |
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-limit-available-plugins/ | |
Description: Limits Which Plugins are Available for Network Sites | |
Version: .1 | |
Author: Stranger Studios | |
Author URI: http://www.strangerstudios.com | |
1. Place this file in wp-content/mu-plugins. | |
2. Update the pmpro_plugins_per_level and pmpro_themes_per_levels globals in the plugin. | |
3. Make sure that you have "Enable administration menus" checked in the Network Settings page of the network dashboard. | |
*/ | |
/* | |
This is the array to store which plugins are available for which level | |
Level 1 members have access to akisment and hello dolly. | |
Level 2 members have access to just hello dolly. | |
Make sure that the plugin entry in each array is the actual path and file name of the plugin on your server | |
*/ | |
global $pmpro_plugins_per_level; | |
$pmpro_plugins_per_level = array( | |
1 => array( | |
'akismet/akismet.php', | |
'hello.php' | |
), | |
2 => array( | |
'hello.php' | |
) | |
); | |
/* | |
This is the array to store which themes are available for which level | |
Level 1 members have access to twenetytwelve, twentyeleven and twentyten. | |
Level 2 members have access to twentytwelve and twentyten. | |
Make sure that the level entry in each array is the directory name of the theme | |
*/ | |
global $pmpro_themes_per_level; | |
$pmpro_themes_per_level = array( | |
1 => array( | |
'twentyeleven', | |
'twentytwelve' | |
), | |
2 => array( | |
'twentytwelve', | |
'twentyten' | |
) | |
); | |
/* | |
Limit the listed plugins is the admin | |
*/ | |
function pmpro_limit_available_plugins($plugins) | |
{ | |
//don't filter network admins | |
if(!current_user_can("manage_network_plugins")) | |
{ | |
global $pmpro_plugins_per_level; | |
$membership_id = plap_getMembershipId(); | |
//filter by membership level | |
if(!empty($pmpro_plugins_per_level[$membership_id])) | |
{ | |
$available_plugins = $pmpro_plugins_per_level[$membership_id]; | |
$newplugins = array(); | |
foreach($plugins as $plugin => $data) | |
{ | |
if(in_array($plugin, $available_plugins)) | |
$newplugins[$plugin] = $data; //add it | |
} | |
$plugins = $newplugins; | |
return $plugins; | |
} | |
else | |
{ | |
//plugins weren't specified for the users membership (or he has none) so return no plugins | |
return array(); | |
} | |
} | |
return $plugins; | |
} | |
add_filter("all_plugins", "pmpro_limit_available_plugins"); | |
/* | |
Limit the listed themes is the admin | |
*/ | |
function pmpro_limit_available_themes($themes) | |
{ | |
//don't filter network admins | |
if(!current_user_can("manage_network_themes")) | |
{ | |
global $pmpro_themes_per_level; | |
$membership_id = plap_getMembershipId(); | |
//filter by membership level | |
if(!empty($pmpro_themes_per_level[$membership_id])) | |
{ | |
$available_themes = $pmpro_themes_per_level[$membership_id]; | |
$newthemes = array(); | |
foreach($themes as $theme => $data) | |
{ | |
if(in_array($theme, $available_themes)) | |
$newthemes[$theme] = $data; //add it | |
} | |
$themes = $newthemes; | |
return $themes; | |
} | |
else | |
{ | |
//themes weren't specified for the users membership (or he has none) so return no themes | |
return array(); | |
} | |
} | |
return $themes; | |
} | |
add_filter("allowed_themes", "pmpro_limit_available_themes"); | |
/* | |
Get the membership id of the current user at the main site level | |
*/ | |
function plap_getMembershipId() | |
{ | |
global $wpdb, $current_user; | |
$prefix = str_replace($wpdb->blogid . "_", "", $wpdb->prefix); | |
$membership_id = $wpdb->get_var("SELECT membership_id FROM " . $prefix . "pmpro_memberships_users WHERE user_id = '" . $current_user->ID . "' AND status = 'active' ORDER BY id DESC"); | |
return $membership_id; | |
} |
Note: Make sure that you have “Enable Administration Menus” checked in the Network Settings page of the network dashboard.
Want more pre-configuration options?
There are many ways to pre-congifure the site that is created at checkout (custom code, this recipe above, or the plugin described below). We’ve guided our PMPro Plus members through this process via the members forums.
One way is to use the pmpro_network_new_site
hook to run custom code after a new site is setup. During this action, you can change properties of the admin user, change the default theme, create stub pages, or really run any code you need to. Here is an example that uses the hook to changes new users to the editor role when their site is created.
function pmpro_network_new_site_editor($blog_id, $user_id) | |
{ | |
//switch to new blog | |
switch_to_blog($blog_id); | |
//change user's role on blog to "editor" | |
$wp_user_object = get_userdata($user_id); | |
$wp_user_object->set_role('editor'); | |
//switch back to main blog | |
restore_current_blog(); | |
} | |
add_action('pmpro_network_new_site', 'pmpro_network_new_site_editor', 10, 2); |
Author: Jason Coleman
Jason Coleman is the co-founder and CEO of Paid Memberships Pro, the most trusted membership platform that grows with you. With a deep passion for open source software, Jason is the author of Building Web Apps With WordPress, published by O'Reilly Media.
Jason's entrepreneurial spirit is driven by uncertainty, risk, and the thrill of new opportunities. With over two decades of experience in development, management, and marketing, he is committed to Paid Memberships Pro: the only open source platform focused on helping creators get paid so they can find freedom in their life and fulfill their goals.
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.