Skip to content

fix: Add missing capability for editing SEO settings#128

Open
dtakken wants to merge 1 commit into
mainfrom
fix/seo-cap-group
Open

fix: Add missing capability for editing SEO settings#128
dtakken wants to merge 1 commit into
mainfrom
fix/seo-cap-group

Conversation

@dtakken

@dtakken dtakken commented May 29, 2026

Copy link
Copy Markdown
Contributor

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_posts capability to the seo_redirections capability group in the user roles config.

'gravityforms_edit_entry_notes',
],
'seo_redirections' => [
'edit_posts',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check even of dit niet teveel rechten geeft aan deze 'eenvoudige' rol, volgens mij kunnen ze zo de rol van editor aannemen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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....

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' => [],
                ],
            ],
        ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants