Skip to content

Instantly share code, notes, and snippets.

@mihdan
Forked from lilumi/hooks.php
Created April 13, 2023 20:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihdan/830b2e2190c64f5472b43618e7e9d847 to your computer and use it in GitHub Desktop.
Save mihdan/830b2e2190c64f5472b43618e7e9d847 to your computer and use it in GitHub Desktop.
Disable WPML String Translations for Gutenberg Blocks
<?php
/*
WPML checks for gutenberg like this:
\WPML_Page_Builders_Defined->has()
```
if ( 'gutenberg' === $page_builder ) {
if ( version_compare( $wp_version, '5.0-beta1', '>=' ) ) {
return true;
}
}
```
so I created a hooks to override $wp_version during this checks.
*/
add_action('after_setup_theme', 'lm_init_wpml');
function lm_init_wpml() {
add_action('wpml_load_page_builders_integration', 'lm_disable_wpml_gutenberg_integration_before', 9);
add_action('wpml_load_page_builders_integration', 'lm_disable_wpml_gutenberg_integration_after', 11);
}
function lm_disable_wpml_gutenberg_integration_before() {
global $wp_version, $site_wp_version;
$site_wp_version = $wp_version;
$wp_version = 3; // anything lower than 5.0-beta1
}
function lm_disable_wpml_gutenberg_integration_after() {
global $wp_version, $site_wp_version;
$wp_version = $site_wp_version;
unset($site_wp_version);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment