Hello!
I'm developing WP plugin that needs to modify post content AFTER post is saved (so I'm sure it has and ID and permalink). I want it to fire only when users presses "publish" or "update" button (not for autosave).
My idea was to hook to "save post" action, change what I need and use $wpdb->update() to modify row in wp_post table. I came up with something similar to following code:
function myplugin_parse_post( $postId )
{
global $post, $wpdb;
$post->post_content = $post->post_content . '<div>my addition</div>';
$wpdb->update( $wpdb->posts, array( 'post_content' => $post->post_content ), array( 'ID' => $postId ) );
}
add_action( 'save_post', 'myplugin_parse_post' );
After trying out my plugin I realized that this doesn't work. I checked revisions and saw that they were modified, however changes weren't visible in editor.
I tried a few different approaches (like using wp_is_post_revision()) but none of them worked.
Can you help me with this? WP plugin development is new topic for me and it is a little difficult to understand how exactly saving post works.
Thanks!