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 | includes/class-convertkit-gutenberg.php +2 -172 3.4.22.7.4 View file →
@@ -31,71 +31,11 @@
31 31
32 32 // Register Gutenberg Blocks.
33 33 add_action( 'init', array( $this, 'add_blocks' ) );
34 34
35 - // Register Gutenberg Plugin Sidebars.
36 - add_action( 'init', array( $this, 'add_plugin_sidebars' ) );
37 -
38 - // Register REST API routes.
39 - add_action( 'rest_api_init', array( $this, 'register_routes' ) );
40 -
41 35 }
42 36
43 37 /**
44 - * Register REST API routes.
45 - *
46 - * @since 3.1.0
47 - */
48 - public function register_routes() {
49 -
50 - // Register route to refresh resources andreturn all blocks registered by the Plugin,
51 - // when the user clicks the refresh button in the Gutenberg editor.
52 - register_rest_route(
53 - 'kit/v1',
54 - '/blocks',
55 - array(
56 - 'methods' => WP_REST_Server::READABLE,
57 -
58 - // Return blocks.
59 - 'callback' => function () {
60 - // Refresh Forms.
61 - $forms = new ConvertKit_Resource_Forms( 'block_edit' );
62 - $result = $forms->refresh();
63 - if ( is_wp_error( $result ) ) {
64 - // Return blocks without refreshing other resources.
65 - return rest_ensure_response( convertkit_get_blocks() );
66 - }
67 -
68 - // Refresh Posts.
69 - $posts = new ConvertKit_Resource_Posts( 'block_edit' );
70 - $result = $posts->refresh();
71 - if ( is_wp_error( $result ) ) {
72 - // Return blocks without refreshing other resources.
73 - return rest_ensure_response( convertkit_get_blocks() );
74 - }
75 -
76 - // Refresh Products.
77 - $products = new ConvertKit_Resource_Products( 'block_edit' );
78 - $result = $products->refresh();
79 - if ( is_wp_error( $result ) ) {
80 - // Return blocks without refreshing other resources.
81 - return rest_ensure_response( convertkit_get_blocks() );
82 - }
83 -
84 - // Return blocks, which will now include the refreshed resources.
85 - return rest_ensure_response( convertkit_get_blocks() );
86 - },
87 -
88 - // Only refresh resources for users who can edit posts.
89 - 'permission_callback' => function () {
90 - return current_user_can( 'edit_posts' );
91 - },
92 - )
93 - );
94 -
95 - }
96 -
97 - /**
98 38 * Registers the ConvertKit Block Category.
99 39 *
100 40 * @since 1.9.6
101 41 *
@@ -150,11 +90,8 @@
150 90 if ( ! count( $blocks ) ) {
151 91 return;
152 92 }
153 93
154 - // Determine the block API version to use for registering blocks.
155 - $block_api_version = $this->get_block_api_version();
156 -
157 94 // Get registered blocks.
158 95 $registered_blocks = array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() );
159 96
160 97 // Iterate through blocks, registering them.
@@ -166,9 +103,9 @@
166 103 }
167 104
168 105 // Register block.
169 106 register_block_type(
170 - CONVERTKIT_PLUGIN_PATH . '/includes/blocks/v' . (string) $block_api_version . '/' . $block,
107 + CONVERTKIT_PLUGIN_PATH . '/includes/blocks/' . $block,
171 108 array(
172 109 'attributes' => $properties['attributes'],
173 110 'editor_script' => 'convertkit-gutenberg',
174 111 'render_callback' => array(
@@ -190,101 +127,8 @@
190 127
191 128 }
192 129
193 130 /**
194 - * Registers post meta for any registered plugin sidebars using register_post_meta(),
195 - * so data is saved when using the Gutenberg editor.
196 - *
197 - * @since 3.3.0
198 - */
199 - public function add_plugin_sidebars() {
200 -
201 - // Get plugin sidebars.
202 - $plugin_sidebars = convertkit_get_plugin_sidebars();
203 -
204 - // Bail if no plugin sidebars are available.
205 - if ( ! count( $plugin_sidebars ) ) {
206 - return;
207 - }
208 -
209 - foreach ( $plugin_sidebars as $plugin_sidebar ) {
210 - register_post_meta(
211 - '',
212 - $plugin_sidebar['meta_key'],
213 - array(
214 - 'show_in_rest' => array(
215 - 'schema' => array(
216 - 'type' => 'object',
217 - 'properties' => $plugin_sidebar['attributes'],
218 - ),
219 - ),
220 - 'single' => true,
221 - 'type' => 'object',
222 - 'default' => $plugin_sidebar['default_values'],
223 - 'sanitize_callback' => function ( $meta ) use ( $plugin_sidebar ) {
224 -
225 - // If the value is not an array, return the default values.
226 - if ( ! is_array( $meta ) ) {
227 - return $plugin_sidebar['default_values'];
228 - }
229 -
230 - // Iterate through the attributes and sanitize the meta.
231 - foreach ( $plugin_sidebar['attributes'] as $key => $attribute ) {
232 - $meta[ $key ] = sanitize_text_field( $meta[ $key ] ?? $attribute['default'] );
233 - }
234 -
235 - // If a Form or Landing Page was specified, request a review.
236 - // This can safely be called multiple times, as the review request
237 - // class will ensure once a review request is dismissed by the user,
238 - // it is never displayed again.
239 - if ( $meta['form'] || $meta['landing_page'] ) {
240 - WP_ConvertKit()->get_class( 'review_request' )->request_review();
241 - }
242 -
243 - // Return the sanitized meta.
244 - return $meta;
245 -
246 - },
247 - 'auth_callback' => function () use ( $plugin_sidebar ) {
248 -
249 - return current_user_can( $plugin_sidebar['minimum_capability'] );
250 -
251 - },
252 - )
253 - );
254 - }
255 -
256 - }
257 -
258 - /**
259 - * Determines the block API version to use for registering blocks.
260 - *
261 - * @since 3.2.0
262 - *
263 - * @return int Block API version.
264 - */
265 - public function get_block_api_version() {
266 -
267 - // Determine the block API version to use for registering blocks.
268 - // WordPress supports Version 3 from WordPress 6.3:
269 - // https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/.
270 - $block_api_version = ( version_compare( get_bloginfo( 'version' ), '6.3', '>=' ) ? 3 : 2 );
271 -
272 - /**
273 - * Determine the block API version to use for registering blocks.
274 - *
275 - * @since 3.1.4
276 - *
277 - * @param int $block_api_version Block API version.
278 - * @return int Block API version.
279 - */
280 - $block_api_version = apply_filters( 'convertkit_gutenberg_block_api_version', $block_api_version );
281 -
282 - return absint( $block_api_version );
283 -
284 - }
285 -
286 - /**
287 131 * Enqueues scripts for Gutenberg blocks in the editor view.
288 132 *
289 133 * @since 1.9.6
290 134 */
@@ -301,34 +145,20 @@
301 145 // Get blocks and block toolbar buttons.
302 146 $blocks = convertkit_get_blocks();
303 147 $block_formatters = convertkit_get_block_formatters();
304 148 $pre_publish_actions = convertkit_get_pre_publish_actions();
305 - $plugin_sidebars = convertkit_get_plugin_sidebars();
306 149
307 150 // Enqueue Gutenberg Javascript, and set the blocks data.
308 151 wp_enqueue_script( 'convertkit-gutenberg', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/gutenberg.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
309 152 wp_localize_script( 'convertkit-gutenberg', 'convertkit_blocks', $blocks );
310 -
311 - // If pre-publish actions are available, set the data.
312 153 if ( count( $pre_publish_actions ) ) {
313 154 wp_localize_script( 'convertkit-gutenberg', 'convertkit_pre_publish_actions', $pre_publish_actions );
314 155 }
315 -
316 - // If plugin sidebars are available, set the data.
317 - if ( count( $plugin_sidebars ) ) {
318 - wp_localize_script( 'convertkit-gutenberg', 'convertkit_plugin_sidebars', $plugin_sidebars );
319 - }
320 -
321 - // Set the Gutenberg data.
322 156 wp_localize_script(
323 157 'convertkit-gutenberg',
324 158 'convertkit_gutenberg',
325 159 array(
326 - 'ajaxurl' => rest_url( 'kit/v1/blocks' ),
327 - 'block_api_version' => $this->get_block_api_version(),
328 - 'get_blocks_nonce' => wp_create_nonce( 'wp_rest' ),
329 - 'refresh_resources_url' => rest_url( 'kit/v1/resources/refresh/' ),
330 - 'refresh_resources_nonce' => wp_create_nonce( 'wp_rest' ),
160 + 'get_blocks_nonce' => wp_create_nonce( 'convertkit_get_blocks' ),
331 161 )
332 162 );
333 163
334 164 // Enqueue Gutenberg Block Toolbar Javascript, and set the block toolbar buttons data.