WordPress.org

Ready to get started?Download WordPress

Forums

New users does not get new capabilities (3 posts)

  1. Andrea Barghigiani
    Member
    Posted 2 years ago #

    Hi all,

    I am developing a new theme and I need to create some new roles and set them tiwh some capabilities. So I started to edit my functions.php and I added this code:

    function controllo_utenti(){
    	global $wp_roles;
    
    	$studente_cap = array(
    		'read',
    		'read_private_pages',
    		'read_private_posts',
    		'studente'
    	);
    	$centro_cap = array(
    		'delete_posts',
    		'delete_published_posts',
    		'edit_post',
    		'edit_posts',
    		'edit_published_posts',
    		'publish_posts',
    		'read',
    		'read_private_pages',
    		'read_private_posts',
    		'centro'
    	);
    	$docente_cap = array(
    		'read',
    		'read_private_pages',
    		'read_private_posts',
    		'docente'
    	);
    
    	$roles_set = get_option('ifp_role_set');
    
    	if( !$roles_set){
    		add_role( 'studente', 'Studente', $studente_cap);
    		add_role( 'centro', 'Centro', $centro_cap );
    		add_role( 'docente', 'Docente', $docente_cap );
    
    		update_option( 'ifp_role_set', true );
    	}
    }
    
    add_action( 'after_setup_theme', 'controllo_utenti');

    For the time beign everythings is working just fine, as I check the capabilities of each role I can see the all setted up.

    But when I register a new user and I set it to one of the roles, the brand new role does not have other capabilities than the name of the new role.

    To set the new role I am using this string:
    wp_update_user( array ('ID' => $user_id, 'role' => $posted['your_role'] ) ) ;

    Maybe I missunderstood something but, when I give a role to a new user is it supposed to inherit the capabilities of that role?

    Does anyone have an idea about how solve this issue?

    Thanks in advance for your answers!

  2. Andrea Barghigiani
    Member
    Posted 2 years ago #

    I've just installed the plugin User Role Editor and with my surprise my new roles doesn't have any of the capabilities I've specified inside my functions.php

    Is something strange because as seen from this image the WP system is saving the id of my capabilities inside the array... there's something that I am missing??

  3. TCBarrett
    Member
    Posted 2 years ago #

    Did you edit the code, or paste it exactly as it is? What happens if you delete the 'ifp_role_set' option so that the code re-runs?

Topic Closed

This topic has been closed to new replies.

About this Topic