WordPress.org

Ready to get started?Download WordPress

Forums

WP User Frontend
Restrict categories to Roles (7 posts)

  1. setnaps
    Member
    Posted 1 year ago #

    Good evening.
    I'm starting to enjoy this wonderful plugin but I have a little issue.

    In my WP site I want to restrict some certain categores to some certain user roles, for doing so i use the Restrict Categories Plugin.
    However, WP User Frontend seems to disable this restriction as it has it's own, in the Frontend Posting area, "Exclude category ID's".
    Here I have a little problem as I can't exclude categories anymore for some certain roles, so my users will see all the categories, even those restricted to other Roles that were not supposed to see.
    Is there any way for WP user frontend to leave the responsibility of restricting categories to the other plugin?

    Thank you very much for your support.

    My kindest regards.

    Victor

    http://wordpress.org/extend/plugins/wp-user-frontend/

  2. setnaps
    Member
    Posted 1 year ago #

    Or even better...
    Is it possible for WP User Frontend to group the category restriction by Roles? instead by all the Users?
    My kindest regards again.

  3. professor99
    Member
    Posted 1 year ago #

    This very much depends on how that plugin is filtering the categories.

    Frontend uses two standard wordpress calls to get the categories.

    For dropdowns it uses wp_dropdown_categories().

    For checklists it uses wp_terms_checklist().

    Try the various Frontend category display options in case Restrict Categories Plugin already filters one of these.

    Else this is really a question for Restrict Categories Plugin support.

    eg Does Restrict Categories Plugin filter wp_dropdown_categories() and wp_terms_checklist()? If not what WordPress category functions does it filter?

    With that info you could code Frontend (or Restrict Categories Plugin) to suit

  4. setnaps
    Member
    Posted 1 year ago #

    Thanks porfessor99 for your answer.
    The issue, as told by the developer of "User Front End" plugin means lots of new code into the plugin, as probably it will need to reconsider seriously some of the very basics of the code.
    What I'm considering is the possibility of writing ( not myself ) a third plugin that "connects" these 2 main plugins and then upload it to WordPress.org.
    The 2 plugins separately work just fine, so I don't think it's a good idea to code them, I prefer to leave them the way they are.

  5. gpspake
    Member
    Posted 1 year ago #

    Hey setnaps,

    You ever get anywhere with this?
    It's a tricky issue. I could probably think of at least 5 more args that should be included in wp_terms_checklist(), this being one of them.

    There should be an option to pass an array of categories to exclude as well as a boolean '$showuncategorized' arg.

    Unfortunately, since there aren't, I'm finding that it's kind of a pain to pull out any cats.
    I'll probably end up hardcoding this. If you ever made any progress, I'd appreciate any suggestions. In the meantime, I'm going to keep trying to figure out how to do this without modifying the walker.

  6. setnaps
    Member
    Posted 1 year ago #

    Hi Gpspake.
    I just let it pass, it seems quite complicated to reach what I was looking for.
    Playing with different plugins that include similar options can lead to parts of the plugin not working properly. In which case I think it should be better to consider making your own plugin in order to reach the specific requests that one has. Or try doing another research and find something that fits better.
    The user frontend plugin is a very good plugin if you want to avoid your users mess with the admin panel which probably will not understand.
    Good luck

  7. gpspake
    Member
    Posted 1 year ago #

    Well man, if you're still interested, I think I just figured it out, at least for what I needed. It was surprisingly simple and I don't see how it could require very much additional code to fully integrate in to the plugin.

    I only needed to exclude a couple of categories from the list so in wpuf-functions.php, inside of WPUF_Walker_Category_Checklist I added the following:

    class WPUF_Walker_Category_Checklist extends Walker {
    
    ...
    
    function start_el( &$output, $category, $depth, $args ) {
    
    if ($category->term_id == 1 || $category->term_id == 31 || $category->term_id == 37 ) { // If the term id is 1, 31, or 37
      return; // Skip it
    }

    That's it for me.
    Now, in your case, you could wrap it up in a conditional that checks the user's role and, to really do it right you could replace the conditions in the if statement with an array or something and add some options to the plugin settings interface in the dashboard.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic