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 | 'blockquote', |
---|
80 | 'bullist', |
---|
81 | 'numlist', |
---|
82 | 'alignleft', |
---|
83 | 'aligncenter', |
---|
84 | 'alignright', |
---|
85 | 'link', |
---|
86 | 'unlink', |
---|
87 | 'wp_more', |
---|
88 | 'wp_adv', |
---|
89 | 'dfw', // Used only on the "Add/Edit Post" screens. Do not remove. |
---|
90 | ); |
---|
91 | |
---|
92 | private $toolbar_2 = array( |
---|
93 | 'hr', |
---|
94 | 'strikethrough', |
---|
95 | 'charmap', |
---|
96 | 'removeformat', |
---|
97 | 'pastetext', |
---|
98 | 'indent', |
---|
99 | 'outdent', |
---|
100 | 'undo', |
---|
101 | 'redo', |
---|
102 | 'wp_help', |
---|
103 | ); |
---|
104 | |
---|
105 | public function __construct() { |
---|
106 | if ( ! defined( 'ABSPATH' ) ) { |
---|
107 | return; |
---|
108 | } |
---|
109 | |
---|
110 | add_filter( 'the_editor_content', array( $this, 'add_filters' ) ); |
---|
111 | } |
---|
112 | |
---|
113 | public function add_filters( $content ) { |
---|
114 | if ( get_current_screen()->base === 'post' ) { |
---|
115 | add_filter( 'mce_buttons', array( $this, 'mce_buttons_1' ) ); |
---|
116 | add_filter( 'mce_buttons_2', array( $this, 'mce_buttons_2' ) ); |
---|
117 | add_filter( 'tiny_mce_before_init', array( $this, 'mce_options' ) ); |
---|
118 | } |
---|
119 | |
---|
120 | return $content; |
---|
121 | } |
---|
122 | |
---|
123 | public function mce_buttons_1( $buttons_array ) { |
---|
124 | return $this->toolbar_1; |
---|
125 | } |
---|
126 | |
---|
127 | public function mce_buttons_2( $buttons_array ) { |
---|
128 | return array_diff( $this->toolbar_2, $this->toolbar_1 ); |
---|
129 | } |
---|
130 | |
---|
131 | public function mce_options( $init_array ) { |
---|
132 | |
---|
133 | $init_array['block_formats'] = |
---|
134 | 'Paragraph=p;' . |
---|
135 | // 'Heading 1=h1;' . // Disable H1 |
---|
136 | 'Heading 2=h2;' . |
---|
137 | 'Heading 3=h3;' . |
---|
138 | 'Heading 4=h4;' . |
---|
139 | 'Heading 5=h5;' . |
---|
140 | 'Heading 6=h6;' . |
---|
141 | 'Preformatted=pre'; |
---|
142 | |
---|
143 | return $init_array; |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | new WP_Test_Tinymce_Toolbars; |
---|
148 | endif; |
---|