Created
August 17, 2022 17:58
-
-
Save Archie22is/259a892e190f734ee15b2e34c826467f to your computer and use it in GitHub Desktop.
WordPress: modify user roles dynamically with functions.php
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 characters
| <?php | |
| function custom_user_role() { | |
| // get user | |
| $user = new WP_User( <user-ID> ); | |
| //$user = new WP_User( '<user-login-name>' ); | |
| //$user = wp_get_current_user(); | |
| // modify roles | |
| // for example, set/unset them as administrator | |
| $user->add_role( 'administrator' ); | |
| //$user->remove_role( 'administrator' ); | |
| } | |
| // register action | |
| add_action( 'admin_init', 'custom_user_role' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment