탐색 건너뛰기

Open

Reported for: WPML Multilingual CMS 4.6.13

Topic Tags: Compatibility

Overview of the issue

When using Elementor Pro’s Display Conditions feature to control widget visibility, the conditions do not apply correctly on translated pages. Specifically, tags or categories in the translated language do not trigger the display conditions as expected, causing elements that should be hidden to remain visible.

Workaround

Please, make sure of having a full site backup of your site before proceeding.

  • Open your theme’s functions.php file.
  • Add the following snippet:
    /*
    * WPML Workaround for compsupp-7656
    */
    add_filter( 'elementor/frontend/before_render', 'wpml_compsupp7656_filter_e_display_conditions_from_widget');
    
    function wpml_compsupp7656_filter_e_display_conditions_from_widget($element) {
        $settings = $element->get_settings();
    
        if (array_key_exists('e_display_conditions', $settings) && !empty($settings['e_display_conditions'])) {
            foreach ($settings['e_display_conditions'] as $key => $condition_json) {
                $condition = json_decode($condition_json, true);
                
                foreach ($condition as &$condition_group) {
                    foreach ($condition_group as &$single_condition) {    
                        if (isset($single_condition['condition']) && strpos($single_condition['condition'], 'in_') === 0) {
                            $taxonomy_key = substr($single_condition['condition'], 3); // Remove 'in_' prefix
                            if (isset($single_condition[$taxonomy_key])) {
                                foreach ($single_condition[$taxonomy_key] as &$term) {
                                    if (isset($term['id'])) {
                                        $term_obj = get_term($term['id']);
                                        if ($term_obj && !is_wp_error($term_obj)) {
                                            $term['id'] = apply_filters('wpml_object_id', $term['id'], $term_obj->taxonomy, true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
    
                // Encode the modified condition back to JSON
                $settings['e_display_conditions'][$key] = json_encode($condition);
            }
    
            // Update the element's settings with the modified conditions
            $element->set_settings('e_display_conditions', $settings['e_display_conditions']);
        }
    }
    

2 응답 에게 “Elementor Pro - Display Conditions Is Not Supported Yet”

  1. Same can be done for conditions depending on the current page by replacing the foreach loop with the following :

    foreach ($condition as &$condition_group) {
    foreach ($condition_group as &$single_condition) {
    if (isset($single_condition['condition']) && strpos($single_condition['condition'], 'in_') === 0) {
    $taxonomy_key = substr($single_condition['condition'], 3); // Remove 'in_' prefix
    if (isset($single_condition[$taxonomy_key])) {
    foreach ($single_condition[$taxonomy_key] as &$term) {
    if (isset($term['id'])) {
    $term_obj = get_term($term['id']);
    if ($term_obj && !is_wp_error($term_obj)) {
    $term['id'] = apply_filters('wpml_object_id', $term['id'], $term_obj->taxonomy, true);
    }
    }
    }
    }
    } else if (isset($single_condition['condition']) && $single_condition['condition'] === 'page_title') {
    foreach ($single_condition['titles'] as &$title) {
    if (isset($title['id'])) {
    $page = get_post($title['id']);
    if ($page && !is_wp_error($page) && $page->post_type === 'page') {
    $title['id'] = apply_filters('wpml_object_id', $page->ID, 'page', true);
    $title['text'] = get_post($title['id'])->post_title;
    }
    }
    }
    }
    }
    }

답장을 남겨주세요

주제를 유지하고 다른 사람을 존중하십시오. 이 게시물과 관련 없는 문제에 대한 도움이 필요한 경우 지원 포럼을 사용하여 채팅을 시작하거나 티켓을 제출하십시오.

다음 태그를 사용할 수 있습니다.
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>