Skip to content

Instantly share code, notes, and snippets.

@ditikos
Last active August 29, 2015 14:07
Show Gist options
  • Save ditikos/d4571d8618345393505d to your computer and use it in GitHub Desktop.
Save ditikos/d4571d8618345393505d to your computer and use it in GitHub Desktop.
Wordpress: Post to an e-mail when you publish for the first time
// Συνδεση στο hook που ανιχνεύει τις αλλαγές των post status
add_action('transition_post_status', 'post_to_list2', 10, 3);
function post_to_list2($new_status, $old_status, $post) {
// Σε ενα νέο post το post status είναι πάντα draft->publish
// Σε ενα ανανεωμένο post το post status είναι πάντα publish->publish
if ('publish' === $old_status)
return; // new posts only!
if ('publish' !== $new_status)
return;
// Τίτλος mail
$subject = 'publish' === $new_status ? __('Created: %s', 'txt') : __('New post: %s', 'txt');
// Ενεργοποίηση html e-mail header
add_filter('wp_mail_content_type', 'wpse27856_set_content_type');
// Αποστολή e-mail
$sendtomail = "ΒΑΛΕ ΤΟ mail ΕΔΩ"; // π.χ. [email protected]
$content = apply_filters( 'the_content', get_the_content() );
$content = str_replace( ']]>', ']]>', $content );
wp_mail(
$sendtomail, sprintf($subject, $post->post_title), $content
);
// Απενεργοποίηση html e-mail header
remove_filter('wp_mail_content_type', 'wpse27856_set_content_type');
}
// προσθήκη html header στο e-mail.
function wpse27856_set_content_type() {
return "text/html";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment