1 <?php
2
3 /**
4 * Custom formats for the the TinyMCE editor useful in the Vanilla WordPress
5 * framework.
6 *
7 * @author Nevma, http://www.nevma.gr, info@nevma.gr
8 *
9 * @license http://www.gnu.org/licenses/gpl-3.0.en.html GPLv3
10 */
11
12
13
14 /**
15 * Sets actions and filters necessary for the Vanilla TinyMCE custom
16 * formats.
17 *
18 * @return void
19 */
20
21 function vanilla_tinymce_formats_add_action () {
22
23 add_filter( 'mce_buttons_2', 'vanilla_tinymce_formats_add_button' );
24
25 }
26
27 add_action( 'admin_init', 'vanilla_tinymce_formats_add_action' );
28
29
30
31 /**
32 * Ensures the TinyMCE editor has a custom formats button.
33 *
34 * @param array $buttons The TinyMCE buttons array.
35 *
36 * @return array The array enhanced.
37 */
38
39 function vanilla_tinymce_formats_add_button ( $buttons ) {
40
41 array_unshift( $buttons, 'styleselect' );
42
43 return $buttons;
44
45 }
46
47
48
49 /**
50 * Adds custom formats contents to the TinyMCE editor. These formats are
51 * custom blockquotes, buttons, etc, which are found under the Formats
52 * dropdown menu of the TinyMCE editor.
53 *
54 * @param array $formats The contents of the TinyMCE editor format dropdown
55 * menu which is to be enhanced with Vanilla stylings.
56 *
57 * @return void
58 */
59
60 function vanilla_tinymce_formats_add_styles ( $formats ) {
61
62 if ( isset( $formats['style_formats'] ) ) {
63 $formats_array = json_decode( $formats['style_formats'] );
64 } else {
65 $formats_array = array();
66 }
67
68
69 // Creates a blockquote with a .
70
71 $formats_array []= array(
72 'selector' => 'blockquote',
73 'title' => 'Blockquote panel',
74 'classes' => 'panel',
75 'wrapper' => false
76 );
77
78 // Makes a blockquote big and shouting.
79
80 $formats_array []= array(
81 'selector' => 'blockquote',
82 'title' => 'Blockquote shout',
83 'classes' => 'shout',
84 'wrapper' => false
85 );
86
87 // Floats a blockquote to the left.
88
89 $formats_array []= array(
90 'selector' => 'blockquote',
91 'title' => 'Blockquote left',
92 'classes' => 'alignleft',
93 'wrapper' => false
94 );
95
96 // Floats a blockquote to the right.
97
98 $formats_array []= array(
99 'selector' => 'blockquote',
100 'title' => 'Blockquote right',
101 'classes' => 'alignright',
102 'wrapper' => false
103 );
104
105 // Makes a link become like a button.
106
107 $formats_array []= array(
108 'selector' => 'a',
109 'title' => 'Button link',
110 'classes' => 'button inline',
111 'wrapper' => false
112 );
113
114 // Makes a text part smaller.
115
116 $formats_array []= array(
117 'selector' => '',
118 'title' => 'Smaller text',
119 'inline' => 'span',
120 'classes' => 'smaller',
121 'wrapper' => false
122 );
123
124 // Makes a text part bigger.
125
126 $formats_array []= array(
127 'selector' => '',
128 'title' => 'Bigger text',
129 'inline' => 'span',
130 'classes' => 'bigger',
131 'wrapper' => false
132 );
133
134 $formats['style_formats'] = json_encode( $formats_array );
135
136 return $formats;
137
138 }
139
140 add_filter( 'tiny_mce_before_init', 'vanilla_tinymce_formats_add_styles' );
141
142 ?>