字符被 bbcode 插件替换
我有一个用于 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();' ) );
I have a bbcode plugin for wordpress.
But for some reason, if I post something like
[i]v497212he2x2MfMi[/i]
the "X" character is outputted as ×
, which is some other sort of X. How can I fix this?
Plugin code is below:
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();' ) );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种转换是因为 WordPress 的 wptexturize() 函数返回给定文本,并将引号转换为智能引号、撇号、破折号、省略号、商标符号和乘号。
这是来自 WP 3.2.1 wp-includes/formatting.php 第 55 行:
$dynamic_characters
数组中的最后一个正则表达式是将“X”转换为 ×正如 wptexturize 函数页面上所述...
"[t]ext 包含在标签
This transformation is taking place because of Wordpress's wptexturize() function that returns given text with transformations of quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol.
This is from WP 3.2.1 wp-includes/formatting.php line 55:
The last regex in that
$dynamic_characters
array is the one turning the "X" into ×As stated on the function page for wptexturize...
"[t]ext enclosed in the tags <pre>, <code>, <kbd>, <style>, <script>, <tt>, and [code] will be skipped."
, you can fix this by putting that bbcode in one of those tags, or use a plugin that can disable wptexturize, such as InScript or Disabler or Disable wptexturize.