Skip Navigation

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

Problem:

HTTP Headers plugin - Call to a member function switch_to_locale() when String Translation is active

https://wordpress.org/plugins/http-headers/

Solution:

1. Take a backup of your site in case something goes wrong.

2. Edit with code editor the following file in the HTTP Headers plugin folder.
/wp-content/plugins/http-headers/http-headers.php

3. Replace the following lines 1417/1418

add_action("added_option", 'http_headers_option');
add_action("updated_option", 'http_headers_option');

with:

add_action("added_option", function() {
     add_action('admin_init', 'http_headers_option');
     add_action("updated_option", 'http_headers_option');});

4. This should solve the fatal error issue when saving the HTTP Headers options.

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.

Our next available supporter will start replying to tickets in about 6.89 hours from now. Thank you for your understanding.

This topic contains 10 replies, has 2 voices.

Last updated by alexD-36 4 years, 6 months ago.

Assisted by: Itamar.

Author Posts
April 13, 2020 at 7:24 am #5894573

alexD-36

I installed WPML on a working WP site. It might have an incompatibility with the HTTP Headers plugin https://wordpress.org/plugins/http-headers/.As soon as I change the headers config, I get this message in the browser.

April 13, 2020 at 9:20 am #5895287

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi.

We need to replicate this issue on a fresh WordPress installation. Then I'll be able to escalate it to our compatibility team. For this, I created a test website with a clean WordPress install. You can access it through this link:

-site removed--

With this link, you'll be directly logged in.

Could you please install the https://wordpress.org/plugins/http-headers/ plugin and see if the issue is replicable on a clean WordPress installation?
Please configures WPML and WooCommerce as it is set on your site (just the basics usually is enough).
Please also make sure that you are installing the latest version of the plugin.

When everything is finished, and you can replicate the problem, please let me know.

Thanks,
Itamar.

April 15, 2020 at 12:33 am #5908589

alexD-36

Hi,
I reply to the email notification on Monday so not sure you got my answer.
Hi,
I installed "HTTP Headers", imported some settings and added a new header
(image1)
and on validation, I get this
(image2)

Then, I desactivated WPML String Translation plugin, and I was able to add the header without problem.

Alex

image1.png
image2.png
April 15, 2020 at 7:51 pm #5916761

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi, Alex and thanks for installing the plugin on the test site.

I'm sorry but I'm not familiar with this plugin and how to configure it.
Can you please explain the step by step process that I need to do in order to replicate this critical error?

Thanks,
Itamar.

April 15, 2020 at 11:02 pm #5917495

alexD-36

Hi,
1) Go to the plugin's setting page
hidden link
2) Enter the security sections
hidden link
3) Add a new header value. ex : new endpoint "hidden link" in the "frame-src" section so the value is now hidden link hidden link hidden link
4) Click on "save changes" (at the bottom of the page)
5) you get this error "There has been a critical error on your website. Please check your site admin email inbox for instructions. Learn more about debugging in WordPress."

Notice that this problem is more serious than it looks. Initialy, I installed WPML on the site with WooCommerce, Elementor and HTTP Headers plugins. After the upload of the plugin, it took some time, I got a 503 error. The web site was down, killed. We lost hours trying to figure out what happened. We are in a kubernetes environement. The container would no longer start, even after re-initialization. In fact, some files stayed on attached volumes. Not that easy to edit when the container would not even start...

April 18, 2020 at 7:25 am #5937627

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi and thanks for the extra details.

I've escalated this issue to our compatibility team and they will debug it and try to find a fix for it. If we would not be able to fix this issue only from our side, we might need the cooperation of the author of the plugins. It would be great if you could contact the authors and urge them to join our Go Global Program. You can find details about it here.
https://wpml.org/documentation/theme-compatibility/go-global-program/
We will be happy to cooperate with the authors in making their plugin officially compatible with WPML.

In any case, I'll keep you updated here when I have news from our compatibility team regarding this issue.

Thank you for your patience.
Itamar.

April 18, 2020 at 12:52 pm #5939135

alexD-36

Hi,
Thank you.
I created an entry in the support forum of the HTTP Headers plugin page
https://wordpress.org/support/topic/incompatibility-with-wpml-3/

April 20, 2020 at 12:09 pm #5949049

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi,

Our compatibility team has found a fix for this issue. Here is what you need to do.

1. Take a backup of your site in case something goes wrong.

2. Edit with code editor the following file in the HTTP Headers plugin folder.
/wp-content/plugins/http-headers/http-headers.php

3. Replace the following lines 1417/1418

add_action("added_option", 'http_headers_option');
add_action("updated_option", 'http_headers_option');

with:

add_action("added_option", function() {
     add_action('admin_init', 'http_headers_option');
     add_action("updated_option", 'http_headers_option');});

4. This should solve the fatal error issue when saving the HTTP Headers options. It work for me on the test site.

Can you please check if it works for you as well?
If it does you can share it with the plugin's author.

Regards,
Itamar.

May 4, 2020 at 11:10 pm #6056547

alexD-36

Itama, would it be possible to give access to an evaluation version of WPML to HTTP Headers author?
He said the fix has side effects
https://wordpress.org/support/topic/incompatibility-with-wpml-3/

April 24, 2021 at 5:15 pm #8615115

alexD-36

Hello,
Could you work with the plugin author to include this fix ?
Today, I'm obliged to manual modify the code each time a new version is pushed :S
https://wordpress.org/support/topic/http-header-wpml-crash/

Alex