Commit 194d87607e9 for woocommerce

commit 194d87607e99059e961b6c5c276b66e85288dff4
Author: Allison Levine <1689238+allilevine@users.noreply.github.com>
Date:   Thu Dec 3 09:50:36 2026 -0500

    Email Editor: Space the first paragraph of Classic editor posts in emails (#71675)

    * Email Editor: Wrap the first paragraph of Classic editor posts in emails

    Classic content has no blocks, so do_blocks renders it as one freeform
    block, which the email renderer wraps in a table before wpautop runs.
    wpautop then leaves the first paragraph bare, so the p + p gap never
    applies between the first two paragraphs. Run wpautop before the_content
    for content without blocks, and take it off the_content for that call so
    it doesn't run twice.

    * Email Editor: Check wpautop's priority in its own Post_Content test

    * Email Editor: Put wpautop back even when a the_content callback throws

    A render that throws partway through the_content would otherwise leave
    wpautop off the_content for every later render in the same request, such
    as the next email in a batch.

    * Email Editor: Restore the global post and query when a the_content callback throws

    Move the restore into the same finally block as wpautop, so a failed render
    doesn't leave later renders in the request pointing at the email post.

    * Email Editor: Rethrow unexpected exceptions in the wpautop restore test

diff --git a/packages/php/email-editor/changelog/fix-nl-1235-classic-first-paragraph b/packages/php/email-editor/changelog/fix-nl-1235-classic-first-paragraph
new file mode 100644
index 00000000000..2c532ae8243
--- /dev/null
+++ b/packages/php/email-editor/changelog/fix-nl-1235-classic-first-paragraph
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Add space between the first and second paragraphs of Classic editor posts in emails.
diff --git a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-post-content.php b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-post-content.php
index cddd62b1edd..07ad30134db 100644
--- a/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-post-content.php
+++ b/packages/php/email-editor/src/Integrations/Core/Renderer/Blocks/class-post-content.php
@@ -92,12 +92,27 @@ class Post_Content {
 			$post_content .= wp_link_pages( array( 'echo' => 0 ) );
 		}

-		// Apply the_content filter to process blocks.
-		$post_content = apply_filters( 'the_content', str_replace( ']]>', ']]&gt;', $post_content ) );
+		// Content without blocks (Classic editor) is one freeform block, which the email renderer wraps
+		// in a table before wpautop runs, so wpautop would leave the first paragraph unwrapped.
+		// Run wpautop first instead, and skip it in the_content so it doesn't run twice.
+		$wpautop_priority = has_blocks( $post_content ) ? false : has_filter( 'the_content', 'wpautop' );
+		if ( false !== $wpautop_priority ) {
+			$post_content = wpautop( $post_content );
+			remove_filter( 'the_content', 'wpautop', $wpautop_priority );
+		}
+
+		try {
+			// Apply the_content filter to process blocks.
+			$post_content = apply_filters( 'the_content', str_replace( ']]>', ']]&gt;', $post_content ) );
+		} finally {
+			if ( false !== $wpautop_priority ) {
+				add_filter( 'the_content', 'wpautop', $wpautop_priority );
+			}

-		// Restore global state.
-		$post     = $backup_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
-		$wp_query = $backup_query; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+			// Restore global state.
+			$post     = $backup_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+			$wp_query = $backup_query; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+		}

 		if ( empty( $post_content ) ) {
 			return '';
diff --git a/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php b/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php
index af328b921ad..9cdac93ed13 100644
--- a/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php
+++ b/packages/php/email-editor/tests/integration/Engine/Renderer/ContentRenderer/Content_Renderer_Test.php
@@ -1154,9 +1154,11 @@ class Content_Renderer_Test extends \Email_Editor_Integration_Test_Case {

 	/**
 	 * Paragraphs in one chunk of HTML (Classic content, a Custom HTML block) are separated by the
-	 * email's block gap, as paragraph blocks are.
+	 * email's block gap, as paragraph blocks are. Classic content saved without <p> tags gets them
+	 * on every paragraph.
 	 *
 	 * @testWith ["<p>First</p>\n<p>Second</p>"]
+	 *           ["First\n\nSecond"]
 	 *           ["<!-- wp:html --><p>First</p><p>Second</p><!-- /wp:html -->"]
 	 *
 	 * @param string $post_content Post content holding two paragraphs that are not paragraph blocks.
diff --git a/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Blocks/Post_Content_Test.php b/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Blocks/Post_Content_Test.php
index 29e62d40e7a..3db69b794a8 100644
--- a/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Blocks/Post_Content_Test.php
+++ b/packages/php/email-editor/tests/integration/Integrations/Core/Renderer/Blocks/Post_Content_Test.php
@@ -358,4 +358,50 @@ class Post_Content_Test extends \Email_Editor_Integration_Test_Case {

 		$this->assertSame( PHP_INT_MAX, $priority );
 	}
+
+	/**
+	 * Rendering Classic content takes wpautop off the_content for that render only, so it is put back
+	 * at the priority the site gave it. It and the global post and query are restored even when another
+	 * the_content callback throws.
+	 *
+	 * @testWith [false]
+	 *           [true]
+	 *
+	 * @param bool $a_callback_throws Whether a the_content callback throws during the render.
+	 * @throws \RuntimeException When the render fails for any other reason.
+	 */
+	public function testItRestoresWpautopAndGlobalsAfterRenderingClassicContent( bool $a_callback_throws ): void {
+		remove_filter( 'the_content', 'wpautop' );
+		add_filter( 'the_content', 'wpautop', 12 );
+		if ( $a_callback_throws ) {
+			add_filter(
+				'the_content',
+				static function ( string $content ): string {
+					if ( false !== strpos( $content, 'Second' ) ) {
+						throw new \RuntimeException( 'the_content failed' );
+					}
+					return $content;
+				}
+			);
+		}
+		$post_id      = $this->factory->post->create( array( 'post_content' => "First\n\nSecond" ) );
+		$block        = new \WP_Block( array( 'blockName' => 'core/post-content' ), array( 'postId' => $post_id ) );
+		$global_post  = $GLOBALS['post'] ?? null;
+		$global_query = $GLOBALS['wp_query'];
+		$threw        = false;
+
+		try {
+			( new Post_Content() )->render_stateless( array(), '', $block );
+		} catch ( \RuntimeException $e ) {
+			if ( 'the_content failed' !== $e->getMessage() ) {
+				throw $e;
+			}
+			$threw = true;
+		}
+
+		$this->assertSame( $a_callback_throws, $threw );
+		$this->assertSame( 12, has_filter( 'the_content', 'wpautop' ) );
+		$this->assertSame( $global_post, $GLOBALS['post'] ?? null );
+		$this->assertSame( $global_query, $GLOBALS['wp_query'] );
+	}
 }