• Resolved bluemeansgo

    (@bluemeansgo)


    I was wondering if there is a way to get the details of the user level in code.

    I have a Rule which restricts categories for a user level.

    E.g. Sam is a member of the “HR-Access” rule. The “hr-access” rule can see the taxonomy “payroll”.

    What I’d like to do is when listing all the taxonomies, I’d like to see all the condition groups. If a user has access to a piece of content, I want to display is normally, otherwise, I want to add a CSS class.

    what I’d love to see is rua_get_access_level($id) which returned an array of condition groups. I’ve been looking into the SQL to figure out how it’s stored in the database, but I haven’t quite cracked the nut. If I had a little insight perhaps into where the details of the condition_group are stored, that would be a great help! Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Joachim Jensen

    (@intoxstudio)

    It might be a little cumbersome to achieve it the way you describe.

    Taxonomy conditions are stored as a taxonomy term for the post type condition_group, which in case has a restriction post type as post_parent.

    So you could perhaps do something like this:
    1. Use the API to get the user level IDs
    2. Get condition_group IDs with post_parent = level IDs
    3. wp_get_object_terms( condition_group IDs, taxonomies);

    Let me know if this works for you.

    I am planning on changing the API and make it more OOP, but I am not sure if conditions will be part of it, as it will most likely get its own API (it’s another library).

    Thread Starter bluemeansgo

    (@bluemeansgo)

    I’ve been using it as an excuse to dig into the database and code. I like how clean the code is, by the way. Thanks for the suggestion. I’ll try it and let you know either here or send you a quick tweet ( I’m @armstrongest )

    If I can also make one more suggestion, it would be an API call to get a list of all the levels… like rua_get_levels() or even better, a test that you pass user ID and page/post ID to.

    rua_user_has_access( $user_id:int, $post_id:int );

    Thanks for all your hard work on this!

    Plugin Author Joachim Jensen

    (@intoxstudio)

    Thanks for the kind words, there are some parts of the code that I’d like to rewrite entirely, but with limited time that’s not really a priority now (and if it ain’t broke, don’t fix it).

    I’m @intoxstudio on twitter, and you’re also welcome to open an issue on Github: https://github.com/intoxstudio/restrict-user-access

    The problem with a function such as rua_user_has_access() is that if it only takes a post ID, it doesn’t recognize “mixed” conditions, such as posts in category, or posts by author.
    While mixing post IDs with other conditions isn’t really needed right now, there will be conditions in the future where it’s possible (e.g. URL parameters).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get details of a User Level in Code’ is closed to new replies.