yoast seo plugin – remove bulk title and description editor menu from non-admins [closed]

Yoast SEO uses capabilities (WordPress docs on roles and capabilities) to determine whether users are allowed to bulk edit tiles and descriptions. The name of the capability used for this is wpseo_bulk_edit.

By default, Yoast SEO adds this capability to the administrator, editor, author and contributor roles. To remove this capability from all roles except for the administrator roles, it is enough to call remove_cap on all other roles. To remove a capability from a role, you first need to fetch the role object:

 $role = get_role( $rolename );
 $role->remove_cap( $cap );

remove_cap needs to be called only once: capability settings for roles are saved to the options table.

Thus, calling this once would to the trick:

$roles = array(
    'editor',
    'author',
    'contributor'
);

foreach ( $roles as $rolename ) {
    $role = get_role( $rolename );

    if ( $role ) {
        $role->remove_cap( 'wpseo_bulk_edit' );
    }
}

EDIT

On (manual) activation of the plugin, the capability will automatically be added to these user roles. Therefore, it would be useful to use the wpseo_bulk_edit_roles (explained in the answer by @fischi) in addition to calling the snippet above once:

function myplugin_wpseo_bulk_edit_roles( $roles ) {
    return array( 'administrator' );
}

add_filter( 'wpseo_bulk_edit_roles', 'myplugin_wpseo_bulk_edit_roles' );