if( current_user_can( 'edit_posts' ) ) { // User has permission, do something } else { // User does not have permission, show error message }
$post_id = 123; // ID of post to check if( user_can( $post_id, 'edit_post' ) ) { // User has permission to edit the post, do something } else { // User does not have permission to edit the post, show error message }
$custom_cap = 'my_custom_capability'; // Custom capability to check if( current_user_can( $custom_cap ) ) { // User has the custom capability, do something } else { // User does not have the custom capability, show error message }