wordpressで会員限定ページを作成しています。urlを打った時、ログイン画面に飛ぶようになっているのですが一部それに除外したページを作成したいのですがうまくいきません・・・
一部例外ページ: sample.php
Template name: sample
functions.php内に以下を書き込みました。
php
1function require_login() { 2 if (! is_page_template( 'sample.php' )) { 3 if ( ! is_user_logged_in() && 4 ! preg_match( '/^(wp-login.php|async-upload.php)/', basename( $_SERVER['REQUEST_URI'] ) ) && 5 ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) && 6 ! ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { 7 auth_redirect(); 8 } 9 } 10} 11add_action( 'init', 'require_login' );
ご助力のほうよろしくお願いします…
変更点を教えていただいてこのように書きました。
php
1function require_login() { 2 if ( ! is_user_logged_in() && 3 ! array_search( basename( $_SERVER['REQUEST_URI'] ), ['wp-login.php', 'async-upload.php'] ) && 4 ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) && 5 ! ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { 6 auth_redirect(); 7 } 8} 9add_action( 'init', 'require_login' );
この場合、リダイレクトを繰り返し以下のようなエラーが出ました。
Submitted URI too large! The length of the requested URL exceeds the capacity limit for this server. The request cannot be processed. If you think this is a server error, please contact the webmaster. Error 414
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/28 04:56
2018/06/28 04:57
退会済みユーザー
2018/06/28 05:07
2018/06/28 05:15
退会済みユーザー
2018/06/28 06:35 編集