Skip to content

Instantly share code, notes, and snippets.

@atwellpub
Last active Oct 28, 2018
Embed
What would you like to do?
<?php
/**
* Class Liked_Videos_Custom_Shortcode
* @package
*/
final class Liked_Videos_Custom_Shortcode {
/**
* Main Liked_Videos_Custom_Shortcode Instance
*/
public function __construct() {
self::load_hooks();
}
public function load_hooks() {
add_shortcode('latest-video' , array( __CLASS__ , 'latest_video_shortcode'));
}
public function latest_video_shortcode() {
$posts = get_posts(array(
'post_type' => 'liked-videos',
'posts_per_page' => 1,
'orderby' => 'rand'
));
echo '<style>.liked-video-embed iframe { min-height:450px!important; }</style>';
foreach ($posts as $post) {
$content = $post->post_content;
$parts = explode( '</iframe>' , $content );
$final_content = $parts[0].'</iframe><caption><i>Random liked video. Refresh to load a new one!</i></caption>';
if ( current_user_can( 'manage_options' ) ) {
/* delete button */
$delete_button = get_delete_post_link( $post->ID , false, false );
$final_content .= '<div><a href="'.$delete_button.'" target="_blank">[delete]</a>';
}
return $final_content;
}
}
}
/* Initiate Class */
new Liked_Videos_Custom_Shortcode;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment