Skip to content

Instantly share code, notes, and snippets.

@boonebgorges
Last active August 29, 2015 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boonebgorges/4ee64723ba75caa3c7e1 to your computer and use it in GitHub Desktop.
Save boonebgorges/4ee64723ba75caa3c7e1 to your computer and use it in GitHub Desktop.
reset user role in an mu-plugin
<?php
/**
* Instructions:
*
* 1. If you don't have a directory called wp-content/mu-plugins, create it
* 2. Create a file at wp-content/mu-plugins/user-role.php
* 3. Paste the entire contents of this gist into the user-role.php file
* 4. Replace the value of $user_login ('boone1') with your user name
* 5. Replace the value of $user_role ('editor') with your desired role. You probably want 'administrator'
* 6. Save the file
* 7. Load your website in a browser
* 8. Now attempt to visit wp-admin. You should have full access again. Assuming you do, you should immediately delete the user-role.php file (or comment out the add_action() line at the bottom)
*/
function bbg_reset_user_role() {
$user_login = 'boone1';
$user_role = 'editor';
// Don't edit anything below here
$user = get_user_by( 'login', $user_login );
$user->add_role( $user_role );
}
add_action( 'init', 'bbg_reset_user_role', 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment