-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix conflicts with markdown plugins #5288
Conversation
Here's the test case I have that duplicates this issue: 1. Install Jetpack and enable markdown 2. Create post in Gutenberg with a couple paragraphs. 3. Open post in classic editor and click update 4. One big paragraph. This change adds the filter on `wp_insert_post_data` since edits in classic editor do not go through the rest API. Additionally, it changes the call to remove markdown which is more inclusive of all the actions and filters this markdown implementation touches.
lib/plugin-compat.php
Outdated
} | ||
add_filter( 'rest_pre_insert_post', 'gutenberg_remove_wpcom_markdown_support' ); | ||
add_filter( 'wp_insert_post_data', 'gutenberg_remove_wpcom_markdown_support', 1, 1 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be so early in priority? Can't it just be one step before where Jetpack it filtering it at?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fourth argument is 1
by default and can be omitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
lib/plugin-compat.php
Outdated
remove_post_type_support( 'post', 'wpcom-markdown' ); | ||
function gutenberg_remove_wpcom_markdown_support( $post_data ) { | ||
if ( gutenberg_content_has_blocks( implode( "\n", $post_data ) ) ) { | ||
if ( class_exists ( 'WPCom_Markdown' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for nesting if
, just combine into the top-level condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
lib/plugin-compat.php
Outdated
remove_post_type_support( 'post', 'wpcom-markdown' ); | ||
function gutenberg_remove_wpcom_markdown_support( $post_data ) { | ||
if ( gutenberg_content_has_blocks( implode( "\n", $post_data ) ) ) { | ||
if ( class_exists ( 'WPCom_Markdown' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace issues here (needs tabs, not spaces).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, wrong editor.
lib/plugin-compat.php
Outdated
if ( gutenberg_content_has_blocks( $post->post_content ) ) { | ||
remove_post_type_support( 'post', 'wpcom-markdown' ); | ||
function gutenberg_remove_wpcom_markdown_support( $post_data ) { | ||
if ( gutenberg_content_has_blocks( implode( "\n", $post_data ) ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the shape of $post_data
? From what I can tell, it's a compacted associative array of all properties:
Why do we test anything other than content?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. I misread documentation that post_data was just the post_content in an array. I'm not sure what I did on my initial inspection of the data to convince me that was the case.
Thanks for the review @aduth - I rushed through the initial implementation and hadn't circled back yet to clean up. Updated with all the suggestions and fixed lint errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm that this resolves the issue with paragraphs being stripped when saving in the classic editor.
I'm seeing that the classic editor inserts many paragraphs of its own in-between the blocks, which persist into the published copy. Seeing whether this is specific to Markdown module...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra paragraph tags are unrelated to Markdown module, tracked separately at #3901
There is a conflict with wpcom-markdown which is used in Jetpack and other plugins which add markdown support.
Here's the test case that duplicates the issue:
Description
This change adds the filter on
wp_insert_post_data
sinceedits in classic editor do not go through the rest API.
Additionally, it changes the call to remove markdown which
is more inclusive of all the actions and filters this markdown
implementation touches.
Checklist: