-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom-tinymce-dashicons.php
62 lines (49 loc) · 1.49 KB
/
custom-tinymce-dashicons.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
<?php
/**
* Plugin Name: Custom WordPress Dashicons for TinyMCE Buttons
* Plugin URI: http://www.n7studios.co.uk/?p=2148&preview=true
* Version: 1.0
* Author: Tim Carr
* Author URI: http://www.n7studios.co.uk
* Description: Demonstrates how to use WordPress Dashicons in TinyMCE toolbar buttons.
*/
/**
* Called on the admin_head action, adds filters to:
* - register the TinyMCE Plugin Javascript,
* - add a button to the TinyMCE Editor
*/
function setupTinyMCEPlugins() {
add_filter( 'mce_external_plugins', 'addTinyMCEPlugin' );
add_filter( 'mce_buttons', 'addTinyMCEButton' );
}
/**
* Registers the TinyMCE Plugin Javascript
*
* @param array $plugins Plugins
* @return array Plugins
*/
function addTinyMCEPlugin( $plugins ) {
$plugins['custom_tinymce_dashicons'] = plugins_url( 'custom-tinymce-dashicons.js', __FILE__ );
return $plugins;
}
/**
* Adds a button to the TinyMCE Editor
*
* @param array $buttons Buttons
* @return array Buttons
*/
function addTinyMCEButton( $buttons ) {
array_push( $buttons, 'custom_tinymce_dashicons' );
return $buttons;
}
/**
* Called on the admin_enqueue_scripts action, enqueues CSS to
* make all WordPress Dashicons available to TinyMCE. This is
* where most of the magic happens.
*/
function adminScriptsAndCSS() {
wp_enqueue_style( 'custom_tinymce_dashicons', plugins_url( 'custom-tinymce-dashicons.css', __FILE__ ) );
}
// Register actions
add_action( 'admin_head', 'setupTinyMCEPlugins' );
add_action( 'admin_enqueue_scripts', 'adminScriptsAndCSS' );