admin管理员组

文章数量:1122832

I am using a ACF field on the user profile.php to assign a post id to a user. The users need to be able to receive the capability to edit this post, but only this post. They should not be allowed to edit any other posts, or see them in the admin.

I cannot do this by simply assigning them as the post author, as there are multiple users per post.

I tried using map_meta_cap but cannot get it to work.

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

    if( user_can($user_id, 'koppel_recht') ) {  
        return $caps;
    } 

    $currentuser = 'user_' . $user_id;
    $koppel = get_field('gekoppeld_register', $currentuser);

    if ( 'edit_registers' == $cap || 'edit_others_registers' == $cap ) {

        if ( $args[0] != $koppel) {
            return [ 'do_not_allow' ];
        }
        else {
            return $caps;
        }
    }
    return $caps;
}
add_filter( 'map_meta_cap', 'my_map_meta_cap', 10, 4 );

koppel_recht is the capability for roles that are allowed to see all the posts in this post type.

本文标签: custom fieldOnly allow users (that are not admins) to edit a specific post