Skip to content

Commit

Permalink
Site screenshot: Add size as a separate parameter from type
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle committed Sep 22, 2023
1 parent 28c5d02 commit 42d54b4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );
Expand Down

0 comments on commit 42d54b4

Please sign in to comment.