Created
June 7, 2021 10:31
-
-
Save koen12344/45cfc6d8bf391b02f7282e1e30bf4afd 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 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){ | |
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); | |
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