fix: Add missing capability for editing SEO settings#128
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a missing WordPress capability to the theme’s role/capability configuration so the configured SEO redirections capability group has the baseline permission needed to access/edit related admin functionality.
Changes:
- Added the
edit_postscapability to theseo_redirectionscapability group in the user roles config.
| 'gravityforms_edit_entry_notes', | ||
| ], | ||
| 'seo_redirections' => [ | ||
| 'edit_posts', |
There was a problem hiding this comment.
Check even of dit niet teveel rechten geeft aan deze 'eenvoudige' rol, volgens mij kunnen ze zo de rol van editor aannemen?
There was a problem hiding this comment.
Dit blijkt bij nader inzien inderdaad te veel rechten te geven. Het lijkt er nu op dat toegang tot redirections niet via alleen caps te regelen is....
There was a problem hiding this comment.
Zoals al vermeld in Teams:
Het gaat hier fout:
if ( current_user_can( 'manage_options' ) ) {
add_action( 'init', 'seopress_404_fn', 10 );
} else {
add_action( 'admin_init', 'seopress_404_fn', 10 );
}
Locatie: web/app/plugins/wp-seopress-pro/inc/admin/redirections/redirections.php
Voor rollen zonder manage_options wordt de post type pas geregistreerd op de admin_init hook.
WordPress controleert voor dat moment of de post type bestaat. Omdat seopress_404 op dat moment nog niet bestaat herkent WordPress de pagina /wp-admin/edit.php?post_type=seopress_404 niet en blokkeert de toegang.
Door onderstaande toe te voegen werkt ie wel:
/**
* Registers the redirections post type if it doesn't exist yet. This is needed for the redirections to work for users
* that don't have the 'manage_options' capability, but do have the 'edit_redirections' capability.
*/
#[Action('init', 10)]
public function registerRedirectionsPostType(): void
{
global $pagenow;
if (! is_string($pagenow) || 0 === strlen(trim($pagenow))) {
return;
}
$redirectionPages = ['edit.php', 'post.php', 'post-new.php'];
if (
! is_admin()
|| ! in_array($pagenow, $redirectionPages, true)
|| ('edit.php' === $pagenow && isset($_GET['post_type']) && 'seopress_404' !== $_GET['post_type'])
|| post_type_exists('seopress_404')
|| ! function_exists('seopress_404_fn')
) {
return;
}
seopress_404_fn();
}
En dan de bestaande filter aanpassing: (brave-hooks)
#[Filter('seopress_capability')]
public function dashboardOptions(string $cap, string $context): string
{
if (! is_admin()) {
return $cap;
}
if ('bot' == $context) {
$cap = 'edit_posts';
}
// Lower the main SEO menu cap from manage_options to edit_redirections so roles without manage_options can access it.
if ('menu' == $context && 'manage_options' === $cap) {
return 'edit_redirections';
}
return $cap;
}
Een gebruiker met deze rol werkt nu bij mij:
'payer' => [
'display_name' => 'Betaler',
'clone' => [
'from' => 'subscriber',
'add' => [
'caps' => [
'read',
'wf2fa_activate_2fa_self',
],
'post_type_caps' => [],
'cap_groups' => [
'wpseo',
],
],
'remove' => [
'caps' => [],
'post_type_caps' => [],
'cap_groups' => [],
],
],
],
EDIT: Dit geeft helaas te brede rechten. Lijkt erop dat we via een hook ad-hoc rechten moeten geven op die specifieke SEO pagina. Dat ga ik proberen, en dan hier een comment toevoegen dat alleen deze caps niet afdoende zijn.