把這個放在functions.php
* m% w% x. K" Y/ O: \5 v# B# B[mw_shl_code=php,false]5 ]6 R& b& g5 N$ T* r$ o
function login_need() { t" w+ l7 g6 T) D- T: `9 l# T
//global $user_ID; ( z1 m( I; a6 w* O7 u5 X
$user_ID = get_current_user_id();
# Z7 k, U( R5 V1 P$ u if ($user_ID == '' && $_SERVER['PHP_SELF'] != "/wp-login.php" && $_SERVER['PHP_SELF'] != "/wp-signup.php")
1 F: U8 s5 u# A) _# C0 v/ E {
% u% G5 P/ @2 F. f% u header('Location: /wp-login.php');
% }( q& K9 ]$ P1 `# ^' S/ S) i% f$ b exit; 2 q- k3 o0 q) t3 F
}0 Y9 s* i! @" B! {4 l) Z
}
( Z5 f8 y+ X9 [+ c( |add_action( 'init', 'login_need' );[/mw_shl_code]
, y" Y" S: R- P% h5 d- b4 M% V
: O- @, ~9 Y! f7 H N+ q# E |