The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [RESOLVED] WordPress: executing wpmail after user info changes

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #158821

    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
    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. ;)


    There’s no need to add hacks. Simply write a “plug-in” with your logic then just activate it. So if something changes and it screws up something just deactivate plug-in and that’s it. Or you could store php file inside the theme folder and require it in functions.php.

    As far as how to hook into that event, am not sure…

          • goes poking around WP code * * * *

    Thanks for pointing in the right direction, I figured that I’d have to go the plugin way, but seeing that I have zero experience with writing actual plugins, I’m stuck there.


    Just write the logic in your functions.php file.

    Something like…

    add_action( 'profile_update' , 'profile_update_function' );
    function profile_update_function( $user_id, $old_user_data){
      // compare filed values, logic
      // if true send mail



    Solved, plugin has been created like this:

        Plugin Name: User Notification
        Plugin URI:
        Description: Notifies a new user by email when his/her account has been approved.
        Author: Senff
        Version: 1.0
        Author URI:
        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 = 'Your user account has been approved and will now be visible on our site at '.get_site_url().'/je-mimplique/ambassadeurs/ ';
                    wp_mail($useremail, 'Account approved', $emailmessage, 'From: Accounts <[email protected]>');
Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.