- This topic is empty.
-
AuthorPosts
-
December 19, 2013 at 7:38 pm #158821SenffParticipant
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:
- open user details at http://www.mysite.com/wp-admin/users.php
- click on user to view details
- change checkbox from unchecked to checked
- 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. ;)
December 19, 2013 at 8:11 pm #158824AlenParticipantThere’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 * * * *
-
-
December 19, 2013 at 8:22 pm #158826December 19, 2013 at 8:26 pm #158827SenffParticipantThanks 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.
December 19, 2013 at 8:44 pm #158830AlenParticipantJust 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 }
Untested.
December 20, 2013 at 10:30 am #158859SenffParticipantSolved, plugin has been created like this:
<?php /* Plugin Name: User Notification Plugin URI: http://www.blablabla.com Description: Notifies a new user by email when his/her account has been approved. Author: Senff Version: 1.0 Author URI: http://www.senff.com */ ?> <?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 = '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]>'); } } ?>
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.