【问题标题】:add, edit, delete pages capability in custom user role在自定义用户角色中添加、编辑、删除页面功能
【发布时间】:2019-03-05 00:26:37
【问题描述】:

尝试在 Wordpress 自定义用户角色中添加“添加、编辑和删除页面”功能。

我正在下面创建一个自定义用户角色,即“sub admin”。我正在尝试授予对所有“页面”功能的访问权限;但即使确定以下内容,它也不起作用。 (没有'添加页面,编辑当前页面标签显示)。

也许还要注意;我正在从自定义子主题的 /function.php 文件中尝试此操作。该角色在以下代码(即子管理员)之后显示在 WP 仪表板中,但是我未能成功允许访问页面。

add_role(
    'sub_admin',
    __( 'Sub Admin' ),
    array(
        'read'         => true,  
        'edit_posts'   => true,
        'publish_posts' => true,
        'edit_pages'   => true,
        'edit_others_pages' => true,
        'publish_page' => true,
        'edit_pages'=>true,
        'edit_published_pages'=>true,
        'publish_pages'=>true,
        'delete_pages'=>true,
        'delete_others_pages'=>true,
        'delete_published_pages'=>true,
    )
);

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    请尝试通过这些方法解决您的问题

    请确保您的角色是通过从 add_role 获取结果创建的

    $result = add_role(/*your args*/);
    if ( null !== $result ) {
      echo 'Yay! New role created!';
    }
    else {
          echo 'Oh... the basic_contributor role already exists.';
    }
    

    如果不行。请确保,当您尝试编辑页面时,您具有此 sub_admin 角色

    如果问题仍然存在,请注意 wordpress 开发者指南通知

    在第一次调用 add_role() 之后,角色及其能力 将存储在数据库中!

    顺序调用不会做任何事情:包括更改功能 列表,这可能不是您所期望的行为。

    也许你需要remove_role(),然后再add_role。 也许你第一次创建角色时没有一些能力。

    另外,请尝试使用初始化操作来添加角色

    function wporg_simple_role()
    {
        remove_role('sub_admin');
        // or add_role('sub_admin');
    }
    
    
    add_action('init', 'wporg_simple_role');
    

    也许没有编辑角色,所有管理员权限是

    activate_plugins
    delete_others_pages
    delete_others_posts
    delete_pages
    delete_posts
    delete_private_pages
    delete_private_posts
    delete_published_pages
    delete_published_posts
    edit_dashboard
    edit_others_pages
    edit_others_posts
    edit_pages
    edit_posts
    edit_private_pages
    edit_private_posts
    edit_published_pages
    edit_published_posts
    edit_theme_options
    export
    import
    list_users
    manage_categories
    manage_links
    manage_options
    moderate_comments
    promote_users
    publish_pages
    publish_posts
    read_private_pages
    read_private_posts
    read
    remove_users
    switch_themes
    upload_files
    customize
    delete_site
    

    也许管理栏也依赖于 manage_options。 您可以通过检查不是管理页面来删除 manage_options 功能

    function change_role() {
        global $wp_roles;
    
        if ( ! is_admin() ) {
            return;
        }
    
        // if not admin page - you could temporary remove manage capabilities from 
        // sub_admin role
    
    
    }
    
    add_action('wp', 'change_role');
    

    【讨论】:

      猜你喜欢
      • 2014-09-05
      • 2019-07-17
      • 1970-01-01
      • 2018-05-15
      • 1970-01-01
      • 1970-01-01
      • 2012-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多