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