【问题标题】:New user role in WordPressWordPress 中的新用户角色
【发布时间】:2018-11-08 14:34:43
【问题描述】:

我在我的 functions.php 文件中的 WordPress 中创建了新用户 role (Manager)。这是我的代码,但它不起作用。管理员只能阅读帖子,不能编辑和删除。怎么了?

谢谢。

function ui_new_role() {  

    //add the new user role
    add_role(
        'manager',
        'Manager',
        array(

    'edit_'              => true,
    'read_'              => true,
    'delete_'            => true,


    'edit_s'             => true,
    'edit_others_s'      => true,
    'publish_s'          => true,
    'read_private_s'     => true,


    'delete_s'           => true,
    'delete_private_s'   => true,
    'delete_published_s' => true,
    'delete_others_s'    => true,
    'edit_private_s'     => true,
    'edit_published_s'   => true,
        )
    );

}
add_action('admin_init', 'ui_new_role');

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    创建一个新的“经理”角色。

    $result = add_role(
        'manager',
        __( 'Manager' ),
        array(
            'read'         => true,  // true allows this capability
            'edit_posts'   => true,
            'delete_posts' => true, // Use false to explicitly deny
        )
    );
    if ( null !== $result ) {
        echo 'New role created!';
    }
    else {
        echo 'Manager role already exists.';
    }
    

    reference

    【讨论】:

    • 对不起,但仍然无法使用它。用户只阅读帖子。
    • 如果然后删除所有缓存,您是否使用缓存插件。
    【解决方案2】:

    根据documentation,您添加的角色不正确。您的特权名称与我所知道的任何内容都不匹配。在我看来,通过插件添加会更好。

    function add_mgr_role()
    {
        add_role(
            'manager',
            'Manager',
            array(
                'read' => true,
                'edit_posts' => true,
                'delete_posts' => true
            )
        );
    }
    
    register_activation_hook(__FILE__, 'add_mgr_role');
    

    【讨论】:

      猜你喜欢
      • 2018-01-12
      • 1970-01-01
      • 2015-11-26
      • 2016-01-10
      • 2018-05-10
      • 2017-12-15
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      相关资源
      最近更新 更多