qtranslate / qtranslate-xt

qTranslate-XT (eXTended) - reviving qTranslate-X multilingual plugin for WordPress. A new community-driven plugin soon. Built-in modules for WooCommerce, ACF, slugs and others.
GNU General Public License v2.0
553 stars 104 forks source link

Apply filter to remove querystring arguments from url in widget #216

Open herrvigg opened 6 years ago

herrvigg commented 6 years ago

Issue by soft79 Thursday Aug 13, 2015 at 07:57 GMT Originally opened as https://github.com/qTranslate-Team/qtranslate-x/issues/216


Hi!

I use qTranslate-X succesfully in combination with Woocommerce and qTranslate Slug. I have a feature request. When a product is added to the cart with WooCommerce, it adds ?add-to-cart=1234 to the url. Unfortunately this is also added to the urls in language selector widget. I propose a filter to allow me to modify the generated urls, something like this:

in qtranslate_widget.php function qtranxf_generateLanguageSelectCode, append the following before the switch statement:

    $translated_urls = array();
    foreach(qtranxf_getSortedLanguages() as $language) {
        $translated_urls[$language] = apply_filters( 'qtranxf_widget_url', qtranxf_convertURL($url, $language, false, true), $language );
    }

Then use the $translated_urls array in the output part, for example in the 'both' part:

        case 'both':
            echo PHP_EOL.'<ul class="qtranxs_language_chooser" id="'.$id.'">'.PHP_EOL;
            foreach($translated_urls as $language => $translated_url) {
                echo '<li';
                if($language == $q_config['language'])
                    echo ' class="active"';
                echo '><a href="'.$translated_url.'"';
                echo ' class="qtranxs_flag_'.$language.' qtranxs_flag_and_text" title="'.$q_config['language_name'][$language].'">';
                //echo '<img src="'.$flag_location.$q_config['flag'][$language].'"></img>';
                echo '<span>'.$q_config['language_name'][$language].'</span></a></li>'.PHP_EOL;
            }
            echo '</ul><div class="qtranxs_widget_end"></div>'.PHP_EOL;
            break;

Additionaly, I noticed that qtranxf_convertURL returns an esc_url escaped url. This is done by qTranslate Slug function qts_get_url that is called by qtranxf_convertURL. This is unwanted I guess? Should I contact the Slug guys about this?

herrvigg commented 6 years ago

Comment by LC43 Thursday Nov 26, 2015 at 02:05 GMT


hi @josk79 , i'm maintaining qts, glad to know you've successfully used qtx + qts + woocommerce!

why wouldn't you want the escaped url?