Skip to content

Instantly share code, notes, and snippets.

@avillegasn
Last active December 2, 2019 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avillegasn/503fb8bc1112bbd3024e9753e4d26a29 to your computer and use it in GitHub Desktop.
Save avillegasn/503fb8bc1112bbd3024e9753e4d26a29 to your computer and use it in GitHub Desktop.
Creating a function
<?php
/**
* Sends and email when a post is published.
*
* Sends and email using wp_mail standard WordPress function including data about
* the post being published.
*/
<?php
/**
* Sends and email when a post is published.
*
* Sends and email using wp_mail standard WordPress function including data about
* the post being published.
*
* @param int $ID Post ID.
* @param WP_Post $post Post object.
*/
function nelio_notify_on_post_published( $ID, $post ) {
// Assemble the message.
$message = 'Hi, a new post has been published. Here is the content:';
$message .= $post->post_content;
// Assemble the subject.
$subject = '[New Post] ' . $post->post_title;
// Send the notification.
wp_mail( 'recipient@example.com', $subject, $message );
}//end nelio_notify_on_post_published()
add_action( 'publish_post', 'nelio_notify_on_post_published', 10, 2 );
<?php
/**
* Sends and email when a post is published.
*
* Sends and email using wp_mail standard WordPress function including data about
* the post being published.
*
* @param int $ID Post ID.
* @param WP_Post $post Post object.
*/
function nelio_notify_on_post_published( $ID, $post ) {
// Assemble the message.
$message = 'Hi, a new post has been published. Here is the content:';
$message .= $post->post_content;
// Assemble the subject.
$subject = '[New Post] ' . $post->post_title;
// Send the notification.
wp_mail( 'recipient@example.com', $subject, $message );
}//end nelio_notify_on_post_published()
<?php
/**
* Sends and email when a post is published.
*
* Sends and email using wp_mail standard WordPress function including data about
* the post being published.
*
* @param int $ID Post ID.
* @param WP_Post $post Post object.
*/
function nelio_notify_on_post_published( $ID, $post ) {
}//end nelio_notify_on_post_published()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment