Hot answers tagged

4 votes

Wordpress roles - Protect administrator role

It's a bit different in WP than in Drupal. First, the admin role is specifically designed to be the role that can do everything. Rather than try to restrict the admin role, it's best practice to ...
  • 8,998
4 votes

Custom Roll/Custom Post Type - Can't Select Categories

I had the same problem, a custom role couldn't assign categories to my CPT. When doing register_taxonomy(), I added these capabilities: 'capabilities' => array ( '...
3 votes
Accepted

Private member page

You can do it without plugins, you just have to allow subscribers to see Private posts and pages, depending on what you want, so you have to put this code in your functions.php $subRole = get_role( '...
  • 2,134
2 votes

Wordpress roles - Protect administrator role

This is a perfect use for the map_meta_cap filter. function my_map_meta_cap( $caps, $cap, $user_id, $args ) { if( 'delete_user' !== $cap ) { return $caps; } if( isset( $args[0] ) && ...
2 votes
Accepted

BuddyPress | Check if user is in current group

function is_user_a_member_of_this_group($user_id, $group_id) //return: bool return groups_is_user_member( $user_id, $group_id ); }
  • 4,933
2 votes
Accepted

Showing content to specific BuddyPress Member Types

Your answer is on the codex page link in your question. // Get the member type of user 5412. $member_type = bp_get_member_type( 5412 ); So you could do something like this: $member_type = ...
  • 4,933
1 vote

one time visit to the page

Although this is not a WP question, it could be done with some PHP/MySQL code. Just the psuedocode: generate a GUID value on each main page visit check if the GUID is already in the GUID database if ...
1 vote

Hiding posts from non logged in users

Use this code on your child theme’s functions.php file.. //Hide for non-logged-in users (public visitors) function bp_logged_out_page_template_redirect() { if( ! is_user_logged_in() && ...
  • 11
1 vote

Hiding posts from non logged in users

Fiddling with user roles would probably be the most robust solution, however a quick and dirty approach would be to set post meta-data to mark posts that should be hidden, then add a meta-query to ...
  • 6,415
1 vote

How do i put in user id in a banner

You can use get_current_user_id() - if a user is not logged in, the value will be 0: <a href="http://example.com/uid=<?php echo get_current_user_id() ?>">...</a>
  • 35.9k

Only top scored, non community-wiki answers of a minimum length are eligible