CodeHQ

Posts Tagged ‘User’

|

Registration white list | WordPress

Friday, July 1st, 2016

Add this code in to your functions.php to create a domain whitelist for user registrations.

add_action('registration_errors', 'sizeable_restrict_domains', 10, 3);
function sizeable_restrict_domains( $errors, $login, $email ) {
	$whitelist = array(
        'domain.com', 
        'website.com'
    );
	if ( is_email($email) ) {
		$parts = explode('@', $email);
		$domain = $parts[count($parts)-1];
		$to = 'your@adminemail.com';
		$subject = 'Subject of email';
		$message = 'A user tried to register with the following email address: ' . $email;
		if ( !in_array(strtolower($domain), $whitelist) ) {
			$errors->add('email_domain', __('ERROR: You may only register with an approved email address.'));
		wp_mail( $to, $subject, $message );
		}
	}
	return $errors;
}

Tags: , , , , , , ,
Posted in PHP, WordPress | No Comments »

If user is logged in | WordPress

Tuesday, June 28th, 2016

Use to show content if a user is logged in.

<?php if ( is_user_logged_in() ) { ?>
  .....Content here......
<?php }  ?>

Use ! is_user_logged_in() if you want to show if NOT logged in.

Tags: , , , ,
Posted in PHP, WordPress | No Comments »