Resources

My Agape try

Your Agape try


Support Forum

Current User: Guest Login Register
Please consider registering

Search 
Search Forums:


 




Get current users groups

UserPost

9:58 am
March 3, 2009


Josti

Member

posts 4

1

Hello,

First, let me thank you for that GREAT plugin!

I restricted the access to a whole category to a certain RS Group ("members"). Now I have a hardcoded Link to that category which should only be visible when the current user is a member.

Now:

<li><a href="/forum/role-scoper/page-1/<?php echo(get_category_link(1)); ?>">Intern</a></li>

I want to have a check ala current_user_can("read_post", $category_id); to toggle visibility of the link.


Is this possible?

1:12 pm
March 3, 2009


Kevin

Admin

posts 1385

2

I've not yet written a wrapper function to make it quite that easy.

For now, your simplest solutions is probably:

$readable_cat_ids = get_terms( 'category', 'fields=ids&skip_teaser=1' );
if ( in_array( $category_id, $readable_cat_ids ) ) {
  // display your link 
}

Using that argument string, your get_terms request will just pull from the cache that was already generated for post category filtering, so there won't be any performance hit.

You can also check for group membership directly:

global $current_user;
if ( isset( $current_user->groups[$group_id] ) ) {
  // do stuff
}

4:48 am
March 4, 2009


Josti

Member

posts 4

3

Thanks for your solution, working perfectly!

I really would like to see more templating features like those added to Role Scoper!



Reply to Topic: Get current users groups

NOTE: New Posts are subject to administrator approval before being displayed

Guest Name (Required):

Guest EMail (Required):

Guest URL (required)

Math Required!
What is the sum of: 12 + 11        (Required)

Topic Reply:


 

About the Agapetry forum

Currently Online:

10 Guests

Maximum Online: 88

Forums:

Groups: 2

Forums: 7

Topics: 707

Posts: 3193

Members:

There are 642 members

There are 1 guests


Kevin has made 1385 posts

Top Posters:

metal450 - 98

YikYak - 58

Ragnar - 36

Daisy - 35

victar - 33

Administrator: Kevin | Moderators: Kevin