I've replicated and, hopefully, fixed this bug. I'm a little worried about knock on problems as it required a change to the rewrite rules which are basically a kind of voodoo magic.
If you wish to test it out then edit the plugin/filters.php file. Find the function "wps_post_rewrite_rules" and replace it with the one below.
function wps_post_rewrite_rules( $rules ) {
global $wps_this_subdomain, $wp_rewrite;
// If we have %category% in the permalink we also need to create rules without it.
// This is because the category might be the subdomain and so wouldn't be in the url
if ( strstr( $wp_rewrite->permalink_structure, '%category%' ) && $wps_this_subdomain && ($wps_this_subdomain->type == WPS_TYPE_CAT) ) {
// Grab the permalink structure
$perma_tmp = $wp_rewrite->permalink_structure;
// Remove the /%category section
$perma_tmp = str_replace('/%category%','',$perma_tmp);
// Create the extra rules using this new structure
$extra_rules = $wp_rewrite->generate_rewrite_rules($perma_tmp, EP_PERMALINK);
// Now we have to remove the rule that matches a category on it's own
// this is reinstated later but just can't come before the extra rules
$unset_key = array_search('index.php?category_name=$matches[1]', $extra_rules);
if ($unset_key) {
unset($extra_rules[$unset_key]);
}
// Check for the problem attachment rules and remove them.
// Pray this doesn't break anything ;)
foreach ($extra_rules as $regexp => $url) {
if (strpos($url, 'attachment=$matches') && (strpos($regexp, 'attachment') === false)) {
unset($extra_rules[$regexp]);
}
}
// merge to two rule sets into one
$rules = array_merge($extra_rules, $rules);
}
// Check if the permalink structure has any date parts
$has_date = false;
foreach ( array( '%year%', '%monthnum%', '%day%' ) as $datepart ) {
if ( strstr( $wp_rewrite->permalink_structure, $datepart ) ) {
$has_date = true;
}
}
// If there is a date part in the permalink structure filter by the subdomain we're on
// This is incase we're actually looking at an date archive rather than a post
if ( $has_date && $wps_this_subdomain) {
$rules = $wps_this_subdomain->addRewriteFilter($rules);
}
//print('<pre>'.print_r($rules,true).'</pre>');
return $rules;
}
Let me know how you get on and if you notice anything else go wrong. If it's ok for you I will release an 0.6.1-rc2 with the fix and see if anyone else find issues with it.
Hi Paul,
I've replicated and, hopefully, fixed this bug. I'm a little worried about knock on problems as it required a change to the rewrite rules which are basically a kind of voodoo magic.
If you wish to test it out then edit the plugin/filters.php file. Find the function "wps_post_ rewrite_ rules" and replace it with the one below.
function wps_post_ rewrite_ rules( $rules ) { subdomain, $wp_rewrite;
global $wps_this_
// If we have %category% in the permalink we also need to create rules without it. >permalink_ structure, '%category%' ) && $wps_this_subdomain && ($wps_this_ subdomain- >type == WPS_TYPE_CAT) ) { >permalink_ structure;
// This is because the category might be the subdomain and so wouldn't be in the url
if ( strstr( $wp_rewrite-
// Grab the permalink structure
$perma_tmp = $wp_rewrite-
// Remove the /%category section '/%category% ','',$perma_ tmp);
$perma_tmp = str_replace(
// Create the extra rules using this new structure >generate_ rewrite_ rules($ perma_tmp, EP_PERMALINK);
$extra_rules = $wp_rewrite-
// Now we have to remove the rule that matches a category on it's own 'index. php?category_ name=$matches[ 1]', $extra_rules);
// this is reinstated later but just can't come before the extra rules
$unset_key = array_search(
if ($unset_key) { $extra_ rules[$ unset_key] );
unset(
}
// Check for the problem attachment rules and remove them. $matches' ) && (strpos($regexp, 'attachment') === false)) { $extra_ rules[$ regexp] );
// Pray this doesn't break anything ;)
foreach ($extra_rules as $regexp => $url) {
if (strpos($url, 'attachment=
unset(
}
}
// merge to two rule sets into one $extra_ rules, $rules);
$rules = array_merge(
}
// Check if the permalink structure has any date parts >permalink_ structure, $datepart ) ) {
$has_date = false;
foreach ( array( '%year%', '%monthnum%', '%day%' ) as $datepart ) {
if ( strstr( $wp_rewrite-
$has_date = true;
}
}
// If there is a date part in the permalink structure filter by the subdomain we're on subdomain) { subdomain- >addRewriteFilt er($rules) ;
// This is incase we're actually looking at an date archive rather than a post
if ( $has_date && $wps_this_
$rules = $wps_this_
}
//print( '<pre>' .print_ r($rules, true).' </pre>' );
return $rules;
}
Let me know how you get on and if you notice anything else go wrong. If it's ok for you I will release an 0.6.1-rc2 with the fix and see if anyone else find issues with it.
Cheers,
Alex