Change WordPress user roles and capabilities Forums Bug Reports Issue with Yoast SEO (multiple versions also with Pro) Reply To: Issue with Yoast SEO (multiple versions also with Pro)

#5634
Vladimir
Keymaster

“Yoast SEO” has own capabilities manager, which removes all wpseo capabilities on plugin deactivation and adds them to the pre-defined list of roles on plugin activation.
There is a filter , using which it’s possible to tell “Yoast SEO” which capability to which role add/remove automatically on plugin activation/deactivation.


/**
 * Filter: Allow changing roles that a capability is added to.
 *
 * @api array $roles The default roles to be filtered.
 */
$filtered = apply_filters( $capability . '_roles', $roles );

For example with code below you will have ‘wpseo_manage_options’ capability granted to ‘editor’ role automatically on “Yoast SEO” plugin activation:


add_filter('wpseo_manage_options_roles', 'wpseo_manage_options_roles', 10, 1);

function wpseo_manage_options_roles( $roles ) {

    $roles[] = 'editor';

    return $roles;
}

You may add it to the active theme functions.php file or setup it as a Must Use plugin.