WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/auth redirect

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 logged in. If the user is not logged in, they are redirected to the login page. The user is redirected in such a way that, upon logging in, they will be sent directly to the page they were originally trying to access.

Usage

<?php auth_redirect(); ?>

Parameters

This function accepts no parameters.

Return Values

Function redirects or exits, does not return

Examples

Require a user to log in in order to view a page:

if ( !is_user_logged_in() ) {
   auth_redirect();
}

Notes

As a pluggable function, you can redefine it and your version will be used instead.

Change Log

Since: 1.5

Source File

auth_redirect() is located in wp-includes/pluggable.php

Related

is_user_logged_in(), wp_redirect()

See also index of Function Reference and index of Template Tags.