$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>shortcode - Detecting embeded video format|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

shortcode - Detecting embeded video format

matteradmin9PV0评论

I need to get the video format from the shortcode. Example if i set my post meta "_video_format_embed" with [video src="/myvideo.mp4" /] .

how to get the video format of my shortcode?

$video_embeded = get_post_meta(get_the_ID(), '_video_format_embed');
$video_format = '???'; // please help
if('mp4' === $video_format){
 //some code
}

I need to get the video format from the shortcode. Example if i set my post meta "_video_format_embed" with [video src="https://url.domain/myvideo.mp4" /] .

how to get the video format of my shortcode?

$video_embeded = get_post_meta(get_the_ID(), '_video_format_embed');
$video_format = '???'; // please help
if('mp4' === $video_format){
 //some code
}
Share Improve this question asked Feb 6, 2019 at 7:51 Ferdy SopianFerdy Sopian 132 bronze badges 8
  • what do you get in return, when you place echo '<pre>', print_r( $video_embeded ), '</pre>'; right after your first line? – honk31 Commented Feb 6, 2019 at 9:39
  • it will show the video player. I didn't get any code in there if I dump or echo in a pre tag, it will show the video player. – Ferdy Sopian Commented Feb 6, 2019 at 9:54
  • ok. so it returns the video code. bueno. please add the following to your functions.php and report back: function so327822_wp_video_shortcode($output, $atts, $video, $post_id, $library) { echo '<pre>', print_r($atts), '</pre>'; echo '<pre>', print_r($video), '</pre>'; echo '<pre>', print_r($library), '</pre>'; } add_filter('wp_video_shortcode', 'so327822_wp_video_shortcode', 10, 5); its a filter, that hooks into the wordpress video shortcode function.. – honk31 Commented Feb 6, 2019 at 10:50
  • it show an Array <pre>Array ( [src] => http://domain/video.mp4 [poster] => [loop] => [autoplay] => [preload] => metadata [width] => 640 [height] => 360 [class] => wp-video-shortcode [mp4] => [m4v] => [webm] => [ogv] => [flv] => ) 1</pre> <pre>1</pre> <pre>mediaelement1</pre> – Ferdy Sopian Commented Feb 7, 2019 at 8:31
  • OK. one step further.. please replace this one with the previous code: function so327822_wp_video_shortcode($output, $atts) { $video_id = attachment_url_to_postid( $atts['src'] ); $video_meta = wp_get_attachment_metadata( $video_id ); echo '<pre>' . print_r($video_meta, true) . '</pre>';} add_filter('wp_video_shortcode', 'so327822_wp_video_shortcode', 10, 2); and return back, i'm almost certain, that it includes the mime_type.. – honk31 Commented Feb 7, 2019 at 15:32
 |  Show 3 more comments

1 Answer 1

Reset to default 0

so you place your video inside a shortcode and then you can run a filter on that shortcode function. works like this (to be placed inside functions.php or some custom plugin):

function so327822_wp_video_shortcode($output, $atts) {
    //get video ID by src
    $video_id = attachment_url_to_postid( $atts['src'] );
    //get video meta
    $video_meta = wp_get_attachment_metadata( $video_id );
    //uncomment next line, to view all meta
    //echo '<pre>' . print_r($video_meta, true) . '</pre>';

    if ( $video_meta['fileformat'] === 'mp4' ) {
        //mess with $output here, if we have mp4
    }

    //return 
    return $output;
}
add_filter('wp_video_shortcode', 'so327822_wp_video_shortcode', 10, 2);

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far