Comments Error

Bug #343821 reported by Paul Nus
4
Affects Status Importance Assigned to Milestone
Wordpress Subdomains Plugin
Fix Released
High
Alex Stansfield

Bug Description

Getting an error when trying to add a comment to a subdomain'd category article.

Actually, the error is when it tries to display the comments after it has been submitted because the appending of the comment is successful. I have tried this with and without all my other plugins installed and get the same results. Basically, the error is a result of trying to view comments and not the task of adding them.

Example:

The following URL using the plugin is invalid (IE: Error 404 - Not Found)
http://sports.paulnus.com/iowa-football-signatures/comment-page-1#comment-174

The actual URL being transformed is valid (IE: this works fine)
http://www.paulnus.com/sports/iowa-football-signatures/comment-page-1#comment-174

Revision history for this message
Alex Stansfield (casualgenius) wrote :

Many thanks for being the first to use the bug tracker.

I've looked at the page and can confirm the error.

Can you send me what permalinks you're using, version of the plugin and version of wordpress.

Changed in wordpress-csd:
assignee: nobody → casualgenius
status: New → Confirmed
Revision history for this message
Paul Nus (paul-thenusfamily) wrote : Re: [Bug 343821] Re: Comments Error

Lets hope email reply works. I dont have my password on me (using keypass
generator and dont have my USB handy).

/%category%/%postname%
0.6.1-rc1
WordPress 2.7.1

On Mon, Mar 16, 2009 at 5:31 PM, Alex Stansfield <email address hidden>wrote:

> Many thanks for being the first to use the bug tracker.
>
> I've looked at the page and can confirm the error.
>
> Can you send me what permalinks you're using, version of the plugin and
> version of wordpress.
>
> ** Changed in: wordpress-csd
> Assignee: (unassigned) => Alex Stansfield (casualgenius)
> Status: New => Confirmed
>
> --
> Comments Error
> https://bugs.launchpad.net/bugs/343821
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in Wordpress Subdomains Plugin: Confirmed
>
> Bug description:
> Getting an error when trying to add a comment to a subdomain'd category
> article.
>
> Actually, the error is when it tries to display the comments after it has
> been submitted because the appending of the comment is successful. I have
> tried this with and without all my other plugins installed and get the same
> results. Basically, the error is a result of trying to view comments and not
> the task of adding them.
>
>
> Example:
>
> The following URL using the plugin is invalid (IE: Error 404 - Not Found)
>
> http://sports.paulnus.com/iowa-football-signatures/comment-page-1#comment-174
>
> The actual URL being transformed is valid (IE: this works fine)
>
> http://www.paulnus.com/sports/iowa-football-signatures/comment-page-1#comment-174
>
>

Revision history for this message
Alex Stansfield (casualgenius) wrote :

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 ) {
 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.

Cheers,

Alex

Changed in wordpress-csd:
importance: Undecided → High
status: Confirmed → In Progress
Revision history for this message
Paul Nus (paul-thenusfamily) wrote :
Download full text (4.3 KiB)

Worked like a charm.

I found the function in plugin/rewrite.php ...I assumed you meant there. Ill
let you know if I find anything else. This one appears to be fixed.

On Tue, Mar 17, 2009 at 12:16 AM, Alex Stansfield <email address hidden>wrote:

> 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 ) {
> 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
> i...

Read more...

Revision history for this message
Alex Stansfield (casualgenius) wrote :

Ahh, sorry.

plugin/rewrite.php is the correct file.

Release Candidate 2 should be going up today.

Cheers,

Alex

Revision history for this message
Alex Stansfield (casualgenius) wrote :

Fixed in version 0.6.1 release.

Changed in wordpress-csd:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.