wordpress 自定义注册界面

wordpress 自定义注册界面_第1张图片

 

首先在functions.php中建立如下函数

/**
* start of custom registration module fucntion
*
**/
if (!isset($_SESSION)) {
 	session_start();
	session_regenerate_id(TRUE);
}

/**
 *Admin registration module,to add a registration form and to update the notification to the users
 */
if ( !function_exists('wp_new_user_notification') ) :
/**
 * Notify the blog admin of a new user, normally via email.
 *
 * @since 2.0
 *
 * @param int $user_id User ID
 * @param string $plaintext_pass Optional. The user's plaintext password
 */
function wp_new_user_notification($user_id, $plaintext_pass = '', $flag='') {
	if(func_num_args() > 1 && $flag !== 1)
		return;

	$user = new WP_User($user_id);

	$user_login = stripslashes($user->user_login);
	$user_email = stripslashes($user->user_email);

	// The blogname option is escaped with esc_html on the way into the database in sanitize_option
	// we want to reverse this for the plain text arena of emails.
	$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);

	$message  = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
	$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
	$message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";

	@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
	
	if ( empty($plaintext_pass) )
		return;

	// you can change the format in the Email
	$message  = sprintf(__('Username: %s'), $user_login) . "\r\n";
	$message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n";
	$message .= 'The login url is : ' . wp_login_url() . "\r\n";

	// sprintf(__('[%s] Your username and password'), $blogname) is the email subject
	wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
}
endif;

/* Update the registration form */
function ludou_show_password_field() {
	define('LCR_PLUGIN_URL', plugin_dir_url( __FILE__ ));
?>


add('password_length', "ERROR: Password should be at least 6 characters"); elseif($_POST['user_pass'] != $_POST['user_pass2']) $errors->add('password_error', "ERROR: Please check your confirm password"); if($_POST['user_role'] != 'year7' && $_POST['user_role'] != 'year8' && $_POST['user_role'] != 'year9' && $_POST['user_role'] != 'year10' && $_POST['user_role'] != 'year11' && $_POST['user_role'] != 'year12') $errors->add('role_error', "ERROR: Please choose one correct role"); } /* TO save the submitted data */ function ludou_register_extra_fields($user_id, $password="", $meta=array()) { $userdata = array(); $userdata['ID'] = $user_id; $userdata['user_pass'] = $_POST['user_pass']; $userdata['role'] = $_POST['user_role']; wp_new_user_notification( $user_id, $_POST['user_pass'], 1 ); wp_update_user($userdata); } function remove_default_password_nag() { global $user_ID; delete_user_setting('default_password_nag', $user_ID); update_user_option($user_ID, 'default_password_nag', false, true); } add_action('admin_init', 'remove_default_password_nag'); add_action('register_form','ludou_show_password_field'); add_action('register_post','ludou_check_fields',10,3); add_action('user_register', 'ludou_register_extra_fields'); //end of custom registration module fucntion

 

然后下载如下插件

SI CAPTCHA Anti-Spam

 

设置生效后 就可以得到你想要的结果了

 

 

 

你可能感兴趣的:(PHP+MySQL)