post_type )
&& in_array( $page->post_name, array( 'login', 'logout', 'lostpassword', 'register', 'resetpass' ) )
&& stripos( $page->post_content, 'theme-my-login' ) ) {
return;
}
}
}
/* Point of No Return:
We now know that the Visitor must be forced to login
if the Visitor wants to see the current URL.
*/
if ( !$role ) {
/* User is logged on to a Site where he/she has no Role.
*/
$message = 'You (User "'
. wp_get_current_user()->user_login
. '") cannot view this Site ("'
. get_bloginfo( 'name', 'display' )
. '").
'
. 'Your User ID has not been defined to this Site. '
. 'If you believe that you should be able to access this Site, '
. 'please contact your network administrator or this site\'s webmaster, '
. 'and mention that your access was blocked by the '
. $jr_ps_plugin_data['Name']
. ' plugin.';
wp_die( $message );
}
if ( $settings['custom_login'] && !empty( $settings['login_url'] ) ) {
$url = jr_ps_login_url( $settings['login_url'] );
} else {
/* wp_login_url() returns the standard WordPress login URL,
but the login_url Filter adds the ?redirect_to= query in the URL.
*/
$url = wp_login_url();
}
/* wp_redirect( $url ) goes to $url right after exit on the line that follows.
*/
wp_redirect( $url );
exit;
}
/**
* Add Landing Location to Login URL
*
* Although written to modify the Login URL in the Meta Widget,
* to implement Landing Location, wp_login_url() is also called
* near the end of jr_ps_force_login() above.
*
* @param string $login_url Login URL
* @param string $redirect Path to redirect to on login.
* @return string Login URL
*/
function jr_ps_login_url( $login_url ) {
/* remove_query_arg() simply returns $login_url if a ?redirect_to= query is not present in the URL.
*/
$url = remove_query_arg( 'redirect_to', $login_url );
/* $redirect_to is the URL passed to the standard WordPress login URL,
via the ?redirect_to= URL query parameter, to go to after login is complete.
*/
$redirect_to = jr_ps_after_login_url();
/* Also avoids situations where specific URL is requested,
but URL is blank.
*/
if ( !empty( $redirect_to ) ) {
$url = add_query_arg( 'redirect_to', urlencode( $redirect_to ), $url );
}
return $url;
}
function jr_ps_after_login_url() {
$settings = get_option( 'jr_ps_settings' );
switch ( $settings['landing'] ) {
case 'return':
// $_SERVER['HTTPS'] can be off in IIS
if ( empty( $_SERVER['HTTPS'] ) || ( $_SERVER['HTTPS'] == 'off' ) ) {
$http = 'http://';
} else {
$http = 'https://';
}
if (strpos($_SERVER['REQUEST_URI'], 'resetpass') !== false) {
$after_login_url = get_home_url();
}
else {
$after_login_url = $http . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
}
break;
case 'home':
$after_login_url = get_home_url();
break;
case 'admin':
$after_login_url = get_admin_url();
break;
case 'url':
if (strpos($after_login_url, 'resetpass') !== false) {
$after_login_url = get_home_url();
}
else {
$after_login_url = trim( $settings['specific_url'] );
}
break;
case 'omit':
$after_login_url = '';
break;
}
return $after_login_url;
}
function jr_ps_login_failed() {
$settings = get_option( 'jr_ps_settings' );
if ( $settings['custom_login'] && !empty( $settings['login_url'] ) ) {
/* wp_redirect( $url ) goes to $url right after exit on the line that follows.
*/
wp_redirect( jr_ps_login_url( $settings['login_url'] ) );
exit;
} else {
return;
}
}
function jr_ps_wp_authenticate( $username, $password ) {
foreach ( array( $username, $password ) as $auth ) {
if ( empty( $auth ) ) {
jr_ps_login_failed();
} else {
/* Also catch blanks.
*/
$trim_auth = rtrim( $auth );
if ( empty( $auth ) ) {
jr_ps_login_failed();
}
}
}
}
?>