Skip to content
Browse files

switch_to_blog when the function exists

  • Loading branch information...
1 parent 65c9be7 commit 523b997a78fb83bb4177e62c53c0e9a5ef8ba0d3 @matzko committed
Showing with 66 additions and 22 deletions.
  1. +3 −1 includes/do-transcoding.php
  2. +36 −12 includes/video-transcoder.php
  3. +27 −9 video-access.php
View
4 includes/do-transcoding.php
@@ -34,7 +34,9 @@
$user_id
) );
-switch_to_blog( $blog_id );
+if ( function_exists( 'switch_to_blog' ) ) {
+ switch_to_blog( $blog_id );
+}
global $video_transcoding_control;
View
48 includes/video-transcoder.php
@@ -609,7 +609,9 @@ protected function _video_create_info( $blog_id = 0, $video_id = 0, $path = '' )
$blog_id = (int) $blog_id;
$video_id = (int) $video_id;
- switch_to_blog( $blog_id );
+ if ( function_exists( 'switch_to_blog' ) ) {
+ switch_to_blog( $blog_id );
+ }
global $wpdb;
@@ -626,7 +628,9 @@ protected function _video_create_info( $blog_id = 0, $video_id = 0, $path = '' )
update_post_meta( $video_id, 'fmt_std', 'initiated' );
update_post_meta( $video_id, '_parent_site_video', $video_id );
- restore_current_blog();
+ if ( function_exists( 'restore_current_blog' ) ) {
+ restore_current_blog();
+ }
}
protected function _video_finaltouch(
@@ -640,7 +644,9 @@ protected function _video_finaltouch(
$blog_id = (int) $blog_id;
$video_id = (int) $video_id;
- switch_to_blog( $blog_id );
+ if ( function_exists( 'switch_to_blog' ) ) {
+ switch_to_blog( $blog_id );
+ }
$this->_update_video_info( $blog_id, $video_id, $format, 'fileserver_received_request' );
@@ -732,7 +738,9 @@ protected function _video_finaltouch(
$finish_date_gmt = gmdate( 'Y-m-d H:i:s' );
$this->_update_video_info( $blog_id, $video_id, 'finish_date_gmt', $finish_date_gmt );
- restore_current_blog();
+ if ( function_exists( 'restore_current_blog' ) ) {
+ restore_current_blog();
+ }
}
/*
@@ -799,17 +807,25 @@ public function get_video_height( $blog_id = 0, $video_id = 0 )
$blog_id = (int) $blog_id;
$video_id = (int) $video_id;
- switch_to_blog( $blog_id );
+ if ( function_exists( 'switch_to_blog' ) ) {
+ switch_to_blog( $blog_id );
+ }
$height = get_post_meta( $video_id, 'height', true );
- restore_current_blog();
+ if ( function_exists( 'restore_current_blog' ) ) {
+ restore_current_blog();
+ }
return $height;
}
public function get_video_width( $blog_id = 0, $video_id = 0 )
{
- switch_to_blog( $blog_id );
+ if ( function_exists( 'switch_to_blog' ) ) {
+ switch_to_blog( $blog_id );
+ }
$width = get_post_meta( $video_id, 'width', true );
- restore_current_blog();
+ if ( function_exists( 'restore_current_blog' ) ) {
+ restore_current_blog();
+ }
return $width;
}
@@ -825,7 +841,9 @@ public function get_video_formats( $blog_id = 0, $video_id = 0 )
$blog_id = (int) $blog_id;
$video_id = (int) $video_id;
- switch_to_blog( $blog_id );
+ if ( function_exists( 'switch_to_blog' ) ) {
+ switch_to_blog( $blog_id );
+ }
$key = 'video-info-by-' . $blog_id . '-' . $video_id;
if ( ! $info = wp_cache_get( $key, 'video-format-info' ) ) {
@@ -833,7 +851,9 @@ public function get_video_formats( $blog_id = 0, $video_id = 0 )
wp_cache_set( $key, $info, 'video-format-info', 12*60*60 );
}
- restore_current_blog();
+ if ( function_exists( 'restore_current_blog' ) ) {
+ restore_current_blog();
+ }
return $info;
}
@@ -1188,7 +1208,9 @@ protected function _update_video_info( $blog_id = 0, $video_id = 0, $key = '', $
$blog_id = (int) $blog_id;
$video_id = (int) $video_id;
- switch_to_blog( $blog_id );
+ if ( function_exists( 'switch_to_blog' ) ) {
+ switch_to_blog( $blog_id );
+ }
if ( $key == 'fmt1_ogg' ){
@@ -1217,7 +1239,9 @@ protected function _update_video_info( $blog_id = 0, $video_id = 0, $key = '', $
$key3 = 'video-xml-by-' . $guid;
wp_cache_delete( $key3, 'video-info' );
- restore_current_blog();
+ if ( function_exists( 'restore_current_blog' ) ) {
+ restore_current_blog();
+ }
return true;
}
View
36 video-access.php
@@ -586,6 +586,24 @@ protected function _process_video_upload_form( $posted = array(), $is_ajax = fal
}
}
}
+
+ public static function restore_current_blog()
+ {
+ if ( function_exists( 'restore_current_blog' ) ) {
+ return restore_current_blog();
+ } else {
+ return false;
+ }
+ }
+
+ public static function switch_to_blog( $blog_id = 0 )
+ {
+ if ( function_exists( 'switch_to_blog' ) ) {
+ return switch_to_blog( $blog_id );
+ } else {
+ return false;
+ }
+ }
}
class Video_Access_Model
@@ -655,9 +673,9 @@ public function get_video_actual_path( $blog_id = 0, $video_id = 0 )
{
$blog_id = (int) $blog_id;
$video_id = (int) $video_id;
- switch_to_blog( $blog_id );
+ Video_Access_Control::switch_to_blog( $blog_id );
$file = get_post_meta( $video_id, 'video_file_full', true );
- restore_current_blog();
+ Video_Access_Control::restore_current_blog();
return $file;
}
@@ -696,7 +714,7 @@ public function get_video_filename( $blog_id = null, $video_id = 0 )
{
$blog_id = (int) $blog_id;
$video_id = (int) $video_id;
- switch_to_blog( $blog_id );
+ Video_Access_Control::switch_to_blog( $blog_id );
$actual_file = get_post_meta( $video_id, 'video_file', true );
$ext = array_pop( explode( '.', $actual_file ) );
@@ -707,7 +725,7 @@ public function get_video_filename( $blog_id = null, $video_id = 0 )
$filename = empty( $parent_video_title ) ? get_post_meta( $video_id, 'video_file_hash', true ) : $parent_video_title;
$filename .= '.' . $ext;
- restore_current_blog();
+ Video_Access_Control::restore_current_blog();
return $filename;
}
@@ -725,7 +743,7 @@ public function get_video_image_actual_path( $blog_id = null, $video_id = 0, $im
$blog_id = (int) $blog_id;
$video_id = (int) $video_id;
- switch_to_blog( $blog_id );
+ Video_Access_Control::switch_to_blog( $blog_id );
$attachment_id = (int) get_post_meta( $video_id, 'image_attachment_id', true );
@@ -749,7 +767,7 @@ public function get_video_image_actual_path( $blog_id = null, $video_id = 0, $im
$file = $this->_get_image_path_by_size( $attachment_id, $image_type );
}
- restore_current_blog();
+ Video_Access_Control::restore_current_blog();
return $file;
}
@@ -829,7 +847,7 @@ public function get_video_image_url( $_blog_id = null, $video_id = 0, $image_typ
$_blog_id = (int) $blog_id;
}
- switch_to_blog( $_blog_id );
+ Video_Access_Control::switch_to_blog( $_blog_id );
$hash = get_post_meta( $video_id, 'video_file_hash', true );
@@ -840,7 +858,7 @@ public function get_video_image_url( $_blog_id = null, $video_id = 0, $image_typ
$size
) );
- restore_current_blog();
+ Video_Access_Control::restore_current_blog();
return $url;
}
@@ -849,7 +867,7 @@ public function get_video_url( $blog_id = null, $video_id = 0 )
{
$blog_id = (int) $blog_id;
$video_id = (int) $video_id;
- switch_to_blog( $blog_id );
+ Video_Access_Control::switch_to_blog( $blog_id );
$hash = get_post_meta( $video_id, 'video_file_hash', true );
$url = get_site_url( $blog_id, sprintf(
'/video-file/%1$s/%2$s/%3$s/ext.mp4',

0 comments on commit 523b997

Please sign in to comment.
Something went wrong with that request. Please try again.