<?php
/**
 * Created by PhpStorm.
 * User: adiardana
 * Date: 02/05/19
 * Time: 19.36
 */
add_action('wpex_hook_primary_before', function(){
    if(get_post_type() == 'staff'){
        $id = get_the_ID();
        $html = '<div class="lawyers-information">';
        if(has_post_thumbnail($id)){
            $img = wp_get_attachment_image_url(get_post_thumbnail_id($id), 'full');
            $html .= '<div class="lawyers-image"><img src="'.$img.'"/></div>';
        }
        if(get_field('phone', $id)){
            $phone = get_field('phone', $id);
            $html .= '<p><a href="'.$phone['url'].'" target="'.$phone['target'].'"><i class="fa fa-phone-square" aria-hidden="true"></i> '.$phone['title'].'</a></p>';
        }
        if(get_field('email', $id)){
            $email = get_field('email', $id);
            $html .= '<p><a href="'.$email['url'].'" target="'.$email['target'].'"><i class="fa fa-envelope" aria-hidden="true"></i> '.$email['title'].'</a></p>';
        }
        $html .= '</div>';
        echo $html;
    }
});

add_filter( 'wpex_blog_single_blocks', function( $blocks ) {

//    var_dump($blocks);
//    unset($blocks['related_posts']);
//    var_dump($blocks);
//    // Add new block "advertisement"
//    $blocks['advertisement'] = __( 'My Advertisement', 'total' );

    // Return blocks
    return $blocks;

} );

add_filter( 'wpex_blog_single_layout_blocks', function( $blocks ) {
    $blocks = [
        'featured_media' => 'featured_media',
        'title' => 'title',
        'meta' => 'meta',
        'post_series' => 'post_series',
        'the_content' => 'the_content',
        'post_tags' => 'post_tags',
        'social_share' => 'social_share'
    ];

    $blocks['author'] = function(){
        global $post;

        $id = $post->post_author;
        $display_name = get_the_author_meta('display_name');
        $description = get_the_author_meta('description');
        $user_url = get_author_posts_url($id);

        $html = '';
        $html .= '<div class="post-author-wrapper has-thumbnail">';
            $html .= '<div class="clearfix">';
                $html .= '<div class="author-image"><a href="'.$user_url.'">';
                if (function_exists ( 'mt_profile_img' ) ) {
                    $html .= mt_profile_img( $id, array(
                            'size' => 'full',
                            'echo' => false )
                    );
                }
                $html .= '</a></div>';
                $html .= '<div class="content">';
                    $html .= '<h2 class="heading"><a href="'.$user_url.'">'.$display_name.'</a></h2>';
                    $html .= '<p>'.$description.'</p>';
                    $html .= '<p><a href="'.$user_url.'">Read more about '.$display_name.'</a></p>';
                $html .= '</div>';
            $html .= '</div>';
        $html .= '</div>';

        echo $html;
    };
    return $blocks;
});