From 42d54b4cb4de1cb52b35921ee77cad3b15d2b686 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Fri, 22 Sep 2023 17:44:53 -0400 Subject: [PATCH] Site screenshot: Add size as a separate parameter from type --- .../themes/wporg-showcase-2022/src/site-screenshot/index.php | 4 ++-- .../themes/wporg-showcase-2022/src/site-screenshot/render.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/source/wp-content/themes/wporg-showcase-2022/src/site-screenshot/index.php b/source/wp-content/themes/wporg-showcase-2022/src/site-screenshot/index.php index 179b397e..a410ee46 100644 --- a/source/wp-content/themes/wporg-showcase-2022/src/site-screenshot/index.php +++ b/source/wp-content/themes/wporg-showcase-2022/src/site-screenshot/index.php @@ -30,14 +30,14 @@ function init() { * * @param WP_Post $post * @param string $type + * @param string $size * @return string */ -function get_site_screenshot_src( $post, $type = 'desktop' ) { +function get_site_screenshot_src( $post, $type = 'desktop', $size = 'screenshot-desktop' ) { $screenshot_url = false; $media_id = get_post_meta( $post->ID, 'screenshot-' . $type, true ); $cache_key = '20230913'; // To break out of cached image. - $size = 'screenshot-' . $type; $all_sizes = wp_get_registered_image_subsizes(); if ( ! isset( $all_sizes[ $size ] ) ) { return null; diff --git a/source/wp-content/themes/wporg-showcase-2022/src/site-screenshot/render.php b/source/wp-content/themes/wporg-showcase-2022/src/site-screenshot/render.php index 9a6fc965..9a304fcd 100644 --- a/source/wp-content/themes/wporg-showcase-2022/src/site-screenshot/render.php +++ b/source/wp-content/themes/wporg-showcase-2022/src/site-screenshot/render.php @@ -13,7 +13,8 @@ $has_link = isset( $attributes['isLink'] ) && true == $attributes['isLink']; $is_lazyload = isset( $attributes['lazyLoad'] ) && true === $attributes['lazyLoad']; -$screenshot = get_site_screenshot_src( $current_post, $attributes['type'] ); +$img_size = ( 'desktop' === $attributes['type'] ) ? 'screenshot-desktop' : 'screenshot-mobile'; +$screenshot = get_site_screenshot_src( $current_post, $attributes['type'], $img_size ); $is_mshots = str_contains( $screenshot, 'mshots' ); $classname = 'is-size-' . esc_attr( $attributes['type'] );