1
votes

I want to create new role on Wordpress site, I've made plugin and put this function on plugin file. Here is example code:

add_role( 'imageuploader', 'Image Uploader', $capabilities );
$capabilities = array(
                      'read' => true,
                      'edit_posts' => true,
                      'delete_posts' => true,
                      'upload_files' => true,
                     );

After that, I'm create new user and assign this role to that user. I've try to login WP admin using that user login and it's howed this: You do not have sufficient permissions to access this page.

Why it's showed that error? I've add read capabilities on that user role.

1

1 Answers

1
votes

Advanced Access Manager

WPFront User Role Editor

Using this plugin to add user role and manage access functionality you want.

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

OR add on your theme function.php with manage your roll name to roletypename

function add_theme_caps() {
    $role = get_role( 'roletypename' );
    // create if neccesary
    if (!$role) $role = add_role('roletypename', 'Role Name'); 
    // add theme specific roles
    $role->add_cap('delete_posts');
    $role->add_cap('delete_published_posts');
    $role->add_cap('edit_posts');
    $role->add_cap('edit_published_posts');
    $role->add_cap('publish_posts');
    $role->add_cap('read');
    $role->add_cap('upload_files');
}
add_action( 'admin_init', 'add_theme_caps');