auth_redirect [ WordPress Functions ]
auth_redirect ( No parameters )
| Defined at: |
|
| Codex |
Soorgelijke functies: wp_redirect, is_redirect, wp_safe_redirect, wp_validate_redirect, wp_sanitize_redirect
Checks if a user is logged in, if not it redirects them to the login page.
Source
function auth_redirect() {
// Checks if a user is logged in, if not redirects them to the login page
$secure = ( is_ssl() || force_ssl_admin() );
$secure = apply_filters('secure_auth_redirect', $secure);
// If https is required and request is http, redirect
if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
exit();
} else {
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
exit();
}
}
if ( is_user_admin() )
$scheme = 'logged_in';
else
$scheme = apply_filters( 'auth_redirect_scheme', '' );
if ( $user_id = wp_validate_auth_cookie( '', $scheme) ) {
do_action('auth_redirect', $user_id);
// If the user wants ssl but the session is not ssl, redirect.
if ( !$secure && get_user_option('use_ssl', $user_id) && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
exit();
} else {
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
exit();
}
}
return; // The cookie is good so we're done
}
// The cookie is no good so force login
nocache_headers();
$redirect = ( strpos( $_SERVER['REQUEST_URI'], '/options.php' ) && wp_get_referer() ) ? wp_get_referer() : set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
$login_url = wp_login_url($redirect, true);
wp_redirect($login_url);
exit();
}Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/auth redirect « WordPress Codex
Description. Checks user is logged in, if not it redirects them to login page. When this code is called from a page, it checks to see if the user viewing the page is ...
codex.wordpress.org - How to Redirect Logged-In Users | Digging into WordPress
Aug 8, 2011 ... Next up, we have auth_redirect, which is a “simple function that requires that the user be logged in before they can access a page.” So for ...
digwp.com - Using auth_redirect returns cannot modify header information
Sep 12, 2012 ... I'm hooking auth_redirect to wp_head , but it's returning cannot modify header information. Do I have to hook it to a different action? Something ...
wordpress.stackexchange.com - auth_redirect (WordPress Function) - WPSeek.com
May 11, 2013 ... Checks if a user is logged in, if not it redirects them to the login page. WordPress lookup for auth_redirect, a WordPress Function.
wpseek.com
Gebruikersdiscussies [ wordpress.org ]
- rezon8dev on "Auth_redirect not working"
- sherice on "Wordpress Menu and Buddypress"
- Roswell85 on "Wordpress Menu and Buddypress"
- sherice on "Wordpress Menu and Buddypress"
- krauter on "Using auth_redirect() from shortcode inititated code"
- Warren Harrison on "Using auth_redirect() from shortcode inititated code"
- esmi on "auth_redirect error"
- packtramp on "auth_redirect error"
- esmi on "auth_redirect error"
- packtramp on "auth_redirect error"
