简体   繁体   中英

New user role in WordPress

I created new user role (Manager) in WordPress in my functions.php file. This is my code, but it not functional. The Manager only read the posts, can't edit and delete. What's wrong?

Thx.

function ui_new_role() {  

    //add the new user role
    add_role(
        'manager',
        'Manager',
        array(

    'edit_'              => true,
    'read_'              => true,
    'delete_'            => true,


    'edit_s'             => true,
    'edit_others_s'      => true,
    'publish_s'          => true,
    'read_private_s'     => true,


    'delete_s'           => true,
    'delete_private_s'   => true,
    'delete_published_s' => true,
    'delete_others_s'    => true,
    'edit_private_s'     => true,
    'edit_published_s'   => true,
        )
    );

}
add_action('admin_init', 'ui_new_role');

Create a new "Manager" role.

$result = add_role(
    'manager',
    __( 'Manager' ),
    array(
        'read'         => true,  // true allows this capability
        'edit_posts'   => true,
        'delete_posts' => true, // Use false to explicitly deny
    )
);
if ( null !== $result ) {
    echo 'New role created!';
}
else {
    echo 'Manager role already exists.';
}

reference

According to the documentation you're adding the role incorrectly. Your privilege names don't match anything I know of. In my opinion it's much better to add via a plugin.

function add_mgr_role()
{
    add_role(
        'manager',
        'Manager',
        array(
            'read' => true,
            'edit_posts' => true,
            'delete_posts' => true
        )
    );
}

register_activation_hook(__FILE__, 'add_mgr_role');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM