PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Automatically setting submitted posts to private

  1. RichardBest
    Member

    Hi there

    As you know, it's possible to set the default status for a post submitted through GF to Draft, Pending Review, or Published. What I'd like to be able to do please is set the default status to Private, so that only the user that has submitted them can see them (this may sound odd but makes perfect sense for my particular use case).

    Is there an easy fix for this please? For example, could I change a bit of the code for the plugin to replace, for example, the "Pending Review" status with the "Private" status?

    Would really appreciate your help with this please as it's the missing piece to an access puzzle I've been trying to solve for quite a while.

    Best regards
    Richard

    Posted 9 years ago on Thursday November 26, 2009 | Permalink
  2. Richard,
    I will look into adding "Private" as an option in a future release. Until then, you can use the following code snippet to set your posts to private


    add_filter("gform_post_data", "private_posts", 10, 2);
    function private_posts($post_data, $form){
    if($form["id"] == XXX){
    $post_data["post_status"] = "private";
    }
    return $post_data;
    }

    Replace XXX with your form id.

    Posted 9 years ago on Thursday November 26, 2009 | Permalink
  3. RichardBest
    Member

    Brilliant, thanks. Will try this out right now!

    P.S. I'm assuming I add this code to my theme's functions.php file? Will give that a crack.

    Posted 9 years ago on Thursday November 26, 2009 | Permalink
  4. RichardBest
    Member

    Sorry, but I should have asked... can this be done for multiple or all forms on the same site?

    Posted 9 years ago on Thursday November 26, 2009 | Permalink
  5. For all forms:

    add_filter("gform_post_data", "private_posts", 10, 2);
    function private_posts($post_data, $form){
        $post_data["post_status"] = "private";
        return $post_data;
    }

    For multiple forms: (in this sample, for forms 1,5 and 10)

    add_filter("gform_post_data", "private_posts", 10, 2);
    function private_posts($post_data, $form){
    if(in_array($form["id"], array(1,5,10))){
       $post_data["post_status"] = "private";
    }
    return $post_data;
    }

    For multiple forms

    Posted 9 years ago on Thursday November 26, 2009 | Permalink
  6. RichardBest
    Member

    Thanks so much for the excellent support. Superb.

    Posted 9 years ago on Thursday November 26, 2009 | Permalink
  7. adew
    Member

    +1

    This would be a very useful feature for a future release.

    Posted 9 years ago on Monday April 19, 2010 | Permalink
  8. AxellOnline
    Member

    Where do I place this code theme's function.php or the gravity form's function.php? Thanks.

    Posted 9 years ago on Thursday August 12, 2010 | Permalink
  9. All customizations would go in your themes function.php file, never edit the Gravity Forms plugin files as this can cause issues and upgrades to the plugin would overwrite your work.

    Posted 9 years ago on Thursday August 12, 2010 | Permalink
  10. sascha
    Member

    You can add a line of code to form_detail.php to get it showing as an option. Of course that will be overwritten as soon as you upgrade. Look at lines 983-985, they create the options that are shown. You add another line:
    <option value="private">Private</option>
    to give you the Private option as a dropdown. Not sure if you can add it with a hook/filter? That would be better so it does not get overwritten each time you upgrade.

    Posted 8 years ago on Sunday August 14, 2011 | Permalink
  11. sascha
    Member

    Hi there,
    Could that option <option value="private"><?php _e("Private", "gravityforms") ?></option> be added to the GF code for a next update?

    Posted 7 years ago on Wednesday January 18, 2012 | Permalink