diff options
Diffstat (limited to 'plugins/jetpack/modules/videopress/utility-functions.php')
-rw-r--r-- | plugins/jetpack/modules/videopress/utility-functions.php | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/plugins/jetpack/modules/videopress/utility-functions.php b/plugins/jetpack/modules/videopress/utility-functions.php index 947f7552..345fa719 100644 --- a/plugins/jetpack/modules/videopress/utility-functions.php +++ b/plugins/jetpack/modules/videopress/utility-functions.php @@ -30,8 +30,8 @@ function videopress_get_video_details( $guid ) { return new WP_Error( 'bad-guid-format', __( 'Invalid Video GUID!', 'jetpack' ) ); } - $version = '1.1'; - $endpoint = sprintf( '/videos/%1$s', $guid ); + $version = '1.1'; + $endpoint = sprintf( '/videos/%1$s', $guid ); $query_url = sprintf( 'https://public-api.wordpress.com/rest/v%1$s%2$s', $version, @@ -97,7 +97,7 @@ function videopress_get_attachment_id_by_url( $url ) { 'compare' => 'LIKE', 'value' => $file, ), - ) + ), ); $query = new WP_Query( $query_args ); @@ -113,7 +113,6 @@ function videopress_get_attachment_id_by_url( $url ) { } } } - } return false; @@ -134,7 +133,7 @@ function videopress_download_poster_image( $url, $attachment_id ) { return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL', 'jetpack' ) ); } - $file_array = array(); + $file_array = array(); $file_array['name'] = basename( $matches[0] ); $file_array['tmp_name'] = download_url( $url ); @@ -156,7 +155,7 @@ function videopress_download_poster_image( $url, $attachment_id ) { * Creates a local media library item of a remote VideoPress video. * * @param $guid - * @param int $parent_id + * @param int $parent_id * * @return int|object */ @@ -178,10 +177,13 @@ function create_local_media_library_for_videopress_guid( $guid, $parent_id = 0 ) if ( ! is_wp_error( $attachment_id ) ) { update_post_meta( $attachment_id, 'videopress_guid', $guid ); - wp_update_attachment_metadata( $attachment_id, array( - 'width' => $vp_data->width, - 'height' => $vp_data->height, - ) ); + wp_update_attachment_metadata( + $attachment_id, + array( + 'width' => $vp_data->width, + 'height' => $vp_data->height, + ) + ); $thumbnail_id = videopress_download_poster_image( $vp_data->poster, $attachment_id ); update_post_meta( $attachment_id, '_thumbnail_id', $thumbnail_id ); @@ -212,7 +214,7 @@ function videopress_cleanup_media_library() { 'key' => 'videopress_status', 'value' => 'new', ), - ) + ), ); $query = new WP_Query( $query_args ); @@ -272,7 +274,7 @@ function videopress_get_transcoding_status( $post_id ) { 'std_mp4' => isset( $info->mp4 ) ? $info->mp4 : null, 'std_ogg' => isset( $info->ogg ) ? $info->ogg : null, 'dvd_mp4' => isset( $info->dvd ) ? $info->dvd : null, - 'hd_mp4' => isset( $info->hd ) ? $info->hd : null, + 'hd_mp4' => isset( $info->hd ) ? $info->hd : null, ); return $status; @@ -518,10 +520,10 @@ function videopress_make_media_upload_path( $blog_id ) { function video_get_info_by_blogpostid( $blog_id, $post_id ) { $post = get_post( $post_id ); - $video_info = new stdClass(); - $video_info->post_id = $post_id; - $video_info->blog_id = $blog_id; - $video_info->guid = null; + $video_info = new stdClass(); + $video_info->post_id = $post_id; + $video_info->blog_id = $blog_id; + $video_info->guid = null; $video_info->finish_date_gmt = '0000-00-00 00:00:00'; if ( is_wp_error( $post ) ) { @@ -555,7 +557,7 @@ function video_get_info_by_blogpostid( $blog_id, $post_id ) { * API endpoint add all needed VideoPress data. * * @param stdClass $info - * @param string $format + * @param string $format * @return bool */ function video_format_done( $info, $format ) { @@ -637,16 +639,16 @@ function video_image_url_by_guid( $guid, $format ) { */ function video_get_post_by_guid( $guid ) { $args = array( - 'post_type' => 'attachment', + 'post_type' => 'attachment', 'post_mime_type' => 'video/videopress', - 'post_status' => 'inherit', - 'meta_query' => array( + 'post_status' => 'inherit', + 'meta_query' => array( array( - 'key' => 'videopress_guid', + 'key' => 'videopress_guid', 'value' => $guid, 'compare' => '=', - ) - ) + ), + ), ); $query = new WP_Query( $args ); @@ -661,7 +663,7 @@ function video_get_post_by_guid( $guid ) { * * When the MP4 hasn't been processed yet or this is not a VideoPress video, this will return null. * - * @param int $post_id + * @param int $post_id Post ID of the attachment. * @return string|null */ function videopress_get_attachment_url( $post_id ) { @@ -676,12 +678,15 @@ function videopress_get_attachment_url( $post_id ) { if ( ! isset( $meta['videopress']['files']['hd']['mp4'] ) ) { // Use the original file as the url if it isn't transcoded yet. if ( isset( $meta['original'] ) ) { - return $meta['original']; + $return = $meta['original']; + } else { + // Otherwise, there isn't much we can do. + return null; } - - // Otherwise, there isn't much we can do. - return null; + } else { + $return = $meta['videopress']['file_url_base']['https'] . $meta['videopress']['files']['hd']['mp4']; } - return $meta['videopress']['file_url_base']['https'] . $meta['videopress']['files']['hd']['mp4']; + // If the URL is a string, return it. Otherwise, we shouldn't to avoid errors downstream, so null. + return ( is_string( $return ) ) ? $return : null; } |