PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.4.0
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.4.0
3.4.6 3.4.5 3.4.4 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 All 199 releases
← All changes | admin/class-convertkit-admin-tinymce.php +30 -70 3.3.7 → 2.4.0 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( 'rest_api_init', array( $this, 'register_routes' ) );
24 + add_action( 'wp_ajax_convertkit_admin_tinymce_output_modal', array( $this, 'output_modal' ) );
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,80 +34,38 @@
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 - /**
80 38 * Loads the view for a shortcode's modal in the TinyMCE and Text Editors.
81 39 *
82 40 * @since 1.9.6
83 - *
84 - * @param string $shortcode_name Shortcode Name.
85 - * @param string $editor_type Editor Type (tinymce|quicktags).
86 - * @return string
87 41 */
88 - public function output_modal( $shortcode_name, $editor_type ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
42 + public function output_modal() {
89 43
44 + // Check nonce.
45 + check_ajax_referer( 'convertkit_admin_tinymce', 'nonce' );
46 +
90 47 // Get shortcodes.
91 48 $shortcodes = convertkit_get_shortcodes();
92 49
93 - // Start output buffering.
94 - ob_start();
50 + // Get requested shortcode name.
51 + $shortcode_name = sanitize_text_field( $_REQUEST['shortcode'] );
52 + $editor_type = sanitize_text_field( $_REQUEST['editor_type'] );
95 53
96 54 // If the shortcode is not registered, return a view in the modal to tell the user.
97 55 if ( ! isset( $shortcodes[ $shortcode_name ] ) ) {
98 56 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-missing.php';
99 - return ob_get_clean();
57 + die();
100 58 }
101 59
102 60 // Define shortcode.
103 61 $shortcode = $shortcodes[ $shortcode_name ];
104 62
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'];
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'];
108 66 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-notice.php';
109 - return ob_get_clean();
67 + die();
110 68 }
111 69
112 70 // Show a message in the modal if no resources exist.
113 71 if ( array_key_exists( 'has_resources', $shortcode ) && ! $shortcode['has_resources'] ) {
@@ -112,20 +70,20 @@
112 70 // Show a message in the modal if no resources exist.
113 71 if ( array_key_exists( 'has_resources', $shortcode ) && ! $shortcode['has_resources'] ) {
114 72 $notice = $shortcode['no_resources'];
115 73 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-notice.php';
116 - return ob_get_clean();
74 + die();
117 75 }
118 76
119 77 // If we have less than two panels defined in the shortcode properties, output a basic modal.
120 78 if ( count( $shortcode['panels'] ) < 2 ) {
121 79 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal.php';
122 - return ob_get_clean();
80 + die();
123 81 }
124 82
125 83 // Output tabbed view.
126 84 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-tabbed.php';
127 - return ob_get_clean();
85 + die();
128 86
129 87 }
130 88
131 89 /**
@@ -138,14 +96,14 @@
138 96 // Get shortcodes.
139 97 $shortcodes = convertkit_get_shortcodes();
140 98
141 99 // Bail if no shortcode are available.
142 - if ( ! count( $shortcodes ) ) {
100 + if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
143 101 return;
144 102 }
145 103
146 104 // Enqueue Quicktag JS.
147 - wp_enqueue_script( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/quicktags.js', array( 'quicktags' ), CONVERTKIT_PLUGIN_VERSION, true );
105 + wp_enqueue_script( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/quicktags.js', array( 'jquery', 'quicktags' ), CONVERTKIT_PLUGIN_VERSION, true );
148 106
149 107 // Make shortcodes available as convertkit_quicktags JS variable.
150 108 wp_localize_script( 'convertkit-admin-quicktags', 'convertkit_quicktags', $shortcodes );
151 109
@@ -153,10 +111,9 @@
153 111 wp_localize_script(
154 112 'convertkit-admin-quicktags',
155 113 'convertkit_admin_tinymce',
156 114 array(
157 - 'ajaxurl' => rest_url( 'kit/v1/editor/tinymce/modal' ),
158 - 'nonce' => wp_create_nonce( 'wp_rest' ),
115 + 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ),
159 116 )
160 117 );
161 118
162 119 // Enqueue Quicktag CSS.
@@ -161,8 +118,12 @@
161 118
162 119 // Enqueue Quicktag CSS.
163 120 wp_enqueue_style( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/quicktags.css', array(), CONVERTKIT_PLUGIN_VERSION );
164 121
122 + // Enqueue WordPress JS and CSS.
123 + wp_enqueue_script( 'wp-color-picker' );
124 + wp_enqueue_style( 'wp-color-picker' );
125 +
165 126 // Output Backbone View Template.
166 127 add_action( 'wp_print_footer_scripts', array( $this, 'output_quicktags_modal' ) );
167 128 add_action( 'admin_print_footer_scripts', array( $this, 'output_quicktags_modal' ) );
168 129
@@ -181,30 +142,29 @@
181 142 // Get shortcodes.
182 143 $shortcodes = convertkit_get_shortcodes();
183 144
184 145 // Bail if no shortcodes are available.
185 - if ( ! count( $shortcodes ) ) {
146 + if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
186 147 return $plugins;
187 148 }
188 149
189 150 // Enqueue TinyMCE CSS and JS.
190 151 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 );
152 + wp_enqueue_script( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
153 + wp_enqueue_script( 'convertkit-admin-modal', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/modal.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
193 154 wp_enqueue_style( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/tinymce.css', array(), CONVERTKIT_PLUGIN_VERSION );
194 155
195 156 // Register JS variable convertkit_admin_tinymce.nonce for AJAX calls.
196 157 wp_localize_script(
197 - 'convertkit-admin-editor',
158 + 'convertkit-admin-tinymce',
198 159 'convertkit_admin_tinymce',
199 160 array(
200 - 'ajaxurl' => rest_url( 'kit/v1/editor/tinymce/modal' ),
201 - 'nonce' => wp_create_nonce( 'wp_rest' ),
161 + 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ),
202 162 )
203 163 );
204 164
205 165 // Make shortcodes available as convertkit_shortcodes JS variable.
206 - wp_localize_script( 'convertkit-admin-editor', 'convertkit_shortcodes', $shortcodes );
166 + wp_localize_script( 'convertkit-admin-tinymce', 'convertkit_shortcodes', $shortcodes );
207 167
208 168 // Register TinyMCE Javascript Plugin.
209 169 foreach ( $shortcodes as $shortcode => $properties ) {
210 170 $plugins[ 'convertkit_' . $shortcode ] = CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce-' . $shortcode . '.js';
@@ -227,9 +187,9 @@
227 187 // Get shortcodes.
228 188 $shortcodes = convertkit_get_shortcodes();
229 189
230 190 // Bail if no shortcodes are available.
231 - if ( ! count( $shortcodes ) ) {
191 + if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) {
232 192 return $buttons;
233 193 }
234 194
235 195 // Register each Shortcode as a TinyMCE Button.