Support » Plugins and Hacks » Polylang and WP-ecommerce

Polylang and WP-ecommerce

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Chouby!

    So I reached a point in which I have to either add (preferred) or modify the rewrite rules in order for the translated permalinks to be matched by them.

    I added this filter in my plugin:

    // create rewrite rules with a filter 'something_rewrite_rules'
    add_filter('generate_rewrite_rules', 'p4we_translated_rules');
    function p4we_translated_rules($wp_rewrite) {
            $rules = $myrules;               // Processing removed for simplicity.
    	$rules = apply_filters('p4we_translated_rewrite_rules', $rules);
    	$wp_rewrite->rules = array_merge(rules, $wp_rewrite->rules);
    //add the filter (without '_rewrite_rules') to the Polylang list
    			create_function('$rules','return array_merge($rules, array(\'p4we_translated\'));'));

    And I see that it’s being added as the last item of PLL_Links_Directory->rewrite_rules as ‘p4we_translated’ when PLL’s prepare_rewrite_rules filter applies the ‘pll_rewrite_rules’ filter.

    The thing is that my filter, even though registered by PLL, is never applied. I’ve looked for filters being applied by ‘generate_rewrite_rules’ during my debugging tests, and none of them are being applied either.

    The problem here is that the rules need to be updated (either appended or modified in $wp_rewrite, no flushing needed) every time the language is changed, so that the translated permalinks may match the newly selected language AND the rewrite rules.

    I already did this about 2 weeks ago, but I did it modifying the WordPress source code directly, which I found it wasn’t the recommended approach (I now know that’s what filters are for).

    I’ve looked for information on generate_rewrite_rules and I only found that it triggers after all rewrite rules have been created, but I don’t get when/why/how this happens.

    Can you recommend an approach to tackle this issue?

    Thank you in advance, Chouby!

    EDIT: I need to finish this in order to move on to testing PLL 1.2dev58. I’m still at PLL 1.2dev57.

    EDIT 2: To exemplify my situation:

    This is one default language rewrite rule:


    For Spanish, I need to add another rule or modify it to say:


    Never mind.

    I just hooked my filter to ‘option_rewrite_rules’ and it’s doing exactly what I was looking for.

    Have a nice weekend!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Polylang and WP-ecommerce’ is closed to new replies.