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').'

'; if ( !empty($current_user->ID) ) { $is_member = get_usermeta($current_user->ID,'comicpress-is-member'); + if ($is_member == 'yes' || current_user_can('publish_posts')) { + $content = str_replace('

', '', $content); + $content = str_replace('

', '', $content); + $returninfo = "
\r\n

$content

\r\n
\r\n"; + } } - if ($is_member != 'yes' || empty($is_member)) { - $query->set('cat',$excludeset); - } + return $returninfo; } - 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').'

'; - if ( !empty($current_user->ID) ) { - $is_member = get_usermeta($current_user->ID,'comicpress-is-member'); - if ($is_member == 'yes' || current_user_can('publish_posts')) { - $content = str_replace('

', '', $content); - $content = str_replace('

', '', $content); - $returninfo = "
\r\n

$content

\r\n
\r\n"; - } - } - return $returninfo; -} - -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'; - ?> -

- - - + + 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'; + ?> +

+
+ + - -
- -    - - - + +    + + +
- + + ID))) > 0); -} - -function comicpress_is_member() { - global $user_ID; - if (!empty($user_ID)) { - $is_member = get_usermeta($user_ID,'comicpress-is-member'); - if ($is_member == 'yes' || current_user_can('publish_posts')) { - return true; + + function comicpress_profile_members_only_save() { + $id = $_POST['user_id']; + $comicpress_is_member = $_POST['comicpress-is-member']; + + if (!empty($comicpress_is_member)) { + update_usermeta($id, 'comicpress-is-member', $comicpress_is_member); } } - return false; + + /** + * Return true if the current post is in the members category. + */ + function in_members_category() { + global $post, $category_tree, $comicpress_options; + $members_post_category = $comicpress_options['members_post_category']; + $members_post_category_array = array(); + $members_post_category_array = explode($members_post_category); + + return (count(array_intersect($members_post_category, wp_get_post_categories($post->ID))) > 0); + } + + function comicpress_is_member() { + global $user_ID; + if (!empty($user_ID)) { + $is_member = get_usermeta($user_ID,'comicpress-is-member'); + if ($is_member == 'yes' || current_user_can('publish_posts')) { + return true; + } + } + 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 '

'.__('There is Members Only content here.
To view this content you need to be a member of this site.','comicpress').'

'; + + } + + add_filter('comment_text', 'comicpress_members_comment_filter', $content); + } ?> \ No newline at end of file diff --git a/members-blog.php b/members-blog.php index 62f6ab8..e3d9965 100644 --- a/members-blog.php +++ b/members-blog.php @@ -2,27 +2,35 @@ /* Template Name: Members Only Blog */ -?> - - +get_header(); +global $comicpress_options; +remove_filter('pre_get_posts','comicpress_members_filter'); +include(get_template_directory() . '/layout-head.php'); - - - - +get_sidebar('underblog'); - - +include(get_template_directory() . '/layout-foot.php'); + +get_footer() ?> diff --git a/options/addonoptions.php b/options/addonoptions.php index bd6f286..5b1ef61 100644 --- a/options/addonoptions.php +++ b/options/addonoptions.php @@ -39,6 +39,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+ /> + + +
+ /> + + +
+ + ]*)>#', ' + +
+

Dashboard -> Users -> Authors & Users and flag the user you want to be a member with the option at the bottom.','comicpress'); ?>

+

+

+

+

+
diff --git a/options/generaloptions.php b/options/generaloptions.php index 76a123f..df21475 100644 --- a/options/generaloptions.php +++ b/options/generaloptions.php @@ -188,36 +188,6 @@
- - - - - - - - - - - - - -
- - ]*)>#', ' - -
-

Dashboard -> Users -> Authors & Users and flag the user you want to be a member with the option at the bottom.','comicpress'); ?>

-

-

-

-

-
-