PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.8.6
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.8.6
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 +21 -59 3.3.22.8.6 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,34 @@
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 + // Bail if no shortcode or editor type is specified.
51 + if ( ! isset( $_REQUEST['shortcode'] ) || ! isset( $_REQUEST['editor_type'] ) ) {
52 + require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-missing.php';
53 + die();
54 + }
95 55
56 + // Get requested shortcode name.
57 + $shortcode_name = sanitize_text_field( wp_unslash( $_REQUEST['shortcode'] ) );
58 + $editor_type = sanitize_text_field( wp_unslash( $_REQUEST['editor_type'] ) );
59 +
96 60 // If the shortcode is not registered, return a view in the modal to tell the user.
97 61 if ( ! isset( $shortcodes[ $shortcode_name ] ) ) {
98 62 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-missing.php';
99 - return ob_get_clean();
63 + die();
100 64 }
101 65
102 66 // Define shortcode.
103 67 $shortcode = $shortcodes[ $shortcode_name ];
@@ -105,9 +69,9 @@
105 69 // Show a message in the modal if no Access Token is specified.
106 70 if ( array_key_exists( 'has_access_token', $shortcode ) && ! $shortcode['has_access_token'] ) {
107 71 $notice = $shortcode['no_access_token'];
108 72 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-notice.php';
109 - return ob_get_clean();
73 + die();
110 74 }
111 75
112 76 // Show a message in the modal if no resources exist.
113 77 if ( array_key_exists( 'has_resources', $shortcode ) && ! $shortcode['has_resources'] ) {
@@ -112,20 +76,20 @@
112 76 // Show a message in the modal if no resources exist.
113 77 if ( array_key_exists( 'has_resources', $shortcode ) && ! $shortcode['has_resources'] ) {
114 78 $notice = $shortcode['no_resources'];
115 79 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-notice.php';
116 - return ob_get_clean();
80 + die();
117 81 }
118 82
119 83 // If we have less than two panels defined in the shortcode properties, output a basic modal.
120 84 if ( count( $shortcode['panels'] ) < 2 ) {
121 85 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal.php';
122 - return ob_get_clean();
86 + die();
123 87 }
124 88
125 89 // Output tabbed view.
126 90 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-tabbed.php';
127 - return ob_get_clean();
91 + die();
128 92
129 93 }
130 94
131 95 /**
@@ -153,10 +117,9 @@
153 117 wp_localize_script(
154 118 'convertkit-admin-quicktags',
155 119 'convertkit_admin_tinymce',
156 120 array(
157 - 'ajaxurl' => rest_url( 'kit/v1/editor/tinymce/modal' ),
158 - 'nonce' => wp_create_nonce( 'wp_rest' ),
121 + 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ),
159 122 )
160 123 );
161 124
162 125 // Enqueue Quicktag CSS.
@@ -196,10 +159,9 @@
196 159 wp_localize_script(
197 160 'convertkit-admin-editor',
198 161 'convertkit_admin_tinymce',
199 162 array(
200 - 'ajaxurl' => rest_url( 'kit/v1/editor/tinymce/modal' ),
201 - 'nonce' => wp_create_nonce( 'wp_rest' ),
163 + 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ),
202 164 )
203 165 );
204 166
205 167 // Make shortcodes available as convertkit_shortcodes JS variable.