diff --git a/comicpress-options.php b/comicpress-options.php index 3b758d4..22055cf 100644 --- a/comicpress-options.php +++ b/comicpress-options.php @@ -65,8 +65,7 @@ function comicpress_admin() { } foreach (array( - 'graphicnav_directory', - 'members_post_category' + 'graphicnav_directory' ) as $key) { $comicpress_options[$key] = wp_filter_nohtml_kses($_REQUEST[$key]); } @@ -152,6 +151,7 @@ function comicpress_admin() { if ($_REQUEST['action'] == 'comicpress_save_addons') { foreach (array( 'enable_custom_image_header', + 'enable_members_only_post_comments', 'buy_print_add_shipping' ) as $key) { $comicpress_options[$key] = (bool)( $_REQUEST[$key] == 1 ? true : false ); @@ -159,6 +159,8 @@ function comicpress_admin() { foreach (array( 'custom_image_header_width', 'custom_image_header_height', + 'enable_members_only', + 'members_post_category', 'buy_print_email', 'buy_print_url', 'buy_print_us_amount', diff --git a/functions/membersonly.php b/functions/membersonly.php index 183998d..aa8a222 100644 --- a/functions/membersonly.php +++ b/functions/membersonly.php @@ -9,117 +9,131 @@ * 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; - -add_shortcode( 'members', 'shortcode_for_comicpress_members_only' ); -add_shortcode( 'member', 'shortcode_for_comicpress_members_only' ); -add_action('show_user_profile', 'comicpress_profile_members_only'); -add_action('edit_user_profile', 'comicpress_profile_members_only'); -add_action('profile_update', 'comicpress_profile_members_only_save'); - - -// add_filter('pre_get_posts','comicpress_members_filter'); - -function comicpress_members_filter($query) { - global $comicpress_options, $current_user; - $members_post_category = $comicpress_options['members_post_category']; - if ($members_post_category != 'none' && !empty($members_post_category) && !$query->is_search && !$query->is_page && !$query->is_archive) { - $oldset = $query->get('cat'); - $is_member = ''; - - if (!empty($oldset)) { - $excludeset = $oldset.',-'.$members_post_category; - } else { - $excludeset = '-'.$members_post_category; +if ($comicpress_options['enable_members_only']) { + + add_shortcode( 'members', 'shortcode_for_comicpress_members_only' ); + add_shortcode( 'member', 'shortcode_for_comicpress_members_only' ); + add_action('show_user_profile', 'comicpress_profile_members_only'); + add_action('edit_user_profile', 'comicpress_profile_members_only'); + add_action('profile_update', 'comicpress_profile_members_only_save'); + + + if ($comicpress_options['members_post_category']) + add_filter('pre_get_posts','comicpress_members_filter'); + + function comicpress_members_filter($query) { + global $comicpress_options, $current_user; + $members_post_category = $comicpress_options['members_post_category']; + if ($members_post_category != 'none' && !empty($members_post_category) && !$query->is_search && !$query->is_page && !$query->is_archive) { + $oldset = $query->get('cat'); + $is_member = ''; + + if (!empty($oldset)) { + $excludeset = $oldset.',-'.$members_post_category; + } else { + $excludeset = '-'.$members_post_category; + } + + if ( !empty($current_user->ID) ) { + $is_member = get_usermeta($current_user->ID,'comicpress-is-member'); + } + if ($is_member != 'yes' || empty($is_member)) { + $query->set('cat',$excludeset); + } } - + return $query; + } + + function shortcode_for_comicpress_members_only( $atts, $content = null ) { + global $post, $userdata, $profileuser, $current_user, $errormsg; + $returninfo = '
'.__('There is Members Only content here.
To view this content you need to be a member of this site.','comicpress').'
', '', $content); + $content = str_replace('
', '', $content); + $returninfo = "$content
\r\n'.__('There is Members Only content here.
To view this content you need to be a member of this site.','comicpress').'
', '', $content); - $content = str_replace('
', '', $content); - $returninfo = "$content
\r\n+ + function comicpress_profile_members_only() { + global $profileuser, $current_user, $errormsg; + $comicpress_is_member = get_usermeta($profileuser->ID,'comicpress-is-member'); + if (empty($comicpress_is_member)) $comicpress_is_member = 'no'; + ?> + |
---|
- - - - - + + + + + | -
'.__('There is Members Only content here.
To view this content you need to be a member of this site.','comicpress').'
+ | ||
---|---|---|
+ | + /> + | ++ + | +
+ | + /> + | ++ + | +
+ + ]*)>#', ' | ++ + | +|
+ Dashboard -> Users -> Authors & Users and flag the user you want to be a member with the option at the bottom.','comicpress'); ?> + + + + + |
+
- | |
---|---|
- - ]*)>#', ' | -- - | -
- Dashboard -> Users -> Authors & Users and flag the user you want to be a member with the option at the bottom.','comicpress'); ?> - - - - - |
-