Skip Navigation

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.

This topic contains 6 replies, has 2 voices.

Last updated by Yvette 9 months, 3 weeks ago.

Assigned support staff: Yvette.

Author Posts
November 1, 2019 at 11:31 am

per-egilR

Hi there,

I have a OceanWP + WooCommerce + WPML site (all current versions, incl. WPML 4.3.2) in English and German.

The links of one of my 10 product attributes are malformed by the WPML "the_content" filter "fix_fallback_links". The "Destination" product attribute is hierarchical and the links has the form of

<em><u>hidden link</u></em>{country}/{city}/

However, when I apply

apply_filters( 'the_content', $content );

to any content containing these links, I get

<em><u>hidden link</u></em>{country}//{city}

(the last slash is misplaced, causing unnecessary redirects).

The problem is resolved by removing the [php]WPML_Fix_Links_In_Display_As_Translated_Content::fix_fallback_links[php] hook. There is no easy way to do so, as the instance of the WPML_Fix_Links_In_Display_As_Translated_Content class is hard to obtain.

I guess that the reason why only one of my 10 product attributes are affected, is that the first two characters of "destination" equals the German language code "de". This seems be be a general issue when links are matching one of the language codes in use.

I think that this is a bug that should be fixed in future versions.

November 4, 2019 at 2:03 pm #4881861

Yvette
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/Madrid (GMT+02:00)

Thank you very much for bringing this to our attention

You wrote: ".., when I apply the filter to any content containing these links, I get (the last slash is misplaced, causing unnecessary redirects):
hidden link{country}//{city}.."

apply_filters( 'the_content', $content );

1. Problem Scope
Are you applying this filter in some kind of custom code? Or is this problem identifiable within the normal functioning of the OceanWP theme only? Or is it the case that the issue is reproducable with the Storefront theme ?

2. Steps to replicate the error on your site
I was able to connect to your dashboard (thanks). I understand that this problem is affecting hierarchical attributes.
Could you please indicate what page, navigation steps or URL I have to visit in order to see the malformed links?

Thanks for your ongoing collaboration,

November 4, 2019 at 2:49 pm #4882297

per-egilR

1. This is custom code and not related to OceanWP. I identified the issue by
a) comparing results before and after

apply_filters( 'the_content', $content );

b) and then narrowed it down by disabling all "the_content" filters one by one until I could identify "fix_fallback_links" as the source of this issue.

However, the scope seems to be general, because this issue would affect ALL links filtered through the "the_content" filter (basically every post type), provided that one of the language codes in use matches the beginning of one of the links.

2. This page is one of many examples: hidden link.

You'll find TWO links to the destination "Wellington" on this page:
a) Directly beneath the page title "Private Wellington Lord of the Rings 2-Day Tour" (image wpml-10.png). This occurrence does NOT apply the "the_content" filter and the link is CORRECT.
b) Scroll down to the section "Tour details" and look for the attribute "Where" (image wpml-11.png). This second occurrence of "Wellington" is filtered by "the_content" and the link is NOT correct.

I have fixed this issue on production (different site) by ONLY removing the "fix_fallback_links" filter: hidden link. Here both links are correct.

November 6, 2019 at 7:58 pm #4901389

Yvette
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/Madrid (GMT+02:00)

Again I really appreciate your time and excellent example.

However, when I view the 2 links on the page you gave, in both cases they resolve to the same place:
hidden link

Are you sure that the fix has not been applied to your dev site?
Or is there something else that I should focus on to see the results of the filter being applied or not?

November 6, 2019 at 8:46 pm #4901739

per-egilR

Yes, eventually both links end up on the same page, but the malformed one

<em><u>hidden link</u></em>

will only get there after a server redirect, which is not good for SEO and performance reasons. Please check the links in the source code:

CORRECT: hidden link
MALFORMED: hidden link

November 8, 2019 at 6:05 pm #4915779

Yvette
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/Madrid (GMT+02:00)

This issue has been escalate to our 2nd tier support team

November 29, 2019 at 11:58 am #5042683

Yvette
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/Madrid (GMT+02:00)

Hello

Our 2nd tier was unable to reproduce this problem on a fresh installation or on another server.
Which means that the issue may only be happening on the your server.

It may be also related with the custom plugin (filming-locations).

They suggest an alternative workaround in case you need one.
You can replace the following snippet ('wp-content/plugins;filming-locations/includes/widgets/attribute.php' - around lines 197-205):

from this:

if( 'regular' == $this->format) {
	$output .= sprintf( '<li class="filoc attribute-item %s">', $key );
	$output .= sprintf( '<i class="fa fa-lg %s"></i>', esc_attr( $icon ) );
	$output .= sprintf( '<div>' );
	$output .= sprintf( '<h4>%s</h4>', esc_html( $label ) );
	$output .= wp_kses_post( trim( apply_filters( 'the_content', $content ) ) );
	$output .= sprintf( '</div>' );
	$output .= sprintf( '</li>' );
}

to this:

if( 'regular' == $this->format) {			
	if( $key == 'destination' ) {
		$content = wp_kses_post( trim( $content ) );	
	} else {
		$content = wp_kses_post( trim( apply_filters( 'the_content', $content ) ) );	
	}			
	$output .= sprintf( '<li class="filoc attribute-item %s">', $key );
	$output .= sprintf( '<i class="fa fa-lg %s"></i>', esc_attr( $icon ) );
	$output .= sprintf( '<div>' );
	$output .= sprintf( '<h4>%s</h4>', esc_html( $label ) );
	$output .= $content;
	$output .= sprintf( '</div>' );
	$output .= sprintf( '</li>' );
}

As they were unable to reproduce this reliably, the solution is offered only for your case but not recommended for any core changes to our plugin.

I hope this serves of some use to you.