把這個放在functions.php! o, f5 L8 C {, U9 @- l0 K+ U
[mw_shl_code=php,false]. M C6 a! O: X
function login_need() {
' O. t! t* W4 n1 F //global $user_ID; 8 `$ y J: z! ]/ x0 l" l/ t$ H( c5 ^
$user_ID = get_current_user_id();! M8 \% s0 }, F( g5 ]# j7 M5 d9 [
if ($user_ID == '' && $_SERVER['PHP_SELF'] != "/wp-login.php" && $_SERVER['PHP_SELF'] != "/wp-signup.php")
1 S* `1 V, D- l. q8 U. a {
, [0 b! ]) G( c( R* K% e. ?$ g header('Location: /wp-login.php');
* e A3 B; B1 _4 J, J; [: D exit; # @% u- w2 x9 [, t
}: u9 R3 C# u6 X4 l# Z7 M/ d" {4 g9 ?, f
}8 `$ J/ x; w/ `" o+ \% h
add_action( 'init', 'login_need' );[/mw_shl_code]
n2 z3 g" x( M/ O. {' K$ i6 {; N) `+ n7 u
|