| 1 |
<?php |
| 2 |
if(!function_exists('curPageURL')){ |
| 3 |
function curPageURL() { |
| 4 |
$pageURL = 'http'; |
| 5 |
if ((isset($_SERVER["HTTPS"])) && ($_SERVER["HTTPS"] == "on")) { |
| 6 |
$pageURL .= "s"; |
| 7 |
} |
| 8 |
$pageURL .= "://"; |
| 9 |
if ($_SERVER["SERVER_PORT"] != "80") { |
| 10 |
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; |
| 11 |
} else { |
| 12 |
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; |
| 13 |
} |
| 14 |
return $pageURL; |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
/* wp_signon can only be executed before anything is outputed in the page because of that we're adding it to the init hook */ |
| 19 |
global $wppb_login; |
| 20 |
$wppb_login = false; |
| 21 |
|
| 22 |
function wppb_signon(){ |
| 23 |
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'log-in' && wp_verify_nonce($_POST['login_nonce_field'],'verify_true_login')) : |
| 24 |
global $error; |
| 25 |
global $wppb_login; |
| 26 |
$wppb_login = wp_signon( array( 'user_login' => $_POST['user-name'], 'user_password' => $_POST['password'], 'remember' => $_POST['remember-me'] ), false ); |
| 27 |
endif; |
| 28 |
} |
| 29 |
add_action('init', 'wppb_signon'); |
| 30 |
|
| 31 |
function wppb_front_end_login(){ |
| 32 |
ob_start(); |
| 33 |
global $wppb_login; |
| 34 |
|
| 35 |
echo '<div class="wppb_holder" id="wppb_login">'; |
| 36 |
|
| 37 |
if ( is_user_logged_in() ) : // Already logged in |
| 38 |
global $user_ID; |
| 39 |
$wppb_user = get_userdata( $user_ID ); |
| 40 |
if($wppb_user->display_name == ''){ |
| 41 |
$wppb_user->display_name = $wppb_user->user_login; |
| 42 |
} |
| 43 |
|
| 44 |
?> |
| 45 |
|
| 46 |
<p class="alert"> |
| 47 |
<?php printf( __('You are currently logged in as <a href="%1$s" title="%2$s">%2$s</a>.', 'profilebuilder'), get_author_posts_url( $wppb_user->ID ), $wppb_user->display_name ); ?> <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="<?php _e('Log out of this account', 'profilebuilder'); ?>"><?php _e('Log out »', 'profilebuilder'); ?></a> |
| 48 |
</p><!-- .alert --> |
| 49 |
|
| 50 |
<?php elseif ( $wppb_login->ID ) : // Successful login ?> |
| 51 |
<?php |
| 52 |
//$wppb_login = get_userdata( $wppb_login->ID ); |
| 53 |
if($wppb_login->display_name == ''){ |
| 54 |
$wppb_login->display_name = $wppb_login->user_login; |
| 55 |
} |
| 56 |
|
| 57 |
?> |
| 58 |
|
| 59 |
<p class="success"> |
| 60 |
<?php printf( __('You have successfully logged in as <a href="%1$s" title="%2$s">%2$s</a>.', 'profilebuilder'), get_author_posts_url( $wppb_login->ID ), $wppb_login->display_name ); ?> |
| 61 |
<?php |
| 62 |
$permaLnk2 = get_permalink(); |
| 63 |
$wppb_addons = wppb_plugin_dir . '/premium/addon/'; |
| 64 |
if (file_exists ( $wppb_addons.'addon.php' )){ |
| 65 |
//check to see if the redirecting addon is present and activated |
| 66 |
$wppb_premium_addon_settings = get_option('wppb_premium_addon_settings'); //fetch the descriptions array |
| 67 |
if ($wppb_premium_addon_settings['customRedirect'] == 'show'){ |
| 68 |
//check to see if the redirect location is not an empty string and is activated |
| 69 |
$customRedirectSettings = get_option('customRedirectSettings'); |
| 70 |
if ((trim($customRedirectSettings['afterLoginTarget']) != '') && ($customRedirectSettings['afterLogin'] == 'yes')){ |
| 71 |
$permaLnk2 = trim($customRedirectSettings['afterLoginTarget']); |
| 72 |
$findHttp = strpos($permaLnk2, 'http'); |
| 73 |
if ($findHttp === false) |
| 74 |
$permaLnk2 = 'http://'. $permaLnk2; |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
?> |
| 79 |
|
| 80 |
</p><!-- .success--> |
| 81 |
<?php echo '<font color="black">You will soon be redirected automatically. If you see this page for more than 1 second, please click <a href="'.$permaLnk2.'">here</a>.<meta http-equiv="Refresh" content="1;url='.$permaLnk2.'" /></font><br/><br/>'; ?> |
| 82 |
<br/><br/> |
| 83 |
<?php else : // Not logged in ?> |
| 84 |
|
| 85 |
<?php if (!empty( $_POST['action'] )): ?> |
| 86 |
<p class="error"> |
| 87 |
<?php if ( trim($_POST['user-name']) == '') echo '<strong>ERROR:</strong> The username field is empty. '; ?> |
| 88 |
<?php if ( is_wp_error($wppb_login) ) echo $wppb_login->get_error_message();?> |
| 89 |
</p><!-- .error --> |
| 90 |
<?php endif; ?> |
| 91 |
|
| 92 |
<?php /* use this action hook to add extra content before the login form. */ ?> |
| 93 |
<?php do_action( 'wppb_before_login' ); ?> |
| 94 |
|
| 95 |
<form action="<?php curPageURL(); ?>" method="post" class="sign-in"> |
| 96 |
<p class="login-form-username"> |
| 97 |
<label for="user-name"><?php _e('Username', 'profilebuilder'); ?></label> |
| 98 |
<?php |
| 99 |
if (isset($_POST['user-name'])) |
| 100 |
$userName = esc_html( $_POST['user-name'] ); |
| 101 |
else $userName = ''; |
| 102 |
?> |
| 103 |
<?php echo '<input type="text" name="user-name" id="user-name" class="text-input" value="'.$userName.'" />'; ?> |
| 104 |
</p><!-- .form-username --> |
| 105 |
|
| 106 |
<p class="login-form-password"> |
| 107 |
<label for="password"><?php _e('Password', 'profilebuilder'); ?></label> |
| 108 |
<input type="password" name="password" id="password" class="text-input" /> |
| 109 |
</p><!-- .form-password --> |
| 110 |
<p class="login-form-submit"> |
| 111 |
<input type="submit" name="submit" class="submit button" value="<?php _e('Log in', 'profilebuilder'); ?>" /> |
| 112 |
<input class="remember-me checkbox" name="remember-me" id="remember-me" type="checkbox" checked="checked" value="forever" /> |
| 113 |
<label for="remember-me"><?php _e('Remember me', 'profilebuilder'); ?></label> |
| 114 |
<input type="hidden" name="action" value="log-in" /> |
| 115 |
</p><!-- .form-submit --> |
| 116 |
<p> |
| 117 |
<a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=lostpassword"><?php _e('Lost password?', 'profilebuilder'); ?></a> |
| 118 |
</p> |
| 119 |
<?php wp_nonce_field('verify_true_login','login_nonce_field'); ?> |
| 120 |
</form><!-- .sign-in --> |
| 121 |
|
| 122 |
<?php endif;?> |
| 123 |
|
| 124 |
<?php /* use this action hook to add extra content after the login form. */ ?> |
| 125 |
<?php do_action( 'wppb_after_login' ); ?> |
| 126 |
|
| 127 |
</div> |
| 128 |
<?php |
| 129 |
$output = ob_get_contents(); |
| 130 |
ob_end_clean(); |
| 131 |
|
| 132 |
$output = apply_filters ('wppb_login', $output); |
| 133 |
|
| 134 |
return $output; |
| 135 |
} |