我有一个wordpress bbcode插件。
但是由于某些原因,如果我发布了像
这样的内容 [i]v497212he2x2MfMi[/i]
的"X"字符输出为×
,这是某种其他类型的X,我怎么能解决这个问题?
插件代码如下:
class BBCode {
// Plugin initialization
function BBCode() {
// This version only supports WP 2.5+ (learn to upgrade please!)
if ( !function_exists('add_shortcode') ) return;
// Register the shortcodes
add_shortcode( 'b' , array(&$this, 'shortcode_bold') );
add_shortcode( 'i' , array(&$this, 'shortcode_italics') );
}
// No-name attribute fixing
function attributefix( $atts = array() ) {
if ( empty($atts[0]) ) return $atts;
if ( 0 !== preg_match( '#=("|')(.*?)("|')#', $atts[0], $match ) )
$atts[0] = $match[2];
return $atts;
}
// Bold shortcode
function shortcode_bold( $atts = array(), $content = NULL ) {
if ( NULL === $content ) return '';
return '<strong>' . do_shortcode( $content ) . '</strong>';
}
// Italics shortcode
function shortcode_italics( $atts = array(), $content = NULL ) {
if ( NULL === $content ) return '';
return '<em>' . do_shortcode( $content ) . '</em>';
}
}
// Start this plugin once all other plugins are fully loaded
add_action( 'plugins_loaded', create_function( '', 'global $BBCode; $BBCode = new BBCode();' ) );
这个转换发生是因为Wordpress的wptexturize()函数返回给定的文本,并将引号转换为智能引号、省略号、划线、省略号、商标符号和乘法符号。
这是来自WP 3.2.1 WP -includes/format .php第55行:$dynamic_characters = array('/'(dd(?:’|')?s)/', '/'(d)/', '/(s|A|[([{<]|")'/', '/(d)"/', '/(d)'/', '/(S)'([^'s])/', '/(s|A|[([{<])"(?!s)/', '/"(s|S|Z)/', '/'([s.]|Z)/', '/b(d+)x(d+)b/');
$dynamic_replacements = array('’$1','’$1', '$1‘', '$1″', '$1′', '$1’$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '’$1', '$1×$2');
$dynamic_characters
数组中的最后一个正则表达式是将"X"变成×
如wptexturize函数页所述…"[t]ext enclosed in the tags <pre>, <code>, <kbd>, <style>, <script>, <tt>, and [code] will be skipped."
,您可以通过将bbcode放在这些标签之一来修复此问题,或使用可以禁用wptexturize的插件,例如InScript或禁用或禁用wptexturize。