• So, working with a site that’s built by someone else. Plugins and hacks are not guaranteed to be done exactly right, but this is what I have right now:

    Every user in the system (standard WP users, level subscriber) has some extra information fields, created by some custom plugin. One is a YES/NO checkbox that states whether or not the user will be listed on the site. Works fine.

    However, I want to add functionality so that a wpmail() function is fired when that setting for any user changes from NO to YES. Hence:

    1. open user details at https://www.mysite.com/wp-admin/users.php
    2. click on user to view details
    3. change checkbox from unchecked to checked
    4. hit UPDATE PROFILE button

    And so right after that, the wpmail() needs to be executed.

    I will hardcode the recipient and message and such, but I need to know how/where I put the actual execution. Dirty solutions are accepted, the site is a mess already anyway. ?? But since it probably involves creating a plugin solution, I’ve put it in this section (feel free to move if it’s misplaced).

    Thanks for your help!

Viewing 1 replies (of 1 total)
  • Thread Starter Senff – a11n

    (@senff)

    <?php
    	add_action('edit_user_profile_update', 'update_extra_profile_fields');
    	function update_extra_profile_fields($user_id) {
    			$showuser = $_POST['show'];
    			if ($showuser == 'on') {
    				$useremail = get_user_meta($user_id, 'nickname', true);
    				$emailmessage = "Some message goes here...";
    				wp_mail($useremail, 'Here goes the subject', $emailmessage, 'From: WP Notification <user@domain.com>');
    			}
    	    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Executing wpmail() when user info changes’ is closed to new replies.