Sunday, December 11

Wordpress User Only page

4 years ago I implemented the same functionality but lost the source code. So I re-invented the wheel again. Maybe not the same way.

What I modified is adding 4 lines in the function get_the_content of wp-includes\post-template.php:
$content = $pages[$page-1];
if ( preg_match('/< !--more(.*?)?-->/', $content, $matches) ) {
$content = explode($matches[0], $content, 2);
if ( !empty($matches[1]) && !empty($more_link_text) )
$more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
if ( !is_user_logged_in() ){
$content[1] = "Please login to view the content\n\n";
$content[1] .= wp_login_form(array('echo' => false));
}
$hasTeaser = true;
} else {
$content = array($content);
}

Looks easy.