【问题标题】:How to enable a custom post type to custom user role in WordPress如何在 WordPress 中启用自定义帖子类型以自定义用户角色
【发布时间】:2018-01-04 13:55:50
【问题描述】:

我使用 WordPress Custom Post Type UI 插件创建了一个名为 Course Documents 的自定义帖子类型。 我还创建了一个名为 Teacher 的新用户角色。

add_role('rpt_teacher',
            'Teacher',
            array(
                'read' => true,
                'edit_posts' => false,
                'delete_posts' => false,
                'publish_posts' => false,
                'upload_files' => true,
            )
        );

现在我想在教师仪表板导航菜单中启用自定义帖子类型。 我在我的functions.php中使用了以下代码 但什么也没发生。如何解决我的问题?

add_action('admin_init','rpt_add_role_caps',999);
    /**
    add teachers capability
    */
    function rpt_add_role_caps() {

        // Add the roles you'd like to administer the custom post types
        $roles = array('rpt_teacher','editor','administrator');

        // Loop through each role and assign capabilities
        foreach($roles as $the_role) {    
             $role = get_role($the_role);               
             $role->add_cap( 'read' );
             $role->add_cap( 'read_course_document');
             $role->add_cap( 'edit_course_document' );
             $role->add_cap( 'edit_course_documents' );
             $role->add_cap( 'edit_published_course_documents' );
             $role->add_cap( 'publish_course_documents' );
             $role->add_cap( 'delete_published_course_documents' );
        }
        }

【问题讨论】:

标签: php wordpress custom-post-type user-roles


【解决方案1】:

您可以将此插件用于您的自定义帖子类型和自定义用户角色。

希望这会对您有所帮助。

如需了解更多信息,

【讨论】:

    猜你喜欢
    • 2021-06-09
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 1970-01-01
    • 2012-09-01
    相关资源
    最近更新 更多