bagwaa
bagwaa

Reputation: 359

Wordpress Post HTML after Posting

I am writing a plugin for WordPress, one of the tasks I need to-do is send the HTML content of a new post to an e-mail address at the time of posting, I know I can use certain hooks to fire after the post has been saved, but is there a way to get the full HTML content of the new page/post with the theme applied?

I have custom fields within the post so ideally I would like to get the whole post from the URL rather then reconstructing all the fields to then send in HTML.

Any help would be appreciated!

Thanks

Upvotes: 0

Views: 131

Answers (1)

maiorano84
maiorano84

Reputation: 11971

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;
}

Be sure to set your headers or anything else you might need to populate your email correctly. This is untested, but it should help get you started.

Upvotes: 1

Related Questions