From 740a73b00fd806eba0167a97142cd1ff99541552 Mon Sep 17 00:00:00 2001 From: Greg Date: Sun, 22 Jan 2023 01:25:50 -0500 Subject: [PATCH] Add size attribute to the image shortcode. --- includes/class-shortcodes.php | 14 +++++++++++++- templates/settings.php | 14 +++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/includes/class-shortcodes.php b/includes/class-shortcodes.php index 7b25128..7091106 100644 --- a/includes/class-shortcodes.php +++ b/includes/class-shortcodes.php @@ -257,7 +257,19 @@ class Shortcodes { return ''; } - $image = \get_the_post_thumbnail_url( $this->post->ID, 'full' ); + $size = 'full'; + + if( is_array( $atts ) && array_key_exists( 'size', $atts ) ) { + $registered_sizes = wp_get_registered_image_subsizes(); + + if( array_key_exists( $atts['size'], $registered_sizes ) ) { + $size = intval( $atts['size'] ); + } + } + + if( ! $size ) { $size = 'full'; } + + $image = \get_the_post_thumbnail_url( $this->post->ID, $size ); if ( ! $image ) { return ''; diff --git a/templates/settings.php b/templates/settings.php index 498c2ac..6e81b94 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -9,7 +9,15 @@ ); $image_sizes = wp_get_registered_image_subsizes(); -$thumnail_size = $image_sizes['thumbnail']['width'] . 'x' . $image_sizes['thumbnail']['height'] . ' px'; +$thumbnail_size = $image_sizes['thumbnail']['width'] . 'x' . $image_sizes['thumbnail']['height'] . ' px'; +$registered_sizes = ''; + +foreach( $image_sizes as $name => $size ) { + $registered_sizes .= $name . ', '; +} + +$registered_sizes = trim( $registered_sizes, ', ' ); +$registered_sizes .= '.'; ?> @@ -73,8 +81,8 @@ $thumnail_size = $image_sizes['thumbnail']['width'] . 'x' . $image_sizes['thumbn
  • [ap_shortlink] - Hum, to prettify the Shortlinks', 'activitypub' ), 'default' ); ?>
  • [ap_hashtags] -
  • [ap_hashcats] -
  • -
  • [ap_image] -
  • -
  • [ap_thumbnail] -
  • +
  • [ap_image size=xxx] -
  • +
  • [ap_thumbnail] -
  • [ap_author] -
  • [ap_authorurl] -
  • [ap_date] -