WPML
状态
等待作者
相关插件/主题
Visual Composer
主题标签
Bug, Compatibility

问题概述

Visual Composer Pro 与 WPML 配合使用并访问“翻译管理”页面时,您可能会遇到以下致命错误:

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

临时解决方法

继续操作前,请确保您已对站点进行了完整备份。

临时解决方法 1(推荐)

将以下代码添加到您主题的 functions.php 文件中:

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;
} );
  
临时解决方法 2(备选)

此临时解决方法涉及直接修改插件代码,这些修改可能会在更新时丢失。

  • 打开:/wp-content/uploads/visualcomposer-assets/addons/themeEditor/themeEditor/PostTypeController.php
  • 查找:

    protected function registerPostType()
        {
            register_post_type(  
  • 并将其替换为:
    protected function registerPostType()
         {
    	if (!isset($this->postNamePlural)){
    		$this->postNamePlural = $this->postNameSlug;
         }
       register_post_type(
      

所有已知问题 →