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.

Save Post as Draft/Published depening if user is logged in

  1. Hello,

    Is it possible to have posts submitted via a GF to be set as a draft if a user is not logged in? But if a user is logged in, the post will be published right away.

    I know I can set the form to either be set as a draft or published for everyone, but I would love to be able to changed this based on the users logged in status.

    Thanks!

    Posted 8 years ago on Tuesday January 31, 2012 | Permalink
  2. Ok so I was able to figure it out. For those interested here is what I added to my functions.php file.

    // Change post status depending if user is logged in
    add_filter('gform_post_data_4', 'update_post_status');
    function update_post_status($post_data){
        $current_user = wp_get_current_user();
    	if ( 0 == $current_user->ID ) {
        	// Not logged in
        	$post_data['post_status'] = 'draft';
    	} else {
    	// Logged in
        	$post_data['post_status'] = 'publish';
    	}
    
        return $post_data;
    }
    Posted 8 years ago on Tuesday January 31, 2012 | Permalink