Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem: Language in directory using default language in directory -> issue with REST calls to the default language Solution: I was fixed in WPML 4.3.4

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 9 replies, has 3 voices.

Last updated by Bruno Kos 8 months ago.

Assigned support staff: Bruno Kos.

Author Posts
October 31, 2019 at 6:36 am #4860609

jackS-7

I am trying to:
Load the WP REST API using the default language prefix.

Link to a page where the issue can be seen:
hidden link

I expected to see:
A list of the site pages.

Instead, I got:
Not that.

You can see the normal path works.
hidden link

…and that the non-default language works:
hidden link

October 31, 2019 at 9:08 am #4861805

Bruno Kos
Supporter

Languages: English (English )

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

Hi,

This has been escalated to our 2nd tier team and may take some debugging time, I'll get back to you as soon as I have any news or questions for you.

Regards,
Bruno Kos

October 31, 2019 at 11:40 am #4863235

Bruno Kos
Supporter

Languages: English (English )

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

Hi,

This issue has been escalated to WPML developers. As for fixing it, I can't give you any dates, it could end up in the next release or in 6 months. This is totally up to developers - severity of the issue and number of reported cases (among other things) decide its queue on the list.

I will keep this thread updated as soon as I get any new information from them!

But as a workaround, you can try this:
sitepress-multilingual-cms\classes\request-handling\class-wpml-rest-request-analyze.php, line 62, find:

$cleaned_uri = ltrim( wpml_strip_subdir_from_url( $request_uri ), '/' );

and replace it with:

$cleaned_uri = $request_uri;

Regards,
Bruno Kos

October 31, 2019 at 3:46 pm #4865747

jackS-7

Thanks, Bruno, we'll try that or avoid updating the plugin until it's resolved.

Looking through the forums, I can see the developers have broken this before.

I'd recommend they add some type of unit test or integration test to catch this in the future.

November 2, 2019 at 10:26 pm #4875549

steffenW-9

Be aware: There are some other parts broken.

rest_url() returns now the url without the language code.

This is crucial and has been working before.

Hotfix: Modify this in wpml-url-filters.class.php:

    public function add_global_hooks()
    {
        add_filter('home_url', array($this, 'home_url_filter'), -10, 4);
        // posts and pages links filters
        add_filter('post_link', array($this, 'permalink_filter'), 1, 2);
        add_filter('post_type_link', array($this, 'permalink_filter'), 1, 2);
        add_filter('wpml_filter_link', array($this, 'permalink_filter'), 1, 2);
        add_filter('get_edit_post_link', array($this, 'get_edit_post_link'), 1, 3);


        $http_referer_factory = new WPML_URL_HTTP_Referer_Factory();
        $http_referer = $http_referer_factory->create();
        if (
            in_array((int) $this->sitepress->get_setting('language_negotiation_type'), array(WPML_LANGUAGE_NEGOTIATION_TYPE_PARAMETER, WPML_LANGUAGE_NEGOTIATION_TYPE_DIRECTORY), true)
            && !$http_referer->is_post_edit_page()
        ) {
            add_filter('rest_url', array($this, 'add_lang_in_rest_url'));
        }
    }
    public function add_lang_in_rest_url($url)
    {
        return $this->url_converter->convert_url($url, $this->get_request_language());
    }

Sorry WPML, but this release is not ready for production.

November 6, 2019 at 3:03 am #4894671

jackS-7

Can we add joelR-9 to this ticket?

November 13, 2019 at 1:37 pm #4939541

Bruno Kos
Supporter

Languages: English (English )

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

Hi,

Our team published an errata about this:
https://wpml.org/errata/use-directory-for-default-language-does-not-work-with-rest-api/

As for the fix, it should go into WPML 4.3.4. Once this version comes out (I don't have specific dates), let me know if it fixed it.

Regards,
Bruno Kos

December 4, 2019 at 8:04 am #5065755

Bruno Kos
Supporter

Languages: English (English )

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

Hi,

Since this issue was resolved in WPML 4.3.4, can you confirm that it works properly in your setup as well?

Regards,
Bruno Kos

January 8, 2020 at 11:15 am #5253321

steffenW-9

No, this is not fixed in WPML 4.3.6.

The rest_url filter is completely missing in wpml-url-filters.class.php.

Currently when submitting e.g. a form of contact form 7, the rest url of the "/feedback" route is without the language code, which leads to wrong language responses.

I readded the fix I mentionned above.

Can you please investigate?

January 21, 2020 at 8:32 am #5330093

Bruno Kos
Supporter

Languages: English (English )

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

Hi,

@steffenw-9, can you open a new ticket for this?

Regards,
Bruno Kos