[wp-hackers] Help to fix orphaned plugin

Hikari lists at hikarinet.info
Mon Feb 15 05:16:56 UTC 2010


Ok, now I'm cool I tried again, searched on WP doc and verified its source. Now I understand a bit better how rewrite rule works and 
narrowed down the source of the bug.


First of all, here's my permalink:
/%scategory%/%post_id%/%postname%/

/%scategory% is added by the plugin



v0.3.0 had this code in a function hooked to filter 'post_rewrite_rules':

{
...

    $scategory_structure = $wp_rewrite->root . "%scategory%/%postname%";
    return array_merge($rewrite, $wp_rewrite->generate_rewrite_rules($scategory_structure));
}



THIS array_merge was removed from later versions. I have no idea what it does exactaly, but adding it back fixes the bug of posts 
returning 404.

Apparently it is also the cause of paged comments returning 404, and maybe that's why the author removed it. But without it, ANY 
permalink I try that uses /%scategory% anywhere will always generate 404 for posts.


I was only able to understand that generate_rewrite_rules() is the main function for generating all rewrite rules, but I can't 
understand what its other parameters mean, and I have no idea why adding "%scategory%/%postname%" to rewrite rules is required to 
make sCategory works, or why it's only needed on my 2 sites (if author removed it and released a few versions later, I suppose the 
bug doesn't happen with him).


Is anybody able to understand it and would help me find a way to make the new rewrite tag works without breaking comments pages?


---------------------------
Hikari -  A Luz ilumina a PAZ
http://Hikari.ws
http://ConscienciaPlanetaria.com

Tenha seu próprio email meunome @ ConscienciaPlanetaria.com.br!: http://seunome.ConscienciaPlanetaria.com.br


----- Original Message ----- 
From: "Hikari" <lists at hikarinet.info>
To: <wp-hackers at lists.automattic.com>
Sent: Monday, 15 February, 2010 1:09 AM
Subject: [wp-hackers] Help to fix orphaned plugin


Hello guys, as a coincidence I'm having trouble with a plugin whose author is not accessible. It's essencial for my sites and I'm
not able to fix it.

The plugin is sCategory Permalink: http://wordpress.org/extend/plugins/scategory-permalink/

It's on version 0.6.2, but I'm still using 0.3.0.



- 0.3.0 would be perfect if it didn't have a bug: comments pages return 404, so comments can't be breaken on pages.

- 0.4.0 fix this bug, but this version generates 404 for any permalink that uses %scategory% in it

- any other version after 0.4.0 has the same 404 bug, only 0.3.0 works



Well, I've tried everything. Disabled and re-enabled permalinks a lot of times, tried all kinds of permalinks. As soon as I remove
%scategory% from permalink posts start back working. As soon as I add %scategory% back 404 is back too.

I decided to concentrate on 0.3.0 to 0.4.0 differences because they are almost the same.



There are basically 2 changes on these versions, one of them must be creating the 404 bug:

1) The following function is moved from 'post_rewrite_rules' filer to 'init' action:

0.3.0:

function addRewriteRules($rewrite) {
    global $wp_rewrite;
    $wp_rewrite->add_rewrite_tag('%scategory%', '(.+?)', 'category_name=');

    $scategory_structure = $wp_rewrite->root . "%scategory%/%postname%";

    $structure = ltrim($wp_rewrite->permalink_structure, '/');
    if (0 === strpos($structure, '%scategory%'))
        $wp_rewrite->use_verbose_page_rules = true;

    return array_merge($rewrite, $wp_rewrite->generate_rewrite_rules($scategory_structure));
}


0.4.0:

function addRewriteRules() {
    global $wp_rewrite;
    $wp_rewrite->add_rewrite_tag('%scategory%', '(.+?)', 'category_name=');
}




2) this new function, added to 0.4.0, hooked to 'post_rewrite_rules' filter:

function setVerbosePageRules($post_rewrite) {
    global $wp_rewrite;
    if (preg_match("/^[^%]*%scategory%/", $wp_rewrite->permalink_structure) )
        $wp_rewrite->use_verbose_page_rules = true;

    return $post_rewrite;
}





The lack of comments explaining what he is doing makes it harder to understand. IDK why he split the old function into 2 and moved
part of it to 'init'. What he wanted to do and consequences.

I'm also not able to distinguish what part of code is fixing comment pages bug, and where permalink bug may be happening.

Any help will be very much appreciated.




More information about the wp-hackers mailing list