[英]Auto redirect a user who isn't logged into the Wordpress site
沒有人知道在用戶未登錄時重定向到登錄頁面時如何設置functions.php嗎? 這是我的代碼,會造成一些障礙,例如文章頁面上沒有預覽等。
add_filter( 'pre_get_posts', 'swpm_auto_redirect_non_members' );
function swpm_auto_redirect_non_members() {
if( !is_admin() && !SwpmMemberUtils::is_member_logged_in() && !is_page( array( 'membership-login', 'membership-join' )) ) {
wp_redirect( 'http://example.com/membership-login/' );
exit;
}
}
它僅在網站處於服務而非管理員模式時才有效。 提前致謝。
嘗試使$ _SESSION [“ member],並使其
if(!isset($_SESSION["member"]))
{
echo "<script>location='/login.php'</script>";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.