• Resolved TrishaM

    (@trisham)


    EDITED: OMG, I am an idiot….apparently I was adding some code in my functions already to restrict access to this CPT…geesh, I will just modify that…..BUT I’m still hoping you’ll consider my request at the end of this for a future update. ??

    <ignore>
    Users who are not Admins apparently don’t have access to this custom post type in the left-side menu……and we need Authors to be able to add FAQs.

    I’m familiar with registering post types, so can you please tell me the best way to modify this plugin to add this ability (to add FAQs) to Authors? I’m guessing probably a snippet of some code that I can add to my functions.php to protect it from getting overwritten when the plugin gets updated?
    </ignore>

    Also, could you consider adding a few very basic settings, such as allowing site admins to set permissions based on user role? E.G. Allow Contributors to Add but not Publish FAQs, Authors to Add and Publish but not Delete FAQs, and Editors the ability to Add/Edit/Delete them?

    Many thanks!

    • This topic was modified 8 years, 5 months ago by TrishaM.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author John Gardner

    (@jgardner03)

    Hi Trisha,

    On my roadmap is integration with the popular Members plugin. I was thinking that might make more sense than trying to create my own settings page for restricting access. What do you think?

    Thread Starter TrishaM

    (@trisham)

    Hi John, thanks for the speedy reply!

    So that’s more or less what I have done, I added a snippet of code to my functions that adds both the capability type and the capabilities to the registration of the FAQ CPT, then in the “User Roles” setting added by the Members Plugin the FAQ post type shows up along with my capabilities, and I check grant or deny them based on the user role. ??

    Here’s what I added to my functions:

    function my_faq_defaults( $defaults ) {
        $defaults['post_type']['args']['has_archive'] = true;
    	$defaults['post_type']['args']['capability_type'] = array('faq','faqs');
        $defaults['post_type']['args']['capabilities'] = array(
               'publish_posts' => 'create_faqs',
               'edit_posts' => 'create_faqs',
               'edit_others_posts' => 'create_faqs',
               'delete_posts' => 'delete_faqs',
               'create_faqs' => 'create_faqs',
               'read_private_posts' => 'create_faqs',
               'edit_post' => 'create_faqs',
               'delete_post' => 'delete_faqs',
               'read_post' => 'create_faqs',
        	);
        return $defaults;
    }
    add_filter( 'arconix_faq_defaults', 'my_faq_defaults' );
    

    Adding the capability_type was required for the Members plugin to ‘see’ it as a CPT.

    Also I went with custom capabilities because I allow contributors to ‘create_posts’ and I didn’t want them to also be able to create FAQs……so a new capability was required, I couldn’t just use the default ‘create_posts’.

    Then I granted “create_faqs” to Authors, but not the ability to “delete_faqs”, I only gave that capability to Editors and above. I am, for now, letting Authors publish them, but I could restrict that by changing ‘publish_posts’ => ‘create_faqs’, to ‘publish_posts’ => ‘publish_faqs’, and then NOT granting them that.

    Interestingly, I found that I also had to grant both capabilities to Administrators – not sure if that can be added by default in the CPT registration, I’m not actually a coder.

    So for now it’s working perfectly in conjunction with the Members plugin.

    ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Required minimum user level?’ is closed to new replies.