Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Email a member whenever their User Page (PMPro User Pages Add On) is updated - PMPro
<?php // do not copy this line
/**
* This recipe will email the member whose user page is updated, everytime it is updated with any information.
* Thanks to @ShoboySnr and @webcreativeng for helping with this gist, and @JarrydLong for modifying further
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_userpage_updated_send_email( $post_id ) {
// If this is just a revision, don't send the email.
if ( ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] != 'editpost' ) || !is_admin() ) {
return;
}
$the_post = get_post( $post_id ); //returns Post Object
$the_author = $the_post->post_author; //returns Author ID
$author_email = get_the_author_meta( 'user_email', $the_author ); //returns Author Email
$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
$subject = 'A post has been updated';
$message = "A post has been updated on your website:\n\n";
$message .= $post_title . ": " . $post_url;
// Send email to member whose user page is updated.
wp_mail( $author_email, $subject, $message );
}
add_action( 'save_post', 'my_pmpro_userpage_updated_send_email' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment