Skip to content

Instantly share code, notes, and snippets.

@koen12344
Last active June 8, 2021 12:05
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/130109aa59f13a07a5b56e439d216ac5 to your computer and use it in GitHub Desktop.
Save koen12344/130109aa59f13a07a5b56e439d216ac5 to your computer and use it in GitHub Desktop.
<?php
function pgmb_gf_post_created($post_id, $feed, $entry, $form){
global $post_to_google_my_business_plugin;
$post_type = 'your_post_type';
// -- Do not edit after this
//If this is a different post type, abort
if($post_type != get_post_type($post_id)){
return;
}
//Make sure the snippet doesn't crash the site if the plugin is disabled or the name of the variable is changed
if(!isset($post_to_google_my_business_plugin) || !$post_to_google_my_business_plugin instanceof MBP_Plugin){
return;
}
$reflection = new ReflectionObject($post_to_google_my_business_plugin);
try{
//Make sure the metabox property actually exists
$metabox = $reflection->getProperty('metabox');
} catch (ReflectionException $ex) {
return;
}
$metabox->setAccessible(true);
$instance = $metabox->getValue($post_to_google_my_business_plugin);
//Cancel the default auto post
add_filter('mbp_autopost_before_insert_subpost', '__return_false');
$instance->save_autopost_template($post_id, get_post($post_id), false);
}
add_action( 'gform_advancedpostcreation_post_after_creation', 'pgmb_gf_post_created', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment