-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorbis-comment-editor.php
72 lines (54 loc) · 1.74 KB
/
orbis-comment-editor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
Plugin Name: Orbis Comment Editor
Plugin URI: http://www.orbiswp.com/
Description: The Orbis Comment Editor plugin convert the comments textarea to a WordPress editor.
Version: 1.0.0
Requires at least: 3.5
Author: Pronamic
Author URI: http://www.pronamic.eu/
Text Domain: orbis-comment-editor
Domain Path: /languages/
License: Copyright (c) Pronamic
GitHub URI: https://github.com/pronamic/wp-orbis-comment-editor
*/
/**
* Comment form field comment.
*
* @see https://github.com/WordPress/WordPress/blob/4.5.2/wp-includes/comment-template.php#L2295-L2302
* @see https://github.com/WordPress/WordPress/blob/4.5.2/wp-includes/js/comment-reply.js
* @see http://bechster.com/add-tinymce-visual-editor-comment-form-wordpress/
* @see http://stackoverflow.com/questions/10095696/remove-tinymce-control-and-re-add
* @see https://www.tinymce.com/docs/api/class/tinymce/#get
* @param string $field
* @return string
*/
function orbis_comment_form_field_comment( $field ) {
ob_start();
?>
<script type="text/javascript">
var fixCommentEditor = function() {
var settings = tinymce.get( 'comment' ).settings;
tinymce.remove( '#comment' );
tinymce.init( settings );
var editor = tinymce.get( 'comment' );
editor.focus();
editor.selection.select( editor.getBody(), true );
editor.selection.collapse( false );
};
jQuery( function( $ ) {
$( '.comment-reply-link' ).click( function( e ) {
fixCommentEditor();
$( '#cancel-comment-reply-link' ).one( 'click', fixCommentEditor );
} );
} );
</script>
<?php
wp_editor( '', 'comment', array(
'teeny' => true,
'textarea_rows' => '7',
) );
$field = ob_get_clean();
return $field;
}
add_filter( 'comment_form_field_comment', 'orbis_comment_form_field_comment' );