-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor_ui.php
124 lines (112 loc) · 3.83 KB
/
editor_ui.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Remove pods shortcode editor and other buttons for non-admins.
*/
add_action( 'admin_init', 'lfm_remove_editor_buttons', 14 );
function lfm_remove_editor_buttons () {
$user = wp_get_current_user();
if ( in_array( 'administrator', (array) $user->roles ) ) {
# Admins see everything.
}
else {
remove_action( 'media_buttons', array( PodsInit::$admin, 'media_button' ), 12 );
remove_action( 'media_buttons', 'media_buttons' );
}
}
/**
* Remove Visual/Text tab from editor if non-admin.
*/
add_filter( 'admin_footer', 'lfm_remove_editor_tabs_css', 99 );
function lfm_remove_editor_tabs_css(){
$user = wp_get_current_user();
if ( in_array( 'administrator', (array) $user->roles ) ) {
// Admins see everything.
}
else {
echo ' <style type="text/css">
.wp-editor-tabs {
display:none;
}
</style>';
}
}
add_filter( 'admin_footer', 'lfm_remove_caldera_form_link', 99 );
function lfm_remove_caldera_form_link() {
$user = wp_get_current_user();
if ( in_array( 'administrator', (array) $user->roles ) ) {
// Admins see everything.
}
else {
echo ' <style type="text/css">
#caldera-forms-form-insert {
display:none;
}
</style>';
}
}
/** Add a JavaScript snippet to show the word limit in TinyMCE Editor. */
add_filter( 'admin_print_footer_scripts', 'lfm_add_tinymce_word_limits' );
function lfm_add_tinymce_word_limits() {
global $post_type;
if ( 'referentn' == $post_type ) {
$word_limit = 200;
} elseif ( 'lernort' == $post_type ) {
$word_limit = 400;
$excerpt_word_limit = 70;
} elseif ( 'veranstaltung' == $post_type ) {
$word_limit = 800;
$excerpt_word_limit = 50;
} else {
return;
}
?>
<script type="text/javascript">
window.onload = function () {
if (!tinyMCE) { return; }
var word_limit = <?php echo $word_limit; ?>;
tinyMCE.editors[0].on('keyup', function(ed,e) {
var word_count_element = document.querySelectorAll('.word-count')[0];
var word_count = parseInt( word_count_element.textContent );
if(word_count > word_limit) {
document.getElementById('post-status-info').style.backgroundColor = '#ff3333';
var text_to_change = document.getElementById('wp-word-count').childNodes[0];
text_to_change.nodeValue = 'Wortanzahl (max ' + word_limit + '): ';
} else {
document.getElementById('post-status-info').style.backgroundColor = '#f7f7f7';
var text_to_change = document.getElementById('wp-word-count').childNodes[0];
text_to_change.nodeValue = 'Wortanzahl (max ' + word_limit + '): ';
//text_to_change.nodeValue = 'Wortanzahl: ';
}
});
var excerpt_element = document.getElementById('excerpt');
var excerpt_word_limit = <?php echo $excerpt_word_limit ?>;
if (excerpt_element) {
var excerpt_box = document.getElementById('postexcerpt');
var limit_span = document.getElementById('postexcerpt-limit');
if (!limit_span) {
var limit_span = document.createElement('span');
limit_span.innerHTML = "Wort-Limit: " + excerpt_word_limit;
limit_span.id = "postexcerpt-limit";
var excerpt_inside = document.querySelectorAll('#postexcerpt .inside')[0];
excerpt_inside.appendChild(limit_span);
}
excerpt_element.onkeyup = function() {
// or words: w+ ?
var word_count = this.value.trim().split(/\s+/).length;
limit_span.innerHTML = "Wort-Limit: " + excerpt_word_limit + " (" + word_count + ")";
if (word_count > excerpt_word_limit) {
limit_span.style.backgroundColor = 'red';
excerpt_box.style.border = "1px solid red";
} else {
limit_span.style.backgroundColor = 'white';
excerpt_box.style.border = "1px solid #ccd0d4";
}
};
}
}
</script>
<style type="text/css">
</style>
<?php
}
?>