Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature filters for translation prevention #1350

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

koskinenaa
Copy link

@koskinenaa koskinenaa commented Sep 20, 2023

This pull request and the associated commits are motivated by a curious edge case when using Polylang with WP-Matomo Integration (WP-Piwik) plugin.

Here's the background briefly,

  • A site was setup with Polylang and WP-Matomo Integration plugins
  • The site used example.tld domain and 123 Matomo ID
  • The site was migrated to foobar.tld domain and the Matomo ID changed to 321
  • WP-CLI search-replace was used to change domain in the database, flush rewrites and transients, etc.
  • Matomo ID was updated from the Dashboard via the plugin's settings page

Problem
After the site migration one could see the correct Matomo ID (321) in the admin view, but on the front-end the old ID (123) was used to generate the tracking script. Rather undesirable result.

Fix
It took me some time to realize that the Matomo ID option (wp-piwik-site_id) had found its way to the Polylang string translations, where the value was showing the new ID (321), but the translations still had the old ID (123). After clearing the string translations I got the tracking script working in the front-end with the correct Matomo ID (321) as Polylang was no longer interfering with the option value retrieval.

Investigation
After some digging I figured out that I could use the pll_get_strings filter to remove the Matomo ID option from the Polylang string translations list table and loop through the global $wp_filter to unhook any PLL_Translate_Option objects from the option_wp-piwik-site_id filter. This kind of filtering should prevent the same situation from arising again.

But to me this doesn't seem like an optimal solution as I'm basically erasing something that has already happened. In my opinion a better way would be to prevent the option string registration and the option value translation in the first place so that they don't ever happen.

Solution
The proposed filters would provide developers an easy way to prevent Polylang from registering or translating certain options or other strings.

Add pll_allow_register_string filter to PLL_Admin_Strings::register_string() to enable conditional prevention of string registration
Add pll_allow_register_or_translate_option filter to PLL_WPML_Config::register_or_translate_option() to enable conditional prevention of option translation
Add pll_allow_translate_option filter to PLL_Translate_Option::__construct() to enable conditional prevention of option translation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant