2009-08-21 19:29:45 +00:00
< ? php
/**
* Members Only
* by Philip M . Hofer ( Frumph )
* http :// webcomicplanet . com /
*
* Displays content that only registered users that are marked members can see .
*
* example : [ members ] Only members can read this . [ / members ]
*
*
* Still need to do , make it a way to flag someone a site_member TRUE
*
*/
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' );
2009-09-19 10:11:37 +00:00
add_filter ( 'pre_get_posts' , 'comicpress_members_filter' );
function comicpress_members_filter ( $query ) {
global $members_post_category , $current_user ;
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 ;
}
2009-08-21 19:29:45 +00:00
function shortcode_for_comicpress_members_only ( $atts , $content = null ) {
global $post , $userdata , $profileuser , $current_user , $errormsg ;
2009-10-05 06:08:01 +00:00
$returninfo = '<div class="non-member">' . __ ( 'There is Members Only content here. To view this content you need to be a member of this site.' , 'comicpress' ) . '</div>' ;
2009-09-19 10:11:37 +00:00
if ( ! empty ( $current_user -> ID ) ) {
2009-08-21 19:29:45 +00:00
$is_member = get_usermeta ( $current_user -> ID , 'comicpress-is-member' );
2009-09-19 10:11:37 +00:00
if ( ( $is_member == 'yes' ) ) {
$returninfo = '<div class="members-only">' . $content . '</div>' ;
2009-08-21 19:29:45 +00:00
}
}
2009-09-19 10:11:37 +00:00
return $returninfo ;
2009-08-21 19:29:45 +00:00
}
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' ;
?>
2009-10-05 06:08:01 +00:00
< h3 >< ? php _e ( 'Member of' , 'comicpress' ); ?> <?php bloginfo('name'); ?></h3>
2009-08-21 19:29:45 +00:00
< table class = " form-table " >
< tr >
2009-10-05 06:08:01 +00:00
< th >< label for = " Memberflag " >< ? php _e ( 'Member?' , 'comicpress' ); ?> </label></th>
2009-08-21 19:29:45 +00:00
< td >
< ? php
if ( current_user_can ( 'manage_options' )) { ?>
2009-10-05 06:08:01 +00:00
< label >< input name = " comicpress-is-member " id = " comicpress-is-member-yes " type = " radio " value = " yes " < ? php if ( get_usermeta ( $profileuser -> ID , 'comicpress-is-member' ) == " yes " ) { echo " checked " ; } ?> /><?php _e('Yes','comicpress'); ?></label>
2009-08-21 19:29:45 +00:00
& nbsp ; & nbsp ;
2009-10-05 06:08:01 +00:00
< label >< input name = " comicpress-is-member " id = " comicpress-is-member-no " type = " radio " value = " no " < ? php if ( get_usermeta ( $profileuser -> ID , 'comicpress-is-member' ) != " yes " ) { echo " checked " ; } ?> /><?php _e('No','comicpress'); ?></label>
2009-08-21 19:29:45 +00:00
< ? php } else {
if ( $comicpress_is_member == 'yes' ) {
echo 'Yes' ;
} else {
echo 'No' ;
}
}
?>
</ td >
</ tr >
</ table >
< ? php }
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 );
}
}
2009-09-19 10:11:37 +00:00
/**
* Return true if the current post is in the members category .
*/
function in_members_category () {
global $post , $category_tree , $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 $current_user ;
if ( ! empty ( $current_user )) {
$is_member = get_usermeta ( $current_user -> ID , 'comicpress-is-member' );
if ( $is_member == 'yes' || current_user_can ( 'publish_post' )) {
return true ;
}
}
return false ;
}
2009-08-21 17:45:23 +00:00
?>