I have a custom post type called “secure_blog”. Users have a custom field on their user’s page that’s called “user_intern_yes”. So if an admin ticks this option for a user (no matter which user role) this user can see the custom post types pages of “secure_blog” which is an “internal” area of the website.
For me it was the easiest way to include an “internal” area without dealing with custom user roles etc. .
Now I see there is one problem: The “secure_blog” custom post type has the ability for leaving comments. All these comments are visible in the comments section of the wordpress backend. Now this is a problem. How can I make this comments in the backend only visible to users who have the custom field “user_intern_yes” active on their user’s page?
In frontend I do it with:
// current user
$user = new WP_User(get_current_user_id());
// the custom field on the user's pages
$showintern = get_field('user_intern_yes', 'user_'.$user->ID);
// check if user has set $showintern field to "yes"
if($showintern == 1) :
// show stuff
endif;
Any idea how to filter the wordpress backend comments section? So that only this users see the comments for the “secure_blog” custom post type?
I have this function to hide the post type and the comments:
function wpse28782_remove_menu_items() {
$user = new WP_User(get_current_user_id());
$showintern = get_field('user_intern_yes', 'user_'.$user->ID);
if($showintern == 0) :
remove_menu_page( 'edit.php?post_type=intern' );
remove_menu_page( 'edit-comments.php' );
endif;
}
add_action( 'admin_menu', 'wpse28782_remove_menu_items' );
But this hides ALL comments in backend. I only want to hide the comments for the custom post type “secure_blog”.