【问题标题】:WordPress Subscribe2 plugin escapes characters in blog name when sending emailWordPress Subscribe2 插件在发送电子邮件时转义博客名称中的字符
【发布时间】:2009-08-25 15:55:15
【问题描述】:

我在即将发布的新 WordPress 博客 (http://www.adlerr.com) 中使用了 Subscribe2 插件。我的博客标题是“Roee Adler 的博客”。发送邮件时,Subscribe2 将我博客标题中的撇号转义,收到邮件主题如下:

[Roee Adler's Blog] Please confirm your request

电子邮件正文是:

Roee Adler's Blog has received a request to 
subscribe for this email address. To complete your 
request please click on the link below:
...

我自然希望在标题和正文中包含我的博客名称的“正常”未转义版本。

我在doctype.com 上提出了这个问题,但没有成功(here's the question),但是从答案中我了解到这可能需要更改插件的 PHP 代码,所以我宁愿在这里问。

根据我在 doctype 上收到的答案,我确实更改了以下代码部分:

function substitute($string = '') {
    if ('' == $string) {
        return;
    }
    $string = htmlspecialchars_decode(str_replace("BLOGNAME", get_option('blogname'), $string));
    $string = str_replace("BLOGLINK", get_bloginfo('url'), $string);
    $string = htmlspecialchars_decode(str_replace("TITLE", stripslashes($this->post_title), $string));
    $string = str_replace("PERMALINK", $this->permalink, $string);

在上面的代码中,我为 BLOGNAME 和 TITLE 的生成添加了一个 htmlspecialchars_decode 包装器,但是电子邮件主题和正文仍然包含 '

我能做些什么来解决这个问题?

谢谢

【问题讨论】:

    标签: php html wordpress special-characters subscribe2


    【解决方案1】:

    根据the documentation on htmlspecialchars_decode,您需要将ENT_QUOTES 作为$quote_style 参数传递,以便将' 转换为'。尝试设置ENT_QUOTES

    function substitute($string = '') {
            if ('' == $string) {
                    return;
            }
            $string = htmlspecialchars_decode(str_replace("BLOGNAME", get_option('blogname'), $string), ENT_QUOTES);
            $string = str_replace("BLOGLINK", get_bloginfo('url'), $string);
            $string = htmlspecialchars_decode(str_replace("TITLE", stripslashes($this->post_title), $string), ENT_QUOTES);
            $string = str_replace("PERMALINK", $this->permalink, $string);
    

    【讨论】:

      【解决方案2】:

      WordPress 将博客标题中的撇号替换为',然后再将其存储到数据库中。如果要覆盖它,请编辑 functions.php 文件并插入以下语句:

      update_option("blogname", "My Blog's Title With Apostrophe");
      

      这将强制标题与您输入的内容完全相同。您在“设置”菜单中对博客标题所做的更改将无效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-11-27
        • 2015-06-17
        • 2014-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-10
        • 2013-04-03
        相关资源
        最近更新 更多