如何在wordpress中制作只读自定义帖子类型?

时间:2015-03-19 12:43:06

标签: wordpress

我创建名为“预订”的自定义帖子类型。我想让这个帖子类型只读意味着“添加新”和“编辑”选项不应该显示在后端。 此帖子类型与插件无关。这是一个简单的自定义帖子类型,用于显示预订详情。这是我的代码..

function demotheme_register_post_types() {    

    //custom posttype booking
    $booking_labels = array(
                                'name'               => _x( 'Bookings', 'demotheme_booking', 'demotheme' ),
                                'singular_name'      => _x( 'Booking', 'demotheme_booking', 'demotheme' ),
                                'menu_name'          => _x( 'Bookings', 'demotheme_booking', 'demotheme' ),
                                'name_admin_bar'     => _x( 'Bookings', 'demotheme_booking', 'demotheme' ),
                                'add_new'            => _x( 'Add New', 'demotheme_booking', 'demotheme' ),
                                'add_new_item'       => __( 'Add New Booking', 'demotheme' ),
                                'new_item'           => __( 'New Booking', 'demotheme' ),
                                'edit_item'          => __( 'Edit Booking', 'demotheme' ),
                                'view_item'          => __( 'View Booking', 'demotheme' ),
                                'all_items'          => __( 'All Bookings', 'demotheme' ),
                                'search_items'       => __( 'Search Booking', 'demotheme' ),
                                'parent_item_colon'  => __( 'Parent Booking:', 'demotheme' ),
                                'not_found'          => __( 'No bookings found.', 'demotheme' ),
                                'not_found_in_trash' => __( 'No bookings found in Trash.', 'demotheme' ),
                            );

    $booking_args = array(
                            'labels'             => $booking_labels,
                            'public'             => true,
                            'publicly_queryable' => true,
                            'show_ui'            => true,
                            'show_in_menu'       => true,
                            'query_var'          => true,
                            'rewrite'            => false,
                            'capability_type'    => 'post',
                            'capabilities'       => array('read_post'=>'read_demotheme_booking'),
                            'map_meta_cap'       => true,
                            'has_archive'        => true,
                            'hierarchical'       => false,
                            'menu_position'      => null,
                            'supports'           => array( 'title', 'editor', 'excerpt', 'thumbnail', 'page-attributes' )
                        );

    register_post_type( DEMOTHEME_BOOKING_POST_TYPE, $booking_args );


    //flush rewrite rules
    flush_rewrite_rules();
}

//add action to create custom post type
add_action( 'init', 'demotheme_register_post_types' );

在后端,我只想查看预订/所有预订选项。不应显示发布或更新按钮。

1 个答案:

答案 0 :(得分:0)

您可能需要考虑使用插件来管理此任务的用户角色。我喜欢这个User Role Editor

仅供参考,无论您添加到CPT中的哪些功能,都会在用户角色编辑器的功能列表中显示。