1 | <?php |
---|
2 | /** |
---|
3 | Plugin Name: Test TinyMCE Toolbars |
---|
4 | Plugin URI: https://wordpress.org |
---|
5 | Description: Small plugin for testing different configurations for the TinyMCE toolbars. |
---|
6 | Version: 1.0 |
---|
7 | Author: Andrew Ozz |
---|
8 | Author URI: http://www.laptoptips.ca/ |
---|
9 | License: GPL2 |
---|
10 | License URI: https://www.gnu.org/licenses/gpl-2.0.html |
---|
11 | |
---|
12 | Test TinyMCE Toolbars is free software: you can redistribute it and/or modify |
---|
13 | it under the terms of the GNU General Public License as published by |
---|
14 | the Free Software Foundation, either version 2 of the License, or |
---|
15 | any later version. |
---|
16 | |
---|
17 | Test TinyMCE Toolbars is distributed in the hope that it will be useful, |
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
20 | GNU General Public License for more details. |
---|
21 | |
---|
22 | You should have received a copy of the GNU General Public License along |
---|
23 | with WordPress. If not, see https://www.gnu.org/licenses/gpl-2.0.html. |
---|
24 | |
---|
25 | Copyright (c) Andrew Ozz. All rights reserved. |
---|
26 | */ |
---|
27 | |
---|
28 | if ( ! class_exists( 'WP_Test_Tinymce_Toolbars' ) ) : |
---|
29 | class WP_Test_Tinymce_Toolbars { |
---|
30 | /** |
---|
31 | * Available TinyMCE buttons: |
---|
32 | * bold Applies the bold format to the current selection. |
---|
33 | * italic Applies the italic format to the current selection. |
---|
34 | * underline Applies the underline format to the current selection. |
---|
35 | * strikethrough Applies strike though format to the current selection. |
---|
36 | * alignleft Left aligns the current block or image. |
---|
37 | * aligncenter Left aligns the current block or image. |
---|
38 | * alignright Right aligns the current block or image. |
---|
39 | * alignjustify Full aligns the current block or image. |
---|
40 | * alignnone Removes the alignment of the current block or image. |
---|
41 | * styleselect Dropdown list with styles to apply to selection. |
---|
42 | * formatselect Dropdown list with block formats to apply to selection. |
---|
43 | * fontselect Dropdown list with font families to apply to selection. |
---|
44 | * fontsizeselect Dropdown list with font sizes to apply to selection. |
---|
45 | * bullist Formats the current selection as a bullet list. |
---|
46 | * numlist Formats the current selection as a numbered list. |
---|
47 | * outdent Outdents the current list item or block element. |
---|
48 | * indent Indents the current list item or block element. |
---|
49 | * blockquote Applies block quote format to the current block level element. |
---|
50 | * undo Undoes the last operation. |
---|
51 | * redo Redoes the last undoed operation. |
---|
52 | * removeformat Removes the formatting from the current selection. |
---|
53 | * subscript Applies subscript format to the current selection. |
---|
54 | * superscript Applies superscript format to the current selection. |
---|
55 | * visualaid Toggles the visual aids for invisible elements. |
---|
56 | * hr Inserts a horizontal rule into the editor. |
---|
57 | * link Creates/Edits links within the editor. |
---|
58 | * unlink Removes links from the current selection. |
---|
59 | * charmap Inserts custom characters into the editor. |
---|
60 | * pastetext Toggles plain text pasting mode on/off. |
---|
61 | * ltr Sets the directionality of contents to ltr. |
---|
62 | * rtl Sets the directionality of contents to rtl. |
---|
63 | * forecolor Applies foreground/text color to selection. |
---|
64 | * backcolor Applies background color to selection. |
---|
65 | * |
---|
66 | * WordPress specific: |
---|
67 | * wp_more Inserts the <!-- more --> tag. |
---|
68 | * wp_help Opens the help. |
---|
69 | * wp_adv Toggles the second toolbar on/off. |
---|
70 | * dfw Distraction-free mode on/off. |
---|
71 | * |
---|
72 | */ |
---|
73 | |
---|
74 | // Add buttons (once) from the above list. |
---|
75 | private $toolbar_1 = array( |
---|
76 | 'formatselect', |
---|
77 | 'bold', |
---|
78 | 'italic', |
---|
79 | 'underline', |
---|
80 | 'strikethrough', |
---|
81 | 'blockquote', |
---|
82 | 'bullist', |
---|
83 | 'numlist', |
---|
84 | 'aligncenter', |
---|
85 | 'link', |
---|
86 | 'unlink', |
---|
87 | 'hr', |
---|
88 | 'wp_more', |
---|
89 | 'wp_adv', |
---|
90 | 'dfw', // Used only on the "Add/Edit Post" screens. Do not remove. |
---|
91 | ); |
---|
92 | |
---|
93 | private $toolbar_2 = array( |
---|
94 | 'alignleft', |
---|
95 | 'alignjustify', |
---|
96 | 'alignright', |
---|
97 | 'indent', |
---|
98 | 'outdent', |
---|
99 | 'forecolor', |
---|
100 | 'backcolor', |
---|
101 | 'pastetext', |
---|
102 | 'charmap', |
---|
103 | 'removeformat', |
---|
104 | 'undo', |
---|
105 | 'redo', |
---|
106 | 'wp_help', |
---|
107 | ); |
---|
108 | |
---|
109 | public function __construct() { |
---|
110 | if ( ! defined( 'ABSPATH' ) ) { |
---|
111 | return; |
---|
112 | } |
---|
113 | |
---|
114 | add_filter( 'the_editor_content', array( $this, 'add_filters' ) ); |
---|
115 | } |
---|
116 | |
---|
117 | public function add_filters( $content ) { |
---|
118 | if ( get_current_screen()->base === 'post' ) { |
---|
119 | add_filter( 'mce_buttons', array( $this, 'mce_buttons_1' ) ); |
---|
120 | add_filter( 'mce_buttons_2', array( $this, 'mce_buttons_2' ) ); |
---|
121 | add_filter( 'tiny_mce_before_init', array( $this, 'mce_options' ) ); |
---|
122 | } |
---|
123 | |
---|
124 | return $content; |
---|
125 | } |
---|
126 | |
---|
127 | public function mce_buttons_1( $buttons_array ) { |
---|
128 | return $this->toolbar_1; |
---|
129 | } |
---|
130 | |
---|
131 | public function mce_buttons_2( $buttons_array ) { |
---|
132 | return array_diff( $this->toolbar_2, $this->toolbar_1 ); |
---|
133 | } |
---|
134 | |
---|
135 | public function mce_options( $init_array ) { |
---|
136 | |
---|
137 | $init_array['block_formats'] = |
---|
138 | 'Paragraph=p;' . |
---|
139 | // 'Heading 1=h1;' . // Disable H1 |
---|
140 | 'Heading 2=h2;' . |
---|
141 | 'Heading 3=h3;' . |
---|
142 | 'Heading 4=h4;' . |
---|
143 | 'Heading 5=h5;' . |
---|
144 | 'Heading 6=h6;' . |
---|
145 | 'Preformatted=pre'; |
---|
146 | |
---|
147 | return $init_array; |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | new WP_Test_Tinymce_Toolbars; |
---|
152 | endif; |
---|