Plugin Directory

Changeset 2651431


Ignore:
Timestamp:
12/31/2021 06:17:42 PM (4 years ago)
Author:
ankittiwaari
Message:

Add shortcode aoc_video_box

Location:
video-metabox-aoc/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • video-metabox-aoc/trunk/readme.txt

    r2651422 r2651431  
    3333== Changelog ==
    3434
     35= 1.1 =
     36* Add shortcode `aoc_video_box`
     37
     38= 1.0 =
     39* Bugfix - return video URL instead of video ID
     40
    3541= 0.1 =
    3642* First stable version
  • video-metabox-aoc/trunk/video-metabox-aoc.php

    r2651426 r2651431  
    77 * Plugin name: Video Metabox AOC
    88 * Description: This plugin allows you to upload video as a custom field for a post/page.
    9  * Version: 1.0
     9 * Version: 1.1
    1010 */
    1111function aoc_vid_register_meta_boxes()
     
    3030                    <source src="<?= esc_url(wp_get_attachment_url(intval($aoc_vid_video))) ?>">
    3131                    Your browser does not support the video tag.
    32                 </video><input type="hidden" name="aoc_vid_video" id="aoc_vid_vid_input" value="<?= intval($aoc_vid_video) ?>"><button data-vid-id="<?= intval($aoc_vid_video) ?>" class="aoc-del-vid" type="button">X</button></div>
     32                </video>
     33                <input type="hidden" name="aoc_vid_video" id="aoc_vid_vid_input" value="<?= intval($aoc_vid_video) ?>">
     34                <button data-vid-id="<?= intval($aoc_vid_video) ?>" class="aoc-del-vid" type="button">X</button>
     35            </div>
    3336        <?php
    3437        endif;
     
    7174    return wp_get_attachment_url($vid);
    7275}
     76
     77add_action('init', 'aoc_init_shortcode');
     78function aoc_init_shortcode()
     79{
     80    add_shortcode('aoc_video_box', 'aoc_video_box');
     81}
     82
     83function aoc_video_box($atts)
     84{
     85    $id = get_queried_object_id();
     86    $video = get_post_meta($id, 'aoc_vid_video', true);
     87
     88    if (!$video) {
     89        return '';
     90    }
     91    $video_url = wp_get_attachment_url($video);
     92    if (!$video_url) {
     93        return;
     94    }
     95    $attributes = '';
     96    if ($atts && is_array($atts)) {
     97        foreach ($atts as $key => $value) {
     98            $attributes .= $key . '= "' . $value . '" ';
     99        }
     100        if (isset($atts['controls']) && $atts['controls']) {
     101            $attributes .= ' controls="true"';
     102        }
     103    }
     104    return '<video ' . $attributes . '>
     105  <source src="' . $video_url . '">
     106  Your browser does not support the video tag.
     107</video>';
     108};
Note: See TracChangeset for help on using the changeset viewer.