把這個放在functions.php
. q7 O* H& ~! C- U% c. F[mw_shl_code=php,false] }, n2 }& C/ y# A) m, m2 w
function login_need() {, a, w0 l: U" u( i' D$ d
//global $user_ID; : i) l! V4 [+ Z* Y
$user_ID = get_current_user_id();7 x% ?/ g3 h% \( ^
if ($user_ID == '' && $_SERVER['PHP_SELF'] != "/wp-login.php" && $_SERVER['PHP_SELF'] != "/wp-signup.php")
- G& x/ i: K7 \9 {" _ {
- I. @3 v% e9 }: c+ e header('Location: /wp-login.php'); ' |' ]' U |' [0 x
exit; ; D" Y( l' ?4 V- E* _
}
& p! x/ J7 J1 Q* F}
9 S, l; g) c" i' Nadd_action( 'init', 'login_need' );[/mw_shl_code]
- c* D' l- w) y( _* Y, W0 ~
8 x% m/ L& ^) }: T/ ` |