0

Here's a brief summary of how my site is setup:

I have a relatively simple Intranet site. Right now I am utilizing posts as a means to provide news to users. I am also using pages. I only want certain users to be able to do these things (let's say "Editors").

What I would like to do is to setup a community section of the site where all users are able to make a post (to sell things, etc). I am wondering what the best way to go about this is? I could use a category to make it easy to show only these types of posts. But, I don't want users to be able to make any type of post. I only want them to be able to post to the community. If someone is posting news, I want them to have a higher security level.

If I am thinking about this the wrong way, I'd love to hear other ideas!

Edit:

Here is my current custom post code:

function createCommunityPostType() {
    $args = array(
            'public' => true,
            'label' => 'Community'
    );
    register_post_type('community', $args );
}
add_action('init', 'createCommunityPostType');
6
  • 2
    I would create a custom post type for your community posts. That way you can require specific capabilities in order to post that CPT.
    – vancoder
    Mar 27, 2013 at 19:18
  • 1
    In addition to vancoder's comment I advice to read the perfect explanation of meta capabilities by Justin Tadlock: Meta capabilities for custom post types.
    – Max Yudin
    Mar 27, 2013 at 19:29
  • both the above comments are spot on, or you can also do this extremely easily with Gravity Forms, so users just use a front-end form to create a post without having to use the WordPress backend. it's perfect if you're dealing with non-teccie users. Mar 27, 2013 at 22:18
  • @vancoder and @Max - Thanks for the response. I used register_post_type which seems like a very easy way to setup a post. I'm still not certain on how I would go about securing the default posts so that only certain roles are allowed to create them and simultaneously allowing only a different set of roles to use my new post type. Would either of you be able to explain that a bit more? Mar 28, 2013 at 17:36
  • Can you show your CPT code thus far?
    – vancoder
    Mar 28, 2013 at 17:40

1 Answer 1

1

The following will assign capability requirements to your CPT. So, users will require edit_community, delete_community etc capabilities to perform those actions.

function createCommunityPostType() {
    $args = array(
            'public' => true,
            'label' => 'Community'
            'capability_type' => 'community',
            'map_meta_cap' => true
    );
    register_post_type('community', $args );
}
add_action('init', 'createCommunityPostType');

See the parts about capabilities in the codex.

You also need to assign these caps to your users. You could use a plugin for this (see the members plugin), or you can do it yourself:

function my_after_setup_theme() {

    $role = get_role( 'subscriber' );
    $caps_set = get_option( 'my_caps_set' );
    if ( !$caps_set ) {
        $role->add_cap( 'edit_community' );
        $role->add_cap( 'read_community' );
        $role->add_cap( 'delete_community' );
        // ... and so forth (see codex for caps list)

        update_option( 'my_caps_set', true );
    }
}

add_action( 'after_setup_theme', 'my_after_setup_theme' );

We set a settings flag to save from resetting the caps more than once.

the above code assumes you want to assign these caps to subscribers, but you can change this to any role, or create your own role.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.