block.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * Name: Single image
  4. * Section: content
  5. * Description: A single image with link
  6. */
  7. /* @var $options array */
  8. /* @var $wpdb wpdb */
  9. $defaults = array(
  10. 'image' => '',
  11. 'url' => '',
  12. 'block_background' => '#ffffff',
  13. 'block_padding_left' => 0,
  14. 'block_padding_right' => 0,
  15. 'block_padding_bottom' => 15,
  16. 'block_padding_top' => 15
  17. );
  18. $options = array_merge($defaults, $options);
  19. $alt = '';
  20. if (empty($options['image']['id'])) {
  21. // A placeholder can be set by a preset and it is kept indefinitely
  22. if (!empty($options['placeholder'])) {
  23. $image = $options['placeholder'];
  24. } else {
  25. $image = 'https://source.unsplash.com/600x250/daily';
  26. }
  27. } else {
  28. $image = tnp_media_resize($options['image']['id'], array(600, 0));
  29. $alt = $options['image_alt'];
  30. }
  31. $url = $options['url'];
  32. ?>
  33. <?php if (!empty($url)) { ?>
  34. <a href="<?php echo $url ?>" target="_blank"><img src="<?php echo $image ?>" border="0" alt="" style="max-width: 100%!important; height: auto!important; display: inline-block;"></a>
  35. <?php } else { ?>
  36. <img src="<?php echo $image ?>" border="0" alt="<?php echo esc_attr($alt) ?>" style="max-width: 100%!important; height: auto!important; display: inline-block;">
  37. <?php } ?>