plugins - Can’t delete a custom post in front end with custom role

forks!Well, I’m developing a plugin with a custom post type and I need create a front end page with form who allow a cus

forks!

Well, I’m developing a plugin with a custom post type and I need create a front end page with form who allow a custom role (create by third part plugin) create and delete my custom post. But, I receive a not allow delete error alert.

Register CPT.

register_post_type('zonas',
    array(
        'labels'      => array(
            'name'          => __('Zonas de treino'),
            'singular_name' => __('Zona de treino'),
    ),
        'public'      => true,
        'has_archive' => true,
        'rewrite'     => ["slug" => "zonas"],
        "menu_position" => 120, 
        'capabilities' => array(
            'edit_post'          => 'edit_zonas', 
            'read_post'          => 'read_zonas', 
            'delete_post'        => 'delete_zonas', 
            'edit_posts'         => 'edit_zonas', 
            'edit_others_posts'  => 'edit_others_zonas', 
            'publish_posts'      => 'publish_zonas',       
            'read_private_posts' => 'read_private_zonas', 
            'create_posts'       => 'edit_zonas', 
            'delete_published_posts' => 'delete_published_zonas'
        ),
        "menu_icon"     => "dashicons-clock",
        "supports"      => [
            "title"
        ]
    )
);

Function to generate delete link (works with administrator role)

function wp_delete_post_link($link = 'Excluir', $before = '', $after = '', $post) {    
    $link = "".$link."";
    echo $before . $link . $after;
}

forks!

Well, I’m developing a plugin with a custom post type and I need create a front end page with form who allow a custom role (create by third part plugin) create and delete my custom post. But, I receive a not allow delete error alert.

Register CPT.

register_post_type('zonas',
    array(
        'labels'      => array(
            'name'          => __('Zonas de treino'),
            'singular_name' => __('Zona de treino'),
    ),
        'public'      => true,
        'has_archive' => true,
        'rewrite'     => ["slug" => "zonas"],
        "menu_position" => 120, 
        'capabilities' => array(
            'edit_post'          => 'edit_zonas', 
            'read_post'          => 'read_zonas', 
            'delete_post'        => 'delete_zonas', 
            'edit_posts'         => 'edit_zonas', 
            'edit_others_posts'  => 'edit_others_zonas', 
            'publish_posts'      => 'publish_zonas',       
            'read_private_posts' => 'read_private_zonas', 
            'create_posts'       => 'edit_zonas', 
            'delete_published_posts' => 'delete_published_zonas'
        ),
        "menu_icon"     => "dashicons-clock",
        "supports"      => [
            "title"
        ]
    )
);

Function to generate delete link (works with administrator role)

function wp_delete_post_link($link = 'Excluir', $before = '', $after = '', $post) {    
    $link = "".$link."";
    echo $before . $link . $after;
}
Share Improve this question asked Jun 25, 2019 at 20:09 Patrick AcioliPatrick Acioli 1
Add a comment  | 

1 Answer 1

Reset to default 1

Look at line 63 of the code https://developer.wordpress/reference/functions/map_meta_cap/

If you don't provide a specific post, it is not allowed.

Your code is mixing meta capabilities with primitive capabilities. (yours are all plural or primitive)

"Meta" capabilities, e.g. 'edit_post', 'edit_user', etc., are capabilities used by map_meta_cap() to map to other "primitive" capabilities, e.g. 'edit_posts', 'edit_others_posts', etc.

The meta capability uses the object to make it into a primitive, but if you don't pass it in the link, how can it be used?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745369434a4624732.html

相关推荐

  • plugins - Can’t delete a custom post in front end with custom role

    forks!Well, I’m developing a plugin with a custom post type and I need create a front end page with form who allow a cus

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信