WordPress Video API

From NewTube Docs

Jump to: navigation, search

The WordPress Video API was created because of a need of a standard developers API for dealing with video in WordPress.


Contents

Introduction

The WordPress Video API let developers access video information from WordPress code. (Like from custom WordPress plug-ins.)

It is done by additions to the WordPress $post and $posts global variables.

For example, we have

$post->video

and

$posts[$i]->video


History

The WordPress Video API was created as part of the Show in a Box project, and implemented first in VideoPress and vPIP.


Specification

The WordPress Video API is as the following...

  • $post->video (object)
    • $post->video->href (string)
    • $post->video->poster (object)
      • $post->video->poster->href (string)
    • $post->video->thumbnail (object)
      • $post->video->thumbnail->href (string)
    • $post->video->playlist (array)
      • $post->video->playlist[$x] (object)
        • $post->video->playlist[$x]->href (string)


(An analogous API is available through $posts[$i] too.)


Examples

Here are some example of using Video API.

Creating a thumbnail image...

<img src="<?= htmlspecialchars( $post->video->thumbnail->href ) ?>" alt="<?= htmlspecialchars( $post->post_title)?>" />

Creating a poster image linking to the page the video is on...

 <a href="<?= htmlspecialchars( $post->guid ) ?>">
     <img src="<?= htmlspecialchars( $post->video->poster->href ) ?>" alt="<?= htmlspecialchars( $post->post_title)?>" />
 </a>
 

Making a SMIL playlist...

 // ...
 
 header('Content-Type: video/smil+xml');
 
 print('<smil><body><seq>');
 
 foreach ($post->video->playlist AS $v) {
 
     print('<video src="<?= xmlspecialchars($v->href) ?>" />');
 
 } // foreach
 
 print('</seq></body></smil>');
 
 
 function xmlspecialchars($s)
 {
     return str_replace('"','&quot;',
            str_replace('>','&gt;',
            str_replace('<','&lt;',
            str_replace('&','&amp;',
            $s))));
 }
 


Implementations

The following software supports the WordPress Video API...

Personal tools