Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * This controls how the login, logout,
- * registration, and forgot your password pages look.
- * It overrides the default WP pages by intercepting the request.
- *
- */
- global $pagenow;
- // check to prevent php "notice: undefined index" msg
- if(isset($_GET['action'])) $theaction = $_GET['action']; else $theaction ='';
- // if the user is on the login page, then let the games begin
- if ($pagenow == 'wp-login.php' && $theaction != 'logout' && !isset($_GET['key'])) {
- add_action('init', 'cp_login_init', 98);
- add_filter('wp_title','cp_title');
- }
- // if the current user has no edit rights, redirect them to their dashboard page
- add_filter('login_redirect', 'cp_redirect', 10, 3);
- // main function that routes the request
- function cp_login_init() {
- require_once(ABSPATH . '/wp-load.php');
- if (isset($_REQUEST["action"])) {
- $action = $_REQUEST["action"];
- } else {
- $action = 'login';
- }
- switch($action) {
- case 'lostpassword' :
- case 'retrievepassword' :
- cp_password();
- break;
- case 'register':
- cp_show_register();
- break;
- case 'login':
- default:
- cp_show_login();
- break;
- }
- die();
- }
- // redirect the user
- function cp_redirect($redirect_to, $request_redirect_to, $user) {
- if (is_a($user, 'WP_User') && $user->has_cap('level_3') === false) {
- return get_bloginfo('wpurl');
- }
- return $redirect_to;
- }
- // assemble the header
- function cp_head($cp_msg) {
- global $cp_options;
- include(TEMPLATEPATH . '/header.php');
- ?>
- <!-- CONTENT -->
- <div class="content">
- <div class="content_botbg">
- <div class="content_res">
- <!-- full block -->
- <div class="shadowblock_out">
- <div class="shadowblock">
- <h2 class="dotted"><span class="colour"><?php _e($cp_msg) ?></span></h2>
- <?php
- }
- // display the meta page title based on the current page
- function cp_title($title) {
- global $pagenow;
- if ($pagenow == "wp-login.php") {
- switch($_GET['action'])
- {
- case 'register':
- $title = __('Register at ','cp');
- break;
- case 'lostpassword':
- $title = __('Retrieve your lost password for ','cp');
- break;
- case 'login':
- default:
- $title = __('Login at ','cp');
- break;
- }
- } else if ($pagenow == "profile.php") {
- $title = __('Your Profile at ','cp');
- }
- return $title;
- }
- // show the custom login page if on wp-login.php
- function cp_show_login() {
- 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 the user can't edit posts, send them to their profile.
- if ( !$user->has_cap('edit_posts') && ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' ) )
- $redirect_to = admin_url('profile.php');
- wp_safe_redirect($redirect_to);
- exit();
- }
- $errors = $user;
- // Clear errors if loggedout is set.
- if ( !empty($_GET['loggedout']) )
- $errors = new WP_Error();
- cp_head(__('Login','cp'));
- // 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.','cp'));
- if ( isset($_GET['loggedout']) && TRUE == $_GET['loggedout'] )
- $errors->add('loggedout', __('You are now logged out.','cp'), 'message');
- elseif ( isset($_GET['registration']) && 'disabled' == $_GET['registration'] )
- $errors->add('registerdisabled', __('User registration is currently not allowed.','cp'));
- elseif ( isset($_GET['checkemail']) && 'confirm' == $_GET['checkemail'] )
- $errors->add('confirm', __('Check your email for the confirmation link.','cp'), 'message');
- elseif ( isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail'] )
- $errors->add('newpass', __('Check your email for your new password.','cp'), 'message');
- elseif ( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] )
- $errors->add('registered', __('Registration complete. Please check your e-mail.','cp'), 'message');
- ?>
- <div class="left-box">
- <?php echo cp_show_errors($errors); ?>
- <div id="message"><?php _e('Please complete the fields below to login.', 'cp') ?></div>
- <form class="loginform" action="<?php bloginfo('wpurl'); ?>/wp-login.php" method="post" >
- <p>
- <label for="user_login"><?php _e('Username:','cp') ?></label>
- <input name="log" value="<?php echo attribute_escape(stripslashes($_POST['log'])); ?>" class="mid" id="user_login" type="text" />
- <br/>
- <label for="user_pass"><?php _e('Password:','cp') ?></label>
- <input name="pwd" class="mid" id="user_pass" type="password" />
- <br/>
- </p>
- <div class="clr"></div>
- <div id="checksave">
- <input name="rememberme" class="checkbox" id="rememberme" value="forever" type="checkbox" checked="checked"/>
- <label for="rememberme"><?php _e('Remember me','cp'); ?></label>
- <br/><br/>
- <p class="submit">
- <input type="submit" class="btn_orange" name="wp-submit" id="wp-submit" value="<?php _e('Login','cp'); ?> »" />
- <input type="hidden" name="testcookie" value="1" />
- </p>
- </div>
- </form>
- </div><!--/left-box -->
- <div class="right-box">
- </div><!-- /right-box -->
- <?php cp_footer(); ?>
- <?php
- }
- // show the forgot your password page
- function cp_password() {
- $errors = new WP_Error();
- if ( $_POST['user_login'] ) {
- $errors = retrieve_password();
- if ( !is_wp_error($errors) ) {
- wp_redirect('wp-login.php?checkemail=confirm');
- exit();
- }
- }
- if ( 'invalidkey' == $_GET['error'] )
- $errors->add('invalidkey', __('Sorry, that key does not appear to be valid.','cp'));
- do_action('lost_password');
- do_action('lostpassword_post');
- cp_head("Lost Password");
- ?>
- <div class="left-box">
- <?php echo cp_show_errors($errors); ?>
- <div id="message"><?php _e('Please enter your username or email address. A new password will be emailed to you.', 'cp') ?></div>
- <form class="loginform" name="lostpasswordform" id="lostpasswordform" action="<?php echo site_url('wp-login.php?action=lostpassword', 'login_post') ?>" method="post">
- <p>
- <label><?php _e('Username or Email:','cp') ?></label>
- <input type="text" name="user_login" id="user_login" class="mid" value="<?php echo attribute_escape(stripslashes($_POST['user_login'])); ?>" size="20" tabindex="10" />
- </p>
- <div id="checksave">
- <?php do_action('lostpassword_form'); ?>
- <p class="submit"><input type="submit" class="btn_orange" name="wp-submit" id="wp-submit" value="<?php _e('Get New Password','cp'); ?>" tabindex="100" /></p>
- </div>
- </form>
- </div><!--/left-box -->
- <div class="right-box">
- </div><!-- /right-box -->
- <?php cp_footer(); ?>
- <?php
- }
- // show the new user registration page
- function cp_show_register() {
- global $cp_pluginpath, $cp_options;
- if ( !get_option('users_can_register') ) {
- wp_redirect(get_bloginfo('wpurl').'/wp-login.php?registration=disabled');
- exit();
- }
- $user_login = '';
- $user_email = '';
- if ( isset($_POST['user_login']) ) {
- if( !$cp_options['captcha'] || ( $cp_options['captcha'] && ($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code']) ) )) {
- unset($_SESSION['security_code']);
- require_once( ABSPATH . WPINC . '/registration.php');
- $user_login = $_POST['user_login'];
- $user_email = $_POST['user_email'];
- $errors = register_new_user($user_login, $user_email);
- if ( !is_wp_error($errors) ) {
- wp_redirect('wp-login.php?checkemail=registered');
- exit();
- }
- } else {
- $user_login = $_POST['user_login'];
- $user_email = $_POST['user_email'];
- $errors = new WP_error();
- $errors->add('captcha', __("<strong>ERROR</strong>: You didn't correctly enter the captcha, please try again.",'cp'));
- }
- }
- cp_head(__('Register','cp'));
- ?>
- <div class="left-box">
- <?php cp_show_errors($errors); ?>
- <div id="message"><?php _e('Complete the fields below to become a member. Your password will be emailed to you so make sure to use a valid email address. Once registration is complete, you will be able to submit your ads.', 'cp') ?></div>
- <form class="loginform" name="registerform" id="registerform" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" method="post">
- <p>
- <label><?php _e('Username','cp') ?>:</label>
- <input tabindex="1" type="text" name="user_login" id="user_login" class="mid" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" size="20" /><br/>
- <label><?php _e('Email','cp') ?>:</label>
- <input tabindex="2" type="text" name="user_email" id="user_email" class="mid" value="<?php echo attribute_escape(stripslashes($user_email)); ?>" size="25" />
- <?php if ($cp_options['captcha']) { ?>
- <label> </label>
- <img alt="captcha" width="155" height="30" src="<?php echo $cp_pluginpath; ?>captcha.php?width=155&height=30&characters=5" /><br/>
- <label for="security_code"><?php _e('Type the code above:','cp');?></label>
- <input tabindex="3" id="security_code" name="security_code" class="input" type="text" />
- <?php } ?>
- </p>
- <div id="checksave">
- <?php do_action('register_form'); ?>
- <p class="submit"><input tabindex="4" class="btn_orange" type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Register','cp'); ?>" /></p>
- </div>
- </form>
- </div><!-- /left-box -->
- <div class="right-box">
- </div><!-- /right-box -->
- <?php cp_footer(); ?>
- <?php
- }
- // assemble the footer
- function cp_footer() {
- global $pagenow, $user_ID, $cp_options;
- if ($pagenow == 'wp-login.php') {
- // check to prevent php "notice: undefined index" msg
- if(isset($_GET['action'])) $theaction = $_GET['action']; else $theaction ='';
- // Show the appropriate options
- echo '<div class="cpnav">'."\n";
- if (isset($_GET['action']) && $theaction != 'login')
- echo '<a href="'.site_url('wp-login.php', 'login').'">'.__('Log in','cp').'</a><br />'."\n";
- if (get_option('users_can_register') && $theaction != 'register')
- echo '<a href="'.site_url('wp-login.php?action=register', 'login').'">'.__('Register','cp').'</a><br />'."\n";
- if ($theaction != 'lostpassword')
- echo '<a href="'.site_url('wp-login.php?action=lostpassword', 'login').'" title="'.__('Password Lost and Found','cp').'">'.__('Lost your password?','cp').'</a>'."\n";
- echo '</div>'."\n";
- ?>
- <!-- autofocus the field -->
- <script type="text/javascript">try{document.getElementById('user_login').focus();}catch(e){}</script>
- <?php
- } else if (isset($user_ID)) {
- // do nothing
- }
- ?>
- </div><!-- /shadowblock -->
- </div><!-- /shadowblock_out -->
- <div class="clr"></div>
- </div><!-- /content_res -->
- </div><!-- /content_botbg -->
- </div><!-- /content -->
- <?php include(TEMPLATEPATH . '/footer.php'); ?>
- <?php
- }
- // process the errors if there are any
- function cp_show_errors($wp_error) {
- global $error;
- if ( !empty( $error ) ) {
- $wp_error->add('error', $error);
- unset($error);
- }
- if ( !empty($wp_error) ) {
- if ( $wp_error->get_error_code() ) {
- $errors = '';
- $messages = '';
- foreach ( $wp_error->get_error_codes() as $code ) {
- $severity = $wp_error->get_error_data($code);
- foreach ( $wp_error->get_error_messages($code) as $error ) {
- if ( 'message' == $severity )
- $messages .= ' ' . $error . "<br />\n";
- else
- $errors .= ' ' . $error . "<br />\n";
- }
- }
- if ( !empty($errors) )
- echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
- if ( !empty($messages) )
- echo '<div id="message">' . apply_filters('login_messages', $messages) . "</div>\n";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement