<?php


function tzinteriart_partner_item($atts)
{
    $tz_partner_image = $tz_partner_title = $tz_partner_link = '';
    extract(shortcode_atts(array(
        'tz_partner_image' => '',
        'tz_partner_title' => '',
        'tz_partner_link' => '',
    ), $atts));
    ob_start();

    $tz_img_id = preg_replace('/[^\d]/', '', $tz_partner_image);
    $tz_width_img = '';
    $tz_height_img = '';
    $tz_name = '';
    $tz_images_info = wp_get_attachment_image_src($tz_img_id, $size = 'full');
    if (isset($tz_images_info) && !empty($tz_images_info)) :
        $tz_url_img = $tz_images_info[0];
        $tz_width_img = $tz_images_info[1];
        $tz_height_img = $tz_images_info[2];
    endif;
    ?>
    <?php
    if ($tz_partner_link):
        ?>
        <div class="tz_partner_item">
            <a class="tz_partner_link" href="<?php if ($tz_partner_link) :
                echo esc_url($tz_partner_link);
            endif; ?>" target="_blank">
                <img width="<?php echo esc_attr($tz_width_img); ?>"
                     height="<?php echo esc_attr($tz_height_img); ?>"
                     alt="<?php echo esc_attr($tz_name); ?>"
                     src="<?php echo esc_url($tz_url_img); ?>"
                     title="<?php if ($tz_partner_title) :
                         echo esc_attr($tz_partner_title);
                     endif; ?>">
            </a>
        </div>
    <?php
    else:
        ?>
        <div class="tz_partner_item">
            <img width="<?php echo esc_attr($tz_width_img); ?>"
                 height="<?php echo esc_attr($tz_height_img); ?>"
                 alt="<?php echo esc_attr($tz_name); ?>"
                 src="<?php echo esc_url($tz_url_img); ?>"
                 title="<?php if ($tz_partner_title) :
                     echo esc_attr($tz_partner_title);
                 endif; ?>">
        </div>
    <?php
    endif;
    ?>
    <?php
    return ob_get_clean();
}

add_shortcode('tz-partner-item', 'tzinteriart_partner_item');
?>
