John Garcia Fernandez
asked 4 years ago

Hello. Congratulations for this awesome plugin.

I need to include the TinyMCE in the comments textarea. Is it possible?

Thanks.

1 Answers
DominicStaff
answered 4 years ago

At the moment, our plugin does not support to make TinyMCE in comments Textarea. If you want to have it, you can try to add the following code to the functions.php file.

add_filter('dwqa_ask_form_tag_output','dwqa_ask_form_tag_output',10,1);
function dwqa_ask_form_tag_output($output){
    $args=array(
      'orderby'    => 'count',
      'order'    => 'DESC',
      'hide_empty' => false,
     );
    $tag_terms=get_terms('dwqa-question_tag', $args ) ;
    $output='<select name="question-tag" id="question-tag" class="postform">';
    $output.='<option value="">Select question Tags</option>';
    foreach($tag_terms as $tag_term)
      $output.='<option value="'.$tag_term->name.'">'.$tag_term->name.'</option>';
    $output.='</select>';
  return $output;
}

add_filter( 'comment_form_field_comment', 'comment_editor' );

function comment_editor() {
  global $post;

  ob_start();

  wp_editor( '', 'comment', array(
    'textarea_rows' => 15,
    'teeny' => true,
    'quicktags' => false,
    'media_buttons' => false
  ) );

  $editor = ob_get_contents();

  ob_end_clean();

  //make sure comment media is attached to parent post
  $editor = str_replace( 'post_id=0', 'post_id='.get_the_ID(), $editor );

  return $editor;
}

// wp_editor doesn't work when clicking reply. Here is the fix.
add_action( 'wp_enqueue_scripts', '__THEME_PREFIX__scripts' );
function __THEME_PREFIX__scripts() {
    wp_enqueue_script('jquery');
}
add_filter( 'comment_reply_link', '__THEME_PREFIX__comment_reply_link' );
function __THEME_PREFIX__comment_reply_link($link) {
    return str_replace( 'onclick=', 'data-onclick=', $link );
}
add_action( 'wp_head', '__THEME_PREFIX__wp_head' );
function __THEME_PREFIX__wp_head() {
?>
<script type="text/javascript">
  jQuery(function($){
    $('.comment-reply-link').click(function(e){
      e.preventDefault();
      var args = $(this).data('onclick');
      args = args.replace(/.*\(|\)/gi, '').replace(/\"|\s+/g, '');
      args = args.split(',');
      tinymce.EditorManager.execCommand('mceRemoveEditor', true, 'comment');
      addComment.moveForm.apply( addComment, args );
      tinymce.EditorManager.execCommand('mceAddEditor', true, 'comment');
    });
  });
</script>
<?php } ?>

Then add the following code to the style.css file:

.dwqa-comment-form #submit {
    display: block;
}

Hope this helps!

john_garcia_fernandez
replied 4 years ago

Hello Dominic, Thanks for your answer.
I have tried the solution, but unfortunately it does not work.

dominic Staff
replied 4 years ago

You can send me username & password of your site via private answer for further checking.

Powered by DW Question & Answer Pro