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