PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 1.9.7.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v1.9.7.4
3.4.2 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 All 195 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 1.9.7.4, at admin/class-convertkit-admin-tinymce.php

186 lines 5.4 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
53 // If the shortcode is not registered, return a view in the modal to tell the user.
54 if ( ! isset( $shortcodes[ $shortcode_name ] ) ) {
55 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-missing.php';
56 die();
57 }
58
59 // Define shortcode.
60 $shortcode = $shortcodes[ $shortcode_name ];
61
62 // Output the modal.
63 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal.php';
64 die();
65
66 }
67
68 /**
69 * Registers QuickTags JS for the TinyMCE Text (non-Visual) Editor
70 *
71 * @since 3.0.0
72 */
73 public function register_quicktags() {
74
75 // Get shortcodes.
76 $shortcodes = convertkit_get_shortcodes();
77
78 // Bail if no shortcode are available.
79 if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
80 return;
81 }
82
83 // Enqueue Quicktag JS.
84 wp_enqueue_script( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/quicktags.js', array( 'jquery', 'quicktags' ), CONVERTKIT_PLUGIN_VERSION, true );
85 wp_enqueue_script( 'convertkit-admin-modal', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/modal.js', array( 'jquery' ), 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 // Output Backbone View Template.
103 ?>
104 <script type="text/template" id="tmpl-convertkit-quicktags-modal">
105 <div id="convertkit-quicktags-modal">
106 <div class="media-frame-title"><h1>Title</h1></div>
107 <div class="media-frame-content">Content</div>
108 </div>
109 </script>
110 <?php
111
112 }
113
114 /**
115 * Register JS plugins for the TinyMCE Editor
116 *
117 * @since 1.5.0
118 *
119 * @param array $plugins JS Plugins.
120 * @return array JS Plugins
121 */
122 public function register_tinymce_plugins( $plugins ) {
123
124 // Get shortcodes.
125 $shortcodes = convertkit_get_shortcodes();
126
127 // Bail if no shortcodes are available.
128 if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
129 return $plugins;
130 }
131
132 // Enqueue TinyMCE CSS and JS.
133 wp_enqueue_script( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
134 wp_enqueue_script( 'convertkit-admin-modal', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/modal.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
135 wp_enqueue_style( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . '/resources/backend/css/tinymce.css', array(), CONVERTKIT_PLUGIN_VERSION );
136
137 // Register JS variable convertkit_admin_tinymce.nonce for AJAX calls.
138 wp_localize_script(
139 'convertkit-admin-tinymce',
140 'convertkit_admin_tinymce',
141 array(
142 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ),
143 )
144 );
145
146 // Make shortcodes available as convertkit_shortcodes JS variable.
147 wp_localize_script( 'convertkit-admin-tinymce', 'convertkit_shortcodes', $shortcodes );
148
149 // Register TinyMCE Javascript Plugin.
150 foreach ( $shortcodes as $shortcode => $properties ) {
151 $plugins[ 'convertkit_' . $shortcode ] = CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce-' . $shortcode . '.js';
152 }
153
154 return $plugins;
155
156 }
157
158 /**
159 * Registers buttons in the TinyMCE Editor
160 *
161 * @since 1.5.0
162 *
163 * @param array $buttons Buttons.
164 * @return array Buttons
165 */
166 public function register_tinymce_buttons( $buttons ) {
167
168 // Get shortcodes.
169 $shortcodes = convertkit_get_shortcodes();
170
171 // Bail if no shortcodes are available.
172 if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
173 return $buttons;
174 }
175
176 // Register each Shortcode as a TinyMCE Button.
177 foreach ( $shortcodes as $shortcode => $properties ) {
178 $buttons[] = 'convertkit_' . $shortcode;
179 }
180
181 return $buttons;
182
183 }
184
185 }
186