Skip to content

Commit

Permalink
Inline Comments: Strip 'data-incom' attribute during post save.
Browse files Browse the repository at this point in the history
The Inline Comments plugin adds the 'data-incom' attribute to the content.

This attribute should never be saved into the database as it interferes
with revisions via auto-save and comment positioning.

See #42.
  • Loading branch information
r-a-y committed Oct 30, 2015
1 parent 90b65f2 commit ea7ba24
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions includes/hooks-inline-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,3 +568,24 @@ function cacsp_update_comment_references( $post_id ) {

}
add_action( 'save_post', 'cacsp_update_comment_references' );

/**
* Strip the 'data-incom' attribute from paper content.
*
* Inline Comments adds a 'data-incom' attribute to the content. When a
* frontend editor is enabled, this attribute should not be saved into the DB
* as it interferes with comment positioning.
*
* @param array $retval Post data.
* @param array $post Post attributes.
* @return array
*/
function cacsp_inline_comments_strip_data_incom_attribute( $retval, $post ) {
if ( 'cacsp_paper' !== $post['post_type'] ) {
return $retval;
}

$retval['post_content'] = preg_replace('/(<[^>]+) data-incom=".*?"/i', '$1', $retval['post_content'] );
return $retval;
}
add_filter( 'wp_insert_post_data', 'cacsp_inline_comments_strip_data_incom_attribute', 10, 2 );

0 comments on commit ea7ba24

Please sign in to comment.