Brightcove 3 Embed Plugin For WordPress 2.X

On November 17, 2008, in Brightcove, PHP, by admin

This code snippet shows how to create a Brightcove player plugin for the WordPress 2.X CMS that allows easy placement of videos within posts using the syntax [ brightcove video="123456" /].

/*
Plugin Name: Brightcove Video Player
Version: 1.0
Plugin URI: http://www.brightcove.com
Description: Simplifies the process of adding a Brightcove video to a WordPress blog.
Author: Bob de Wit
Author URI: http://brigthcove.active6.com
*/


//Set the publisher ID - YOU MUST SET THIS TO YOUR OWN PUBLISHER ID
$publisher = 1705665024;

//Set a default player to use - YOU MUST SET THIS TO YOUR OWN DEFAULT PLAYER
$player = 1911416499;

//Set width and height for the default video player
$width = 486;
$height = 412;

//Define default video variable
$videoid = 0;

//The actual parse content function called by the filter
//This will use the callback function BCVideo_Render to do the
//actual text replacement for the widget
function Brightcove_Parse($content)
{
$content = preg_replace_callback("/\[brightcove ([^]]*)\/\]/i", "Brightcove_Render", $content);
return $content;
}

function Brightcove_Render($matches)
{
global $video, $player, $publisher, $width, $height, $arguments;
$output = '';
$matches[1] = str_replace(array('”','?'), '', $matches[1]);
preg_match_all('/(\w*)=(.*?) /i', $matches[1], $attributes);
$arguments = array();

foreach ( (array) $attributes[1] as $key => $value )
{
// Strip out legacy quotes
$arguments[$value] = str_replace('"', '', $attributes[2][$key]);
}

//print_r( $arguments );

if (( !array_key_exists('video', $arguments) ) && ( !array_key_exists('player', $arguments) ))
{
return '
Brightcove Player Widget Error: Required parameter "video" or "player" is missing!

'
;
exit;
}
else
{
$video = $arguments['video'];
}

if( array_key_exists('width', $arguments) )
{
$height = $arguments['width'];
}

if( array_key_exists('height', $arguments) )
{
$height = $arguments['height'];
}

if( array_key_exists('player', $arguments) )
{
$player = $arguments['player'];
}

//$flashVars = "isVid=1&playerID=$player&publisherID=$publisher&@videoPlayer=$video";

$output .= "
"
;

return $output;
}

//Add a filter hook - this registers the function for all content
//text (Pages and Posts) to search for the [CONTRIBUTOR_WIDGET] tag.
add_filter('the_content', 'Brightcove_Parse');
 

2 Responses to Brightcove 3 Embed Plugin For WordPress 2.X

  1. rondonvon says:

    is this still an active project ?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>