Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
Snippet to create GMB posts from the Advanced Post Creation plugin of Gravity Forms
**/
function pgmb_gf_create_post_advancedpostcreation($post_id, $feed, $entry, $form){
$subpost = new \PGMB\PostTypes\SubPost();
$subpost->set_parent( $post_id );
$savedAutopostTemplate = get_post_meta( $post_id, '_mbp_autopost_template', true );
$settings = new \PGMB\WeDevsSettingsAPI();
$defaultAutoPostTemplate = $settings->get_option( 'autopost_template', 'mbp_quick_post_settings', \PGMB\FormFields::default_autopost_fields() );
if ( empty($defaultAutoPostTemplate) ) {
$defaultAutoPostTemplate = \PGMB\FormFields::default_autopost_fields();
}
$subpost->set_form_fields( $defaultAutoPostTemplate );
$subpost->set_autopost();
try {
$child_post_id = wp_insert_post( $subpost->get_post_data(), true );
} catch ( Exception $e ) {
error_log( $e->getMessage() );
}
update_post_meta( $post_id, 'mbp_autopost_created', true );
update_post_meta( $post_id, '_mbp_gutenberg_autopost', false );
return true;
}
add_action( 'gform_advancedpostcreation_post_after_creation', 'pgmb_gf_create_post_advancedpostcreation', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment