<?php

function mpwbpk_template_func__get_post_excerpt($post_id){
    $post = get_post($post_id);
    if($post){
        $text = $post->post_excerpt;
        $text = apply_filters('the_excerpt', $text);
        if(empty($text)){
            $text = $post->post_content;
            $text = apply_filters('the_content', $text);
            $text = substr( $text, 0, strpos( $text, '</p>' ) + 4 );
            $text = wp_kses($text, ['p', 'div']);
        }
        $text = wp_trim_words($text, 32);
        return trim($text);
    }
    return '';
}