WPML Multilingual CMS throws fatal error upon update to 2.0.0

I have just updated CP 1.7.2 to 2.0.0. I used WPML (ver. 4.6.9), which worked in previous CP, however after update, I am receiving fatal error:

[24-Feb-2024 13:32:30 UTC] PHP Fatal error: Uncaught Error: Call to undefined function WPML\BlockEditor\Blocks\register_block_type() in /wp-content/plugins/sitepress-multilingual-cms/classes/block-editor/Blocks/LanguageSwitcher.php:47
Stack trace:
#0 /wp-content/plugins/sitepress-multilingual-cms/classes/block-editor/Blocks/LanguageSwitcher.php(36): WPML\BlockEditor\Blocks\LanguageSwitcher->registerLanguageSwitcherBlock()
#1 /wp-content/plugins/sitepress-multilingual-cms/classes/block-editor/Loader.php(59): WPML\BlockEditor\Blocks\LanguageSwitcher->register()
#2 /wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Either.php(207): WPML\BlockEditor\Loader->registerBlocks()
#3 /wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Either.php(257): WPML\FP\Right->map()
#4 /wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Promise.php(24): WPML\FP\Right->chain()
#5 /wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Hooks.php(50): WPML\FP\Promise->resolve()
#6 /wp-includes/class-wp-hook.php(308): WPML\LIB\WP\Hooks::WPML\LIB\WP{closure}()
#7 /wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#8 /wp-includes/plugin.php(517): WP_Hook->do_action()
#9 /wp-settings.php(568): do_action()
#10 /wp-config.php(101): require_once(‘…’)
#11 /wp-load.php(50): require_once(‘…’)
#12 /wp-admin/admin.php(34): require_once(‘…’)
#13 /wp-admin/plugins.php(10): require_once(‘…’)
#14 {main}
thrown in /wp-content/plugins/sitepress-multilingual-cms/classes/block-editor/Blocks/LanguageSwitcher.php on line 47

This is critical plugin for my websites, so I am wondering if anyone else encounters the same issue and has a workaround?

Thanks.

Please check “Block compatibility” under “Settings” → “General” And try with “Off”.

Hi @Simone,

I tried this before I posted the issue, but changing the option value doesn’t help.

On the WPML website, they say: “WPML is compatible with WordPress versions 3.0 and above.” So maybe you should raise this with them too.

Thinking about this further, it seems that WPML works without blocks but is looking for blocks with CP v2. So there must be something in CP v2 that makes WPML think it uses blocks.

If you can ask WPML what this “trigger” is, we should be able to fix the issue. Unfortunately, since that’s a paid plugin that I don’t personally use, I can’t just go through the code myself and take a look

I admit I didn’t test this plugin in CP RC 2, because it is working in 1.7.2, so I assumed it shouldn’t cause any issues in the final release :). Will try to enquiry support team about this.

Please try to upload new version of Multilingual CMS plugin from here.

I already use the newest version.

I’ve been discussing the issue with WPML support for a last few days, and while not fully resolved, the following piece of code prevents from throwing the fatal error and allows using WPML in CP ver. 2.0.0.:

  1. Go to wp-content/plugins/sitepress-multilingual-cms/classes/block-editor/class-wpml-block-editor-helper.php
  2. On line 31, just before “return true;”
  3. Add this condition:
if ( ! function_exists( 'register_block_type' ) ) {
    return false;
}

However, in my local website, the above fix caused subsequent fatal error:
PHP Fatal error: Uncaught Error: Call to undefined function WPML\BlockEditor\wp_enqueue_block_style() in /wp-content/plugins/sitepress-multilingual-cms/classes/block-editor/Loader.php:97
which I fixed by commenting a few lines in Loader.php:

public function maybeEnqueueNavigationBlockStyles() {
if ( ! wp_style_is( 'wp-block-navigation', 'enqueued' ) || ! wp_style_is( 'wp-block-navigation', 'queue' ) ) {
//wp_enqueue_block_style( LanguageSwitcher::BLOCK_LANGUAGE_SWITCHER, [
// 'handle' => 'wp-block-navigation'
//] );
}
}

This was not necessary in the live website, so apparently this might be server configuration-related.

And one more thing: When translating content, I had to enable use of “WordPress Editor” for the entire content, because “WPML Translation Editor” was throwing other fatal errors, apparently related to blocks.

I was told the issues might be resolved in the future WPML releases, but maybe this will help to apply a fix on the CP side anyway. And obviously before applying the above fix it is advised to back up the website.

Thanks Andrey from WPML for help.

2 Likes

Just a side note:
register_block_type can be checked to see if the site is on WP 4.9.
And was also valid to determine that the site is on ClassicPress v1.
But now that v2 has polyfilled version of some block function, the best way is to check for is classicpress_version function.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.