Skip to content Skip to sidebar

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 38 replies, has 2 voices.

Last updated by Mohamed Sayed 1 year, 11 months ago.

Assisted by: Mohamed Sayed.

Author Posts
August 24, 2023 at 2:10 am #14281047

davidF-106

i'm doing it on the WIP site. No, didn't work. Still have those items. I had a script that could delete the menu items but it doesn't work either because only english exists now.

The script looks like below. Could you guys provide a script to get rid of the additional items?

<?php
if (ICL_LANGUAGE_CODE != "en") {
$menus = get_terms('nav_menu', array('hide_empty' => false));
$menus = array_combine(wp_list_pluck($menus, 'term_id'), wp_list_pluck($menus, 'name'));
// print_r( $menus );
foreach($menus as $key => $value) {
print("deleting menu $key: $value ... ");
if ($key<100 || $key==3284) {
print("skipping");
}
else {
$result = wp_delete_nav_menu($key);
if (is_wp_error($result)) {
$error_string = $result->get_error_message();
print("Failed: $error_string");
} else if ($result) {
print("success");
} else {
print("failed");
}
}
print("<br />\n");
}
} else {
print("<p>Skipping for English</p>");
}

August 24, 2023 at 2:45 am #14281089

davidF-106

I have a copy of the database with the wpml stuff still in there - I can provide that then maybe you guys can provide a script to clear it all out of there? But need a private message.

August 24, 2023 at 10:47 am #14284201

Mohamed Sayed

Hi,

I'm checking with our developers for another way to remove this content and will update you here soon.

August 25, 2023 at 12:04 am #14288413

Mohamed Sayed

Our developers suggest the following steps:

1. Check the names of categories and menus that are not deleted
2. Disable WPML
3. Find them by name and delete them
4. Activate WPML again after those are deleted, and use the "Reset" option to start again

However, if the reason for the reset is just to fix the button issue, then we would suggest restoring the backup and letting us take a look.

Doing the translation again is not a good approach. We think the issue with buttons is not complex, and we can fix it if we can check on the live site.

Kind regard,
Mohamed

August 25, 2023 at 1:42 am #14288609

davidF-106

I manually looked up some items and the items in the db pointed to things that didn't exist, maybe it should remove those in clean up. I ended up just deleting all the wp_icl tables.

August 25, 2023 at 10:49 pm #14293949

davidF-106

have your programmers been able to figure out why it won't show? You had one on a cloud service that didn't work, did they figure it out?

August 26, 2023 at 1:56 am #14294043

davidF-106

It looks like it's an issue with WPML - for the issue on the WIP site saying it was moved, I found https://wpml.org/forums/topic/getting-message-this-site-has-moved-to-a-new-location/ which had a link to another support question that fixed it.

August 26, 2023 at 2:17 am #14294047

davidF-106

Okay - so now the WIP site does the same thing. I changed the main page, I just tried updating Spanish, afterwards, no button. I also changed the password so need private message to provide.

August 27, 2023 at 10:34 am #14296111

Mohamed Sayed

Hi David,
Sorry for the late reply due to the weekend.

Our developers couldn't find more clues as they don't have access to the live site. When we tested on the staging last time, the issue was fixed by updating the translations.

If you can replicate the issue there, please provide us with access details so we can check again (I've enabled the private reply).

Please note that we already tested the workaround provided on this ticket: https://wpml.org/forums/topic/separate-a-multisite/#post-14128971 but it resets the ATE settings, so the staging won't share the same translation memory with the live site. This is why we asked for direct access to the live site to check the issue there.

August 27, 2023 at 3:54 pm
August 27, 2023 at 10:25 pm #14296869

Mohamed Sayed

Thanks,

I see that updating the page doesn't fix the issue now on staging. I forwarded this info with the access details to our developers and will let you know once I have some updates.

Kind regards.

August 29, 2023 at 12:53 pm #14307309

Mohamed Sayed

Thanks for your patience!

Our developers found that the problem is not caused by WPML or the translations, the translated button shortcode is saved in DB but not rendered on the front end.

We provided a fix for this issue before in one of your previous tickets https://wpml.org/forums/topic/the-translated-pages-have-buttons-with-the-wrong-url/#post-10999437

But the theme has changed the encoding method they use and now the workaround fails so we don't see the shortcode output on the front-end.

To fix this please try the following steps after creating a full backup:

1. Edit the functions.php file of your child theme
2. Replace the code we provided here https://wpml.org/forums/topic/the-translated-pages-have-buttons-with-the-wrong-url/#post-10999437

With the following:

/*
 * WPML Workaround for compatibility conflict
 */
function wpml_compsupp6164_decode_urlencoded_shortcode( $string, $encoding, $original_string) {
    if ( 'link_with_urlencoded' === $encoding ) {

        $original_string = urldecode( $original_string );
        $is_json = true;
        $strings = json_decode($original_string);
        $string = [];
        
        // There are two types of encoding, the new method uses JSON and old method uses custom encoding.
        if ($strings === NULL) {
            $is_json = false;
            $strings = explode("|", $original_string);
        }
        
        foreach ( $strings as $i => $value ) {
            if ($is_json) {
                $rows[][$i] = $value;
            } else {
                $item =  explode(":", $value);
                $key = $item[0];
                unset($item[0]);
    
                $value = implode(":", $item);
                $row[$key] = $value;
                $rows[] = $row;
    
                unset($row[$key]);
            }
            
        }
 
        foreach ( $rows as $i => $row ) {
            foreach ( $row as $key => $value ) {
                if ( $key == 'url'  ) {
                    $string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => true );
                } else {
                    $string[ $key . '_' . $i ] = array( 'value' => $value, 'translate' => false );
                }
            }
        }
    }
    return $string; 
}
add_filter( 'wpml_pb_shortcode_decode', 'wpml_compsupp6164_decode_urlencoded_shortcode', 10, 3 );
 
function wpml_compsupp6164_encode_urlencoded_shortcode($string, $encoding, $original_string ) {
    if ( 'link_with_urlencoded' === $encoding ) {
        $output = array();
        
        //In translation we can save the new encoding mehtod only i.e. JSON.
        foreach ( $string as $combined_key => $value ) {
            $parts = explode( '_', $combined_key );
            $i = array_pop( $parts );
            $key = implode( '_', $parts );
            $cleaned_keys[ $i ][ $key ] = $value;
        }
 
        foreach ( $cleaned_keys as $subkey ) {
            foreach ( $subkey as $key => $value ) {
                $output[$key] = $value;
            }   
        }
 
        $string = urlencode(json_encode($output));
    }
    return $string; 
}
add_filter( 'wpml_pb_shortcode_encode', 'wpml_compsupp6164_encode_urlencoded_shortcode', 10, 3);

3. Edit the page and make a small change then save it
4. Update the translations

Let us know your feedback please.

August 29, 2023 at 10:04 pm #14309391

davidF-106

That fixed it. Thanks.

I can't tick on how your issue was resolved in my firefox browser,