Skip Navigation

Resolved

Reported for: WPML Multilingual CMS 4.6.3

Resolved in: WPML 4.6.4

Topic Tags: Compatibility

Overview of the issue

When using WPML with WordPress 4.7, a fatal error occurs due to the Language Switcher block being registered for translation. This happens even if Gutenberg is not enabled.

This causes compatibility issues with WordPress versions lower than 5.0.

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

Workaround

Our developers are aware of this situation and they are preparing a beta version of WPML to fix it. In the meantime:

  1. Please, be sure to have a full backup of your site before proceeding.
  2. Open the …/wp-content/plugins/sitepress-multilingual-cms/classes/block-editor/Loader.php file.
  3. Look for line 57.
  4. Change:
    	public function registerBlocks() {
    		$LSLocalizedScriptData     = make( LanguageSwitcher::class )->register();
    		$this->localizedScriptData = array_merge( $this->localizedScriptData, $LSLocalizedScriptData );
    	}
    

    To:

    	public function registerBlocks() {
    		if ( \WPML_Block_Editor_Helper::is_active() ) {
    			$LSLocalizedScriptData     = make( LanguageSwitcher::class )->register();
    			$this->localizedScriptData = array_merge( $this->localizedScriptData, $LSLocalizedScriptData );
    		}
    	}