From 6bc43e81262060bbadeb3b93178dcd962ca1079c Mon Sep 17 00:00:00 2001 From: Luberlu Date: Fri, 10 Dec 2021 18:47:39 +0100 Subject: [PATCH] Reduce API calls with Transients API If a template has several videos, it makes a lot of API calls and it's slow down generation of the page. --- includes/fields/class-acf-field-oembed.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/includes/fields/class-acf-field-oembed.php b/includes/fields/class-acf-field-oembed.php index d13470e9..555f8819 100644 --- a/includes/fields/class-acf-field-oembed.php +++ b/includes/fields/class-acf-field-oembed.php @@ -88,9 +88,16 @@ function wp_oembed_get( $url = '', $width = 0, $height = 0 ) { 'width' => $width, 'height' => $height, ); - - // get emebed - $embed = @wp_oembed_get( $url, $res ); + + // check if a transient exist for this oembed, to reduce API calls + $embed = get_transient($url); + + if(!$embed){ + + // get emebed + $embed = @wp_oembed_get($url, $res); + set_transient($url, $embed); + } // try shortcode if ( ! $embed ) {