真偽フィールドを使ってtrueの場合に表示させたテンプレートファイルにbasic認証で制限をかけたいのですが、うまく認証がかけられずにおります。
該当のファイルは下記のfunctions.phpで作成したproductionというカスタム投稿タイプの中にあります。
function create_post_type(){ $post_supports = [ 'title', 'editor', 'thumbnail', 'revisions' ]; register_post_type('production', array( 'label' => '制作物', 'public' => true, 'has_archive' => true, 'hierarchical' => true, 'menu_position' => 5, 'supports' => $post_supports ) ); } add_action('init', 'create_post_type');
このproduction(single-production.php)の中で、さらに真偽フィールドを用いたとき、trueだったものをsingle-copy.phpとして読み込むようにしています。
<?php $YesNo = get_field('YorN'); if($YesNo == 1): ?> <?php get_template_part('single', 'copy'); ?> <?php else: ?> <?php get_template_part('single', 'original'); ?> <?php endif; ?>
このsingle-copy.phpに認証をかけるようにさせたいです。
.htaccessのfilesの指定では色々な正規表現で試してみましたが、どれも認証はかかりませんでした。
c:からフルパスで指定しても(ローカル環境です)500 Internal Server Error
になってしまいます。
因みに<files ~ "production">とスラッグを指定すると、カスタム投稿ページそのものは認証をかけることができます。
.htaccessの現在の記述はこのようになっています。
<Files ~ "^.(htaccess|htpasswd)$"> deny from all </Files> <files ~ "^production*\single-copy\.php$|^$"> AuthName "Login Password Required" AuthType Basic AuthUserFile c:\xampp\***\****** require valid-user </files> # BEGIN WordPress RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteRule ^.*$ - [CO=LOGIN:1:localhost.localdomain:1:/] #追記 RewriteBase / RewriteRule ^index\.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^wp-admin$ wp-admin/ [R=301,L] RewriteCond %{HTTP:Authorization} ^(.*) #追記 RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^(wp-(content|admin|includes).*) $1 [L] RewriteRule ^(.*\.php)$ $1 [L] RewriteRule . index.php [L] # END WordPress
それぞれのパスはこのようになっています。
C:\xampp\htdocs\wordpress.htaccess
C:\xampp\htdocs\wordpress\wp-content\themes\portfolio\single-production.php
C:\xampp\htdocs\wordpress\wp-content\themes\portfolio\single-copy.php
どうかお力をいただければ幸いです。
よろしくお願いします。