我在我即将推出的新 WordPress 博客中使用 Subscribe2 插件 (http://www.adlerr.com)。我的博客标题是“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 没有成功(这是问题),但是从答案中我了解到这可能需要更改插件的 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);

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

我可以做什么来解决这个问题?

谢谢

有帮助吗?

解决方案

按照 的文档 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);

其他提示

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

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

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top