Last active
April 14, 2021 03:13
-
-
Save strangerstudios/4551348 to your computer and use it in GitHub Desktop.
Revisions
-
ideadude revised this gist
Jan 23, 2013 . 1 changed file with 2 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -104,13 +104,10 @@ function pmpro_limit_available_themes($themes) 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 } -
ideadude revised this gist
Jan 16, 2013 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,13 +7,11 @@ 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 -
ideadude created this gist
Jan 16, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,144 @@ <?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. */ require_once(ABSPATH . "/krumo/class.krumo.php"); /* 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]; var_dump($available_themes); $newthemes = array(); foreach($themes as $theme => $data) { echo "(" . $theme . ")"; 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; }