Conditions for adding capabilities to role?

How can i add custom field validation to this code? if musteri_danismani field is equal to current user, user can edit post. (musteri_danismani is a custom field.)

function author_can_edit_post(){
  	$role = get_role( 'author' );
	$user = wp_get_current_user();
	$userid = $user->ID;
	
	if ( $musteri_danismani == $userid ){ 
    	$role->add_cap( 'edit_others_posts' ); 
 	}
    else {
    	$role->remove_cap( 'edit_others_posts' ); 
  	}
}
add_action( 'init', 'author_can_edit_post' );

Anyone can help me ?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.