Posted on Leave a comment

Default posts restriction

If you are using Groups plugin by @itthinx and you need to set restrictions to posts (or another post type), you can use this code as reference:

function restricted_save_post($post_id, $post) {
if(!is_object($post) || !isset($post->post_type)) {
switch($post->post_type) { // Do different things based on the post type
case "post":
// add your default capabilities
Groups_Post_Access::create( array( 'post_id'=>$post_id, 'capability'=>'Premium' ) );
// Do other stuff
add_action('save_post', 'restricted_save_post', 1, 2);

This code adds the ‘Premium’ capability to all new posts when they are created.

Good luck!