Skip to content

Instantly share code, notes, and snippets.

@atwellpub
Last active October 28, 2018 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atwellpub/cbfa883254c35ff3df99514c50211ff7 to your computer and use it in GitHub Desktop.
Save atwellpub/cbfa883254c35ff3df99514c50211ff7 to your computer and use it in GitHub Desktop.
<?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