• Resolved aredheldynthelor

    (@aredheldynthelor)


    Hi,

    I am creating an intranet for my company and I needed to grant the customize capability to the Editor role. Not a big expert in custom development on WordPress, I added this to the functions.php of my custom theme.

    /**
     * Grants new capabilities to some roles during theme activation
     * Revoke the same capabilities upon theme deactivation
     *
     * @var WP_Role $role_object
     */
    add_action('after_switch_theme', function() {
        $role_object = get_role( 'editor' );
        $role_object->add_cap('customize');
    });
    add_action('switch_theme', function() {
        $role_object = get_role( 'editor' );
        $role_object->remove_cap('customize');
    });

    Looked good for me but after I reactivated my theme, nothing changed. My editors hadn’t have access to the customize menu.
    I tried then with the capability edit_theme_options. It worked, but I don’t want all those options available.

    Did I do something wrong ? Does the customize capability require another one ?

    Here is the context :
    Plugins

    • Force Login
    • Slack Notifications
    • User Access Manager
    • Wordfence

    The Theme is a child of TwentySeventeen

    • This topic was modified 9 years, 4 months ago by aredheldynthelor. Reason: Added some more info
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    It appears you need to add your own admin menu links for non-admins as WP will not do this for you. Users with the customize capability can use the customizer, but WP will not give them the links to the proper resources. That is where you come in.
    https://developer.ww.wp.xz.cn/themes/customize-api/advanced-usage/

    Thread Starter aredheldynthelor

    (@aredheldynthelor)

    Hello,

    thanks for your reply.

    I tried your piece of code. The customize top menu item now appears. That’s great. Sadly, clicking on this new entry gives me this :

    Sorry, you are not allowed to customize this site.

    I had already tried before to hit the customize URI before, and it had given me the same message.
    I also tried with all plugins deactivated, no changes.

    Moderator bcworkz

    (@bcworkz)

    Hmmm. All I can think of is to compare the $caps array returned from the ‘map_meta_cap’ filter callback for editor users with that of administrator users. Alter the callback code as necessary to get something working. Naturally you don’t want them to completely match. Figure out what part is working for admins and replicate it for editors.

    Thread Starter aredheldynthelor

    (@aredheldynthelor)

    Hello,

    So i’m working again on it, and tried some things. First I printed the list of capabilities of an editor. I could see the customize cap. Sadly it was not enough to get it working. So I finally added the edit_theme_options cap to the editor instead of the customize cap. Now they can access the customizer among other options.

    So I have something working, but I don’t understand the utility of the customize cap if I don’t have access to the customizer…

    Anyway thank you for the support !

    Moderator bcworkz

    (@bcworkz)

    You’re welcome. I regret I wasn’t able to help more, but it appears to be the nature of the beast. The entire implementation of the customize cap is unusual. The customizer is still a relatively new feature and some of the finer points have yet to be fully worked out.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘What’s wrong with “customize” capability ?’ is closed to new replies.