Skip to content

Instantly share code, notes, and snippets.

@MjHead
Created June 22, 2015 08:21
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 MjHead/65af9b290adc59920501 to your computer and use it in GitHub Desktop.
Save MjHead/65af9b290adc59920501 to your computer and use it in GitHub Desktop.
Video size for video posts depends from options
function cherry_get_the_post_video() {
/**
* Filter post format video output to rewrite video from child theme or plugins.
*
* @since 4.0.0
*/
$result = apply_filters( 'cherry_pre_get_post_video', false );
if ( false !== $result ) {
return $result;
}
$content = apply_filters( 'the_content', get_the_content() );
$types = array( 'video', 'object', 'embed', 'iframe' );
$embeds = get_media_embedded_in_content( $content, $types );
if ( empty( $embeds ) ) {
return;
}
foreach ( $types as $tag ) {
if ( preg_match( "/<{$tag}[^>]*>(.*?)<\/{$tag}>/", $embeds[0], $matches ) ) {
$result = $matches[0];
break;
}
}
if ( false === $result ) {
return;
}
global $_wp_additional_image_sizes;
$featured_size = cherry_get_option( 'blog-featured-images-size', 'cherry-thumb-l' );
$featured_position = cherry_get_option( 'blog-featured-images-align' );
$replace_args = array(
'width' => false,
'height' => false
);
$width = '100%';
foreach ( $replace_args as $param => $value ) {
if ( isset( $_wp_additional_image_sizes[$featured_size][$param] ) ) {
$replace_args[$param] = $param . '="' . $_wp_additional_image_sizes[$featured_size][$param] . '"';
}
if ( 'width' == $param ) {
$width = $_wp_additional_image_sizes[$featured_size][$param] . 'px';
}
}
$replace_val = array_values( $replace_args );
$patterns = array(
'/width=[\"\']\d+[\"\']/',
'/height=[\"\']\d+[\"\']/'
);
$result = preg_replace( $patterns, $replace_val, $result );
$result = sprintf(
'<div class="entry-video %2$s" style="width:%3$s"><div class="embed-responsive embed-responsive-16by9">%1$s</div></div>',
$result,
$featured_position,
$width
);
/**
* Filter featured video.
*
* @since 4.0.0
*/
return apply_filters( 'cherry_get_the_post_video', $result );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment