-
-
Save strangerstudios/fc455c86697c213c83f6 to your computer and use it in GitHub Desktop.
Remove s2member roles from WordPress.
This file contains 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 characters
/* | |
s2member doesn't remove the custom roles it creates when you deactivate or delete the plugin. | |
This code will remove the custom roles. Steps: | |
1. Add this code to your active theme's functions.php. | |
2. Login as an administrator. | |
3. Navigate to /?s2cleanup=1 to give any user with the s2member_level1 role the subscriber role. | |
4. Ditto /?s2cleanup=2, /?s2cleanup=3, /?s2cleanup=4 | |
5. Navigate to /?s2cleanup=removeroles to delete the roles. | |
6. Remove the code. | |
*/ | |
function init_s2cleanup() | |
{ | |
if(!empty($_REQUEST['s2cleanup']) && current_user_can('manage_options')) | |
{ | |
echo "<h2>s2member Cleanup</h2>\n"; | |
global $wpdb; | |
if($_REQUEST['s2cleanup'] == "removeroles") | |
{ | |
echo "Removing roles s2member_level1-4."; | |
remove_role("s2member_level1"); | |
remove_role("s2member_level2"); | |
remove_role("s2member_level3"); | |
remove_role("s2member_level4"); | |
} | |
else | |
{ | |
$level = intval($_REQUEST['s2cleanup']); | |
//level1 | |
echo "<h3>s2member Level $level</h3>\n"; | |
$users = get_users(array("role"=>"s2member_level" . $level)); | |
foreach($users as $user) | |
{ | |
echo "User " . $user->user_login . " changed to subscriber.<br />"; | |
$user->set_role("subscriber"); | |
} | |
} | |
exit; | |
} | |
} | |
add_action('init', 'init_s2cleanup'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment