Skip to main content

Plugin considerations

For some plugins to work properly in WPCS, some adjustment might be necessary. On this page, you can find what certain plugins require to work properly in a multi-tenant context. That might include some custom code that should be added or maybe as simple as certain settings that need to be a specific way.

Loco Translate

The Loco Translate plugin is a great plugin to manage and adjust translations in-browser. The plugin as-is, however, will not allow for translations to be managed when used from the perspective of a Tenant. The reason behind this mainly is that a Tenant does not have the same write-priviliges as a normal WordPress installation, due to the multi-tenant nature of a Tenant. To work around this assumption in Loco Translate, some custom code should be added to the Version in WPCS that Loco Translate is also installed in. The following code can be added as a plugin or a mu-plugin:

/*
Plugin Name: Loco Tenant Translations
*/

add_action('init', function(){
/**
* Only change the way Loco Translate deals with
* custom language files when running in a Tenant.
* If we are not running in a Tenant, return early.
*/
if(getenv('WPCS_IS_TENANT') !== 'true')
{
return;
}

/**
* Change the directory where Loco Translate stores the
* language files, so they are Tenant specific.
*/
define('LOCO_LANG_DIR', WP_CONTENT_DIR . "/loco-custom-translations/");

/**
* This code explicitely tells Loco that it can write
* to the directory configured above.
*/
add_filter('file_mod_allowed', function($allowed, $context){
if($context == 'wpcs_allowed') {
return true;
}
return $allowed;
}, 10, 2);

add_filter('loco_file_mod_allowed_context', function($context, $file){
if(str_contains($file->getPath(), LOCO_LANG_DIR)){
return 'wpcs_allowed';
}

return $context;
}, 10, 2);
});

WPML

To activate the license of the WPML plugin inside a tenant, you would need to go to the 'Add new plugin' screen. However, as plugins cannot be installed from a tenant in WPCS, that screen is also restricted.

The solution to this problem is to use the WPML supported PHP constant called OTGS_INSTALLER_SITE_KEY_WPML. Using the Tenant PHP constants, you can add the constant with the license key you received from WPML.