Front_End::embed_video( string $content )
Post content filter callback to embed the video into the post content.
Description
The method is called on the "post_content" filter and embeds the attached video above or below the post content, depending on the setting from the plugin Settings or the individual post options.
Parameters
- $content
-
(Required) The post content
Return
(string) The post content
Source
File: includes/libs/front-end.class.php
public function embed_video( $content ){
if( ! Helper::video_is_visible() ){
return $content;
}
global $post;
$_post = get_post( $post );
if( !$_post ){
return $content;
}
// check if post is password protected
if( post_password_required( $_post ) ){
return $content;
}
// check if filters prevent auto embedding
if( !Helper::is_autoembed_allowed() ){
return $content;
}
// if video is in skipped auto embed list (has block or the video position shortcode in content), don't embed
if( $this->skipped_autoembed( $_post ) ){
return $content;
}
$video_post = Helper::get_video_post( $_post );
$settings = $video_post->get_embed_options();
if( !in_array( $settings['video_position'], [ 'above-content', 'below-content' ] ) ){
return $content;
}
$video_container = Helper::embed_video( $_post, [], false );
// put the filter back for other posts; remove in method 'prevent_autoembeds'
add_filter( 'the_content', [
$GLOBALS[ 'wp_embed' ],
'autoembed'
], 8 );
/**
* Fires before the video embed is placed into the post content.
* Action that runs when the video is set to be automatically inserted into the post content.
*
* @param Video_Post $video_post The \Vimeotheque\Video_Post object generated for the current post in loop.
*/
do_action(
'vimeotheque\automatic_embed_in_content',
$video_post
);
if( 'below-content' === $settings[ 'video_position' ] ){
return $content . $video_container;
}else{
return $video_container . $content;
}
}
