• In my site I’ve installed permalink manager with wpml and wp-graphql.
    When I had update Permalink Manager to 2.2.19.3 version the graphql don’t return anymore the right language code and the translated contents.

    In file “pemalink-manager-pro\includes\core\permalink-manager-language-plugins.php”, line 828, there is a wpml filters:

     item_id = apply_filters('wpml_object_id', $element_id, $element_type);

    I try to add the language code parameter to force the language:

    $item_id = apply_filters('wpml_object_id', $element_id, $element_type, false, $element_language_code );

    and it works perfectly right now.

    Is it possible to include this improve in future version?

Viewing 1 replies (of 1 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @mpdechit,

    I need to conduct additional testing to ensure that this change does not break anything. In general, the last argument in the filter should be the language code taken from the URL, and stating a language code of the detected element ($element_language_code) there may disrupt some custom implementations.

    A good alternative idea could be to overwrite the whole function where this line of code is used:

    function pmp_fix_language_mismatch($item_id, $uri_parts, $is_term = false) {
    	global $wp, $polylang, $language_code, $permalink_manager_options;
    
    	$mode = (!empty($permalink_manager_options['general']['fix_language_mismatch'])) ? $permalink_manager_options['general']['fix_language_mismatch'] : 0;
    
    	if($is_term) {
    		$element = get_term($item_id);
    		if(!empty($element) && !is_wp_error($element)) {
    			$element_id = $element->term_taxonomy_id;
    			$element_type = $element->taxonomy;
    		} else {
    			return false;
    		}
    	} else {
    		$element = get_post($item_id);
    
    		if(!empty($element->post_type)) {
    			$element_id = $item_id;
    			$element_type = $element->post_type;
    		}
    	}
    
    	// Stop if no term or post is detected
    	if(empty($element)) { return false; }
    
    	// Get the language code of the found post/term
    	$element_language_code = Permalink_Manager_Language_Plugins::get_language_code($element);
    
    	// Get the detected language code
    	if(defined('ICL_LANGUAGE_CODE')) {
    		$detected_language_code = ICL_LANGUAGE_CODE;
    	} else if(!empty($uri_parts['lang'])) {
    		$detected_language_code = $uri_parts['lang'];
    	} else {
    		return $item_id;
    	}
    
    	if($detected_language_code !== $element_language_code) {
    		$item_id = apply_filters('wpml_object_id', $element_id, $element_type, false, $element_language_code);
    	}
    
    	return $item_id;
    }
    add_filter('permalink_manager_detected_post_id', 'pmp_fix_language_mismatch', 10, 3);
Viewing 1 replies (of 1 total)
  • The topic ‘wpml_object_id parameters in fix_language_mismatch’ is closed to new replies.