Last active
August 31, 2018 15:25
-
-
Save prasidhda/6829ceaf8a2d12a9c0b15c021e1ba358 to your computer and use it in GitHub Desktop.
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
add_action('wpmu_new_blog', 'wpmudev_new_blog_role', 300, 2); | |
function wpmudev_new_blog_role( $blog_id, $user_id ) { | |
//Switch to new network site | |
switch_to_blog( $blog_id ); | |
//Set default fallback user role | |
$default_user_role = 'administrator'; // Will be used as fallback user role, will be used if WP somehow can't create user role programitically | |
//Create free user role | |
$free_user_role = add_role( 'free', 'Free', array('delete_others_pages') ); | |
//Set default user role to Free only if it is successfully created | |
if( null != $free_user_role ){ | |
$default_user_role = 'free'; | |
} | |
//If it is super admin | |
if( is_super_admin( $user_id ) ){ | |
//first create the Master user role and then | |
$master_user_role = add_role( 'master', 'Master', array('setup_network') ); | |
////Set default user role to Master only if it is successfully created | |
if( null != $master_user_role ){ | |
$default_user_role = 'master'; | |
} | |
} | |
$user = new WP_User( $user_id ); | |
$user->set_role( $default_user_role ); | |
restore_current_blog(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment