Support » Plugin: User Role Editor » Role not completely propagating…

  • Hello –

    I’m using multi-site and using role editor.

    I have some code that automatically adds the headmaster to every site that gets created (so that all posts may be reviewed by her )

    I have some working code that works, but it’s not completely setting the role to Headmaster in the user profile of the newly created site.

    This is the code I’m using:

    function caprock_new_user_meta($blog_id, $user_id) {
      $args = array(
    		'blog_id' => '1',
    		'meta_key' => 'position',
    		'meta_value' => 'headmaster',
      $headmasters = get_users($args);
    foreach ( $headmasters as $author ) {
      $userid = $author->ID;
      add_user_to_blog($blog_id, $userid, 'Headmaster' );
      } // End Foreach Headmaster
    add_action( 'wpmu_new_blog', 'caprock_new_user_meta', 10, 2 );

    This is allowing her to be added, but I suspect that when I’m calling ass_user_to_blog() that there might be a complimentary call in User Role Editor that needs to be made as well…


    When I go to look at her newly created profile, the role says it’s not defined ( or something like that), and I select it from the drop down and save and all is good.



Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Vladimir Garagulia


    Hi Matt,

    It seems, that on the moment your ‘caprock_new_user_meta’ action call,
    ‘duplicate_roles_for_new_blog’ from User Role Editor was not executed yet.
    Look, they both have the same priority parameter value – 10.
    add_action( ‘wpmu_new_blog’, ‘duplicate_roles_for_new_blog’, 10, 2 );
    If this is the case, then your ‘headmaster’ role doesn’t exists in the new created blog on the moment your cod execution. Try to increase priority parameter to 11, for example. Will it work as expected after that?


    Hi Vladimir –

    After trying your suggestion, I tried making the role all lowercase, and that appears to solve the problem…

    It may make sense to allow roles to be case insensitive – or there may be a reason that they are not…


    Plugin Author Vladimir Garagulia


    Hi Matt,

    Yes, I missed that you use role name with uppercase first letter.
    Any WordPress role has two different attributes: identifier and name.
    While User Role Editor use the same keyword for both, it’s possible that role not be not equal to its ID.
    When you create role with User Role Editor, even input uppercase name, role identifier is lower cased automatically by User Role Editor as all standard WordPress roles has lower cases identifiers. So we should call functions, which requires role identifier with lowercase parameter value.
    Role identifier is used as the array key to find needed role. Look on example from capabilities.php set_role() function:

    if ( !empty( $role ) ) {
    		$this->caps[$role] = true;
    		$this->roles = array( $role => true );
    	} else {
    		$this->roles = false;

    I suppose that using auto lower case for role ID any time you check user capabilities could become much time consuming and could decrease WordPress productivity.


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Role not completely propagating…’ is closed to new replies.