像本站使用的loper1.3主题,升级至WordPress3.4以上最新版后出现了错误,提示:

Fatal error: Cannot redeclare wp_embed_handler_youku() (previously declared in /home/*** */public_html/wp-content/languages/zh_CN.php:94) in /home/****/public_html/wp-content/themes/loper1.3/functions/shortcode.php on line 44

或升级后首页变成空白

大概意思是出现了至命的冲突,原来从WordPress3.4版本起WP中文团队修改了视频嵌入方式,默认支持对Youku和Tudou视频的嵌入;而有一些wp主题短代码的视频嵌入方式与此相同,所以引起冲突,升级后出现错误。

现给出解决方法,此方法适用于所有升级到wp3.4版本的主题。

1、在你的WordPress安装文件夹中找到wp-content\languages\里的zh_CN.php文件,下载并且打开它。

2、找到以下内容:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
function wp_embed_handler_tudou( $matches, $attr, $url, $rawattr ) {
$embed = sprintf(
'<embed src="http://www.tudou.com/v/%1$s/&resourceId=0_05_05_99&bid=05/v.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="opaque" width="480" height="400"></embed>',
esc_attr( $matches['video_id'] ) );

return apply_filters( 'embed_tudou', $embed, $matches, $attr, $url, $rawattr );
}
wp_embed_register_handler( 'tudou',
'#https?://(?:www\.)?tudou\.com/(?:programs/view|listplay/(?<list_id>[a-z0-9_=\-]+))/(?<video_id>[a-z0-9_=\-]+)#i',
'wp_embed_handler_tudou' );

3.把找到的内容替换为:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
        /**
    function wp_embed_handler_tudou( $matches, $attr, $url, $rawattr ) {
    $embed = sprintf(
    '<object width="480" height="400" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.tudou.com/v/%1$s/&amp;resourceId=0_05_05_99&amp;bid=05/v.swf" /><param name="allowscriptaccess" value="always" /><param name="allowfullscreen" value="true" /><param name="wmode" value="opaque" /><embed width="480" height="400" type="application/x-shockwave-flash" src="http://www.tudou.com/v/%1$s/&amp;resourceId=0_05_05_99&amp;bid=05/v.swf" allowscriptaccess="always" allowfullscreen="true" wmode="opaque" /></object>',
    esc_attr( $matches['video_id'] ) );

    return apply_filters( 'embed_tudou', $embed, $matches, $attr, $url, $rawattr );
    }
    wp_embed_register_handler( 'tudou',
    '#https?://(?:www\.)?tudou\.com/(?:programs/view|listplay/(?[a-z0-9_=\-]+))/(?[a-z0-9_=\-]+)#i',
    'wp_embed_handler_tudou' );
    */

4、找到以下内容:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
    function wp_embed_handler_56com( $matches, $attr, $url, $rawattr ) {
    $matches['video_id'] = $matches['video_id1'] == '' ?
    $matches['video_id2'] : $matches['video_id1'];

    $embed = sprintf(
    "&lt;object width="480" height="405" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="src" value="http://player.56.com/v_%1\$s.swf" /&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="allownetworking" value="all" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;embed width="480" height="405" type="application/x-shockwave-flash" src="http://player.56.com/v_%1\$s.swf" allowfullscreen="true" allownetworking="all" allowscriptaccess="always" /&gt;&lt;/object&gt;",
    esc_attr( $matches['video_id'] ) );

    return apply_filters( 'embed_56com', $embed, $matches, $attr, $url, $rawattr );
    }
    wp_embed_register_handler( '56com',
    '#https?://(?:www\.)?56\.com/[a-z0-9]+/(?:play_album\-aid\-[0-9]+_vid\-(?[a-z0-9_=\-]+)|v_(?[a-z0-9_=\-]+))#i',
    'wp_embed_handler_56com' );

5、替换为:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
    /**
    function wp_embed_handler_56com( $matches, $attr, $url, $rawattr ) {
    $matches['video_id'] = $matches['video_id1'] == '' ?
    $matches['video_id2'] : $matches['video_id1'];

    $embed = sprintf(
    "&lt;object width="480" height="405" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="src" value="http://player.56.com/v_%1\$s.swf" /&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="allownetworking" value="all" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;embed width="480" height="405" type="application/x-shockwave-flash" src="http://player.56.com/v_%1\$s.swf" allowfullscreen="true" allownetworking="all" allowscriptaccess="always" /&gt;&lt;/object&gt;",
    esc_attr( $matches['video_id'] ) );

    return apply_filters( 'embed_56com', $embed, $matches, $attr, $url, $rawattr );
    }
    wp_embed_register_handler( '56com',
    '#https?://(?:www\.)?56\.com/[a-z0-9]+/(?:play_album\-aid\-[0-9]+_vid\-(?[a-z0-9_=\-]+)|v_(?[a-z0-9_=\-]+))#i',
    'wp_embed_handler_56com' );
    */

6、找到以下内容:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
    function wp_embed_handler_youku( $matches, $attr, $url, $rawattr ) {
    $embed = sprintf(
    '&lt;object width="480" height="400" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" align="middle"&gt;&lt;param name="src" value="http://player.youku.com/player.php/sid/%1$s/v.swf" /&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="quality" value="high" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;embed width="480" height="400" type="application/x-shockwave-flash" src="http://player.youku.com/player.php/sid/%1$s/v.swf" allowfullscreen="true" quality="high" allowscriptaccess="always" align="middle" /&gt;&lt;/object&gt;',
    esc_attr( $matches['video_id'] ) );

    return apply_filters( 'embed_youku', $embed, $matches, $attr, $url, $rawattr );
    }
    wp_embed_register_handler( 'youku',
    '#https?://v\.youku\.com/v_show/id_(?[a-z0-9_=\-]+)#i',
    'wp_embed_handler_youku' );

7、替换为:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
    /**
    function wp_embed_handler_youku( $matches, $attr, $url, $rawattr ) {
    $embed = sprintf(
    '&lt;object width="480" height="400" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" align="middle"&gt;&lt;param name="src" value="http://player.youku.com/player.php/sid/%1$s/v.swf" /&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="quality" value="high" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;embed width="480" height="400" type="application/x-shockwave-flash" src="http://player.youku.com/player.php/sid/%1$s/v.swf" allowfullscreen="true" quality="high" allowscriptaccess="always" align="middle" /&gt;&lt;/object&gt;',
    esc_attr( $matches['video_id'] ) );

    return apply_filters( 'embed_youku', $embed, $matches, $attr, $url, $rawattr );
    }
    wp_embed_register_handler( 'youku',
    '#https?://v\.youku\.com/v_show/id_(?[a-z0-9_=\-]+)#i',
    'wp_embed_handler_youku' );
    */

8、保存文件,并且将其上传到wp-content\languages\中。覆盖相同的文件。

以上过程是注释掉了WP中文版本自带的嵌入功能,而使用主题自带的嵌入视频功能。如果以后你更换主题,而新的主题并没有自带的嵌入方式, 可你仍想保留视频的显示,那么还原以上操作即可。