Skip to content

Instantly share code, notes, and snippets.

@Coopeh
Last active December 23, 2015 16:09
Show Gist options
  • Save Coopeh/6660092 to your computer and use it in GitHub Desktop.
Save Coopeh/6660092 to your computer and use it in GitHub Desktop.
Fix Cloudflare Purge plugin to allow Multisite WordPress MU Domain Mapping support
/*
Save Post Hook
*/
function ccpurge_purge_after_save_post_hook( $post_id ){
// possible options...
// add_action('pending_to_publish', 'ccpurge_purge');
// add_action('draft_to_publish', 'ccpurge_purge');
// add_action('new_to_publish', 'ccpurge_purge');
global $hook_running;
remove_action('publish_post', 'ccpurge_purge_after_save_post_hook');
if($hook_running)
return;
$hook_running = true;
if( defined('DOING_SAVE') && DOING_SAVE || !$post_id )
return;
if ( !in_array(get_post_type( $post_id ), array('post', 'page', 'partners')) ) //|| wp_is_post_revision( $post_id ) )
return;
$ccpurge = new CCPURGE_API;
if( $ccpurge->ccpurge_options['auto_purge'] ){
$permalink = get_permalink( $post_id );
// Support for Multisite domain mapping - Start - 1 of 2 changes - Ed Cooper
if( is_multisite() ) :
if( function_exists('domain_mapping_post_content') ) :
global $wpdb;
$orig_url = str_replace( "https", "http", get_original_url( 'siteurl' ) );
$url = str_replace( "https", "http", domain_mapping_siteurl( 'NA' ) );
if ( $url == 'NA' )
return $permalink;
$permalink = str_replace( $orig_url, $url, $permalink );
endif;
endif;
// Support for Multisite domain mapping - End - 1 of 2 changes - Ed Cooper
$ccpurge->ccpurge_suppress_debug = true;
$ccpurge->purge_url_after_post_save( $permalink );
if( in_array(get_post_type( $post_id ), array('post')) ){
// Support for Multisite domain mapping - Start - 2 of 2 changes - Ed Cooper
$siteurl = site_url();
if( is_multisite() ) :
if( function_exists('domain_mapping_siteurl') ) :
$siteurl = domain_mapping_siteurl( get_current_blog_id() );
endif;
endif;
$ccpurge->purge_url_after_post_save( $siteurl );
// Support for Multisite domain mapping - End - 2 of 2 changes- Ed Cooper
}
}
add_action('publish_post', 'ccpurge_purge_after_save_post_hook');
}
add_action('publish_post', 'ccpurge_purge_after_save_post_hook');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment