Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

current user check

checks if currently logged in user is author of post

function by_check_author() {
global $post;
$post_id  = $post->ID;
$post_author_id= get_post_field ('post_author', $post_id);
$current_user_id = get_current_user_id();
        if($current_user_id == $post_author_id) {
           $author='true';
          }
     else {
     $author='false';
    }
return $author;
    
}
function by_check_author_draft() {
$current_user_id=get_current_user_id();
return $current_user_id;
}