Last active
October 28, 2018 04:54
-
-
Save atwellpub/cbfa883254c35ff3df99514c50211ff7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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