Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Function to change the order of the save_post execution. Change the $priority value to change the priority
lower numbers mean earlier execution.
function pgmb_change_autopost_priority(){
global $post_to_google_my_business_plugin;
$priority = 20; //Lower numbers get executed earlier, default is 10
// -- Do not edit after this
//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){
$reflection = new ReflectionObject($post_to_google_my_business_plugin);
//Make sure the metabox property actually exists
$metabox = $reflection->getProperty('metabox');
} catch (ReflectionException $ex) {
$instance = $metabox->getValue($post_to_google_my_business_plugin);
remove_action('save_post', [$instance, 'save_autopost_template']);
add_action('save_post', [$instance, 'save_autopost_template'], $priority, 3);
add_action( 'after_setup_theme', 'pgmb_change_autopost_priority', 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment