Title: Automatically restrict visibility upon post create
Last modified: October 19, 2021

---

# Automatically restrict visibility upon post create

 *  Resolved [giladehven](https://wordpress.org/support/users/giladehven/)
 * (@giladehven)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/automatically-restrict-visibility-upon-post-create/)
 * Is there a way to automatically/programmatically restrict the visibility of a
   post, while creating this post (with a Groups group that already exists)?
 * First challenge: The post is created automatically from a user-submitted Gravity
   Forms form, at unpredictable times, so we can’t wait until after it shows up 
   to go into the admin and manually restrict visibility.
 * Second challenge: Although the Groups group used for this visibility restriction
   is always expected to exist, there are actually quite a few groups that could
   be used. Only one needs to be applied in this visibility restriction, but we 
   cannot predict in advance which one it will be.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [giladehven](https://wordpress.org/support/users/giladehven/)
 * (@giladehven)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/automatically-restrict-visibility-upon-post-create/#post-14985991)
 * Upon further reflection, I realized that the second challenge may not be important
   after all. Rather, by always applying the same Groups group upon the creation
   of this post (some sort of “pending review” group), we could effectively force
   ourselves to review the user-submitted entry, and that review would be an ideal
   time to assign the “actual” intended Groups group.
 * BTW, this automatically created post is actually a custom post specified in a“
   Gravity Forms Advanced Post Creation Add-On” post creation feed.
 * So, only the first challenge applies: The goal is now to have this automatically
   created post, have a Groups group assigned at post creation. And, again, it will
   always be the same Groups group.
 *  [gtsiokos](https://wordpress.org/support/users/gtsiokos/)
 * (@gtsiokos)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/automatically-restrict-visibility-upon-post-create/#post-14987751)
 * Hi giladehven,
 * Yes you can add a restriction to a post programmatically using
    [https://github.com/itthinx/groups/blob/master/lib/access/class-groups-post-access.php#L524](https://github.com/itthinx/groups/blob/master/lib/access/class-groups-post-access.php#L524)
 * taking as argument an array of the post id you wish to add an access restriction
   and the group id you choose to restrict the post to.
 * Apart from this and since we are talking about a custom post type, also make 
   sure to enable restrictions for this post_type under Groups > Options.
    Hope 
   it helps.
 * Kind regards,
    George
 *  Plugin Author [Kento](https://wordpress.org/support/users/proaktion/)
 * (@proaktion)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/automatically-restrict-visibility-upon-post-create/#post-14992630)
 * As this is related to a premium plugin, I would suggest to check the docs [https://docs.gravityforms.com/category/add-ons-gravity-forms/advanced-post-creation-add-on/](https://docs.gravityforms.com/category/add-ons-gravity-forms/advanced-post-creation-add-on/)
   or get in touch with the developers to see if they provide a hook that you could
   use that is triggered when the post is created. At that point you could then 
   assign it to the appropriate group.
 *  Thread Starter [giladehven](https://wordpress.org/support/users/giladehven/)
 * (@giladehven)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/automatically-restrict-visibility-upon-post-create/#post-14992695)
 * Thanks, George!
 * I should be able to have a chance to work on this over the coming weekend. I’ll
   report back after I’m done.
 * Kento: to be clear, I have everything working on the GF side just perfectly. 
   It’s only the Groups side of this effort that I am researching with this post.
   George’s answer seems likely to be what I’m looking for, so I’ll continue my 
   efforts there. Of course, if you have any additional input on the Groups side
   of this challenge, I’d love to “hear” it. The more the better!
 *  Plugin Author [Kento](https://wordpress.org/support/users/proaktion/)
 * (@proaktion)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/automatically-restrict-visibility-upon-post-create/#post-14992723)
 * [@giladehven](https://wordpress.org/support/users/giladehven/) Sounds like you’re
   right on track with [@gtsiokos](https://wordpress.org/support/users/gtsiokos/)’
   s suggestion – BTW if you need examples of working with Groups there’s [https://docs.itthinx.com/document/groups/api/examples/](https://docs.itthinx.com/document/groups/api/examples/)
   which might be helpful

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Automatically restrict visibility upon post create’ is closed to new 
replies.

 * ![](https://ps.w.org/groups/assets/icon-256x256.png?rev=983146)
 * [Groups](https://wordpress.org/plugins/groups/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/groups/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/groups/)
 * [Active Topics](https://wordpress.org/support/plugin/groups/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/groups/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/groups/reviews/)

## Tags

 * [action](https://wordpress.org/support/topic-tag/action/)
 * [api](https://wordpress.org/support/topic-tag/api/)
 * [filter](https://wordpress.org/support/topic-tag/filter/)

 * 5 replies
 * 3 participants
 * Last reply from: [Kento](https://wordpress.org/support/users/proaktion/)
 * Last activity: [4 years, 7 months ago](https://wordpress.org/support/topic/automatically-restrict-visibility-upon-post-create/#post-14992723)
 * Status: resolved