PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.7.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.7.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 2.2.9 2.3.0 2.3.1 All 196 releases
← All changes | admin/class-convertkit-admin-tinymce.php +18 -62 3.4.22.7.4 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,70 +34,28 @@
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 ];
@@ -105,9 +63,9 @@
105 63 // Show a message in the modal if no Access Token is specified.
106 64 if ( array_key_exists( 'has_access_token', $shortcode ) && ! $shortcode['has_access_token'] ) {
107 65 $notice = $shortcode['no_access_token'];
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 /**
@@ -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.
@@ -187,24 +144,23 @@
187 144 }
188 145
189 146 // Enqueue TinyMCE CSS and JS.
190 147 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 );
148 + wp_enqueue_script( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce.js', array(), CONVERTKIT_PLUGIN_VERSION, true );
192 149 wp_enqueue_script( 'convertkit-admin-modal', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/modal.js', array(), CONVERTKIT_PLUGIN_VERSION, true );
193 150 wp_enqueue_style( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/tinymce.css', array(), CONVERTKIT_PLUGIN_VERSION );
194 151
195 152 // Register JS variable convertkit_admin_tinymce.nonce for AJAX calls.
196 153 wp_localize_script(
197 - 'convertkit-admin-editor',
154 + 'convertkit-admin-tinymce',
198 155 'convertkit_admin_tinymce',
199 156 array(
200 - 'ajaxurl' => rest_url( 'kit/v1/editor/tinymce/modal' ),
201 - 'nonce' => wp_create_nonce( 'wp_rest' ),
157 + 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ),
202 158 )
203 159 );
204 160
205 161 // Make shortcodes available as convertkit_shortcodes JS variable.
206 - wp_localize_script( 'convertkit-admin-editor', 'convertkit_shortcodes', $shortcodes );
162 + wp_localize_script( 'convertkit-admin-tinymce', 'convertkit_shortcodes', $shortcodes );
207 163
208 164 // Register TinyMCE Javascript Plugin.
209 165 foreach ( $shortcodes as $shortcode => $properties ) {
210 166 $plugins[ 'convertkit_' . $shortcode ] = CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce-' . $shortcode . '.js';