Skip to content

Commit

Permalink
Add image caching to jetpack_og_get_image() (#6297)
Browse files Browse the repository at this point in the history
* Add image caching to jetpack_og_get_image()

This adds a transient to store the value of the $image_id to "speed up"  the function to fix #6017

* Added missing semicolons at EOL on a couple lines

* Adding some whitespace per coding standards
  • Loading branch information
jeherve authored and dereksmart committed Feb 8, 2017
1 parent 9f8402b commit d66cb0f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions functions.opengraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,13 @@ function jetpack_og_get_image( $width = 200, $height = 200, $max_images = 4 ) {

$img_width = '';
$img_height = '';
$image_id = attachment_url_to_postid( $image_url );
$cached_image_id = get_transient( 'jp_' . $image_url );
if ( false !== $cached_image_id ) {
$image_id = $cached_image_id;
} else {
$image_id = attachment_url_to_postid( $image_url );
set_transient( 'jp_' . $image_url, $image_id );
}
$image_size = wp_get_attachment_image_src( $image_id, $width >= 512
? 'full'
: array( $width, $width ) );
Expand Down Expand Up @@ -351,7 +357,15 @@ function jetpack_og_get_image( $width = 200, $height = 200, $max_images = 4 ) {

$img_width = '';
$img_height = '';
$image_id = get_option( 'site_icon' );
$cached_image_id = get_transient( 'jp_' . $image_url );

if ( false !== $cached_image_id ) {
$image_id = $cached_image_id;
} else {
$image_id = attachment_url_to_postid( $image_url );
set_transient( 'jp_' . $image_url, $image_id );
}

$image_size = wp_get_attachment_image_src( $image_id, $max_side >= 512
? 'full'
: array( $max_side, $max_side ) );
Expand Down

0 comments on commit d66cb0f

Please sign in to comment.