如何在wordpress中只读自定义文章类型?

问题描述:

我创建了名为“预订”的自定义帖子类型。我想让这个帖子类型只读意味着“添加新的”和“编辑”选项不应该显示在后端。 这篇文章类型不是与plugin.This相关的是简单的自定义类型后,显示预订details.Here是我的代码..如何在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'); 

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

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

仅供参考,您添加到您的CPT什么能力,那就是将在用户角色编辑功能列表显示。

+0

谢谢回答。但是我只想让一个CPT只读,而不是全部。 您建议的插件基于用户角色。我认为这些设置会影响所有帖子类型。插件为不同功能提供功能。但这不适合我 – 2015-03-19 13:13:41

+0

我仍然认为这个插件是你正在寻找的,如果我正确地理解你。用户管理员将始终能够创建,发布,编辑和删除CPT,否则无法管理CPT,请更正?如果你想有一个只读到特定的CPT,那么你需要一个不同的用户类型,例如说,“读者”,和用户角色编辑器内设置该用户类型为只读到特定的CPT。通过将'map_meta_cap'设置为true,您可以获得基本功能。我不认为你只能获得阅读能力;必须由用户角色定义。 – 2015-03-19 14:36:47