Skip to content

Instantly share code, notes, and snippets.

@marushu marushu/more_extended.php
Last active Mar 2, 2017

Embed
What would you like to do?
<?php
// カスタムフィールドの値 : for_all, need_loginで分岐
// set single.php
while ( have_posts() ) : the_post();
$raw_content = get_extended( $post->post_content );
$everyone_can_read_content = ! empty( $raw_content )
? $raw_content['main']
: get_the_content();
$logged_in_can_read_content = $raw_content['extended'];
if (
$require_login === 'for_all'
|| is_user_logged_in()
|| ( $require_login === 'need_login' && empty( trim( $logged_in_can_read_content ) ) )
) {
the_content();
} elseif (
$require_login === 'need_login'
&& ! is_user_logged_in()
&& ! empty( trim( $logged_in_can_read_content ) )
) {
echo apply_filters( 'the_content', $everyone_can_read_content );
echo get_login_register_box();
}
endwhile; // End of the loop.
// Box.
// set functions.php
function get_login_register_box() {
$redirect = wp_get_referer() ? wp_get_referer() : home_url();
$register_html = wp_register( '', '', false );
$register_html = str_replace( '登録', '会員登録する', $register_html );
$login_register_html = '';
$login_register_html .= '<div class="login-register">';
$login_register_html .= '<p class="login-register__title">会員登録が必要です</p>';
$login_register_html .= '<p>これより先は会員限定コンテンツです。ログインまたは、会員登録が必要です。</p>';
$login_register_html .= '<ul class="login-register__button-list">';
$login_register_html .= '<li class="login-register__button-list_login">';
$login_register_html .= '<a class="loginout_link" href="' . wp_login_url( esc_url( get_permalink( get_the_ID() ) ) ) . '">ログインする</a>';
$login_register_html .= '</li>';
$login_register_html .= '<li class="login-register__button-list_register login-register__button-list_button">';
$login_register_html .= $register_html;
$login_register_html .= '</li>';
$login_register_html .= '</ul>';
$login_register_html .= '</div><!-- /.login-register -->';
return $login_register_html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.