Hi, I have a solution for the WPMU Domain Mapping and Varnish Purge plugin issues. The solution is to query the database table wp_domain_mapping from within the purging class. Get all mapped domains for the site, and put them in an array, then loop through the array running the purge commands.
From (approximately) line 61 of varnish-purger-abstract.class.php insert the following code up to where you see the closing bracket before the line that says:
function WPAuth($challenge, $secret) {
Paste this code over the existing lines:
(Note that wpv_host has become an array wpv_hosts)
$wpv_wpurl = get_bloginfo('wpurl');
$wpv_replace_wpurl = '/^http:\/\/([^\/]+)(.*)/i';
$wpv_hosts[] = preg_replace($wpv_replace_wpurl, "$1", $wpv_wpurl);
$wpv_blogaddr = preg_replace($wpv_replace_wpurl, "$2", $wpv_wpurl);
$wpv_url = $wpv_blogaddr . $wpv_url;
/*
* WPMU Domain mapping edit by [email protected]
*--------------------------------------------------
*/
//Are we a subdomain install?
global $switched;
switch_to_blog(1);
$tldomain = get_bloginfo('wpurl');
restore_current_blog();
$tld_host = preg_replace($wpv_replace_wpurl, "$1", $tldomain);
preg_match("/$tld_host/","$wpv_hosts[0]",$matches);
if ($matches) :
global $wpdb ;
$domains = $wpdb->get_results( $wpdb->prepare("SELECT * FROM wp_domain_mapping WHERE blog_id = %d", $wpdb->blogid) );
if ( is_array( $domains ) && !empty( $domains ) ) :
foreach( $domains as $details ) :
$wpv_hosts[] =$details->domain ;
endforeach;
endif;
reset($domains);
endif; // if ($matches)
if ( is_array( $wpv_hosts ) && !empty( $wpv_hosts ) ) :
foreach ( $wpv_hosts as $wpv_host ) :
for ($i = 0; $i < count ($wpv_purgeaddr); $i++) {
$varnish_sock = fsockopen($wpv_purgeaddr[$i], $wpv_purgeport[$i], $errno, $errstr, $wpv_timeout);
if (!$varnish_sock) {
error_log("wp-varnish error: $errstr ($errno)");
return;
}
if($wpv_use_adminport) {
$buf = fread($varnish_sock, 1024);
if(preg_match('/(\w+)\s+Authentication required./', $buf, &$matches)) {
# get the secret
$secret = "1beb871d-987a-4bbd-98aa-408e3de596cb";
fwrite($varnish_sock, "auth " . $this->WPAuth($matches[1], $secret) . "\n");
$buf = fread($varnish_sock, 1024);
if(!preg_match('/^200/', $buf)) {
error_log("wp-varnish error: authentication failed using admin port");
fclose($varnish_sock);
return;
}
}
$out = "purge req.url ~ ^$wpv_url && req.http.host == $wpv_host\n";
} else {
$out = "PURGE $wpv_url HTTP/1.0\r\n";
$out .= "Host: $wpv_host\r\n";
if ($useragent != null){
$out .= "User-Agent: $useragent\r\n";
}
$out .= "Connection: Close\r\n\r\n";
}
fwrite($varnish_sock, $out);
fclose($varnish_sock);
}
// store url as purged
$WPVarnishPurger_url_purged[]=$wpv_url.$useragent;
endforeach ;
endif ;
/*
* End WPMU Domain mapping edit
*--------------------------------------------------
*/
After doing this and uploading it to my server I then tested on a few sites on my multi-site WP install with mapped domains. Updating a post from within the subdomain backend works to clear the mapped domain as well.
Using the varnishlog command with a regex for purges, returns:
$ varnishlog -I “purge”
0 CLI – Rd purge req.url ~ ^/submit-your-meeting-experiences/ && req.http.host == deathtomeetings.brellabee.com
0 CLI – Rd purge req.url ~ ^/submit-your-meeting-experiences/ && req.http.host == deathtomeetings.com
0 CLI – Rd purge req.url ~ ^/ && req.http.host == deathtomeetings.brellabee.com
0 CLI – Rd purge req.url ~ ^/ && req.http.host == deathtomeetings.com
0 CLI – Rd purge req.url ~ ^/feed/ && req.http.host == deathtomeetings.brellabee.com
0 CLI – Rd purge req.url ~ ^/feed/ && req.http.host == deathtomeetings.com
0 CLI – Rd purge req.url ~ ^/feed/atom/ && req.http.host == deathtomeetings.brellabee.com
0 CLI – Rd purge req.url ~ ^/feed/atom/ && req.http.host == deathtomeetings.com
0 CLI – Rd purge req.url ~ ^/page/(.*) && req.http.host == deathtomeetings.brellabee.com
0 CLI – Rd purge req.url ~ ^/page/(.*) && req.http.host == deathtomeetings.com
0 CLI – Rd purge req.url ~ ^/date/2011/11/26/ && req.http.host == deathtomeetings.brellabee.com
0 CLI – Rd purge req.url ~ ^/date/2011/11/26/ && req.http.host == deathtomeetings.com
0 CLI – Rd purge req.url ~ ^/date/2011/11/ && req.http.host == deathtomeetings.brellabee.com
0 CLI – Rd purge req.url ~ ^/date/2011/11/ && req.http.host == deathtomeetings.com
0 CLI – Rd purge req.url ~ ^/date/2011/ && req.http.host == deathtomeetings.brellabee.com
0 CLI – Rd purge req.url ~ ^/date/2011/ && req.http.host == deathtomeetings.com
0 CLI – Rd purge req.url ~ ^/26/painful/9-autosave/ && req.http.host == deathtomeetings.brellabee.com
0 CLI – Rd purge req.url ~ ^/26/painful/9-autosave/ && req.http.host == deathtomeetings.com
0 CLI – Rd purge req.url ~ ^/date/2012/01/26/ && req.http.host == deathtomeetings.brellabee.com
0 CLI – Rd purge req.url ~ ^/date/2012/01/26/ && req.http.host == deathtomeetings.com
0 CLI – Rd purge req.url ~ ^/date/2012/01/ && req.http.host == deathtomeetings.brellabee.com
0 CLI – Rd purge req.url ~ ^/date/2012/01/ && req.http.host == deathtomeetings.com
0 CLI – Rd purge req.url ~ ^/date/2012/ && req.http.host == deathtomeetings.brellabee.com
0 CLI – Rd purge req.url ~ ^/date/2012/ && req.http.host == deathtomeetings.com