• Hi,

    I have added a role in my functions php just like this.

    $result = add_role( 'traveler', __(
                'Traveler' ),
                array(
    
                    'read' => true,
                    'edit_posts' => true,
                    'edit_pages' => false,
                    'edit_others_posts' => false,
                    'delete_published_posts' => true,
                    'delete_posts'=> true,
                    'edit_published_posts'=>true,
                    'create_posts' => true,
                    'manage_categories' => true,
                    'publish_posts' => true, 
    
                    )
    
    );

    And in a custom post type I display on the frontend a link to delete the post with the function get_delete_post_link( ).

    This works link works fine for me as an administrator, or for an user with author role, but not for users with traveler role. So I guess there is a capabilitie missing there, but travelers aleready have the same capabilities than a author… What is wrong?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • You need to use and activate User Role Editor wordpress plugin
    https://wordpress.org/plugins/user-role-editor/.
    Once you activated ,Log into wordpress admin dashboard, where in left side admin menu there is “User Role Editor” menu present below the “USER” menu ,from where you need edit capabilities of role “traveler” and need to assign with delete_posts and delete_other_posts capabilities to role “traveler”.

    Thread Starter mchapela

    (@mchapela)

    I tried doing that, but didn’t work. Also I added the capabilitie delete_other_posts to the role traveler in my functions.php but doesn’t work…

    you need to add capabilities delete_other_posts using above plugin.
    As below code not going to update previously added capabilities
    $result = add_role( ‘traveler’, __(
    ‘Traveler’ ),
    array(

    ‘read’ => true,
    ‘edit_posts’ => true,
    ‘edit_pages’ => false,
    ‘edit_others_posts’ => false,
    ‘delete_published_posts’ => true,
    ‘delete_posts’=> true,
    ‘edit_published_posts’=>true,
    ‘create_posts’ => true,
    ‘manage_categories’ => true,
    ‘publish_posts’ => true,

    )

    );

    Thread Starter mchapela

    (@mchapela)

    I did both using the plugin and adding code in functions.php

    Using below capabilities for user traveler, set using User Role Editor Plugin:
    delete_others_posts
    delete_posts
    delete_published_posts
    edit_posts
    edit_published_posts
    manage_categories
    publish_posts
    read

    I can delete post using
    get_delete_post_link($pid) function

    below are my sampel code that I have used for testing:

    while ( have_posts() ) : the_post();
    $pid=get_the_ID();
    
    echo '<a href="'.get_delete_post_link($pid).'">Delete Post</a>';
    
    endwhile;
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Role can't delete post’ is closed to new replies.