Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter art.mu

    (@artmu)

    Hi !

    @chouby: I think that what you post is correct, but it seems that defined(‘REST_REQUEST’) is never defined. For testing I use defined( ‘REST_API_VERSION’) and it works.

    Thread Starter art.mu

    (@artmu)

    After some works I manage to make it works by passing a lang parameter to my WP REST API request (?lang=en for example) with this hook :

    function polylang_json_api_init() {
    
    	global $polylang;
    
    	$default = pll_default_language();
    	$langs = pll_languages_list();
    
    	$cur_lang = $_GET['lang'];
    
    	if (!in_array($cur_lang, $langs)) {
    		$cur_lang = $default;
    	}
    
    	$polylang->curlang = $polylang->model->get_language($cur_lang);
    	$GLOBALS['text_direction'] = $polylang->curlang->is_rtl ? 'rtl' : 'ltr';
    }
    
    add_action('rest_api_init', 'polylang_json_api_init');
Viewing 2 replies - 1 through 2 (of 2 total)