/** * Retrieve a video. * * @since 1.0.0 * * @param int $post_id Optional. Post ID. * @param array $args Optional. (width, height) * @param array $query_args Optional. Provider specific parameters. * @return string Video HTML */ function get_audiotheme_video($post_id = null, $args = array(), $query_args = array()) { global $wp_embed; $post_id = null === $post_id ? get_the_ID() : $post_id; $video_url = get_audiotheme_video_url($post_id); $html = ''; if ($video_url) { // Save current embed settings and restore them after running the shortcode. $restore_post_ID = $wp_embed->post_ID; $restore_linkifunknown = $wp_embed->linkifunknown; $restore_usecache = $wp_embed->usecache; // Can't be sure what the embed settings are, so explicitly set them. $wp_embed->post_ID = $post_id; // Allows WP_Embed caching to work when this function is called outside of the loop. $wp_embed->linkifunknown = false; $wp_embed->usecache = true; $html = $wp_embed->shortcode($args, add_query_arg($query_args, $video_url)); // Restore original embed settings. $wp_embed->post_ID = $restore_post_ID; $wp_embed->linkifunknown = $restore_linkifunknown; $wp_embed->usecache = $restore_usecache; } if (false !== strpos($html, '[video')) { $html = do_shortcode($html); } return apply_filters('audiotheme_video_html', $html, $post_id, $video_url, $args, $query_args); }
/** * Display a field to enter a video URL after the post title. * * @since 1.0.0 */ function audiotheme_video_after_title() { global $post; $video = get_audiotheme_video_url($post->ID); wp_nonce_field('save-video-meta_' . $post->ID, 'audiotheme_save_video_meta_nonce', false); ?> <div class="audiotheme-edit-after-title" style="position: relative"> <p> <label for="audiotheme-video-url" class="screen-reader-text"><?php _e('Video URL:', 'audiotheme'); ?> </label> <input type="text" name="_video_url" id="audiotheme-video-url" value="<?php echo esc_url($video); ?> " placeholder="<?php esc_attr_e('Video URL', 'audiotheme'); ?> " class="widefat"><br> <span class="description"> <?php printf(__('Enter a video URL from one of the %s.', 'audiotheme'), '<a href="https://codex.wordpress.org/Embeds#Okay.2C_So_What_Sites_Can_I_Embed_From.3F" target="_blank">' . __('supported video services', 'audiotheme') . '</a>'); ?> </span> </p> </div> <?php }
/** * Add additional HTML classes to posts. * * @since 1.0.0 * * @param array $classes List of HTML classes. * @return array */ function huesos_audiotheme_post_class($classes) { if ('' === get_the_title()) { $classes[] = 'no-title'; } if (is_singular('audiotheme_gig') && audiotheme_gig_has_venue()) { $classes[] = 'has-venue'; } if ('audiotheme_video' === get_post_type() && get_audiotheme_video_url()) { $classes[] = 'has-video'; } return array_unique($classes); }
?> role="article" itemprop="video" itemscope itemtype="http://schema.org/VideoObject"> <?php if ($thumbnail = get_post_thumbnail_id()) { ?> <meta itemprop="thumbnailUrl" content="<?php echo esc_url(wp_get_attachment_url($thumbnail, 'full')); ?> "> <?php } ?> <?php if ($video_url = get_audiotheme_video_url()) { ?> <meta itemprop="embedUrl" content="<?php echo esc_url($video_url); ?> "> <?php the_audiotheme_video(); ?> <?php } ?> <header class="audiotheme-video-header entry-header"> <?php the_title('<h1 class="audiotheme-video-title entry-title" itemprop="name">', '</h1>');
<?php /** * Template to display a Video widget. * * @package Huesos * @since 1.0.0 */ ?> <?php if (get_audiotheme_video_url($post->ID)) { ?> <figure class="entry-video responsive-video"> <?php echo get_audiotheme_video($post->ID); ?> </figure> <?php } ?> <?php if (!empty($title)) { printf(' <a href="%s">%s</a>', esc_url(get_permalink($post->ID)), $before_title . $title . $after_title); } ?> <?php if (!empty($link_text)) { $text .= sprintf(' <a class="more-link" href="%s">%s</a>', esc_url(get_permalink($post->ID)), $link_text);