php WordPress中受限制的内容 - WordCamp ATL 2015

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WordPress中受限制的内容 - WordCamp ATL 2015相关的知识,希望对你有一定的参考价值。

<?php
	
function restricted_content_filter( $content ) {
	if ( !current_user_can( 'administrator' ) && is_content_restricted() ) {
		$content = 'Restricted!';
	}
	return $content;	
}
add_filter( 'the_content', 'restricted_content_filter' );
add_filter( 'the_excerpt', 'restricted_content_filter' );

function is_content_restricted() {
	global $post;
	$restricted_posts = array( 1, 2, 3, 4, 5 ); //You'll want a UI to set this in the options table
	if ( in_array( $post->ID, $restricted_posts ) ) {
		$user = get_current_user();
		$mode = 'live'; //You'll want to set this to live or test... and store that setting in the options table to set and get it dynamically.
		$status = get_user_meta( '_member_status_' . $mode, true );
		if ( 'active' === $status ) {
			return false;
		} else {
			return true;
		}
	}
}

以上是关于php WordPress中受限制的内容 - WordCamp ATL 2015的主要内容,如果未能解决你的问题,请参考以下文章