0

我注册了一个新的帖子类型并将其命名为eassy.

我还添加了两个新的用户角色,一个是member_area,另一个是Mentor_area。现在,当member_area角色用户登录到仪表板时,他们只能查看、编辑、删除、发布自己的帖子..他们无法控制其他用户的帖子..

但万一mentor_area用户可以看到所有member_area用户的帖子,编辑,删除,(完全控制)。

这可以通过 WordPress 默认功能来完成,还是我必须为此使用插件?任何人都可以给我一个例子吗?

而且我还想知道如何在左侧 sidbar 上仅显示简单的帖子类型链接,用于 member_area 和 Mentor_area 仪表板

add_role ( 'member_area', 'Member Area', array (
        'read' => true 
) );
add_role ( 'mentor_area', 'Mentor Area', array (
        'read' => true 
) );
add_action ( 'init', 'create_my_post_types' );
function create_my_post_types() {
    $capabilities = array (
            'publish_posts' => 'publish_eassy',
            'edit_posts' => 'edit_eassy',
            'edit_others_posts' => 'edit_others_eassy',
            'delete_posts' => 'delete_eassy',
            'delete_others_posts' => 'delete_others_eassy',
            'read_private_posts' => 'read_private_eassy',
            'edit_post' => 'edit_eassy',
            'delete_post' => 'delete_eassy',
            'read_post' => 'read_eassy' 
    );
    register_post_type ( 'eassymamagment', array (
            'labels' => array (
                    'name' => __ ( 'Eassy' ),
                    'singular_name' => __ ( 'eassymamagment' ) 
            ),
            'public' => true,
            'capability_type' => 'eassymamagment',
            'menu_position' => 6,
            'capabilities' => $capabilities,
            'rewrite' => array (
                    'slug' => 'eassymamagment' 
            ) 
    ) );
}
4

1 回答 1

0

您可以创建新的自定义帖子类型的 Easy:

/*Registery of new post-type:Eassy */
add_action('init', 'create_eassy_taxonomies');
    function create_eassy_taxonomies() {
            register_taxonomy('eassy','eassy',
                              array('hierarchical' => true,
                                    'label' => 'Eassy Category') );
    }

add_action( 'init', 'create_post_type' );
    function create_post_type() {
        register_post_type( 'eassy',
            array(
                'labels' => array(
                    'name' => _x( 'Eassy', 'taxonomy general name' ),
                    'singular_name' => _x( 'Eassy', 'taxonomy singular name' ),
                    'search_items' =>  __( 'Search Eassy' ),
                    'all_items' => __( 'All Eassy' ),
                    'edit_item' => __( 'Edit Eassy' ), 
                    'update_item' => __( 'Update Eassy' ),
                    'add_new_item' => __( 'Add New Eassy' ),
                    'new_item_name' => __( 'New Eassy' ),
                    'menu_name' => __( 'Eassy' ),
                ),
            'public' => true,
            'has_archive' => true,
            'hierarchical' => true,
            'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes' )
            )
        );
    }

要显示此帖子类型:

$args = array( 'post_type' => 'eassy', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    the_title();
    echo '<div class="entry-content">';
    the_content();
    echo '</div>';
endwhile;

对于用户角色功能编辑器,您可以使用“用户角色编辑器插件”: http ://wordpress.org/extend/plugins/user-role-editor/

于 2013-05-06T06:00:42.293 回答