-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinymce-table-of-contents.php
74 lines (59 loc) · 2.29 KB
/
tinymce-table-of-contents.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
// This file is part of TinyMCE Table of Contents - https://github.com/julenpardo/tinymce-table-of-contents
//
// TinyMCE Table of Contents is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TinyMCE Table of Contents is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TinyMCE Table of Contents. If not, see <http://www.gnu.org/licenses/>.
/**
* Plugin Name: TinyMCE Table of Contents
* Version: 1.0
* Plugin URI: https://github.com/julenpardo/tinymce-table-of-contents
* Author: Julen Pardo
* Author URI: https://github.com/julenpardo
* Description: Completely automated and instantaneous way of generating tables of contents for posts.
* Tested up to: 4.5
* License: GPLv3
*/
class TinyMCE_Table_of_Contents {
const VERSION = '1.0';
/**
* TinyMCE_Table_of_Contents class constructor.
*/
public function __construct() {
if ( is_admin() ) {
add_action( 'init', array( $this, 'setup_tinymce_plugin' ) );
}
}
/**
* Initializes the plugin.
*/
public function setup_tinymce_plugin() {
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
return;
}
if ( get_user_option( 'rich_editing' ) !== 'true' ) {
return;
}
add_filter( 'mce_external_plugins', array( $this, 'add_tinymce_plugin' ) );
add_filter( 'mce_buttons', array( $this, 'add_tinymce_toolbar_button' ) );
}
public function add_tinymce_plugin( $plugin_array ) {
$plugin_array['table_of_contents'] = plugin_dir_url( __FILE__ ) . '/js/table-of-contents.min.js';
return $plugin_array;
}
public function add_tinymce_toolbar_button( $buttons ) {
array_push( $buttons, 'table_of_contents' );
return $buttons;
}
}
$tinymce_table_of_contents = new TinyMCE_Table_of_Contents();
?>