最近对wordpress 3.1的升级打破了一个自定义插件,该插件是为了使用shortcode为brightcove视频生成简单的嵌入html而编写的。
有人能看到以下与3.1不兼容的代码中发生了什么,以及需要发生什么才能修复它吗?在升级之前,它在3.0中运行良好。
<?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(\'”\',\'″\'), \'\', $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\');
?>
谢谢!
最合适的回答,由SO网友:marvinhagemeister 整理而成
您没有通过短代码API添加短代码。WordPress仅识别添加了以下内容的短代码:
add_shortcode( \'yourshortcode\', \'yourshortcodefunc\' );
我个人不会为此使用preg\\u replace,因为这更像是一个碰运气。您应该遵守
WordPress Codex. 建议短代码的代码结构为:
// [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\' );