PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.3
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.3
3.4.3 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 All 196 releases
← All changes | admin/class-convertkit-admin-tinymce.php +90 -33 2.2.43.4.3 View file →
@@ -20,9 +20,9 @@
20 20 */
21 21 public function __construct() {
22 22
23 23 // Outputs the TinyMCE and QuickTag Modal.
24 - add_action( 'wp_ajax_convertkit_admin_tinymce_output_modal', array( $this, 'output_modal' ) );
24 + add_action( 'rest_api_init', array( $this, 'register_routes' ) );
25 25
26 26 // Add filters to register QuickTag Plugins.
27 27 add_action( 'admin_enqueue_scripts', array( $this, 'register_quicktags' ) ); // WordPress Admin.
28 28 add_action( 'wp_enqueue_scripts', array( $this, 'register_quicktags' ) ); // Frontend Editors.
@@ -34,38 +34,80 @@
34 34
35 35 }
36 36
37 37 /**
38 + * Register REST API routes.
39 + *
40 + * @since 3.1.8
41 + */
42 + public function register_routes() {
43 +
44 + // Register route to return all blocks registered by the Plugin.
45 + register_rest_route(
46 + 'kit/v1',
47 + '/editor/tinymce/modal/(?P<shortcode>[a-zA-Z0-9-_]+)/(?P<editor_type>[a-zA-Z0-9-_]+)',
48 + array(
49 + 'methods' => WP_REST_Server::READABLE,
50 + 'args' => array(
51 + 'shortcode' => array(
52 + 'required' => true,
53 + 'validate_callback' => function ( $param ) {
54 + return is_string( $param ) && in_array( $param, array_keys( convertkit_get_shortcodes() ), true );
55 + },
56 + 'sanitize_callback' => 'sanitize_text_field',
57 + ),
58 + 'editor_type' => array(
59 + 'required' => true,
60 + 'validate_callback' => function ( $param ) {
61 + return is_string( $param ) && in_array( $param, array( 'tinymce', 'quicktags' ), true );
62 + },
63 + 'sanitize_callback' => 'sanitize_text_field',
64 + ),
65 + ),
66 + 'callback' => function ( $request ) {
67 + return rest_ensure_response( $this->output_modal( $request['shortcode'], $request['editor_type'] ) );
68 + },
69 +
70 + // Only refresh resources for users who can edit posts.
71 + 'permission_callback' => function () {
72 + return current_user_can( 'edit_posts' );
73 + },
74 + )
75 + );
76 +
77 + }
78 +
79 + /**
38 80 * Loads the view for a shortcode's modal in the TinyMCE and Text Editors.
39 81 *
40 82 * @since 1.9.6
83 + *
84 + * @param string $shortcode_name Shortcode Name.
85 + * @param string $editor_type Editor Type (tinymce|quicktags).
86 + * @return string
41 87 */
42 - public function output_modal() {
88 + public function output_modal( $shortcode_name, $editor_type ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
43 89
44 - // Check nonce.
45 - check_ajax_referer( 'convertkit_admin_tinymce', 'nonce' );
46 -
47 90 // Get shortcodes.
48 91 $shortcodes = convertkit_get_shortcodes();
49 92
50 - // Get requested shortcode name.
51 - $shortcode_name = sanitize_text_field( $_REQUEST['shortcode'] );
52 - $editor_type = sanitize_text_field( $_REQUEST['editor_type'] );
93 + // Start output buffering.
94 + ob_start();
53 95
54 96 // If the shortcode is not registered, return a view in the modal to tell the user.
55 97 if ( ! isset( $shortcodes[ $shortcode_name ] ) ) {
56 98 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-missing.php';
57 - die();
99 + return ob_get_clean();
58 100 }
59 101
60 102 // Define shortcode.
61 103 $shortcode = $shortcodes[ $shortcode_name ];
62 104
63 - // Show a message in the modal if no API Key is specified.
64 - if ( array_key_exists( 'has_api_key', $shortcode ) && ! $shortcode['has_api_key'] ) {
65 - $notice = $shortcode['no_api_key'];
105 + // Show a message in the modal if no Access Token is specified.
106 + if ( array_key_exists( 'has_access_token', $shortcode ) && ! $shortcode['has_access_token'] ) {
107 + $notice = $shortcode['no_access_token'];
66 108 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-notice.php';
67 - die();
109 + return ob_get_clean();
68 110 }
69 111
70 112 // Show a message in the modal if no resources exist.
71 113 if ( array_key_exists( 'has_resources', $shortcode ) && ! $shortcode['has_resources'] ) {
@@ -70,15 +112,21 @@
70 112 // Show a message in the modal if no resources exist.
71 113 if ( array_key_exists( 'has_resources', $shortcode ) && ! $shortcode['has_resources'] ) {
72 114 $notice = $shortcode['no_resources'];
73 115 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-notice.php';
74 - die();
116 + return ob_get_clean();
75 117 }
76 118
77 - // Output the modal.
78 - require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal.php';
79 - die();
119 + // If we have less than two panels defined in the shortcode properties, output a basic modal.
120 + if ( count( $shortcode['panels'] ) < 2 ) {
121 + require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal.php';
122 + return ob_get_clean();
123 + }
80 124
125 + // Output tabbed view.
126 + require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-tabbed.php';
127 + return ob_get_clean();
128 +
81 129 }
82 130
83 131 /**
84 132 * Registers QuickTags JS for the TinyMCE Text (non-Visual) Editor
@@ -90,14 +138,14 @@
90 138 // Get shortcodes.
91 139 $shortcodes = convertkit_get_shortcodes();
92 140
93 141 // Bail if no shortcode are available.
94 - if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
142 + if ( ! count( $shortcodes ) ) {
95 143 return;
96 144 }
97 145
98 146 // Enqueue Quicktag JS.
99 - wp_enqueue_script( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/quicktags.js', array( 'jquery', 'quicktags' ), CONVERTKIT_PLUGIN_VERSION, true );
147 + wp_enqueue_script( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/quicktags.js', array( 'quicktags' ), CONVERTKIT_PLUGIN_VERSION, true );
100 148
101 149 // Make shortcodes available as convertkit_quicktags JS variable.
102 150 wp_localize_script( 'convertkit-admin-quicktags', 'convertkit_quicktags', $shortcodes );
103 151
@@ -105,9 +153,10 @@
105 153 wp_localize_script(
106 154 'convertkit-admin-quicktags',
107 155 'convertkit_admin_tinymce',
108 156 array(
109 - 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ),
157 + 'ajaxurl' => rest_url( 'kit/v1/editor/tinymce/modal' ),
158 + 'nonce' => wp_create_nonce( 'wp_rest' ),
110 159 )
111 160 );
112 161
113 162 // Enqueue Quicktag CSS.
@@ -112,12 +161,8 @@
112 161
113 162 // Enqueue Quicktag CSS.
114 163 wp_enqueue_style( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/quicktags.css', array(), CONVERTKIT_PLUGIN_VERSION );
115 164
116 - // Enqueue WordPress JS and CSS.
117 - wp_enqueue_script( 'wp-color-picker' );
118 - wp_enqueue_style( 'wp-color-picker' );
119 -
120 165 // Output Backbone View Template.
121 166 add_action( 'wp_print_footer_scripts', array( $this, 'output_quicktags_modal' ) );
122 167 add_action( 'admin_print_footer_scripts', array( $this, 'output_quicktags_modal' ) );
123 168
@@ -136,28 +181,30 @@
136 181 // Get shortcodes.
137 182 $shortcodes = convertkit_get_shortcodes();
138 183
139 184 // Bail if no shortcodes are available.
140 - if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
185 + if ( ! count( $shortcodes ) ) {
141 186 return $plugins;
142 187 }
143 188
144 189 // Enqueue TinyMCE CSS and JS.
145 - wp_enqueue_script( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
146 - wp_enqueue_script( 'convertkit-admin-modal', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/modal.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
190 + wp_enqueue_script( 'convertkit-admin-tabs', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tabs.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
191 + wp_enqueue_script( 'convertkit-admin-editor', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/editor.js', array(), CONVERTKIT_PLUGIN_VERSION, true );
192 + wp_enqueue_script( 'convertkit-admin-modal', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/modal.js', array(), CONVERTKIT_PLUGIN_VERSION, true );
147 193 wp_enqueue_style( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/tinymce.css', array(), CONVERTKIT_PLUGIN_VERSION );
148 194
149 195 // Register JS variable convertkit_admin_tinymce.nonce for AJAX calls.
150 196 wp_localize_script(
151 - 'convertkit-admin-tinymce',
197 + 'convertkit-admin-editor',
152 198 'convertkit_admin_tinymce',
153 199 array(
154 - 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ),
200 + 'ajaxurl' => rest_url( 'kit/v1/editor/tinymce/modal' ),
201 + 'nonce' => wp_create_nonce( 'wp_rest' ),
155 202 )
156 203 );
157 204
158 205 // Make shortcodes available as convertkit_shortcodes JS variable.
159 - wp_localize_script( 'convertkit-admin-tinymce', 'convertkit_shortcodes', $shortcodes );
206 + wp_localize_script( 'convertkit-admin-editor', 'convertkit_shortcodes', $shortcodes );
160 207
161 208 // Register TinyMCE Javascript Plugin.
162 209 foreach ( $shortcodes as $shortcode => $properties ) {
163 210 $plugins[ 'convertkit_' . $shortcode ] = CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce-' . $shortcode . '.js';
@@ -180,9 +227,9 @@
180 227 // Get shortcodes.
181 228 $shortcodes = convertkit_get_shortcodes();
182 229
183 230 // Bail if no shortcodes are available.
184 - if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
231 + if ( ! count( $shortcodes ) ) {
185 232 return $buttons;
186 233 }
187 234
188 235 // Register each Shortcode as a TinyMCE Button.
@@ -204,10 +251,20 @@
204 251
205 252 ?>
206 253 <script type="text/template" id="tmpl-convertkit-quicktags-modal">
207 254 <div id="convertkit-quicktags-modal">
208 - <div class="media-frame-title"><h1>Title</h1></div>
209 - <div class="media-frame-content">Content</div>
255 + <div class="media-frame-title"><h1></h1></div>
256 + <div class="media-frame-content"></div>
257 + <div class="media-frame-toolbar">
258 + <div class="media-toolbar">
259 + <div class="media-toolbar-secondary">
260 + <button type="button" class="button button-large cancel"><?php esc_html_e( 'Cancel', 'convertkit' ); ?></button>
261 + </div>
262 + <div class="media-toolbar-primary">
263 + <button type="button" class="button button-primary button-large"><?php esc_html_e( 'Insert', 'convertkit' ); ?></button>
264 + </div>
265 + </div>
266 + </div>
210 267 </div>
211 268 </script>
212 269 <?php
213 270