Confirm Email Address

If you’re running a WordPress network, and depending on how you’re using it, you may need to get users to confirm or update their email address.

In my situation, I build a lot of sites for clients, and during development I use an email address of my own so they don’t get bombarded with emails they don’t need. But I don’t always change it back when I’m done, or maybe there’s a typo. Or maybe it’s the client that has changed their email address.

Whatever the cause, sometimes these things just need to be double-checked and confirmed. So here’s a small plugin that can be dropped in your mu-plugins folder:

<?php
/*
Plugin Name: User Email Reminder
Plugin URI: https://trepmal.com/
Description: Adds a small 'is this your email address' notice. "yes" creates a cookie that hides the notice for 30 days, "no" directs them to their profile page.
Author: Kailey Lampert
Version: 1.0
Author URI: http://kaileylampert.com/
*/
/*
    Copyright (C) 2010  Kailey Lampert

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

$useremailreminder = new useremailreminder();

class useremailreminder {

	function useremailreminder() {

		add_action( 'admin_init', 'set_cookie' );
		function set_cookie() {
			if ( isset($_GET['email_dismiss']) && !isset($_COOKIE['profile_notice_email']) ) {
				setcookie("profile_notice_email", 'asdf', time()+2592000,'/','yoursite.com');  /* expire in 30 days */
			}
		}

		add_action( 'admin_notices', 'email_check_notice' );
		function email_check_notice() {

			global $current_user;
			get_currentuserinfo();
			
			$email = $current_user->user_email;	
			
			if (isset($_COOKIE['profile_notice_email']) || isset($_GET['email_dismiss']) ) {} else {
				echo '<div class="updated fade">
				<h3><strong>Keeping your profile up-to-date</strong></h3>
				<p>Is this your email address: '. $email .'?</p>
				<p><a href="'.
					($_SERVER['QUERY_STRING'] == '' ? '?' : '?'.$_SERVER['QUERY_STRING'].'&').
					(strpos($_SERVER['QUERY_STRING'],'email_dismiss') !== false ? '' :'email_dismiss=yes' )
					.'">Yes</a> | <a href="/wp-admin/profile.php#email">No</a></p>
				</div>';
			}
		}

	}
	
	
}//end class

?>

If the user clicks Yes, then a cookie is set and they will not be asked again for 30 days. If they select No, then they will be directed to the profile page where they can make the necessary change.

Don’t forget to update yoursite.com

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: