From 416f1cb86c301a63cfa2484bdbc211be8ea137d2 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 25 Mar 2020 20:06:35 +0200 Subject: [PATCH] ensure a video is synced before trying to use metadata --- .../php/media/class-video.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php index cc467401d..a461f841f 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-video.php @@ -199,14 +199,21 @@ public function filter_video_shortcode( $html, $attr ) { if ( false === $this->player_enabled ) { return $html; }; - - // Queue video. - $video = wp_get_attachment_metadata( $attr['id'] ); + // Check for override flag. $overwrite_transformations = false; if ( ! empty( $attr['cldoverwrite'] ) ) { $overwrite_transformations = true; } - $cloudinary_url = $this->media->cloudinary_url( $attr['id'], false, false, null, $overwrite_transformations ); + // Check for a cloudinary url, or prep sync if not found. + $cloudinary_url = $this->media->cloudinary_url( $attr['id'], false, false, null, $overwrite_transformations ); + if ( ! $this->media->plugin->components['sync']->is_synced( $attr['id'] ) ) { + // If the asset is not synced, then the metadata will not be complete since v1 didn't save any. + // Return html for now since cloudinary_url will queue it up for syncing in the background. + return $html; + } + + // Queue video. + $video = wp_get_attachment_metadata( $attr['id'] ); $transformations = $this->media->get_transformations_from_string( $cloudinary_url, 'video' ); $args = array();