Members Only moved to addons, 2 new options made for enable it at all and enable it for comments.

Cleanup and fixes for the members only code

todo: fix the archive/search to ignore the members category if user !comicpress_is_member()

Signed-off-by: Philip M. Hofer (Frumph) <frumph_dragon@yahoo.com>
This commit is contained in:
Philip M. Hofer (Frumph) 2010-01-03 22:39:45 -08:00
parent babb991ba3
commit ee80a7c428
5 changed files with 188 additions and 146 deletions

View File

@ -65,8 +65,7 @@ function comicpress_admin() {
} }
foreach (array( foreach (array(
'graphicnav_directory', 'graphicnav_directory'
'members_post_category'
) as $key) { ) as $key) {
$comicpress_options[$key] = wp_filter_nohtml_kses($_REQUEST[$key]); $comicpress_options[$key] = wp_filter_nohtml_kses($_REQUEST[$key]);
} }
@ -152,6 +151,7 @@ function comicpress_admin() {
if ($_REQUEST['action'] == 'comicpress_save_addons') { if ($_REQUEST['action'] == 'comicpress_save_addons') {
foreach (array( foreach (array(
'enable_custom_image_header', 'enable_custom_image_header',
'enable_members_only_post_comments',
'buy_print_add_shipping' 'buy_print_add_shipping'
) as $key) { ) as $key) {
$comicpress_options[$key] = (bool)( $_REQUEST[$key] == 1 ? true : false ); $comicpress_options[$key] = (bool)( $_REQUEST[$key] == 1 ? true : false );
@ -159,6 +159,8 @@ function comicpress_admin() {
foreach (array( foreach (array(
'custom_image_header_width', 'custom_image_header_width',
'custom_image_header_height', 'custom_image_header_height',
'enable_members_only',
'members_post_category',
'buy_print_email', 'buy_print_email',
'buy_print_url', 'buy_print_url',
'buy_print_us_amount', 'buy_print_us_amount',

View File

@ -9,10 +9,10 @@
* example: [members]Only members can read this.[/members] * example: [members]Only members can read this.[/members]
* *
* *
* Still need to do, make it a way to flag someone a site_member TRUE
*
*/ */
global $comicpress_options;
if ($comicpress_options['enable_members_only']) {
add_shortcode( 'members', 'shortcode_for_comicpress_members_only' ); add_shortcode( 'members', 'shortcode_for_comicpress_members_only' );
add_shortcode( 'member', 'shortcode_for_comicpress_members_only' ); add_shortcode( 'member', 'shortcode_for_comicpress_members_only' );
@ -21,7 +21,8 @@ add_action('edit_user_profile', 'comicpress_profile_members_only');
add_action('profile_update', 'comicpress_profile_members_only_save'); add_action('profile_update', 'comicpress_profile_members_only_save');
// add_filter('pre_get_posts','comicpress_members_filter'); if ($comicpress_options['members_post_category'])
add_filter('pre_get_posts','comicpress_members_filter');
function comicpress_members_filter($query) { function comicpress_members_filter($query) {
global $comicpress_options, $current_user; global $comicpress_options, $current_user;
@ -122,4 +123,17 @@ function comicpress_is_member() {
return false; return false;
} }
function comicpress_members_comment_filter($content) {
global $comicpress_options;
if (comicpress_is_member() || !$comicpress_options['enable_members_only_post_comments']) {
return $content;
}
return '<div class="non-member"><p>'.__('There is Members Only content here.<br />To view this content you need to be a member of this site.','comicpress').'</p></div>';
}
add_filter('comment_text', 'comicpress_members_comment_filter', $content);
}
?> ?>

View File

@ -2,27 +2,35 @@
/* /*
Template Name: Members Only Blog Template Name: Members Only Blog
*/ */
?> get_header();
<?php get_header(); global $members_post_category; ?> global $comicpress_options;
<?php remove_filter('pre_get_posts','comicpress_members_filter'); ?> remove_filter('pre_get_posts','comicpress_members_filter');
include(get_template_directory() . '/layout-head.php');
<?php include(get_template_directory() . '/layout-head.php'); ?> if ($comicpress_options['enable_members_only']) {
if ($comicpress_options['members_post_category'] && comicpress_is_member()) {
<?php if (have_posts()): $blog_query = 'showposts='.$comicpress_options['blog_postcount'].'&cat='.$comicpress_options['members_post_category'].'&paged='.$paged;
$blog_query = '&cat='.$members_post_category.'&paged='.$paged;
$posts = query_posts($blog_query); $posts = query_posts($blog_query);
if (have_posts()) {
while (have_posts()) : the_post(); while (have_posts()) : the_post();
comicpress_display_post(); comicpress_display_post();
endwhile; endwhile;
}
comicpress_pagination(); comicpress_pagination();
} else {
_e("This page is restricted to members only.",'comicpress');
}
} else {
_e('Member\'s Only content is not enabled on this installation.');
}
endif; ?> get_sidebar('underblog');
<?php get_sidebar('underblog'); ?>
<?php include(get_template_directory() . '/layout-foot.php'); ?> include(get_template_directory() . '/layout-foot.php');
<?php get_footer() ?>
get_footer() ?>

View File

@ -40,6 +40,54 @@
</tr> </tr>
</table> </table>
<table class="widefat">
<thead>
<tr>
<th colspan="3"><?php _e('Members Only Content','comicpress'); ?></th>
</tr>
</thead>
<tr class="alternate">
<th scope="row"><label for="enable_members_only"><?php _e('Enable Members Only options?','comicpress'); ?></label></th>
<td>
<input id="enable_members_only" name="enable_members_only" type="checkbox" value="1" <?php checked(true, $comicpress_options['enable_members_only']); ?> />
</td>
<td>
<?php _e('When enabled this will allow all of the members only code to be active and working.','comicpress'); ?>
</td>
</tr>
<tr>
<th scope="row"><label for="enable_members_only_post_comments"><?php _e('Enable Members only comment content?','comicpress'); ?></label></th>
<td>
<input id="enable_members_only_post_comments" name="enable_members_only_post_comments" type="checkbox" value="1" <?php checked(true, $comicpress_options['enable_members_only_post_comments']); ?> />
</td>
<td>
<?php _e('When enabled this will make all the content of each of the comments available to be seen only by users registered and set as members.','comicpress'); ?>
</td>
</tr>
<tr class="alternate">
<th scope="row" colspan="2">
<label for="members_post_category"><?php _e('Members category','comicpress'); ?></label>
<?php
$select = wp_dropdown_categories('show_option_none=Select category&show_count=0&orderby=name&echo=0&selected='.$comicpress_options['members_post_category']);
$select = preg_replace('#<select([^>]*)>#', '<select name="members_post_category" id="members_post_category">', $select);
echo $select;
?>
</th>
<td>
<?php _e('The category that is designated to show members only content.','comicpress'); ?>
</td>
</tr>
<tr>
<td colspan="3">
<p><?php _e('USAGE: Edit the user with <em>Dashboard -> Users -> Authors &amp; Users</em> and flag the user you want to be a member with the option at the bottom.','comicpress'); ?></p>
<p><?php _e('Inside posts, add [members] content you only want members to see [/members]','comicpress'); ?></p>
<p><?php _e('When setting a \'members\' category, you *cannot* use an existing comic category, uncategorized, or blog category!','comicpress'); ?></p>
<p><?php _e('You MUST create a whole new category and called it "members", then you select that category here and create a page called "Members" or something equivelant and associate the Member\'s Only template to it.','comicpress'); ?></p>
<p><?php _e('This will make it so that that category is only seen as blogposts inside that area and not anywhere else on the site unless the user has the members flag.','comicpress'); ?></p>
</td>
</tr>
</table>
<table class="widefat"> <table class="widefat">
<thead> <thead>
<tr> <tr>

View File

@ -188,36 +188,6 @@
</tr> </tr>
</table> </table>
<table class="widefat">
<thead>
<tr>
<th colspan="2"><?php _e('Members Only Content','comicpress'); ?></th>
</tr>
</thead>
<tr class="alternate">
<th scope="row">
<label for="members_post_category"><?php _e('Members category','comicpress'); ?></label>
<?php
$select = wp_dropdown_categories('show_option_none=Select category&show_count=0&orderby=name&echo=0&selected='.$comicpress_options['members_post_category']);
$select = preg_replace('#<select([^>]*)>#', '<select name="members_post_category" id="members_post_category">', $select);
echo $select;
?>
</th>
<td>
<?php _e('The category that is designated to show members only content.','comicpress'); ?>
</td>
</tr>
<tr>
<td colspan="2">
<p><?php _e('USAGE: Edit the user with <em>Dashboard -> Users -> Authors &amp; Users</em> and flag the user you want to be a member with the option at the bottom.','comicpress'); ?></p>
<p><?php _e('Inside posts, add [members] content you only want members to see [/members]','comicpress'); ?></p>
<p><?php _e('When setting a \'members\' category, you *cannot* use an existing comic category, uncategorized, or blog category!','comicpress'); ?></p>
<p><?php _e('You MUST create a whole new category and called it "members", then you select that category here and create a page called "Members" or something equivelant and associate the Member\'s Only template to it.','comicpress'); ?></p>
<p><?php _e('This will make it so that that category is only seen as blogposts inside that area and not anywhere else on the site unless the user has the members flag.','comicpress'); ?></p>
</td>
</tr>
</table>
<table class="widefat"> <table class="widefat">
<thead> <thead>
<tr> <tr>