Forked from andrewlimaza/added-member-custom-email.php
Last active
June 17, 2024 21:10
-
-
Save MaximilianoRicoTabo/bc487a05b5173a9ac7f8df8b6da0f54d to your computer and use it in GitHub Desktop.
Custom Email when a Member change its level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Send an email to the admin when a user changes its level. | |
* | |
* @param int $level_id The ID of the new level. | |
* @param int $user_id The ID of the user. | |
* | |
*/ | |
function custom_pmpro_after_change_membership_level( $level_id, $user_id ) { | |
//Bail if level_id is 0 | |
if ( empty( $level_id ) ) { | |
return; | |
} | |
$level = pmpro_getLevel( $level_id ); | |
$user = get_userdata( $user_id ); | |
$admin_email = get_option( 'admin_email' ); | |
$subject = "a user has changed its level"; | |
$body = "User " . $user->user_login . " has changed its level to " . $level->name; | |
wp_mail( $admin_email, $subject, $body ); | |
} | |
add_action( 'pmpro_after_change_membership_level', 'custom_pmpro_after_change_membership_level', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment