Skip Navigation

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

Problem:
The client is trying to register WPML on a WordPress site hosted on Pantheon, which blocks access to the standard registration URL (wp-admin/plugin-install.php). The client cannot use the PHP constant method for adding the registration key due to security policies that prevent adding sensitive information to the git code repository.

Solution:
We recommend storing the WPML license keys in text files within a private, non-version-controlled directory, such as

wp-content/uploads/private/

on Pantheon. The client should name the text files according to the Pantheon environment name or the local Lando subdomain. For example, the live environment would use 'live.txt'.

The client can then use the following code snippet in the

wp-config.php

file to automatically load the correct license key file based on the environment:

<!-- Code snippet starts --><br />/*<br /> * Define WPML license keys, based on environment name<br /> * ...<br /> */<br />if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) {<br /><br />    // Prepare the license key path...<br />    $wpml_license_key_path = ABSPATH . 'wp-content/uploads/private/wpml/';<br /><br />    // Determine the license file filename...<br />    if ( isset( $_SERVER['LANDO_APP_COMMON_NAME'] ) ) {<br />        $wpml_expected_license_file = $wpml_license_key_path . $_SERVER['LANDO_APP_COMMON_NAME'] . '.txt';<br />    } else {<br />        $wpml_expected_license_file = $wpml_license_key_path . $_ENV['PANTHEON_ENVIRONMENT'] . '.txt';<br />    }<br /><br />    if ( file_exists( $wpml_expected_license_file ) ) {<br />        $wpml_license_key = file_get_contents($wpml_expected_license_file);<br />        define( 'OTGS_INSTALLER_SITE_KEY_WPML', $wpml_license_key );<br />    }<br />}<br /><!-- Code snippet ends -->

For further details, please refer to our documentation on automatic WPML registration using PHP.

If this solution does not seem relevant to your situation, please do not hesitate to open a new support ticket with us.

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 4 replies, has 2 voices.

Last updated by Chainalysis 11 months, 2 weeks ago.

Assisted by: Mihai Apetrei.

Author Posts
December 5, 2023 at 10:07 pm #15003023

Chainalysis

Tell us what you are trying to do?

Hello, is there a way to register WPML from within the WordPress UI, without visiting wp-admin/plugin-install.php? Our hosting provider -- Pantheon -- blocks access to this URL in production.

I believe that there used to be some other way to register WPML in the WordPress UI but I can't seem to find it in WPML 4.6.x. Our copy of WPML was registered in production until we upgraded to WordPress 6.4.1 and WPML 4.6.8 this week, and now WPML is no longer registered.

Or is there a database field where we can add the registration number? I can directly edit our site database as needed.

I know that we can in theory set a PHP constant with the registration key but that's problematic in our case, also related to our hosting setup.

Thank you for any help!

What is the link to your site?
hidden link

December 6, 2023 at 7:55 pm #15011969

Mihai Apetrei
Supporter

Languages: English (English )

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

Hi there.

Before this ticket gets assigned to my colleagues, I will try to help.

Please take a look here:
https://wpml.org/forums/topic/register-key-with-pantheon/

I think the information from that ticket will definitely help.

Unfortunately, the way they have things set up is a bit troubling.

Related documentation:
https://wpml.org/faq/automatic-wpml-registration-using-php-for-easy-moves-between-production-development-and-staging/

I hope that you will find all this information helpful 🙂

Mihai Apetrei

December 6, 2023 at 8:08 pm #15012009

Chainalysis

Hi Mihai, thanks for sharing this.

Unfortunately, here's the reason that I wrote that "I know that we can in theory set a PHP constant with the registration key but that's problematic in our case, also related to our hosting setup."

We can't add our license keys to wp-config.php because that's part of our git code repository, and we can't add license keys to our code due to security policies.

Is there a way to handle this within the WordPress UI? There used to be some other URL where we could register WPML because that's what I used in the past to register WPML in production on Pantheon and it was working for almost two years until this week, and now I can't seem to find the URL or documentation about this other UI option.

December 6, 2023 at 8:31 pm #15012073

Mihai Apetrei
Supporter

Languages: English (English )

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

Hi there.

I tried to check this with my colleagues, too - there might be a "register" url in the main Plugins page, under the plugin name but that might lead to the same URL. I was not able to find any other URL as you mentioned, I checked more than 20 existing tickets about pantheon. Unfortunately, they keep adding more and more obstructions to their system it seems.

There's also this recommendation from their URL (I will also attach a screenshot) but if you already have WPML configured, you won't see that part.

My recommendation is to get in touch with their support and ask for their help.

This is unfortunately not something caused by WPML. We constantly get people that have issues with this provider.

I guess people will have to keep creating support tickets, continue to be unhappy, and at some point, they might do some things to really fix these and not just come with workarounds.

I would have loved to at least be able to offer a workaround but I can't at this point, especially taking into consideration the git repository security policies.

The wp-config.php workaround was the most popular one and all of the customers confirmed that this does the trick.

Mihai

Screenshot 2023-12-06 at 22.20.57.png
December 7, 2023 at 3:31 pm #15018507

Chainalysis

Thank you, Mihai. Based on what you shared, I created a workaround for wp-config.php which enables us to use this constant but also keep the license keys out of our code repository for the sake of security -- never put license keys in your code repo! -- and flexibility in case we need to quick add or edit keys.

If it helps to share it here for others who use Pantheon, this is the solution that I created:

We now store WPML license keys inside of text files, where the name of the text file matches the Pantheon environment name or the local Lando subdomain.

So the license key for the live environment is `live.txt`, a multidev env named 'wpml' would use a key named `wpml.txt`, and a local env with a URL like `mylocalenv.lnod.site` would use a key named `mylocalenv.txt`.

We place these keys in a path that is private and *not* under version control, and Pantheon provides an existing path helps with this:

wp-content/uploads/private/

On Pantheon, that's a symlink for this path:

/files/private/

We use SFTP to create text files within a 'wpml' subfolder that we created within this path, and we insert the license keys into our text files.

From there we have the following code within wp-config.php to load the correct license key files automatically.

I hope that this helps anyone else who is facing the same problem, who needs a secure, flexible solution.

/* 
 * Define WPML license keys, based on environment name
 * 
 * For example, a multidev domain named 'wpml' would have a license key file named 'wpml.txt'; the live env would use 'live.txt'; and Lando envs like 'localwww.lndo.site' would use a file named 'localwww'.
 * License keys are stored within this folder, managed by SFTP: wp-content/uploads/private/wpml/ , aka /files/private/wpml on Pantheon
 * This path is not under version control, intentionally, to keep license keys out of our code repo for improved security and flexibility.
 */
if ( isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) {

	// Prepare the license key path, where we'll find the WPML license key files
	$wpml_license_key_path = ABSPATH . 'wp-content/uploads/private/wpml/';

	// Determine what the license file filename is
	if ( isset( $_SERVER['LANDO_APP_COMMON_NAME'] ) ) {
		// For Lando, use the local subdomain, such as maybe 'localwww'
		$wpml_expected_license_file = $wpml_license_key_path . $_SERVER['LANDO_APP_COMMON_NAME'] . '.txt';
	} else {
		// For other environments, use the Pantheon env name, e.g. 'maintenance', 'dev,', 'test', 'live'
		$wpml_expected_license_file = $wpml_license_key_path . $_ENV['PANTHEON_ENVIRONMENT'] . '.txt';
	}

	if ( file_exists( $wpml_expected_license_file ) ) {
		// Get the WPML license key from the text file, and tell WPML to use it as the environment's license key.
		$wpml_license_key = file_get_contents($wpml_expected_license_file);
		define( 'OTGS_INSTALLER_SITE_KEY_WPML', $wpml_license_key );
	}
}