PluginProbe
Code Snippets / 3.10.0
Code Snippets v3.10.0
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / php / Integration / Classic_Editor / MCE_Plugin.php

MCE_Plugin.php in Code Snippets 3.10.0, at php/Integration/Classic_Editor/MCE_Plugin.php

58 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Code_Snippets\Integration\Classic_Editor;
4
5 use function Code_Snippets\code_snippets;
6 use const Code_Snippets\PLUGIN_FILE;
7
8 /**
9 * This class registers a custom TinyMCE plugin and button.
10 *
11 * @package Code_Snippets
12 */
13 class MCE_Plugin {
14
15 /**
16 * Constructor.
17 */
18 public function __construct() {
19 add_action( 'init', [ $this, 'setup_mce_plugin' ] );
20 }
21
22 /**
23 * Perform the necessary actions to add a button to the TinyMCE editor
24 */
25 public function setup_mce_plugin() {
26 if ( ! code_snippets()->current_user_can() ) {
27 return;
28 }
29
30 /* Register the TinyMCE plugin */
31 add_filter(
32 'mce_external_plugins',
33 function ( $plugins ) {
34 $plugins['code_snippets'] = plugins_url( 'dist/mce.js', PLUGIN_FILE );
35 return $plugins;
36 }
37 );
38
39 /* Add the button to the editor toolbar */
40 add_filter(
41 'mce_buttons',
42 function ( $buttons ) {
43 $buttons[] = 'code_snippets';
44 return $buttons;
45 }
46 );
47
48 /* Add the translation strings to the TinyMCE editor */
49 add_filter(
50 'mce_external_languages',
51 function ( $languages ) {
52 $languages['code_snippets'] = __DIR__ . '/mce-strings.php';
53 return $languages;
54 }
55 );
56 }
57 }
58