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 | includes/blocks/class-convertkit-block-form.php +40 -12 3.3.23.4.3 View file →
@@ -26,8 +26,11 @@
26 26
27 27 // Register this as a Gutenberg block in the ConvertKit Plugin.
28 28 add_filter( 'convertkit_blocks', array( $this, 'register' ) );
29 29
30 + // Register this block's MCP abilities.
31 + add_filter( 'convertkit_abilities', array( $this, 'register_abilities' ) );
32 +
30 33 // Enqueue scripts for this Gutenberg Block in the editor view.
31 34 add_action( 'convertkit_gutenberg_enqueue_scripts', array( $this, 'enqueue_scripts_editor' ) );
32 35
33 36 // Enqueue styles for this Gutenberg Block in the editor view.
@@ -101,8 +104,21 @@
101 104
102 105 }
103 106
104 107 /**
108 + * Returns this block's plural title.
109 + *
110 + * @since 3.4.0
111 + *
112 + * @return string
113 + */
114 + public function get_title_plural() {
115 +
116 + return __( 'Kit Forms', 'convertkit' );
117 +
118 + }
119 +
120 + /**
105 121 * Returns this block's icon.
106 122 *
107 123 * @since 3.1.1
108 124 */
@@ -261,32 +277,44 @@
261 277 * @return bool|array
262 278 */
263 279 public function get_fields() {
264 280
265 - // Get ConvertKit Forms.
281 + // Get ConvertKit Forms. Non-legacy forms populate the sidebar dropdown;
282 + // legacy forms are exposed separately as a fallback so the sidebar can
283 + // keep displaying a previously-saved legacy form as the current
284 + // selection without offering other legacy forms as new choices.
266 285 $forms = array();
286 + $legacy_forms = array();
267 287 $convertkit_forms = new ConvertKit_Resource_Forms( 'block_edit' );
268 288 if ( $convertkit_forms->exist() ) {
269 289 foreach ( $convertkit_forms->get() as $form ) {
270 - // Legacy forms don't include a `format` key, so define them as inline.
271 - $forms[ absint( $form['id'] ) ] = sprintf(
290 + $label = sprintf(
272 291 '%s [%s]',
273 292 sanitize_text_field( $form['name'] ),
293 + // Legacy forms don't include a `format` key, so define them as inline.
274 294 ( ! empty( $form['format'] ) ? sanitize_text_field( $form['format'] ) : 'inline' )
275 295 );
296 +
297 + if ( ! empty( $form['format'] ) ) {
298 + $forms[ absint( $form['id'] ) ] = $label;
299 + } else {
300 + $legacy_forms[ absint( $form['id'] ) ] = $label;
301 + }
276 302 }
277 303 }
278 304
279 305 return array(
280 306 'form' => array(
281 - 'label' => __( 'Form', 'convertkit' ),
282 - 'type' => 'resource',
283 - 'resource' => 'forms',
284 - 'values' => $forms,
285 - 'data' => array(
307 + 'label' => __( 'Form', 'convertkit' ),
308 + 'type' => 'resource',
309 + 'resource' => 'forms',
310 + 'values' => $forms,
311 + 'legacy_values' => $legacy_forms,
312 + 'data' => array(
286 313 // Used by resources/backend/js/gutenberg-block-form.js to determine the selected form's format
287 314 // (modal, slide in, sticky bar) and output a message in the block editor for the preview to explain
288 - // why some formats cannot be previewed.
315 + // why some formats cannot be previewed. Includes legacy forms so the preview code can still find
316 + // them when a saved block references a legacy form.
289 317 'forms' => ( $convertkit_forms->exist() ? $convertkit_forms->get() : array() ),
290 318 ),
291 319 ),
292 320 );
@@ -381,9 +409,9 @@
381 409 // Get Form HTML.
382 410 $forms = new ConvertKit_Resource_Forms( 'output_form' );
383 411 $form = $forms->get_html( $form_id, $post_id );
384 412
385 - // If an error occured, it might be that we're requesting a Form ID that exists in ConvertKit
413 + // If an error occurred, it might be that we're requesting a Form ID that exists in ConvertKit
386 414 // but does not yet exist in the Plugin's Form Resources.
387 415 // If so, refresh the Form Resources and try again.
388 416 if ( is_wp_error( $form ) && $form->get_error_data() === 404 ) {
389 417 // Refresh Forms from the API.
@@ -388,9 +416,9 @@
388 416 if ( is_wp_error( $form ) && $form->get_error_data() === 404 ) {
389 417 // Refresh Forms from the API.
390 418 $result = $forms->refresh();
391 419
392 - // Bail if an error occured.
420 + // Bail if an error occurred.
393 421 if ( is_wp_error( $result ) ) {
394 422 if ( $settings->debug_enabled() ) {
395 423 return '<!-- ' . $result->get_error_message() . ' --> <!-- ' . $form->get_error_message() . ' -->';
396 424 }
@@ -402,9 +430,9 @@
402 430 // Get Form HTML again.
403 431 $form = $forms->get_html( $form_id, $post_id );
404 432 }
405 433
406 - // If an error still occured, the shortcode might be from the ConvertKit App for a Legacy Form ID
434 + // If an error still occurred, the shortcode might be from the ConvertKit App for a Legacy Form ID
407 435 // These ConvertKit App shortcodes, for some reason, use a different Form ID than the one presented
408 436 // to us in the API.
409 437 // For example, a Legacy Form ID might be 470099, but the ConvertKit app says to use the shortcode [convertkit form=5281783]).
410 438 // In this instance, fetch the Form HTML without checking that the Form ID exists in the Form Resources.