My “fix” introduced an error when people wanted to edit a post, they always had a post id of 0.
I changed the function to save the original post id and restore it before exiting this function. Then checks ownership of the post and sets the media as unattached only if the current user does not own the post the comment is on.
This is the modified function:
function mdc_comment_toolbar() {
global $post;
global $current_user;
// save post ID
$post_id_orig = $post->ID;
/* a post->ID of '0' means the media is unattached.
** if the current user does not own the post, use post->ID = '0'
** or if the user can 'edit any post', keep the post->ID
*/
$current_user = wp_get_current_user();
if ( !(( current_user_can('edit_others_posts')) || ($current_user->ID == $post->post_author)) ) {
$post->ID = 0;
}
ob_start();
wp_editor( '', 'comment', array(
'textarea_rows' => textarea_rows(),
'teeny' => is_teeny(), //hide some icons
'quicktags' => is_quick_tag(), //enable html toolbar
'media_buttons' => is_media_button(),
'drag_drop_upload' => is_media_button()
)
);
$toolbar = ob_get_contents();
ob_end_clean();
// make sure comment media is attached to parent post
$toolbar = str_replace( 'post_id=0', 'post_id='.get_the_ID(), $toolbar );
// get back post ID
$post->ID = $post_id_orig;
return $toolbar;
}