WPML
Status
Aguardando o autor
Plugin/tema relacionado
Visual Composer
Tags de tópico
Bug, Compatibility

Visão geral do problema

Ao usar o Visual Composer Pro com o WPML, você pode encontrar o seguinte erro fatal ao acessar a página Gerenciamento de tradução:

PHP Fatal error: Uncaught TypeError: Argument 2 passed to WPML\Core\SharedKernel\Component\Post\Application\Query\Dto\PostTypeDto::__construct() must be of the type string, null given, called in ../public_html/wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wpml/src/Core/SharedKernel/Component/Post/Application/Query/Dto/PostTypeDto.php:26

Solução alternativa

Certifique-se de ter um backup completo do seu site antes de prosseguir.

Solução alternativa 1 (Recomendada)

Adicione o seguinte código ao arquivo functions.php do seu tema:

add_filter( 'wpml_post_type_dto_filter', function ( $postTypeObject ) {
	if ( is_object( $postTypeObject ) ) {
		$default = $postTypeObject->name ?? '';
		if ( ! isset( $postTypeObject->labels ) || ! is_object( $postTypeObject->labels ) ) {
			$postTypeObject->labels = new stdClass();
		}
		if ( empty( $postTypeObject->name ) ) {
			$postTypeObject->name = $default;
		}

		if ( empty( $postTypeObject->labels->name ) ) {
			$postTypeObject->labels->name = $default;
		}

		if ( empty( $postTypeObject->labels->singular_name ) ) {
			$postTypeObject->labels->singular_name = $default;
		}
	}
	return $postTypeObject;
} );
  
Solução alternativa 2 (Alternativa)

Esta solução alternativa envolve a modificação direta do código do plugin, que pode ser perdida em atualizações.

  • Abra: /wp-content/uploads/visualcomposer-assets/addons/themeEditor/themeEditor/PostTypeController.php
  • Procure por:

    protected function registerPostType()
        {
            register_post_type(  
  • E substitua por:
    protected function registerPostType()
         {
    	if (!isset($this->postNamePlural)){
    		$this->postNamePlural = $this->postNameSlug;
         }
       register_post_type(
      

Todos os problemas conhecidos →