I created a function which gets the metadata video length from the selected attachment. I use this together with a plugin called multisite-global-media
which lets me share media from a site to all other sites in the multisite network. But selecting a video from this media site will break my function, as I am not able to pull the metadata from attached media from the other site except if I use the switch_to_blog
function.
But I need to determine if the selected media is from the current site or from the media site.
This is what I am working on:
switch_to_blog($attachment_site);
$attachment_id = attachment_url_to_postid( $_POST[ 'background-video' ] );
$video_meta = get_post_meta( $attachment_id , '_wp_attachment_metadata', true );
restore_current_blog();
if( isset( $_POST[ 'background-video' ] ) && $video_meta['length'] >= 1 ) {
update_post_meta( $post_id, 'slide_duration', $video_meta['length'] );
}
What I need to do is to get the $attachment_site
somehow.
Any idea how?
EDIT:
if( isset( $_POST[ 'background-video' ] ) ) {
update_post_meta( $post_id, 'background-video', $_POST[ 'background-video' ] );
}