发布后Wordpress发布HTML

时间:2012-04-23 10:12:58

标签: php wordpress-plugin wordpress-theming wordpress

我正在为WordPress编写一个插件,我需要做的任务之一是在发布时将新帖子的HTML内容发送到电子邮件地址,我知道我可以使用某些挂钩来解雇邮件保存后,是否有办法获取应用主题的新页面/帖子的完整HTML内容?

我在帖子中有自定义字段,所以理想情况下我希望从URL获取整个帖子,而不是重新构建所有字段,然后以HTML格式发送。

任何帮助将不胜感激!

由于

1 个答案:

答案 0 :(得分:1)

add_action('publish_post', 'email_post');
function email_post($postID)
{
    $post = get_post($postID);
    $content = $post->post_content;
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    $mailto = 'youremail';
    $subject = 'New Post';
    if(mail($mailto, $subject, $content))
        return true;
    else
        return false;
}

请务必设置标题或正确填充电子邮件所需的任何其他内容。这是未经测试的,但它应该有助于您入门。

相关问题