WPML
Stato
In attesa dell’autore
Plugin/tema correlato
Visual Composer
Tag dell’argomento
Bug, Compatibility

Panoramica del problema

Quando usi Visual Composer Pro con WPML, potresti riscontrare il seguente errore fatale accedendo alla pagina Gestione traduzioni:

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

Soluzione alternativa

Assicurati di avere un backup completo del tuo sito prima di procedere.

Soluzione alternativa 1 (consigliata)

Aggiungi il seguente codice al file functions.php del tuo 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;
} );
  
Soluzione alternativa 2 (alternativa)

Questa soluzione alternativa comporta la modifica diretta del codice del plugin, che può andare persa con gli aggiornamenti.

  • Apri: /wp-content/uploads/visualcomposer-assets/addons/themeEditor/themeEditor/PostTypeController.php
  • Cerca:

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

Tutti i problemi noti →