From 701766f88b61b7ab9af90df5c659cc8e494c23b1 Mon Sep 17 00:00:00 2001 From: Tony Arcangelini Date: Thu, 5 Nov 2026 18:57:58 +0100 Subject: [PATCH 1/4] Turn off comment Markdown while the block editor is on --- .../changelog/update-comments-skip-markdown | 4 ++++ .../src/editor/class-block-editor.php | 11 +++++++++++ .../comments/tests/php/Block_Editor_Test.php | 19 +++++++++++++++++++ .../_inc/client/discussion/comments.jsx | 16 +++++++++++++++- .../changelog/update-comments-skip-markdown | 4 ++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 projects/packages/comments/changelog/update-comments-skip-markdown create mode 100644 projects/plugins/jetpack/changelog/update-comments-skip-markdown diff --git a/projects/packages/comments/changelog/update-comments-skip-markdown b/projects/packages/comments/changelog/update-comments-skip-markdown new file mode 100644 index 000000000000..2344a0ee7074 --- /dev/null +++ b/projects/packages/comments/changelog/update-comments-skip-markdown @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Turn off Markdown in comments while the block editor is on. diff --git a/projects/packages/comments/src/editor/class-block-editor.php b/projects/packages/comments/src/editor/class-block-editor.php index a9e5eaee05e9..5194cf9c74ed 100644 --- a/projects/packages/comments/src/editor/class-block-editor.php +++ b/projects/packages/comments/src/editor/class-block-editor.php @@ -49,6 +49,7 @@ private function __construct() { // Either side of kses at 10, which lets the markup of these blocks through. add_filter( 'pre_comment_content', array( $this, 'keep_allowed_blocks' ), 9 ); add_filter( 'pre_comment_content', array( $this, 'forget_blocks' ), 11 ); + add_filter( 'pre_option_wpcom_publish_comments_with_markdown', array( __CLASS__, 'skip_markdown' ) ); add_filter( 'wp_kses_allowed_html', array( $this, 'allowed_html' ), 10, 2 ); // Ahead of wpautop at 30. add_filter( 'comment_text', array( __CLASS__, 'render' ), 5, 2 ); @@ -119,6 +120,16 @@ public static function is_enabled() { return (bool) apply_filters( 'jetpack_comments_block_editor', (bool) get_option( 'enable_blocks_comments', true ) ); } + /** + * Turn off Jetpack Markdown for comments while the editor is on, since it would rewrite the editor's markup. + * + * @param mixed $pre The short-circuit value, false to read the stored option. + * @return mixed + */ + public static function skip_markdown( $pre ) { + return self::is_enabled() ? 0 : $pre; + } + /** * Drop any block the editor does not offer. * diff --git a/projects/packages/comments/tests/php/Block_Editor_Test.php b/projects/packages/comments/tests/php/Block_Editor_Test.php index 21921f403b49..b9d2492517f1 100644 --- a/projects/packages/comments/tests/php/Block_Editor_Test.php +++ b/projects/packages/comments/tests/php/Block_Editor_Test.php @@ -35,4 +35,23 @@ public static function provide_keep_allowed_blocks() { 'heading becomes bold' => array( '

Hi

', "\n

Hi

\n" ), ); } + + /** + * @dataProvider provide_skip_markdown + */ + #[DataProvider( 'provide_skip_markdown' )] + public function test_skip_markdown( $editor_on, $expected ) { + add_filter( 'pre_option_wpcom_publish_comments_with_markdown', array( Block_Editor::class, 'skip_markdown' ) ); + update_option( 'wpcom_publish_comments_with_markdown', '1' ); + add_filter( 'jetpack_comments_block_editor', $editor_on ? '__return_true' : '__return_false' ); + + $this->assertSame( $expected, get_option( 'wpcom_publish_comments_with_markdown' ) ); + } + + public static function provide_skip_markdown() { + return array( + 'editor on turns Markdown off' => array( true, 0 ), + 'editor off keeps the setting' => array( false, '1' ), + ); + } } diff --git a/projects/plugins/jetpack/_inc/client/discussion/comments.jsx b/projects/plugins/jetpack/_inc/client/discussion/comments.jsx index 69d073f89fcd..080230d2badf 100644 --- a/projects/plugins/jetpack/_inc/client/discussion/comments.jsx +++ b/projects/plugins/jetpack/_inc/client/discussion/comments.jsx @@ -60,7 +60,11 @@ class CommentsComponent extends Component { gravatar = this.props.getModule( 'gravatar-hovercards' ), markdown = this.props.getModule( 'markdown' ), commentLikesUnavailable = isUnavailableInOfflineMode( 'comment-likes' ), - commentLikesActive = getOptionValue( 'comment-likes' ); + commentLikesActive = getOptionValue( 'comment-likes' ), + markdownReplacedByEditor = + this.props.hasBlockEditor && + isCommentsActive && + !! this.props.getOptionValue( 'enable_blocks_comments', 'comments' ); return ( } + help={ + markdownReplacedByEditor + ? __( + 'Markdown is off while blocks in comments are on, since the editor has its own formatting toolbar.', + 'jetpack' + ) + : null + } __nextHasNoMarginBottom={ true } /> diff --git a/projects/plugins/jetpack/changelog/update-comments-skip-markdown b/projects/plugins/jetpack/changelog/update-comments-skip-markdown new file mode 100644 index 000000000000..1743551a9b19 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-comments-skip-markdown @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +Discussion: Grey out the comment Markdown setting while blocks in comments are on. From 083326a063f5f2d32d9064c7385ca4da3b0bdfae Mon Sep 17 00:00:00 2001 From: Tony Arcangelini Date: Thu, 5 Nov 2026 19:21:07 +0100 Subject: [PATCH 2/4] Unhook Markdown instead of filtering its option --- .../src/editor/class-block-editor.php | 16 ++++++++++------ .../comments/tests/php/Block_Editor_Test.php | 19 ------------------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/projects/packages/comments/src/editor/class-block-editor.php b/projects/packages/comments/src/editor/class-block-editor.php index 5194cf9c74ed..907c24925d10 100644 --- a/projects/packages/comments/src/editor/class-block-editor.php +++ b/projects/packages/comments/src/editor/class-block-editor.php @@ -49,7 +49,7 @@ private function __construct() { // Either side of kses at 10, which lets the markup of these blocks through. add_filter( 'pre_comment_content', array( $this, 'keep_allowed_blocks' ), 9 ); add_filter( 'pre_comment_content', array( $this, 'forget_blocks' ), 11 ); - add_filter( 'pre_option_wpcom_publish_comments_with_markdown', array( __CLASS__, 'skip_markdown' ) ); + add_filter( 'pre_comment_content', array( __CLASS__, 'skip_markdown' ), 8 ); add_filter( 'wp_kses_allowed_html', array( $this, 'allowed_html' ), 10, 2 ); // Ahead of wpautop at 30. add_filter( 'comment_text', array( __CLASS__, 'render' ), 5, 2 ); @@ -121,13 +121,17 @@ public static function is_enabled() { } /** - * Turn off Jetpack Markdown for comments while the editor is on, since it would rewrite the editor's markup. + * Unhook Jetpack Markdown for comments while the editor is on, since it would rewrite the editor's markup. * - * @param mixed $pre The short-circuit value, false to read the stored option. - * @return mixed + * @param string $content Slashed comment content. + * @return string */ - public static function skip_markdown( $pre ) { - return self::is_enabled() ? 0 : $pre; + public static function skip_markdown( $content ) { + if ( class_exists( 'WPCom_Markdown', false ) && self::is_enabled() ) { + remove_filter( 'pre_comment_content', array( \WPCom_Markdown::get_instance(), 'pre_comment_content' ), 9 ); + } + + return $content; } /** diff --git a/projects/packages/comments/tests/php/Block_Editor_Test.php b/projects/packages/comments/tests/php/Block_Editor_Test.php index b9d2492517f1..21921f403b49 100644 --- a/projects/packages/comments/tests/php/Block_Editor_Test.php +++ b/projects/packages/comments/tests/php/Block_Editor_Test.php @@ -35,23 +35,4 @@ public static function provide_keep_allowed_blocks() { 'heading becomes bold' => array( '

Hi

', "\n

Hi

\n" ), ); } - - /** - * @dataProvider provide_skip_markdown - */ - #[DataProvider( 'provide_skip_markdown' )] - public function test_skip_markdown( $editor_on, $expected ) { - add_filter( 'pre_option_wpcom_publish_comments_with_markdown', array( Block_Editor::class, 'skip_markdown' ) ); - update_option( 'wpcom_publish_comments_with_markdown', '1' ); - add_filter( 'jetpack_comments_block_editor', $editor_on ? '__return_true' : '__return_false' ); - - $this->assertSame( $expected, get_option( 'wpcom_publish_comments_with_markdown' ) ); - } - - public static function provide_skip_markdown() { - return array( - 'editor on turns Markdown off' => array( true, 0 ), - 'editor off keeps the setting' => array( false, '1' ), - ); - } } From 9179600207b8d4e712afdd1489618e876539fe73 Mon Sep 17 00:00:00 2001 From: Tony Arcangelini Date: Thu, 5 Nov 2026 19:30:40 +0100 Subject: [PATCH 3/4] Fix Phan --- projects/packages/comments/src/editor/class-block-editor.php | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/packages/comments/src/editor/class-block-editor.php b/projects/packages/comments/src/editor/class-block-editor.php index 907c24925d10..045313abddbb 100644 --- a/projects/packages/comments/src/editor/class-block-editor.php +++ b/projects/packages/comments/src/editor/class-block-editor.php @@ -128,6 +128,7 @@ public static function is_enabled() { */ public static function skip_markdown( $content ) { if ( class_exists( 'WPCom_Markdown', false ) && self::is_enabled() ) { + // @phan-suppress-next-line PhanUndeclaredClassMethod -- The Jetpack plugin's Markdown module defines it, checked above. remove_filter( 'pre_comment_content', array( \WPCom_Markdown::get_instance(), 'pre_comment_content' ), 9 ); } From 7de3564d9a29573c15aa0d6a270e813fc4a95bbc Mon Sep 17 00:00:00 2001 From: Tony Arcangelini Date: Thu, 5 Nov 2026 23:33:52 +0100 Subject: [PATCH 4/4] Explain Markdown instead of turning it off --- .../changelog/update-comments-skip-markdown | 4 ---- .../comments/src/editor/class-block-editor.php | 16 ---------------- .../jetpack/_inc/client/discussion/comments.jsx | 8 +++----- .../changelog/update-comments-skip-markdown | 2 +- 4 files changed, 4 insertions(+), 26 deletions(-) delete mode 100644 projects/packages/comments/changelog/update-comments-skip-markdown diff --git a/projects/packages/comments/changelog/update-comments-skip-markdown b/projects/packages/comments/changelog/update-comments-skip-markdown deleted file mode 100644 index 2344a0ee7074..000000000000 --- a/projects/packages/comments/changelog/update-comments-skip-markdown +++ /dev/null @@ -1,4 +0,0 @@ -Significance: patch -Type: changed - -Turn off Markdown in comments while the block editor is on. diff --git a/projects/packages/comments/src/editor/class-block-editor.php b/projects/packages/comments/src/editor/class-block-editor.php index 045313abddbb..a9e5eaee05e9 100644 --- a/projects/packages/comments/src/editor/class-block-editor.php +++ b/projects/packages/comments/src/editor/class-block-editor.php @@ -49,7 +49,6 @@ private function __construct() { // Either side of kses at 10, which lets the markup of these blocks through. add_filter( 'pre_comment_content', array( $this, 'keep_allowed_blocks' ), 9 ); add_filter( 'pre_comment_content', array( $this, 'forget_blocks' ), 11 ); - add_filter( 'pre_comment_content', array( __CLASS__, 'skip_markdown' ), 8 ); add_filter( 'wp_kses_allowed_html', array( $this, 'allowed_html' ), 10, 2 ); // Ahead of wpautop at 30. add_filter( 'comment_text', array( __CLASS__, 'render' ), 5, 2 ); @@ -120,21 +119,6 @@ public static function is_enabled() { return (bool) apply_filters( 'jetpack_comments_block_editor', (bool) get_option( 'enable_blocks_comments', true ) ); } - /** - * Unhook Jetpack Markdown for comments while the editor is on, since it would rewrite the editor's markup. - * - * @param string $content Slashed comment content. - * @return string - */ - public static function skip_markdown( $content ) { - if ( class_exists( 'WPCom_Markdown', false ) && self::is_enabled() ) { - // @phan-suppress-next-line PhanUndeclaredClassMethod -- The Jetpack plugin's Markdown module defines it, checked above. - remove_filter( 'pre_comment_content', array( \WPCom_Markdown::get_instance(), 'pre_comment_content' ), 9 ); - } - - return $content; - } - /** * Drop any block the editor does not offer. * diff --git a/projects/plugins/jetpack/_inc/client/discussion/comments.jsx b/projects/plugins/jetpack/_inc/client/discussion/comments.jsx index 080230d2badf..2966329ed8f1 100644 --- a/projects/plugins/jetpack/_inc/client/discussion/comments.jsx +++ b/projects/plugins/jetpack/_inc/client/discussion/comments.jsx @@ -61,7 +61,7 @@ class CommentsComponent extends Component { markdown = this.props.getModule( 'markdown' ), commentLikesUnavailable = isUnavailableInOfflineMode( 'comment-likes' ), commentLikesActive = getOptionValue( 'comment-likes' ), - markdownReplacedByEditor = + hasCommentEditor = this.props.hasBlockEditor && isCommentsActive && !! this.props.getOptionValue( 'enable_blocks_comments', 'comments' ); @@ -170,14 +170,12 @@ class CommentsComponent extends Component { } help={ - markdownReplacedByEditor + hasCommentEditor ? __( - 'Markdown is off while blocks in comments are on, since the editor has its own formatting toolbar.', + 'Comments written in the block editor use its toolbar for formatting instead.', 'jetpack' ) : null diff --git a/projects/plugins/jetpack/changelog/update-comments-skip-markdown b/projects/plugins/jetpack/changelog/update-comments-skip-markdown index 1743551a9b19..3f0c21f6f2a9 100644 --- a/projects/plugins/jetpack/changelog/update-comments-skip-markdown +++ b/projects/plugins/jetpack/changelog/update-comments-skip-markdown @@ -1,4 +1,4 @@ Significance: patch Type: enhancement -Discussion: Grey out the comment Markdown setting while blocks in comments are on. +Discussion: Explain that comment Markdown doesn't apply to comments written in the block editor.