字符被 bbcode 插件替换

发布于 2024-12-16 13:11:50 字数 1488 浏览 1 评论 0原文

我有一个用于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝不服输 2024-12-23 13:11:50

发生这种转换是因为 WordPress 的 wptexturize() 函数返回给定文本,并将引号转换为智能引号、撇号、破折号、省略号、商标符号和乘号。

这是来自 WP 3.2.1 wp-includes/formatting.php 第 55 行:

$dynamic_characters = array('/\'(\d\d(?:’|\')?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 包含在标签

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:

$dynamic_characters = array('/\'(\d\d(?:’|\')?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');

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文