Last active
June 8, 2021 12:05
-
-
Save koen12344/130109aa59f13a07a5b56e439d216ac5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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