Custom Login Page with Header and Footer WordPress
- Article
- Comment (2)
Creating Custom Login page is one a necessary thing while developing premium themes. Here I am going to explain you to create custom loign page for your WordPress theme. Custom login page with header and footer .
Now lets begin with your theme ” functions.php “. Just include the line to require our custom files for our theme.
<?php require_once("login/login_template.php"); ?>
Now lets begin with our code to start making our own login page. first we need to get the current page by using WordPress ” $pagenow ” variable. check whether the url is login url or not. if the current url is login url than we need to override the existing functions using our custom functions.
<?php global $pagenow; include_once("login-form-process.php"); include_once("forgot-password-form.php"); include_once("register-form-process.php"); global $pagenow ; if (isset($_REQUEST['action'])) : $action = $_REQUEST['action']; else : $action = 'login'; // sometimes we changed it as login. so check it here. endif; switch($action) : case 'lostpassword' : case 'retrievepassword' : if(!is_user_logged_in()) kv_show_password(); else wp_redirect(site_url()); break; case 'register': if(!is_user_logged_in()) kv_show_register(); else wp_redirect(site_url()); break; case 'logout' : wp_logout(); wp_redirect(home_url().'/login'); break; default: if(!is_user_logged_in()) kv_show_login(); else wp_redirect(site_url()); break; endswitch; exit;
Now, we have to write the functions to perform register , login, forgot password, and logout . Lets start with registration form. just copy paste the following code to your ” login_template.php” .
function kv_show_register() { global $posted; if (isset($_POST['register']) && $_POST['register']) { $result = kv_process_register_form(); $errors = $result['errors']; $posted = $result['posted']; } elseif (isset($_POST['login']) && $_POST['login']) { $errors = kv_process_login_form(); } // Clear errors if loggedout is set. if ( !empty($_GET['loggedout']) ) $errors = new WP_Error(); // If cookies are disabled we can't log in even with a valid user+pass if ( isset($_POST['testcookie']) && empty($_COOKIE[TEST_COOKIE]) ) $errors->add('test_cookie', __('Cookies are blocked or not supported by your browser. You must enable cookies to continue.','kv_project')); if ( isset($_GET['loggedout']) && TRUE == $_GET['loggedout'] ) $message = __('You are now logged out.','kv_project'); elseif ( isset($_GET['registration']) && 'disabled' == $_GET['registration'] ) $errors->add('registerdisabled', __('User registration is currently not allowed.','kv_project')); elseif ( isset($_GET['checkemail']) && 'confirm' == $_GET['checkemail'] ) $message = __('Check your email for the confirmation link.','kv_project'); elseif ( isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail'] ) $message = __('Check your email for your new password.','kv_project'); elseif ( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] ) $message = __('Registration complete. Please check your e-mail.','kv_project'); get_template_part('header'); ?> <section id="main-content"> <h1><?php _e('Register', 'kv_project'); ?></h1> <?php if (isset($message) && !empty($message)) { echo '<p class="success">'.$message.'</p>'; } ?> <?php if (isset($errors) && sizeof($errors)>0 && $errors->get_error_code()) : echo '<ul class="errors">'; foreach ($errors->errors as $error) { echo '<li>'.$error[0].'</li>'; } echo '</ul>'; endif; ?> <p><?php _e('You must login or create an account in order to access Projects.', 'kv_project'); ?></p> <?php kv_register_form( '', '' ); ?> </section> <?php get_template_part('footer'); }
And here is the login function
// Show login and registation forms function kv_show_login() { global $posted; if (isset($_POST['register']) && $_POST['register']) { $result = kv_process_register_form(); $errors = $result['errors']; $posted = $result['posted']; } elseif (isset($_POST['login']) && $_POST['login']) { $errors = kv_process_login_form(); } // Clear errors if loggedout is set. if ( !empty($_GET['loggedout']) ) $errors = new WP_Error(); // If cookies are disabled we can't log in even with a valid user+pass if ( isset($_POST['testcookie']) && empty($_COOKIE[TEST_COOKIE]) ) $errors->add('test_cookie', __('Cookies are blocked or not supported by your browser. You must enable cookies to continue.','kv_project')); if ( isset($_GET['loggedout']) && TRUE == $_GET['loggedout'] ) $message = __('You are now logged out.','kv_project'); elseif ( isset($_GET['registration']) && 'disabled' == $_GET['registration'] ) $errors->add('registerdisabled', __('User registration is currently not allowed.','kv_project')); elseif ( isset($_GET['checkemail']) && 'confirm' == $_GET['checkemail'] ) $message = __('Check your email for the confirmation link.','kv_project'); elseif ( isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail'] ) $message = __('Check your email for your new password.','kv_project'); elseif ( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] ) $message = __('Registration complete. Please check your e-mail.','kv_project'); get_template_part('header'); ?> <section id="main-content"> <h1><?php _e('Login', 'kv_project'); ?></h1> <?php if (isset($message) && !empty($message)) { echo '<p class="success">'.$message.'</p>'; } if (isset($errors) && sizeof($errors)>0 && $errors->get_error_code()) : echo '<ul class="errors">'; foreach ($errors->errors as $error) { echo '<li>'.$error[0].'</li>'; } echo '</ul>'; endif; ?> <p><?php _e('You must login or create an account in order to access Projects.', 'kv_project'); ?></p> <div> <?php kv_login_form(); ?> </div> </section> <?php get_template_part('footer'); }
and here is the password reset function.
// show the forgot your password page function kv_show_password() { $errors = new WP_Error(); if ( isset($_POST['user_login']) && $_POST['user_login'] ) { $errors = do_action('retrieve_password', $user_login); if ( !is_wp_error($errors) ) { wp_redirect('wp-login.php?checkemail=confirm'); exit(); } } if ( isset($_GET['error']) && 'invalidkey' == $_GET['error'] ) $errors->add('invalidkey', __('Sorry, that key does not appear to be valid.','kv_project')); do_action('lost_password'); do_action('lostpassword_post'); get_template_part('header'); ?> <section id="main-content"> <h1><?php _e('Password Recovery', 'kv_project'); ?></h1> <?php if (isset($message) && !empty($message)) { echo '<p class="success">'.$message.'</p>'; } ?> <?php if ($errors && sizeof($errors)>0 && $errors->get_error_code()) : echo '<ul class="errors">'; foreach ($errors->errors as $error) { echo '<li>'.$error[0].'</li>'; } echo '</ul>'; endif; ?> <?php kv_forgot_password_form(); ?> </section> <?php get_template_part('footer'); }
These are all the calling functions with initial codes. now we are going to write each file which we attached above. now open your ” register-form-process.php ”
<?php /** * KV Project Registration Form * Function outputs the registration form */ function kv_register_form( $action = '', $role = 'buyer' ) { global $posted; $recaptcha_option = get_option("kv_recaptcha"); $settings= get_option("kv_theme_settings"); if ( get_option('users_can_register') ) : if (!$action) $action = site_url('wp-login.php?action=register'); ?> <table> <tr> <td colspan="2" > <h2><?php _e('Create a free account', 'kv_project'); ?></h2> </td> </tr> <form action="<?php echo $action; ?>" method="post" class="account_form"> <tr> <td style="width:40%"> <label for="user_login"><?php _e('Username*', 'kv_project'); ?></label></td> <td> <input type="text" class="text" tabindex="1" name="user_login" id="user_login" value="<?php if (isset($posted['user_login'])) echo $posted['user_login']; ?>" /> </td> </tr> <tr> <td> <label for="user_email"><?php _e('Email*', 'kv_project'); ?></label></td> <td> <input type="text" class="text" tabindex="2" name="user_email" id="user_email" value="<?php if (isset($posted['user_email'])) echo $posted['user_email']; ?>" /> </td> </tr><?php if (get_option('kv_usr_pas',$settings["kv_usr_pas"])=='Enabled') : ?> <td><label for="your_password"><?php _e('Enter a password', 'kv_project'); ?></label></td> <td><input type="password" class="text" tabindex="3" name="your_password" id="your_password" value="" /> </td> </tr> <tr><td><label for="your_password_2"><?php _e('Enter password again', 'kv_project'); ?></label></td> <td><input type="password" class="text" tabindex="4" name="your_password_2" id="your_password_2" value="" /> </td> </tr> <?php endif; ?> <tr><td><label for="kv_first_name"><?php _e('First Name*', 'kv_project'); ?></label> </td> <td> <input type="text" class="text" tabindex="5" name="kv_first_name" id="kv_first_name" value=""/> </td> </tr> <tr><td> <label for="kv_last_name"><?php _e('Last Name', 'kv_project'); ?></label></td> <td><input type="text" class="text" tabindex="6" name="kv_last_name" id="kv_last_name" value="" /> </td> </tr> <tr><td><label for="kv_address"><?php _e('Address Line 1 *', 'kv_project'); ?></label></td> <td><input type="text" class="text" tabindex="7" name="kv_address" id="kv_address" value="" /> </td> </tr> <tr><td><label for="kv_address_2"><?php _e('Address Line 2', 'kv_project'); ?></label></td> <td><input type="text" class="text" tabindex="8" name="kv_address_2" id="kv_address_2" value="" /> </td> </tr> <tr><td><label for="kv_state"><?php _e('State', 'kv_project'); ?></label></td> <td><input type="text" class="text" tabindex="9" name="kv_state" id="kv_state" value="" /> </td> </tr> <tr><td><label for="kv_country"><?php _e('Country', 'kv_project'); ?></label></td> <td><input type="text" class="text" tabindex="10" name="kv_country" id="kv_country" value="" /> </td> </tr> <tr><td><label for="kv_pin"><?php _e('Zip/Pin Code', 'kv_project'); ?></label></td> <td><input type="text" class="text" tabindex="11" name="kv_pin" id="kv_pin" value="" /> </td> </tr> <tr><td><label for="kv_phoneno"><?php _e('Phone Number(with country code)*', 'kv_project'); ?></label></td> <td><input type="text" class="text" tabindex="12" name="kv_phoneno" id="kv_phoneno" value="" /> </td> </tr> <tr> <td class="role"> <label id="kv_buyer"><input type="radio" tabindex="13" name="role" value="buyer_cap" id="buyer_radio_btn"/> <?php _e('I am a <strong>Buyer</strong>', 'kv_project'); ?></label> </td> <td> <label id="kv_seller"><input type="radio" name="role" tabindex="14" value="seller_cap" id="seller_radio_btn"/> <?php _e('I am a <strong>Author/Seller</strong>', 'kv_project'); ?></label> </td> </tr> <tr> <td colspan="2"> <div class="buyer_info" > <label for="subscription"> <input type="checkbox" tabindex="15" name="kv_subscription value=""> <?php _e('Would you like to receive Our latest Projects!' , 'kv_project'); ?> </label> </div> </td> </tr> <tr> <td colspan="2"> <div class="seller_info"><table> <tr> <td class="currency"><label id="kv_rupee"><input type="radio" name="kv_currency" tabindex="16" value="INR" id="rupee_rbtn"/> <?php _e('I use <strong>Indian Rupee ( <span class="Rupee">₹</span> )</strong> ', 'kv_project'); ?></label> </td> <td> <label id="kv_us_dollar"><input type="radio" name="kv_currency" tabindex="17" value="USD" id="usdollar_rbtn"/> <?php _e('I use <strong>U.S Dollar ( $ )</strong>', 'kv_project'); ?></label> </td> </tr> <tr> <td colspan="2" > <div class="kv_indian_rupee"><table> <tr> <td colspan="2"><label for="kv_payment_mode"> <input type="checkbox" class="text" tabindex="18" name="kv_payment_mode" id="kv_payment_mode" value="" /> <?php _e('Make my payment when it reach minimum payout.', 'kv_project'); ?></label> </td> </tr> <tr> <td><label for="kv_min_in_payout"><?php _e('Minimum Payout(* payment process check only) : ', 'kv_project'); ?></label> </td> <td><select name="kv_min_in_payout" tabindex="19" > <option value="5000" <?php if(get_user_meta('kv_min_in_payout')=='5000') echo 'Selected';?> >5000</option> <option value="7500" <?php if(get_user_meta('kv_min_in_payout') == '7500') echo 'Selected';?> >7500</option> <option value="10000" <?php if(get_user_meta('kv_min_in_payout') == '10000') echo 'Selected';?> >10000</option> <option value="15000" <?php if(get_user_meta('kv_min_in_payout') == '15000') echo 'Selected';?> >15000</option> </select> </td> </tr> </table> </div> </td> </tr> </table> <div class="kv_us_dollar"> <table> <tr><td><label for="kv_paypal_email"><?php _e('Your Paypal Email(*Paypal only)', 'kv_project'); ?></label> </td> <td><input type="text" class="email" tabindex="20" name="kv_paypal_email" id="kv_paypal_email" value="" /> </td> </tr> <tr> <td> <label for="kv_min_us_payout"><?php _e('Minimum Payout in US Dollars : ', 'kv_project'); ?> </label> </td> <td><select name="kv_min_us_payout" tabindex="21"> <option value="100" <?php if(get_user_meta('kv_min_us_payout')=='100') echo 'Selected';?> >100</option> <option value="500" <?php if(get_user_meta('kv_min_us_payout') == '500') echo 'Selected';?> >500</option> <option value="1000" <?php if(get_user_meta('kv_min_us_payout') == '1000') echo 'Selected';?> >1000</option> </select> </td></tr> </table> </div> </div> </td> </tr> <tr> <td colspan="2" > <?php if( get_option('use_recapthca',$recaptcha_option["use_recaptcha"]) == 'Enabled') { require_once('recaptchalib.php'); $publickey = get_option('re_public_key',$recaptcha_option["re_public_key"]); echo recaptcha_get_html($publickey); }?> </td> </tr> <?php if (get_option('kv_terms_page_id',$settings["kv_terms_page_id"])>0) : ?><tr> <input type="checkbox" name="terms" tabindex="22" value="yes" id="terms" checked="checked" /> <label for="terms"><?php _e('I accept the ', 'kv_project'); ?><a href="<?php echo get_permalink(get_option('kv_terms_page_id')); ?>" target="_blank"><?php _e('terms & conditions', 'kv_project'); ?></a>.</label> </tr><?php endif; ?> <tr> <td colspan="2" align="right" ><input type="submit" class="class-btn" tabindex="23" name="register" value="<?php _e('Create Account →', 'kv_project'); ?>" /></td> </tr> </form><tr> <td colspan="2" > <a class="login" href="<?php echo site_url('wp-login.php', 'login') ?>" title="<?php _e('Login', 'kv_project'); ?>"><?php _e('Already Have an Account', 'kv_project'); ?></a> </td> </tr> </table> <?php else : ?> <p class="errors"> <?php _e('User registration is disabled by Admin.', 'project'); ?> </p> <br/>Use <a href="<?php echo site_url('contact');?>" class="contact" > Contact </a> To get Access...!<br> <a class="login" href="<?php echo site_url('wp-login.php', 'login') ?>" title="<?php _e('Login', 'kv_project'); ?>"><?php _e('Return to Login Screen', 'kv_project'); ?></a> <?php endif; ?> <?php } function kv_process_register_form( $success_redirect = '' ) { $recaptcha_option = get_option("kv_recaptcha"); $settings = get_option("kv_theme_settings"); // if there's no redirect posted, send them to their job dashboard if (!$success_redirect) $success_redirect = get_permalink(get_option('kv_dashboard_page_id')); if ( get_option('users_can_register') ) : global $posted, $app_abbr; $posted = array(); $errors = new WP_Error(); if (isset($_POST['register']) && $_POST['register']) { // include the WP registration core require_once( ABSPATH . WPINC . '/registration.php'); if( get_option('use_recapthca',$recaptcha_option["use_recaptcha"]) == 'Enabled') { // process the reCaptcha request if it's been enabled require_once (TEMPLATEPATH . '/includes/login/recaptchalib.php'); $resp = null; $error = null; $recaptcha_private_key= get_option('re_private_key',$recaptcha_option["re_private_key"]); // check and make sure the reCaptcha values match $resp = recaptcha_check_answer( $recaptcha_private_key, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] ); } // Get (and clean) data $fields = array( 'user_login', 'user_email', 'your_password', 'your_password_2', 'role', 'kv_subscription', 'kv_first_name', 'kv_last_name', 'kv_address', 'kv_address_2', 'kv_state', 'kv_country', 'kv_pin', 'kv_phoneno', 'kv_currency', 'kv_payment_mode', 'kv_min_in_payout', 'kv_paypal_email', 'kv_min_us_payout' ); foreach ($fields as $field) { if (isset($_POST[$field])) $posted[$field] = stripslashes(trim($_POST[$field])); else $posted[$field] = ''; } $user_login = sanitize_user( $posted['user_login'] ); $user_email = apply_filters( 'user_registration_email', $posted['user_email'] ); $user_role = 'buyer_cap'; // Check Role if (!isset($_POST['role'])) $errors->add('empty_role', __('<strong>Notice</strong>: Please select a role.', 'kv_project')); if (isset($_POST['role'])) : if ($posted['role']!='buyer_cap' && $posted['role']!='seller_cap') $errors->add('empty_role', __('<strong>Notice</strong>: Invalid Role!', 'kv_project')); else $user_role = $posted['role']; endif; $kv_user_first_name = esc_attr($_POST['kv_first_name']); if ($posted['kv_first_name'] == '') $errors->add('empty_first_name', __('<strong>Notice</strong>: You must enter your name in order to register.', 'kv_project')); else $kv_user_first_name = esc_attr($_POST['kv_first_name']); if (isset($_POST['kv_last_name'])) $kv_user_last_name = esc_attr($_POST['kv_last_name']); if ($posted['kv_address'] == '') $errors->add('empty_addres', __('<strong>Notice</strong>: You must enter your address for communication.', 'kv_project')); else $kv_user_addr = esc_attr($_POST['kv_address']); if (isset($_POST['kv_address_2'])) $kv_user_addr_2 = esc_attr($_POST['kv_address_2']); if (isset($_POST['kv_state'])) $kv_user_state= esc_attr($_POST['kv_state']); if (isset($_POST['kv_country'])) $kv_user_country = esc_attr($_POST['kv_country']); if (isset($_POST['kv_pin'])) $kv_user_pin = esc_attr($_POST['kv_pin']); if(!is_numeric($kv_user_pin) ) $errors->add('empty_terms', __('<strong>Notice</strong>: Your pin number is not valid one.', 'kv_project')); if ($posted['kv_phoneno'] =='') $errors->add('empty_terms', __('<strong>Notice</strong>: You must enter your Phone number for Comfirmation to register.', 'kv_project')); else if (!is_numeric($kv_user_phoneno = esc_attr($_POST['kv_phoneno']))) $errors->add('empty_terms', __('<strong>Notice</strong>: Enter Vaild Phone Number only(its for security purpose only).', 'kv_project')); else $kv_user_phoneno = esc_attr($_POST['kv_phoneno']); if ($user_role == 'seller_cap') { if (!isset($_POST['kv_currency'])) { $errors->add('empty_currency', __('<strong>Notice</strong>: You must select your currency to get paid.', 'kv_project')); } else { $kv_user_currency = esc_attr($_POST['kv_currency']); if($kv_user_currency == 'INR' ) { if(isset($_POST['kv_payment_mode'])) $kv_user_payment_mode = esc_attr($_POST['kv_payment_mode']); else $errors->add('empty_payment_mode', __('<strong>Notice</strong>: You must select your Payment Mode.', 'kv_project')); if(isset($_POST['kv_min_in_payout'])) $kv_user_min_in_payout = esc_attr($_POST['kv_min_in_payout']); else $errors->add('empty_payout', __('<strong>Notice</strong>: You must Choose your Minimum Payout in indian_rupee', 'kv_project')); } else if($kv_user_currency == 'USD' ) { if(isset($_POST['kv_paypal_email'])){ $kv_user_paypal_email = esc_attr($_POST['kv_paypal_email']); if(!is_email($kv_user_paypal_email)) $errors->add('empty_paypal_email', __('<strong>Notice</strong>: Your Paypal Email is incorrect. Check your Paypal Email id', 'kv_project')); } else $errors->add('empty_terms', __('<strong>Notice</strong>: You selected U.S Dollar. So enter your Paypal Email id to receive Payment.', 'kv_project')); if(isset($_POST['kv_min_us_payout'])) $kv_user_min_us_payout = esc_attr($_POST['kv_min_us_payout']); else $errors->add('empty_payout', __('<strong>Notice</strong>: You must Choose your Minimum Payout in US Dollar.', 'kv_project')); } } } // Check terms acceptance if (get_option('kv_terms_page_id',$settings["kv_terms_page_id"])>0) { if (!isset($_POST['terms'])) $errors->add('empty_terms', __('<strong>Notice</strong>: You must accept our terms and conditions in order to register.', 'kv_project')); } // Check the username if ( $posted['user_login'] == '' ) $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.', 'kv_project')); elseif ( !validate_username( $posted['user_login'] ) ) { $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.', 'kv_project')); $posted['user_login'] = ''; } elseif ( username_exists( $posted['user_login'] ) ) $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered, please choose another one.', 'kv_project')); // Check the e-mail address if ($posted['user_email'] == '') { $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.', 'kv_project')); } elseif ( !is_email( $posted['user_email'] ) ) { $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.', 'kv_project')); $posted['user_email'] = ''; } elseif ( email_exists( $posted['user_email'] ) ) $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.', 'kv_project')); if (get_option('kv_usr_pas',$settings["kv_usr_pas"])=='Enabled') : // Check Passwords match if ($posted['your_password'] == '') $errors->add('empty_password', __('<strong>ERROR</strong>: Please enter a password.', 'kv_project')); elseif ($posted['your_password_2'] == '') $errors->add('empty_password', __('<strong>ERROR</strong>: Please enter password twice.', 'kv_project')); elseif ($posted['your_password'] !== $posted['your_password_2']) $errors->add('wrong_password', __('<strong>ERROR</strong>: Passwords do not match.', 'kv_project')); else $user_pass = $posted['your_password']; else : $user_pass = wp_generate_password(); endif; // display the reCaptcha error msg if it's been enabled if( get_option('use_recapthca',$recaptcha_option["use_recaptcha"]) == 'Enabled') { // Check reCaptcha match if (!$resp->is_valid) $errors->add('invalid_captcha', __('<strong>ERROR</strong>: The reCaptcha anti-spam response was incorrect.', 'kv_project')); //$error = $resp->error; } do_action('register_post', $posted['user_login'], $posted['user_email'], $errors); $errors = apply_filters( 'registration_errors', $errors, $posted['user_login'], $posted['user_email'] ); // if there are no errors, let's create the user account if ( !$errors->get_error_code() ) { $user_id = wp_create_user( $posted['user_login'], $user_pass, $posted['user_email'] ); if ( !$user_id ) { $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'kv_project'), get_option('admin_email'))); return array( 'errors' => $errors, 'posted' => $posted); } wp_update_user( array ('ID' => $user_id, 'role' => $user_role) ) ; // update_user_meta($user_id, 'kv_user', $kv_user ); update_user_meta($user_id, 'first_name', $kv_user_first_name ); update_user_meta($user_id, 'last_name', $kv_user_last_name ); update_user_meta($user_id, 'kv_user_addr', $kv_user_addr ); update_user_meta($user_id, 'kv_user_addr_2', $kv_user_addr_2 ); update_user_meta($user_id, 'kv_user_state', $kv_user_state ); update_user_meta($user_id, 'kv_user_country', $kv_user_country ); update_user_meta($user_id, 'kv_user_pin', $kv_user_pin ); update_user_meta($user_id, 'kv_user_phoneno', $kv_user_phoneno); if( $user_role == 'seller_cap' ) { update_user_meta($user_id, 'kv_user_currency', $kv_user_currency ); update_user_meta($user_id, 'kv_user_payment_mode', $kv_user_payment_mode ); update_user_meta($user_id, 'kv_user_min_in_payout', $kv_user_min_in_payout ); update_user_meta($user_id, 'kv_user_paypal_email', $kv_user_paypal_email ); update_user_meta($user_id, 'kv_user_min_us_payout', $kv_user_min_us_payout ); } update_user_meta($user_id, 'kv_user_net_amt', 0); update_user_meta($user_id, 'kv_user_available_bal', 0); update_user_meta($user_id, 'kv_user_last_trans_date', 0); update_user_meta($user_id, 'kv_user_last_trans_amt', 0); update_user_meta($user_id, 'kv_user_payment_method', $payout_method='paypal'); update_user_meta($user_id, 'kv_user_make_my_payment', 'no'); kv_new_user_notification($user_id, $user_pass); if (get_option('kv_allow_registration_password')=='yes') : // set the WP login cookie $secure_cookie = is_ssl() ? true : false; wp_set_auth_cookie($user_id, true, $secure_cookie); // redirect wp_redirect($success_redirect); exit; else : //create own password option is turned off so show a message that it's been emailed instead $redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : '?checkemail=newpass'; wp_safe_redirect( $redirect_to ); exit(); endif; } else { // there were errors so go back and display them without creating new user return array( 'errors' => $errors, 'posted' => $posted); } } endif; } ?>
The above code is my older project code , which may looks older, buut everything works fine till now. not much old, just 1 year back with wordpress 3.0 . and now open your next file ” login-form-process.php”
<?php /** * JobRoller Login Form * Function outputs the login form */ function kv_login_form( $action = '', $redirect = '' ) { global $posted; if (!$action) $action = site_url('wp-login.php'); if (!$redirect) { if(trim($_REQUEST['redirect_from']) != null) $redirect = $_REQUEST['redirect_from']; else $redirect= site_url('dashboard'); } ?> <h2><?php _e('Already have an account?', 'kv_project'); ?></h2> <div style=" width : 60% ;" > <table > <form action="<?php echo $action; ?>" method="post" class="account_form"> <tr> <td> <label for="login_username"><?php _e('Username', 'kv_project'); ?></label></td> <td> <input type="text" class="text" name="log" id="login_username" value="<?php if (isset($posted['login_username'])) echo $posted['login_username']; ?>" /> </td> </tr> <tr> <td> <label for="login_password"><?php _e('Password', 'kv_project'); ?></label></td> <td> <input type="password" class="text" name="pwd" id="login_password" value="" /> </td> </tr> <tr> <td colspan="2" > <input type="hidden" name="redirect_to" value="<?php echo $redirect; ?>" /> <input type="hidden" name="rememberme" value="forever" /> <input type="submit" class="class-btn" name="login" value="<?php _e('Login →', 'kv_project'); ?>" /> <a class="lostpass" href="<?php echo site_url('wp-login.php?action=lostpassword', 'login') ?>" title="<?php _e('Password Lost and Found', 'kv_project'); ?>"><?php _e('Lost your password?', 'kv_project'); ?></a> </td> </tr> </form> <tr> <td colspan="2" > <a class="register" href="<?php echo site_url('wp-login.php?action=register', 'login') ?>" title="<?php _e('Sign Up', 'kv_project'); ?>"><?php _e('Register a New Account', 'kv_project'); ?></a> </td> </tr> </table> </div> <?php } if (!function_exists('user_can')) : function user_can( $user, $capability ) { if ( ! is_object( $user ) ) $user = new WP_User( (int) $user ); if ( ! $user || ! $user->ID ) return false; $args = array_slice( func_get_args(), 2 ); $args = array_merge( array( $capability ), $args ); return call_user_func_array( array( &$user, 'has_cap' ), $args ); } endif; function kv_process_login_form() { global $posted; if ( isset( $_REQUEST['redirect_to'] ) ) $redirect_to = $_REQUEST['redirect_to']; else $redirect_to = admin_url(); if ( is_ssl() && force_ssl_login() && !force_ssl_admin() && ( 0 !== strpos($redirect_to, 'https') ) && ( 0 === strpos($redirect_to, 'http') ) ) $secure_cookie = false; else $secure_cookie = ''; $user = wp_signon('', $secure_cookie); $redirect_to = apply_filters('login_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '', $user); if ( !is_wp_error($user) ) { if (user_can($user, 'manage_options')) : $redirect_to = site_url('wp-admin/admin.php?page=theme-config.php'); endif; wp_safe_redirect($redirect_to); exit; } $errors = $user; return $errors; } ?>
Finally , forgot passowrd form. php
<?php function kv_forgot_password_form() { ?> <div style="width:70%" ><table> <tr> <td colspan="2" > <p><?php _e('Please enter your username or email address. A new password will be emailed to you.', 'appthemes') ?></p> </td> </tr> <form action="" method="post" class="main_form"> <tr> <td> <p><label for="login_username"><?php _e('Username/Email', 'appthemes'); ?></label> </td> <td> <input type="text" class="text" name="user_login" id="login_username" /></p> </td> </tr> <tr> <td colspan="2"> <p><?php do_action('lostpassword_form'); ?><input type="submit" class="class-btn" name="login" value="<?php _e('Get New Password','appthemes'); ?>" /></p> </td> </tr> </form> <tr> <td> <a class="login" href="<?php echo site_url('wp-login.php', 'login') ?>" title="<?php _e('Login', 'kv_project'); ?>"><?php _e('→ Back to Login', 'kv_project'); ?></a> </td> </tr> </table> </div> <?php }
that’s it to setup your own custom login page with header and footer of your site. just try the demo here.
Demo
and you can get the source code zip here.
Download
Hey bro,
Nice Article But this is same as like WordPress login register and forgot password page code
If we implement this for the site which we want custom login register pages if they register an login they will get the even admin access and if suppose any user logged in the then-current user set to the logged-in user as admin in the site then for the site we cant maintain custom login functionality
Hello bro, so you have to play more in this. You need to create custom roles and use it for the people who register from the custom register page. And also you have to prevent admin access to such a custom role. This way you can achieve it what you are looking. There are many resources available to create custom role and prevent it for admin access.