WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
Polylang and WP-ecommerce (3 posts)

  1. Chouby
    Member
    Plugin Author

    Posted 10 months ago #

    This topic follows: http://wordpress.org/support/topic/polylang-12-beta-is-ready-for-tests/page/3#post-4820757
    which has moved to a WP-ecommerce compatibility issue.

    To answer to the last question about why the $_SERVER['REQUEST_URI'] is moved from '/?wpsc_user_dynamic_js=true&ver=3.8.12.1.55f8cfa0d7' to '/es/?wpsc_user_dynamic_js=true&ver=3.8.12.1.55f8cfa0d7'

    I have no idea...

    The function home_url is filtered in Polylang (in frontend-links.php) but this filter should not act on a wp-ecommerce call. it should act only on a call to home_url from the theme and only when callin home_url() or home_url('/')

    http://wordpress.org/plugins/polylang/

  2. ReactorShop
    Member
    Posted 10 months ago #

    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
    add_filter('pll_rewrite_rules',
    			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:

    products-page/([^/]+)/?$

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

    pagina-de-productos/([^/]+)/?$

  3. ReactorShop
    Member
    Posted 10 months ago #

    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!

Reply

You must log in to post.

About this Plugin

About this Topic