Last active
January 11, 2017 16:04
-
-
Save mattmcgiv/6d2cb701bd59df6750be75a6dda76792 to your computer and use it in GitHub Desktop.
Add a role to all users
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 | |
| //Uncomment the following line for converting one role to another | |
| //add_action( 'the_post', 'convert_subscribers_to_executives' ); | |
| function convert_subscribers_to_executives() { | |
| //Note: this only works by navigating to the page with ID 5883 on the site | |
| //to kick off the loop that updates all of the users. | |
| if (get_the_ID() === 5883) { | |
| //get all subscribers from this WP site | |
| $blogusers = get_users( 'blog_id=1&orderby=nicename&role=subscriber' ); | |
| //Foreach user: add the Executive role (slug: executive) **in addition to** the current role. | |
| foreach ($blogusers as $user) { | |
| //wp_die(json_encode($user->ID)); | |
| $addMemberToGroup = new WP_User($user->ID); | |
| $addMemberToGroup->add_role( 'executive' ); | |
| } | |
| return; | |
| } | |
| else { | |
| return; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment