Automattic / jetpack

Security, performance, marketing, and design tools — Jetpack is made by WordPress experts to make WP sites safer and faster, and help you grow your traffic.
https://jetpack.com/
Other
1.59k stars 799 forks source link

Markdown: Filtered content lost when editing `menu_order` without passing content. #5272

Open lumpysimon opened 8 years ago

lumpysimon commented 8 years ago

48 out of 56 posts on my site that were previously in markdown are now only in HTML.

The post_content_filtered column for these posts contains HTML, not markdown as I would expect it to.

I have yet to establish a cause or pattern, or notice at what point the posts switched from markdown to HTML.

Unlike #1624 there are no shortcodes in these posts.

Please let me know if there is anything I can do to help pin down the issue.

kraftbj commented 8 years ago

The most common cause I've seen for that is something saving post content that bypasses the filters we setup to process markdown content. What methods have you used to edit those posts (Quick Edit via the posts list table, the text editor, the visual editor, offline/mobile editors, REST API clients, XMLRPC clients, etc)?

lumpysimon commented 8 years ago

Post content is only saved using the standard post editor admin screen (in text mode, not WYSIWYG). We're not using quick edit, REST, XMLRPC etc.

All affected posts are a custom post type, the only thing we do to those is hook into the save_post action to save some post meta fields, but we don't touch post_content or post_content_filtered.

We use wp_update_post function to update the menu_order column, but we just pass in the ID and menu_order, not the content.

It seems that posts are ok for a while, then after some time they seem to switch to HTML, but I have no idea why that might be the case.

jeherve commented 8 years ago

What happens if you do not run your function to update the menu_order column? Does the problem remain on post update?

jeherve commented 7 years ago

Closing this for now, feel free to reopen if you have more details!

lumpysimon commented 7 years ago

Sorry for not updating you - we decided to go with HTML in the end instead of Markdown.

justintadlock commented 7 years ago

@jeherve - I can confirm this behavior. I have a forum plugin that I just integrated with Jetpack Markdown. The topic/thread "positions" in the forum are handled via the menu_order field. Whenever a topic's position is updated, the following code is called:

function mb_set_topic_position( $topic_id, $position ) {
    return wp_update_post( array( 'ID' => $topic_id, 'menu_order' => $position ) );
}

That triggers this code in Jetpack's easy-markdown.php (from filter on wp_insert_post_data):

$post_data['post_content_filtered'] = apply_filters( 'wpcom_untransformed_content', $post_data['post_content'] );

Edit: My previous code to fix this didn't actually work.

Here's how I changed my function above to bypass this:

function mb_set_topic_position( $topic_id, $position ) {

    $data = array( 'ID' => $topic_id, 'menu_order' => $position );

    $is_markdown = get_post_meta( $topic_id, '_wpcom_is_markdown', true );

    if ( $is_markdown ) {

        $post = get_post( $topic_id );

        if ( ! empty( $post->post_content_filtered ) )
            $data['post_content'] = $post->post_content_filtered;
    }

    return wp_update_post( $data );
}
jeherve commented 7 years ago

Thanks for the extra details!

tedeh commented 6 years ago

I have the same issue.

My Wordpress version is 4.9.1. and my Jetpack version is 5.3.

Commenting out this line https://github.com/Automattic/jetpack/blob/master/modules/markdown/easy-markdown.php#L452 makes the issue disappear.

There seems to be a conflict with another plugin I'm using, "Markdown Editor By SEO Themes" at version 0.1.3 although I'm not sure exactly which plugin owns this issue. When using the Visual Editor with that plugin disabled (and only Jetpack) my Markdown is also destructively converted.

This message appears when using "Save as Draft", it seems to be related.

The backup of this post in your browser is different from the version below.
stale[bot] commented 6 years ago

This issue has been marked as stale. This happened because:

No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.

justintadlock commented 6 years ago

As far as I know, it's still an issue (see earlier notes).

tedeh commented 6 years ago

The bot said is not an issue. Move along fellows...

coder-karen commented 6 years ago

Potentially related issue in 1440262-zen

stale[bot] commented 5 years ago

This issue has been marked as stale. This happened because:

No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.