wordpress投稿、固定ページ毎の閲覧パスワード制限

function.phpに以下を記述します。

// 「保護中」を消す----------------------------------------------------//
 
add_filter('protected_title_format', 'remove_protected');
function remove_protected($title) {
       return '%s';
}
	   
 // 「保護中」記事のパスワード入力画面のテキストを変更する----------------------------------------------------//
function my_password_form() {
  return
    '<p>ここを任意の文章に変更できます。<p>
    <form class="post_password" action="' . home_url() . '/wp-login.php?action=postpass" method="post">
    <input name="post_password" type="password" size="24" />
    <input type="submit" name="Submit" value="' . esc_attr__("送信") . '" />
    </form>';
}
add_filter('the_password_form', 'my_password_form');

抜粋を表示させる

// 抜粋を表示させる ----------------------------------------------------//
 
function enable_excerpt_password_protected_post( $output ) {
	global $post;
	if ( post_password_required( $post ) && has_excerpt() ) {
		$output = $post->post_excerpt;
	}
	return $output;
}
add_filter( 'the_excerpt', 'enable_excerpt_password_protected_post', 0 );

 抜粋を表示したい箇所に抜粋のテンプレートタグを記述

<?php the_excerpt(); ?>

パスワードの保存期間を1時間に変更(デフォルトは10日間)

function custom_postpass_time() {
    require_once ABSPATH . 'wp-includes/class-phpass.php';
    $hasher = new PasswordHash( 8, true );
    setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), time() + HOUR_IN_SECONDS, COOKIEPATH );
    wp_safe_redirect( wp_get_referer() );
    exit();
}
add_action( 'login_form_postpass', 'custom_postpass_time' );

 

参考サイト  http://infinityforest.net/home/archives/2904
見ていただいてありがとうございます。↓ポチしてくださいませ。
  • 見た (0)
  • もう少し詳しく書いて! (0)
  • 見たけど役立たず (0)