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 +99 -28 2.2.23.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,37 +34,99 @@
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 - // Output the modal.
64 - require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal.php';
65 - die();
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'];
108 + require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-notice.php';
109 + return ob_get_clean();
110 + }
66 111
112 + // Show a message in the modal if no resources exist.
113 + if ( array_key_exists( 'has_resources', $shortcode ) && ! $shortcode['has_resources'] ) {
114 + $notice = $shortcode['no_resources'];
115 + require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-notice.php';
116 + return ob_get_clean();
117 + }
118 +
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 + }
124 +
125 + // Output tabbed view.
126 + require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-tabbed.php';
127 + return ob_get_clean();
128 +
67 129 }
68 130
69 131 /**
70 132 * Registers QuickTags JS for the TinyMCE Text (non-Visual) Editor
@@ -76,14 +138,14 @@
76 138 // Get shortcodes.
77 139 $shortcodes = convertkit_get_shortcodes();
78 140
79 141 // Bail if no shortcode are available.
80 - if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
142 + if ( ! count( $shortcodes ) ) {
81 143 return;
82 144 }
83 145
84 146 // 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 );
147 + wp_enqueue_script( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/quicktags.js', array( 'quicktags' ), CONVERTKIT_PLUGIN_VERSION, true );
86 148
87 149 // Make shortcodes available as convertkit_quicktags JS variable.
88 150 wp_localize_script( 'convertkit-admin-quicktags', 'convertkit_quicktags', $shortcodes );
89 151
@@ -91,9 +153,10 @@
91 153 wp_localize_script(
92 154 'convertkit-admin-quicktags',
93 155 'convertkit_admin_tinymce',
94 156 array(
95 - 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ),
157 + 'ajaxurl' => rest_url( 'kit/v1/editor/tinymce/modal' ),
158 + 'nonce' => wp_create_nonce( 'wp_rest' ),
96 159 )
97 160 );
98 161
99 162 // Enqueue Quicktag CSS.
@@ -98,12 +161,8 @@
98 161
99 162 // Enqueue Quicktag CSS.
100 163 wp_enqueue_style( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/quicktags.css', array(), CONVERTKIT_PLUGIN_VERSION );
101 164
102 - // Enqueue WordPress JS and CSS.
103 - wp_enqueue_script( 'wp-color-picker' );
104 - wp_enqueue_style( 'wp-color-picker' );
105 -
106 165 // Output Backbone View Template.
107 166 add_action( 'wp_print_footer_scripts', array( $this, 'output_quicktags_modal' ) );
108 167 add_action( 'admin_print_footer_scripts', array( $this, 'output_quicktags_modal' ) );
109 168
@@ -122,28 +181,30 @@
122 181 // Get shortcodes.
123 182 $shortcodes = convertkit_get_shortcodes();
124 183
125 184 // Bail if no shortcodes are available.
126 - if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
185 + if ( ! count( $shortcodes ) ) {
127 186 return $plugins;
128 187 }
129 188
130 189 // 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 );
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 );
133 193 wp_enqueue_style( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/tinymce.css', array(), CONVERTKIT_PLUGIN_VERSION );
134 194
135 195 // Register JS variable convertkit_admin_tinymce.nonce for AJAX calls.
136 196 wp_localize_script(
137 - 'convertkit-admin-tinymce',
197 + 'convertkit-admin-editor',
138 198 'convertkit_admin_tinymce',
139 199 array(
140 - 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ),
200 + 'ajaxurl' => rest_url( 'kit/v1/editor/tinymce/modal' ),
201 + 'nonce' => wp_create_nonce( 'wp_rest' ),
141 202 )
142 203 );
143 204
144 205 // Make shortcodes available as convertkit_shortcodes JS variable.
145 - wp_localize_script( 'convertkit-admin-tinymce', 'convertkit_shortcodes', $shortcodes );
206 + wp_localize_script( 'convertkit-admin-editor', 'convertkit_shortcodes', $shortcodes );
146 207
147 208 // Register TinyMCE Javascript Plugin.
148 209 foreach ( $shortcodes as $shortcode => $properties ) {
149 210 $plugins[ 'convertkit_' . $shortcode ] = CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce-' . $shortcode . '.js';
@@ -166,9 +227,9 @@
166 227 // Get shortcodes.
167 228 $shortcodes = convertkit_get_shortcodes();
168 229
169 230 // Bail if no shortcodes are available.
170 - if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
231 + if ( ! count( $shortcodes ) ) {
171 232 return $buttons;
172 233 }
173 234
174 235 // Register each Shortcode as a TinyMCE Button.
@@ -190,10 +251,20 @@
190 251
191 252 ?>
192 253 <script type="text/template" id="tmpl-convertkit-quicktags-modal">
193 254 <div id="convertkit-quicktags-modal">
194 - <div class="media-frame-title"><h1>Title</h1></div>
195 - <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>
196 267 </div>
197 268 </script>
198 269 <?php
199 270