PluginProbe
Awesome Support – WordPress HelpDesk & Support Plugin / trunk
Awesome Support – WordPress HelpDesk & Support Plugin vtrunk
6.4.0 trunk 3.0.0 3.0.1 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 All 95 releases
awesome-support / includes / admin / functions-editor.php

functions-editor.php in Awesome Support – WordPress HelpDesk & Support Plugin trunk, at includes/admin/functions-editor.php

101 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Awesome Support/Admin/Functions/Editor
4 * @author AwesomeSupport <contact@getawesomesupport.com>
5 * @license GPL-2.0+
6 * @link https://getawesomesupport.com
7 * @copyright 2015-2017 AwesomeSupport
8 */
9
10 // If this file is called directly, abort.
11 if ( ! defined( 'WPINC' ) ) {
12 die;
13 }
14
15 class WPAS_Editor_Email_Template_Tags_Button {
16
17 public function __construct() {
18
19 add_action( 'init', array( $this, 'init' ) );
20 }
21
22 public function init() {
23
24 // Add button to editor
25 // NOTE: THIS IS CURRENTLY HOOKED TO ALL EDITORS
26 // Meaning... it will display on every editor throughout the site.
27 // If the button is only used for template tags; herego only on the email template settings page; then it would be better to define the button when calling those wp_editor() instances.
28 add_filter( 'mce_buttons', array( $this, 'add_editor_button' ) );
29
30 // Add plugin to plugin array
31 add_filter( 'mce_external_plugins', array( $this, 'add_plugin_array' ) );
32
33 // Add language localizeation
34 add_filter( 'mce_external_languages', array( $this, 'editor_tinymce_langs' ) );
35
36 // Pass js variables to tinymce
37 add_action( 'after_wp_tiny_mce', array( $this, 'editor_after_wp_tiny_mce' ) );
38 }
39
40 /**
41 * Add button to row 2 of editor
42 *
43 * @since 3.3.3
44 * @return bool
45 */
46 public function add_editor_button( $buttons ) {
47
48 $screen = get_current_screen();
49
50 array_push( $buttons, 'wpas_editor_email_template_tags' );
51 return $buttons;
52 }
53
54 /**
55 * Add button js to editor plugin array
56 *
57 * @since 3.3.3
58 * @return bool
59 */
60 public function add_plugin_array( $plugin_array ) {
61
62 $plugin_array['wpas_editor_email_template_tags'] = plugins_url( '/includes/admin/tinymce/wpas_editor_email_template_tags/editor_plugin.js', dirname( dirname( __FILE__ ) ) );
63 return $plugin_array;
64 }
65
66 /**
67 * Localize tinymce langs
68 *
69 * @since 3.3.3
70 * @return bool
71 */
72 public function editor_tinymce_langs( $locales ) {
73
74 $locales['wpas_editor_langs'] = plugin_dir_path ( dirname( dirname( __FILE__ ) ) ) . 'includes/admin/tinymce/langs/wpas_editor_langs.php';
75 return $locales;
76 }
77
78 /**
79 * Localize available template tags into tinymce script
80 *
81 * @since 3.3.3
82 * @return bool
83 */
84 public function editor_after_wp_tiny_mce() {
85 // Get WPAS email template tags
86 $list_tags = WPAS_Email_Notification::get_tags();
87 $list_tags = json_encode( $list_tags, true );
88
89 $script = 'var wpas_editor_js_vars = { "template_tags": ' . $list_tags . ' };' ;
90
91 // Proper wp_kses usage with allowed tags and attributes
92 $allowed_html_wpas_editor = array(
93 'script' => array(
94 'type' => true,
95 ),
96 );
97 echo wp_kses("<script type='text/javascript'>$script</script>", $allowed_html_wpas_editor );
98 }
99 }
100
101 $WPAS_Editor_Email_Template_Tags_Button = new WPAS_Editor_Email_Template_Tags_Button();