forked from ouun/clean-wordpress-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwysiwyg.php
57 lines (46 loc) · 1.86 KB
/
wysiwyg.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
<?php
/**
* Set default editor mode to 'html' or 'tinymce'
* @link https://developer.wordpress.org/reference/hooks/wp_default_editor/
*/
add_filter( 'wp_default_editor', create_function( '', 'return "html";' ) );
/**
* Disable rich/visual editor
* @link https://developer.wordpress.org/reference/hooks/user_can_richedit/
*/
add_filter( 'user_can_richedit' , '__return_false', 50 );
/**
* Change default TinyMCE WYSIWYG settings.
* @link https://codex.wordpress.org/TinyMCE
*
* @param $settings Object Array of TinyMCE settings
*/
add_filter( 'tiny_mce_before_init', function ( $settings ) {
$settings['remove_linebreaks'] = true;
$settings['gecko_spellcheck'] = true;
$settings['keep_styles'] = false;
$settings['accessibility_focus'] = true;
$settings['content_css'] = 'path/to/custom-editor-style.css';
$settings['paste_remove_styles'] = true;
$settings['paste_remove_spans'] = true;
$settings['paste_strip_class_attributes'] = 'all';
$settings['toolbar1'] = 'formatselect,bold,italic,bullist,numlist,blockquote,hr,alignleft,aligncenter,alignright,link,unlink,underline';
$settings['toolbar2'] = '';
$settings['block_formats'] = "Paragraph=p; Heading 1=h1; Heading 2=h2; Heading 3=h3;";
// Create your own JavaScript preprocessor that triggers before pasting
$settings['paste_preprocess'] = "function (plugin, args) {
// Strip all HTML tags except those we have whitelisted
var whitelist = 'p,span,b,strong,i,em,h3,h4,h5,h6,ul,li,ol';
var stripped = $('<div>' + args.content + '</div>');
var els = stripped.find('*').not(whitelist);
for (var i = els.length - 1; i >= 0; i--) {
var e = els[i];
$(e).replaceWith(e.innerHTML);
}
// Strip all class and id attributes
stripped.find('*').removeAttr('id').removeAttr('class');
// Return the clean HTML
args.content = stripped.html();
}";
return $settings;
});