PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.0.3
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.0.3
3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 All 194 releases
convertkit / admin / class-convertkit-admin-tinymce.php

class-convertkit-admin-tinymce.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 2.0.3, at admin/class-convertkit-admin-tinymce.php

203 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Admin TinyMCE class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * ConvertKit TinyMCE class. Registers buttons.
11 *
12 * @since 1.5.0
13 * @package ConvertKit
14 * @author ConvertKit
15 */
16 class ConvertKit_Admin_TinyMCE {
17
18 /**
19 * Constructor
20 */
21 public function __construct() {
22
23 // Outputs the TinyMCE and QuickTag Modal.
24 add_action( 'wp_ajax_convertkit_admin_tinymce_output_modal', array( $this, 'output_modal' ) );
25
26 // Add filters to register QuickTag Plugins.
27 add_action( 'admin_enqueue_scripts', array( $this, 'register_quicktags' ) ); // WordPress Admin.
28 add_action( 'wp_enqueue_scripts', array( $this, 'register_quicktags' ) ); // Frontend Editors.
29
30 // Add filters to register TinyMCE Plugins.
31 // Low priority ensures this works with Frontend Page Builders.
32 add_filter( 'mce_external_plugins', array( $this, 'register_tinymce_plugins' ), 99999 );
33 add_filter( 'mce_buttons', array( $this, 'register_tinymce_buttons' ), 99999 );
34
35 }
36
37 /**
38 * Loads the view for a shortcode's modal in the TinyMCE and Text Editors.
39 *
40 * @since 1.9.6
41 */
42 public function output_modal() {
43
44 // Check nonce.
45 check_ajax_referer( 'convertkit_admin_tinymce', 'nonce' );
46
47 // Get shortcodes.
48 $shortcodes = convertkit_get_shortcodes();
49
50 // Get requested shortcode name.
51 $shortcode_name = sanitize_text_field( $_REQUEST['shortcode'] );
52 $editor_type = sanitize_text_field( $_REQUEST['editor_type'] );
53
54 // If the shortcode is not registered, return a view in the modal to tell the user.
55 if ( ! isset( $shortcodes[ $shortcode_name ] ) ) {
56 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-missing.php';
57 die();
58 }
59
60 // Define shortcode.
61 $shortcode = $shortcodes[ $shortcode_name ];
62
63 // Output the modal.
64 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal.php';
65 die();
66
67 }
68
69 /**
70 * Registers QuickTags JS for the TinyMCE Text (non-Visual) Editor
71 *
72 * @since 3.0.0
73 */
74 public function register_quicktags() {
75
76 // Get shortcodes.
77 $shortcodes = convertkit_get_shortcodes();
78
79 // Bail if no shortcode are available.
80 if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
81 return;
82 }
83
84 // Enqueue Quicktag JS.
85 wp_enqueue_script( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/quicktags.js', array( 'jquery', 'quicktags' ), CONVERTKIT_PLUGIN_VERSION, true );
86
87 // Make shortcodes available as convertkit_quicktags JS variable.
88 wp_localize_script( 'convertkit-admin-quicktags', 'convertkit_quicktags', $shortcodes );
89
90 // Register JS variable convertkit_admin_tinymce.nonce for AJAX calls.
91 wp_localize_script(
92 'convertkit-admin-quicktags',
93 'convertkit_admin_tinymce',
94 array(
95 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ),
96 )
97 );
98
99 // Enqueue Quicktag CSS.
100 wp_enqueue_style( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/quicktags.css', array(), CONVERTKIT_PLUGIN_VERSION );
101
102 // Enqueue WordPress JS and CSS.
103 wp_enqueue_script( 'wp-color-picker' );
104 wp_enqueue_style( 'wp-color-picker' );
105
106 // Output Backbone View Template.
107 add_action( 'wp_print_footer_scripts', array( $this, 'output_quicktags_modal' ) );
108 add_action( 'admin_print_footer_scripts', array( $this, 'output_quicktags_modal' ) );
109
110 }
111
112 /**
113 * Register JS plugins for the TinyMCE Editor
114 *
115 * @since 1.5.0
116 *
117 * @param array $plugins JS Plugins.
118 * @return array JS Plugins
119 */
120 public function register_tinymce_plugins( $plugins ) {
121
122 // Get shortcodes.
123 $shortcodes = convertkit_get_shortcodes();
124
125 // Bail if no shortcodes are available.
126 if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
127 return $plugins;
128 }
129
130 // Enqueue TinyMCE CSS and JS.
131 wp_enqueue_script( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
132 wp_enqueue_script( 'convertkit-admin-modal', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/modal.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
133 wp_enqueue_style( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/tinymce.css', array(), CONVERTKIT_PLUGIN_VERSION );
134
135 // Register JS variable convertkit_admin_tinymce.nonce for AJAX calls.
136 wp_localize_script(
137 'convertkit-admin-tinymce',
138 'convertkit_admin_tinymce',
139 array(
140 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ),
141 )
142 );
143
144 // Make shortcodes available as convertkit_shortcodes JS variable.
145 wp_localize_script( 'convertkit-admin-tinymce', 'convertkit_shortcodes', $shortcodes );
146
147 // Register TinyMCE Javascript Plugin.
148 foreach ( $shortcodes as $shortcode => $properties ) {
149 $plugins[ 'convertkit_' . $shortcode ] = CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce-' . $shortcode . '.js';
150 }
151
152 return $plugins;
153
154 }
155
156 /**
157 * Registers buttons in the TinyMCE Editor
158 *
159 * @since 1.5.0
160 *
161 * @param array $buttons Buttons.
162 * @return array Buttons
163 */
164 public function register_tinymce_buttons( $buttons ) {
165
166 // Get shortcodes.
167 $shortcodes = convertkit_get_shortcodes();
168
169 // Bail if no shortcodes are available.
170 if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
171 return $buttons;
172 }
173
174 // Register each Shortcode as a TinyMCE Button.
175 foreach ( $shortcodes as $shortcode => $properties ) {
176 $buttons[] = 'convertkit_' . $shortcode;
177 }
178
179 return $buttons;
180
181 }
182
183 /**
184 * Outputs the QuickTags modal view in the footer of the site, which is
185 * used when using the Text editor button to insert a shortcode.
186 *
187 * @since 1.9.7.5
188 */
189 public function output_quicktags_modal() {
190
191 ?>
192 <script type="text/template" id="tmpl-convertkit-quicktags-modal">
193 <div id="convertkit-quicktags-modal">
194 <div class="media-frame-title"><h1>Title</h1></div>
195 <div class="media-frame-content">Content</div>
196 </div>
197 </script>
198 <?php
199
200 }
201
202 }
203