title: "Capability Roles Filter" post_status: publish comment_status: open taxonomy: category: - yoast-developer post_tag: - Filters - Yoast Seo - Customization


Yoast SEO ships with a variety of custom capabilities that are assigned to various roles, which allow for granular control over what features are available for a particular role. However, in some cases you might want to expand or limit these capabilities. To support this, we’ve introduced a filter named {$capability}_roles, where {$capability} needs to be replaced with the name of one of the capabilities that is registered by Yoast SEO.

Default roles

Yoast SEO has the following two default roles and their respective capabilities. These roles can be seen as an extension to the default WordPress role of Editor. As such, they inherit all capabilities of the Editor role as well.

wpseo_editor - wpseo_bulk_edit - wpseo_edit_advanced_metadata

wpseo_manager - wpseo_bulk_edit - wpseo_edit_advanced_metadata - wpseo_manage_options - view_site_health_checks

Usage

Adding roles

The example below shows how you can use the filters to add one or multiple roles to a specific capability.

<?php

/**
 * Adds the editor and wpseo_editor roles to the view_site_health_checks capability.
 * 
 * @param array $roles The currently allowed roles.
 *
 * @return array The allowed roles.
 */
function add_site_health_roles( $roles ) {
    return array_merge( $roles, [ 'editor', 'wpseo_editor' ] );
}

add_filter( 'view_site_health_checks_roles', 'add_site_health_roles' );

Removing roles

The example below shows how you can use the filters to remove roles from a specific capability.

<?php

/**
 * Removes the wpseo_editor role from the view_site_health_checks_roles capability.
 * 
 * @param array $roles The currently allowed roles.
 *
 * @return array The allowed roles.
 */
function remove_site_health_roles( $roles ) {
    return array_filter( $roles, function( $role ) {
        if ( $role !== 'wpseo_editor' ) {
            return $role;
        }
  } );
}

add_filter( 'view_site_health_checks_roles', 'remove_site_health_roles' );

Applicable capabilities

Currently, the following capabilities are registered and can be altered with the filter: