Skip to content

Instantly share code, notes, and snippets.

@koen12344
Last active March 11, 2022 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koen12344/27375647094bb541dc922ebc9a344d60 to your computer and use it in GitHub Desktop.
Save koen12344/27375647094bb541dc922ebc9a344d60 to your computer and use it in GitHub Desktop.
<?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){
if(!class_exists('\PGMB\PostTypes\SubPost') || !class_exists('\PGMB\FormFields') || !class_exists('\PGMB\Vendor\WeDevsSettingsAPI')){
return false;
}
$subpost = \PGMB\PostTypes\SubPost::create($post_id);
$savedAutopostTemplate = get_post_meta( $post_id, '_mbp_autopost_template', true );
$settings = new \PGMB\Vendor\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