簡體   English   中英

在WordPress中將白名單首頁

[英]Whitelist home page in wordpress

我正在使用強制登錄wordpress插件來限制用戶在查看某些頁面之前登錄,但是我想在不登錄的情況下查看主頁我試圖在白名單中添加主頁,但它不起作用,我正在使用我的自定義主題。我應該為此目的使用/應該做什么。

function my_forcelogin_whitelist( $whitelist ) {
            //$whitelist[] = 'http://localhost/wordpress/index.php/home/';
            //$whitelist[] = site_url( '/index.php/home/' );
              $whitelist[] = 'http://localhost/wordpress/index.php/';
              $whitelist[] = site_url( '/index.php/' );

        return $whitelist;
    }
    add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);

將此代碼插入主題的functions.php中。 它將檢查您是否已登錄。 接下來,如果當前頁面不是主頁或首頁,它將把用戶重定向到登錄頁面。

而且您不需要其他插件來重定向,因此請在測試此代碼之前禁用任何強制登錄插件。

function logged_in_only() {
    if ( ! is_user_logged_in() ) {
        if( !is_home() || !is_front_page() )
            auth_redirect();
    }
}
add_action( 'template_redirect', 'logged_in_only' );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM