-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom-acf-tinymce.php
49 lines (45 loc) · 1.75 KB
/
custom-acf-tinymce.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
<?php
/*
Plugin Name: ACF Custom Button
Description: Adds a custom button to the ACF TinyMCE toolbar
Version: 1.0
Author: Maxime Bajeux
*/
function my_acf_input_admin_footer() {
?>
<script type="text/javascript">
acf.add_filter('wysiwyg_tinymce_settings', function(mceInit, id, field) {
mceInit.verify_html = false;
mceInit.plugins = 'textcolor,colorpicker,lists,fullscreen,image,wordpress,wpeditimage,wplink,hr';
mceInit.toolbar1 = 'formatselect,bold,italic,underline,strikethrough,forecolor,blockquote,hr';
mceInit.toolbar2 = 'alignleft,aligncenter,alignright,alignjustify,bullist,numlist,link,unlink,undo,redo,removeformat,customButton';
mceInit.setup = function(ed){
ed.addButton( 'customButton', {
type: 'button',
text: 'CTA',
onclick: function() {
// Open a TinyMCE modal window
ed.windowManager.open({
title: 'Insert CTA Link',
body: [
{type: 'textbox', name: 'url', label: 'URL'},
{type: 'checkbox', name: 'newTab', label: 'Open in a new tab', checked: true},
],
onsubmit: function(e) {
var url = e.data.url;
var newTab = e.data.newTab ? ' target="_blank"' : '';
var selected_text = ed.selection.getContent();
var html = '<a class="cta" href="' + url + '"' + newTab + '>' + selected_text + '</a>';
ed.execCommand('mceInsertContent', false, html);
}
});
}
});
}
return mceInit;
});
</script>
<?php
}
add_action('acf/input/admin_footer', 'my_acf_input_admin_footer');
?>