• Resolved sundoggie

    (@sundoggie)


    Hi –
    I work on a small all-volunteer professional association website and none of us, myself included, is a coder (or really, knows much about WordPress – just mucking around and trying to figure stuff out on my own since it’s a pretty small-scale site). Our association members can update their profiles on our site, which are the WordPress user profiles. I want the site administrator to get an email whenever a member updates their profile. (Ideally with what was changed, but even just a notification would be OK). I have tried some of other possible solutions I’ve found online (see long explanation below) but none have worked so far.

    By way of background, we have extra fields in our profiles. Basically it’s title/company/address/phone. We had these fields displayed in a member list (like a paper member directory but online) via another plugin that worked with the CIMY extra user fields we were using. The member list plugin stopped working a few months ago with a WordPress update, so I’ve installed a new combination of plugins that holds the extra field data and then displays them as a member directory – I had to change both plugins since the CIMY plugin didn’t play nicely with any of the new member list plugins I tried. Under our old setup, when user updated their profile, the administrator would get an automatically generated email notifying of the change, which we need. This must have been built into the CIMY extra user field plugin – I tested that. Now that I’ve got this new plugin combo going, we no longer get an admin email when a user updates a profile. I’ve searched some for a different member list plugins that will pull the CIMY extra user data fields and display them, but can’t find one – or at least not a free one.

    I’ve seen several other possible code fixes to this admin email problem, usually involving putting some code in my theme’s functions.php file. (I’m using twenty ten theme).

    See here:

    http://wordpress.org/support/topic/notify-admin-when-user-updates-profile-1?replies=2

    http://wordpress.org/support/topic/notify-admin-when-user-updates-profile?replies=5

    http://wpsnipp.com/index.php/functions-php/send-email-notification-when-profile-updates/

    and probably a few more that I’ve found online and tried. But none have worked – perhaps they are too old and not supported? When I put the possible code in the bottom of the theme’s funtions.php file, I get the red squiggly lines and if I save it I get a parse-syntax error that locks me out my site. Luckily it’s a development site I’m toying with, but still.

    Unfortunately none of us in the association are coders. After killing my site a couple of times I’m hoping someone has some advice. I feel like this is something that someone who knows what they are doing might be able to solve in about 5 minutes, but for a non-techie like me, I’ve been poking around for days and just failing at all the possible code snippets I’ve found online.

    Thanks for any advice. And please let me know if I should be directing this to another forum.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Just my $0.02… but I’ve learned from my experience by trying to “fix” one plugin by installing another… is just opening the door to a world of headaches down the road.

    I’m pretty sure you can get an admin notification when a user updates their profile by writing a function like this:

    function my_admin_notification_profile_update($userid) {
    
        $userdata = get_userdata($userid);
        $message = "A user profile has been updated\n\n";
        $message .= print_r($userdata,true);
        @wp_mail(get_option('admin_email'), 'User Profile Update', $message);
    
    }
    add_action('profile_update','my_admin_notification_profile_update');

    Now, this won’t tell you specifically what was changed… or even who made the change. But, some further customization could include all of that info.

    Hope this helps!

    Thread Starter sundoggie

    (@sundoggie)

    Thank you! I guess the red squiggly lines don’t always mean it will kill your site when you hit save. I appreciate the help. I’ll see if I can figure out how to include the changes the user makes to the profile, but for now, this works. Thank you!!

    Where were you getting a red squiggly line?

    I didn’t get a chance to test that code.

    But, if it works.. then idk.. lol.

    If I get a little extra time today or tomorrow.. I’ll try to come back here and “update” the code, providing some additional info when a user makes a change πŸ™‚

    Thread Starter sundoggie

    (@sundoggie)

    I was editing the code right in the WP admin panel – going to theme > edit > function.php. Maybe that’s not the right way to do it? As I said, I’m new to all this. I just dropped your code in the bottom of the file and it did give me the squigglies (is that a technical term?) But I saved it anyway and it worked. The resulting email when I tested the function wasn’t pretty but at least it notified me. You are my favorite person of the week right now. If you have improvements to the code that tells me what got updated I may just have to mail you some cookies.

    Lol – thank you πŸ™‚

    Okay…

    First… we need to introduce you to the world of Child Themes.

    You see.. by adding that function to the bottom of your themes functions.php file… the next time you update your theme, that function is going to be deleted. Your theme author can’t keep track of everyone’s custom edits… so when he/she updates the theme… the ‘updated’ functions.php file is going to overwrite yours… erasing all that custom work.

    Now, imagine you’ve been doing this for a while.. and have all these custom edits… then you update your theme, and BAM…. all that work is lost.

    Hence… Child Themes!!

    In your child theme, you will have a functions.php file and a style.css file. In these files, you can make all of your custom modifications, and never worry about them being lost during updates.

    It’s YOUR child theme.. and no one can ever take that away from you πŸ˜‰

    So… start working on that child theme!! And I’ll start working on seeing if you can pull what was changed from the user profile page.

    Lemme know if you get stuck along the way.

    Oh.. and it never hurts to take a backup first!

    EDIT: This is assuming you don’t use a “framework” which already has a custom functions.php file.

    Well, you caught my interest with this request.

    I’m surprised there is not more out there which describes the process.

    I am just about finished with the code (adding comments now), and will be posting it to pastebin shortly.

    I have ‘beautified’ the email content (using html), so it comes to the admin in a nice, pretty, easily readable output.

    This will make a great plugin.. and I’ll get to that next πŸ˜‰ There are a lot of possibilities available (I made a list.. lol).

    Anyway.. I’ll post the link shortly. You’ll need to copy it into your custom code area until I get a chance to make it a plugin.

    Okay.. here is the link:
    http://pastebin.com/XY4bgiZX

    You can copy the entire thing.. and paste it just above the closing ?> php tag in your functions.php file. Remember, it’ll be over-written there… but I’ll be making a plugin of this soon πŸ™‚

    Have fun!!

    Oh, and do me a favor and let me know if this is also working with your custom fields being added by other plugins, please.

    Thread Starter sundoggie

    (@sundoggie)

    Wow – you have been busy! I am in your eternal debt. First off – I did the child theme. Thank you, makes perfect sense and definitely get the importance of doing that. So, I set that up. And wow, can’t believe you wrote all that code. Thank you. Thank you. Thank you. I pasted it in the child theme’s functions.php file and tested it out on my site. The email generated is much prettier, so yes, that is totally working. The email I get has fields for showing me old and new value for all profile fields, even the extra user detail fields I added, so score – that is working too.

    Since you seem interested in this and are working more on it, I’ll let you know that the email shows the data for all fields filled in, whether they were changed or not. Which is totally fine for my purposes, but it doesn’t show the old value for any of the fields, whether they were changed or not. I don’t really care about that unless the field was actually changed, then it would be handy of course to see what was old and what it was changed to so I know what part the user updated. Here’s the email that is generated: (btw, the “eud” is extra user details, which is the plugin I used for the extra fields.)

    Hello WordPressAdmin,
    The user, Sample User, has updated their profile with the following information:

    url:
    Old Value:
    New Value: njlla.org

    eudtitle:
    Old Value:
    New Value: Sample Title – personal edit

    eudcompany_name:
    Old Value:
    New Value: Sample company – testing live with child theme

    eudtelephone:
    Old Value:
    New Value: 973-xxx-xxxx

    eudaddress_line1:
    Old Value:
    New Value: changed sample address

    eudaddress_line2:
    Old Value:
    New Value: Sample address

    eudcity:
    Old Value:
    New Value: Sample city – personal edit

    eudstate:
    Old Value:
    New Value: changed sample state

    eudzip_code:
    Ol d Value:
    New Value: Sample ZIP


    I really don’t want to take advantage of your help any more but since you seem to be running with it, wanted to let you know the results in action. You are really helped me out above and beyond. Thank you – this is awesome.

    Great!! Thanks for the feedback!

    Okay.. let’s see…

    That shouldn’t be happening.

    Can you copy and paste your ENTIRE child theme functions.php file to “pastebin.com“. Just paste it in.. and select “PHP” from the dropdown language. When you submit, it will take you to a new page showing the code. Copy that url from the address bar, and post the link here.

    Lemme make sure your code is right, before moving on πŸ™‚

    Well, I’ve got it started as a plugin. I can verify it is working as intended.

    You may use my contact form here:
    http://joshlobe.com/contact-me/

    Please include a link to this thread, so I know who you are.

    I’ll reply back, and attach a copy of the plugin.

    I’ll also submit the plugin to WP.. so we can get started on that as well πŸ™‚

    Talk to you soon!

    Thread Starter sundoggie

    (@sundoggie)

    Hi Josh –
    Here’s the link to the code in Pastebin from my child theme functions.php file: http://pastebin.com/Lm9SUwdB

    If I get your plugin, that means that I don’t need this function anymore, right? So I would just delete it?

    Thank you again. I feel like Dorothy stumbling into Oz and luckily I found the Good Witch!

    ps: I hope you sleep at some point.

    I responded to you via email.

    Is this the plugin you are using for the extra fields?

    Thread Starter sundoggie

    (@sundoggie)

    Thank you SO much for all the help you provided, both in this forum and working with me directly. You’ve been very patient and generous and resolved my issue perfectly.

    Thanks!

    Kristan

    (@kristansartor)

    Hi Josh,

    Did you end up submitting the plugin to the directory? Would love to know the name/url as I could definitely use it myself!

    Thanks for being an awesome part of the WordPress community! πŸ™‚

    Oh…. this feature is exactly what I’m looking for… I need recibe a mail with the fields modifying by the user, but for me don’t works the code:

    I try this one I found

    /**
     *	Updated User Profile Notification
     *
     *	Every time a user updates his/her profile an email is sent
     *	to the site administrator.
     *
     *	@author		Nate Jacobs
     *	@link		https://gist.github.com/1286583
     */
    
    add_action( 'profile_update', 'ngtj_updated_user_profile_notify', 10, 2 );
    function ngtj_updated_user_profile_notify( $user_id, $old_user_data )
    {
    	// get the user data into an object
    	$user = get_userdata( $user_id );
    	// get the site administrator's email address
    	$admin_email = get_option( 'admin_email' );
    	// the email body
    	$message = sprintf( __( 'This user has updated their profile on your site: %s' ), get_option('blogname') ) . "\r\n\r\n";
    	$message .= sprintf( __( 'Display Name: %s' ), $user->display_name ). "\r\n\r\n";
    	$message .= sprintf( __( 'Username: %s' ), $user->user_login ). "\r\n\r\n";
    	$message .= sprintf( __( 'Old Email: %s' ), $old_user_data->user_email ). "\r\n\r\n";
    	$message .= sprintf( __( 'Email: %s' ), $user->user_email );
    	// send the email
    	wp_mail( $admin_email, sprintf( __( '[%s] User Updated a Profile' ), get_option('blogname') ), $message );
    }

    But this one only advertise me than anyone change the profile, but no say me what fields are changing.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Notify admin when user updates profile’ is closed to new replies.