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 wordpress hook with gravityforms

  1. dennispedrie
    Member

    I've got a function to automatically create a taxonomy entry when I create or edit a post. It's called using the save_post hook in WordPress, and works perfectly on the backend.

    It doesn't work in Gforms though, and I'm assuming based on that that Gforms doesn't use WordPress' built-in post creation functions.

    I found in forms_model.php that gforms uses the wp_insert_post() function, which does call the save_post hook. Why doesn't it seem to be working right then?

    Posted 14 years ago on Monday April 18, 2011 | Permalink
  2. Hi Dennis,

    I did some tests locally and the save_post hook was fired successfully when creating a new post with Gravity Forms. Could you post the function you are firing on save_post?

    Posted 14 years ago on Monday April 18, 2011 | Permalink
  3. dennispedrie
    Member

    I did a bit more digging. The hook gets fired, but I'm getting caught up on my post type checking.

    I added a function to my site to allow Gforms to add content to a post type called "bloggers". This works fine.

    I have the following code in my save_post function to make sure I'm only getting the right post type. This is where my problem is. The function gets returned before any of the important stuff happens.

    How can I change this code to allow Gforms to get through my validation?

    // verify if this is an auto save routine. If it is our form has not been submitted, so we dont want
    	// to do anything
    	if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
    		return $post_id;
    
    	// Check permissions
    	if ( 'bloggers' == $_POST['post_type'] ) {
    		if ( !current_user_can( 'edit_page', $post_id ) )
    			return $post_id;
    	}
    	else
    		return $post_id;
    Posted 14 years ago on Monday April 18, 2011 | Permalink
  4. Unless you're adding $_POST['post_type'] into the $_POST before the save_post action is fired, it probably is not available in the $_POST. Here is print_r of what was available in the $_POST when the save_post action was fired on my localhost:

    {"input_1":"Test","input_2":"Test","input_3":"http:\/\/","input_10":"","input_11":"","is_submit_39":"1","gform_submit":"39","gform_unique_id":"4dadf6b88beea","state_39":"YToyOntpOjA7czo2OiJhOjA6e30iO2k6MTtzOjMyOiJjM2Q2MTc3MWFiODc5MGExODg3YTAwYmI1NzNmYmZjNSI7fQ==","gform_target_page_number_39":"0","gform_source_page_number_39":"1","gform_field_values":""}
    Posted 14 years ago on Tuesday April 19, 2011 | Permalink
  5. dennispedrie
    Member

    I figured it out. :)

    Problem with field names, and the $_POST['post_type'] like you said.

    Thanks.

    Fantastic plugin, btw. Absolute lifesaver.

    Posted 14 years ago on Wednesday April 20, 2011 | Permalink
  6. Glad you were able to figure out and glad Gravity Forms is serving you well! :)

    Posted 14 years ago on Wednesday April 20, 2011 | Permalink

This topic has been resolved and has been closed to new replies.