Automattic\WooCommerce\Internal\EmailEditor

EmailApiController::get_change_summary_response │ public │ WC 10.9.0

Return a localized summary of differences between the merchant's woo_email post and the canonical core render.

Thin wrapper over WCEmailTemplateChangeSummary::summarize(). The
404 path mirrors {@see self::get_default_content_response()} — when the email type cannot be resolved from the post ID, the post is either non-existent or not a woo_email.

The 200 path differs for valid posts that are NOT in WCEmailTemplateSyncRegistry{}: default-content returns the canonical content; change-summary returns a fallback payload with is_fallback: true and a generic release-notes line because no registered version is available to diff against. Consumers gating on is_fallback should treat that case as "no actionable summary," regardless of HTTP status.

Метод класса: EmailApiController{}

Хуков нет.

Возвращает

WP_REST_Response|WP_Error.

Использование

$EmailApiController = new EmailApiController();
$EmailApiController->get_change_summary_response( $request );
$request(WP_REST_Request) (обязательный)
The REST request.

Список изменений

С версии 10.9.0 Введена.

Код EmailApiController::get_change_summary_response() WC 11.3.0

public function get_change_summary_response( WP_REST_Request $request ) {
	if ( ! ( $this->post_manager && $this->posts_generator ) ) {
		return new WP_Error(
			'woocommerce_email_editor_not_initialized',
			__( 'Email editor is not initialized.', 'woocommerce' ),
			array( 'status' => 500 )
		);
	}

	$post_id    = (int) $request->get_param( 'id' );
	$email_type = $this->post_manager->get_email_type_from_post_id( $post_id );
	$email      = $this->get_email_by_type( $email_type ?? '' );

	if ( ! $email ) {
		return new WP_Error(
			'woocommerce_email_not_found',
			__( 'No email found for the given post ID.', 'woocommerce' ),
			array( 'status' => 404 )
		);
	}

	return new WP_REST_Response(
		WCEmailTemplateChangeSummary::summarize( $post_id ),
		200
	);
}