- ステータス
- 開発者からの返答待ち
- 関連するプラグイン/テーマ
- Visual Composer
- トピックタグ
- Bug, Compatibility
問題の概要
WPMLとVisual Composer Proを併用している場合、「翻訳管理」ページにアクセスすると以下の致命的なエラーが発生する場合があります:
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(