Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更改功能标签后自定义帖子类型消失_Php_Wordpress - Fatal编程技术网

Php 更改功能标签后自定义帖子类型消失

Php 更改功能标签后自定义帖子类型消失,php,wordpress,Php,Wordpress,我希望用户组“订阅者”中的用户有权编写(自定义帖子类型)“指南”。我下载了会员插件,并授予编辑指南、删除指南权限。My Function.php当前为: add_action('init', 'cptui_register_my_cpt_guides'); function cptui_register_my_cpt_guides() { register_post_type('guides', array( 'label' => 'Guides', 'description' =>

我希望用户组“订阅者”中的用户有权编写(自定义帖子类型)“指南”。我下载了会员插件,并授予编辑指南、删除指南权限。My Function.php当前为:

add_action('init', 'cptui_register_my_cpt_guides');
function cptui_register_my_cpt_guides() {
register_post_type('guides', array(
'label' => 'Guides',
'description' => 'League of Legends Player Guides',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'guides',
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'guides', 'with_front' => true),
'query_var' => true,
'has_archive' => true,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats'),
'labels' => array (
  'name' => 'Guides',
  'singular_name' => 'guides',
  'menu_name' => 'Guides',
  'add_new' => 'Add guides',
  'add_new_item' => 'Add New guides',
  'edit' => 'Edit',
  'edit_item' => 'Edit guides',
  'new_item' => 'New guides',
  'view' => 'View guides',
  'view_item' => 'View guides',
  'search_items' => 'Search Guides',
  'not_found' => 'No Guides Found',
  'not_found_in_trash' => 'No Guides Found in Trash',
  'parent' => 'Parent guides',
)
) ); }

如果我的能力类型为post,则一切正常。但每当我改变它时,向导就会从wp管理中消失。提前感谢。

通过安装(插件)修复了它。出于某种原因,它确实能起作用

add_filter( 'map_meta_cap', 'my_map_meta_cap', 10, 4 );

function my_map_meta_cap( $caps, $cap, $user_id, $args ) {

    /* If editing, deleting, or reading a guides, get the post and post type object. */
    if ( 'edit_guides' == $cap || 'delete_guides' == $cap || 'read_guides' == $cap ) {
        $post = get_post( $args[0] );
        $post_type = get_post_type_object( $post->post_type );

        /* Set an empty array for the caps. */
        $caps = array();
    }

    /* If editing a guides, assign the required capability. */
    if ( 'edit_guides' == $cap ) {
        if ( $user_id == $post->post_author )
            $caps[] = $post_type->cap->edit_posts;
        else
            $caps[] = $post_type->cap->edit_others_posts;
    }

    /* If deleting a guides, assign the required capability. */
    elseif ( 'delete_guides' == $cap ) {
        if ( $user_id == $post->post_author )
            $caps[] = $post_type->cap->delete_posts;
        else
            $caps[] = $post_type->cap->delete_others_posts;
    }

    /* If reading a private guides, assign the required capability. */
    elseif ( 'read_guides' == $cap ) {

        if ( 'private' != $post->post_status )
            $caps[] = 'read';
        elseif ( $user_id == $post->post_author )
            $caps[] = 'read';
        else
            $caps[] = $post_type->cap->read_private_posts;
    }

    /* Return the capabilities required by the user. */
    return $caps;
}