Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

A recent upgrade to wordpress 3.1 broke a custom plugin written to make use of shortcode in order to generate easy embed html for brightcove videos.

Can anyone see what is happening in the following code that is incompatible with 3.1, and what needs to happen for it to be fixed? It was working fine in 3.0 prior to upgrade.

<?php

/*
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://brightcove.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('&#8221;','&#8243;'), '', $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 '<div style="background-color:#f99; padding:10px;">Brightcove Player Widget Error: Required parameter "video" or "player" is missing!</div>';
        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 .= "<embed src='http://c.brightcove.com/services/viewer/federated_f9/$player?isVid=1&publisherID=$publisher'
    bgcolor='#FFFFFF'
    flashVars='@videoPlayer=$video&playerID=$player&domain=embed&'
    base='http://admin.brightcove.com'
    name='flashObj'
    width='$width'
    height='$height'
    seamlesstabbing='false'
    type='application/x-shockwave-flash'
    allowFullScreen='true'
    swLiveConnect='true'
    pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>
  </embed>";    

    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');

?>

Thanks!

share|improve this question
    
it does work for me on 3.1, try to put in the html view of the editor. what doesn't work is outputting using do_shortcode(). –  Amit Mar 7 '11 at 20:18
add comment

1 Answer

up vote 4 down vote accepted

You didn't add the shortcode via the shortcode API. WordPress only recognizes shortcodes if they are added with:

add_shortcode( 'yourshortcode', 'yourshortcodefunc' );

I personally would not use preg_replace for this because it is more of a hit and miss. You should follow the official guidelines off the WordPress Codex. Recommended code structure for shortcodes is:

// [bartag foo="foo-value"]
function bartag_func( $atts ) {
    extract( shortcode_atts( array(
        'foo' => 'something',
        'bar' => 'something else',
    ), $atts ) );

    return "foo = {$foo}";
}
add_shortcode( 'bartag', 'bartag_func' );
share|improve this answer
    
Thanks for your insight! –  Dave Kiss Mar 10 '11 at 2:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.