WPML
상태
미해결
주제 태그
WCML

문제 개요

WooCommerce 상품 짧은 설명은 글 요약 필드를 기반으로 하며, 이는 일반적으로 숏코드를 처리하지 않는 단순한 텍스트 필드입니다. 따라서 글 요약에 페이지 빌더 숏코드를 붙여넣어도 작동할 것으로 예상되지 않으며, 글 요약을 번역할 때 WPML은 이러한 숏코드를 처리하려고 시도하지 않습니다.

하지만 WC는 이러한 “요약”을 조금 다르게 처리하여 숏코드가 작동하지만, WPML은 여전히 작동하지 않는 것처럼 동작합니다. 따라서 숏코드에 번역이 필요한 속성이나 자동으로 처리해야 하는 내부 링크가 포함되어 있는 경우 이를 원활하게 처리할 수 없습니다.

임시 해결 방법

이 기능을 제공하기 위해 플러그인으로 추가할 수 있는 코드를 준비했습니다. 아래 코드를 복사하여 wpmlpb-excerpts.php라는 이름의 파일에 붙여넣고 wp-content/plugins/ 디렉터리에 저장한 다음 플러그인을 활성화하세요.

<?php
/**
 * Plugin Name: WPML Page Builders - Proces Excerpts
 * Description: Parses shortcode strings in exceprts.
 * Version: 1.0
 */
namespace WPMLPB686;

( new Excerpts() )->add_hooks();

class Excerpts {

	const SEPARATOR_START = '<!--WPML_EXCERPT_START-->';
	const SEPARATOR_END   = '<!--WPML_EXCERPT_END-->';

	public function add_hooks() {
		add_filter( 'wpml_pb_shortcode_content_for_translation', [ $this, 'joinWithContent' ], 10, 2 );
		add_filter( 'wpml_tm_translation_job_data', [ $this, 'excludeFromJob' ], 10, 2 );
		add_action( 'wpml_pro_translation_completed', [ $this, 'splitFromContent' ], 999 );
	}

	public function joinWithContent( $content, $id ) {
		$post = get_post( $id );
		if ( $post && $post->post_excerpt ) {
			$content .= self::SEPARATOR_START . $post->post_excerpt . self::SEPARATOR_END;
		}

		return $content;
	}

	public function excludeFromJob( $package, $post ) {
		if ( preg_match( '/[[^]]+]/', $post->post_excerpt ) ) {
			$package['contents']['excerpt']['translate'] = 0;
			$package['contents']['excerpt']['data']      = '';
		}

		return $package;
	}

	public function splitFromContent( $post_id ) {
		$post = get_post( $post_id );
		if ( $post && false !== strpos( $post->post_content, self::SEPARATOR_START ) ) {
			$start_pos = strpos( $post->post_content, self::SEPARATOR_START );
			$end_pos   = strpos( $post->post_content, self::SEPARATOR_END, $start_pos );

			if ( false !== $end_pos ) {
				$content = substr( $post->post_content, 0, $start_pos );
				$excerpt = substr( $post->post_content, $start_pos + strlen( self::SEPARATOR_START ), $end_pos - $start_pos - strlen( self::SEPARATOR_START ) );

				if ( $excerpt ) {
					wp_update_post(
						[
							'ID'           => $post_id,
							'post_content' => $content,
							'post_excerpt' => $excerpt,
						]
					);
				}
			}
		}
	}
}

알려진 모든 문제 →