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-trigger.php +121 -102 2.2.33.4.3 View file →
@@ -26,10 +26,10 @@
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 - // Enqueue scripts and styles for this Gutenberg Block in the editor view.
31 - add_action( 'convertkit_gutenberg_enqueue_scripts', array( $this, 'enqueue_scripts_editor' ) );
30 + // Register this block's MCP abilities.
31 + add_filter( 'convertkit_abilities', array( $this, 'register_abilities' ) );
32 32
33 33 // Enqueue scripts and styles for this Gutenberg Block in the editor and frontend views.
34 34 add_action( 'convertkit_gutenberg_enqueue_styles_editor_and_frontend', array( $this, 'enqueue_styles' ) );
35 35
@@ -35,19 +35,8 @@
35 35
36 36 }
37 37
38 38 /**
39 - * Enqueues scripts for this Gutenberg Block in the editor view.
40 - *
41 - * @since 2.2.0
42 - */
43 - public function enqueue_scripts_editor() {
44 -
45 - wp_enqueue_script( 'convertkit-gutenberg-block-form-trigger', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/gutenberg-block-form-trigger.js', array( 'convertkit-gutenberg' ), CONVERTKIT_PLUGIN_VERSION, true );
46 -
47 - }
48 -
49 - /**
50 39 * Enqueues styles for this Gutenberg Block in the editor and frontend views.
51 40 *
52 41 * @since 2.2.0
53 42 */
@@ -52,10 +41,13 @@
52 41 * @since 2.2.0
53 42 */
54 43 public function enqueue_styles() {
55 44
56 - wp_enqueue_style( 'convertkit-button', CONVERTKIT_PLUGIN_URL . 'resources/frontend/css/button.css', array(), CONVERTKIT_PLUGIN_VERSION );
45 + convertkit_enqueue_frontend_css();
57 46
47 + // Enqueue the block button CSS.
48 + wp_enqueue_style( 'wp-block-button' );
49 +
58 50 }
59 51
60 52 /**
61 53 * Returns this block's programmatic name, excluding the convertkit- prefix.
@@ -73,8 +65,43 @@
73 65
74 66 }
75 67
76 68 /**
69 + * Returns this block's title.
70 + *
71 + * @since 3.1.1
72 + */
73 + public function get_title() {
74 +
75 + return __( 'Kit Form Trigger', 'convertkit' );
76 +
77 + }
78 +
79 + /**
80 + * Returns this block's plural title.
81 + *
82 + * @since 3.4.0
83 + *
84 + * @return string
85 + */
86 + public function get_title_plural() {
87 +
88 + return __( 'Kit Form Triggers', 'convertkit' );
89 +
90 + }
91 +
92 + /**
93 + * Returns this block's icon.
94 + *
95 + * @since 3.1.1
96 + */
97 + public function get_icon() {
98 +
99 + return 'resources/backend/images/block-icon-formtrigger.svg';
100 +
101 + }
102 +
103 + /**
77 104 * Returns this block's Title, Icon, Categories, Keywords and properties.
78 105 *
79 106 * @since 2.2.0
80 107 */
@@ -79,42 +106,63 @@
79 106 * @since 2.2.0
80 107 */
81 108 public function get_overview() {
82 109
110 + $convertkit_forms = new ConvertKit_Resource_Forms( 'block_edit' );
111 + $settings = new ConvertKit_Settings();
112 +
83 113 return array(
84 - 'title' => __( 'ConvertKit Form Trigger', 'convertkit' ),
85 - 'description' => __( 'Displays a modal, sticky bar or slide in form to display when the button is pressed.', 'convertkit' ),
86 - 'icon' => 'resources/backend/images/block-icon-formtrigger.png',
87 - 'category' => 'convertkit',
88 - 'keywords' => array(
114 + 'title' => $this->get_title(),
115 + 'description' => __( 'Displays a modal, sticky bar or slide in form to display when the button is pressed.', 'convertkit' ),
116 + 'icon' => $this->get_icon(),
117 + 'category' => 'convertkit',
118 + 'keywords' => array(
89 119 __( 'ConvertKit', 'convertkit' ),
120 + __( 'Kit', 'convertkit' ),
90 121 __( 'Form', 'convertkit' ),
91 122 ),
92 123
93 124 // Function to call when rendering as a block or a shortcode on the frontend web site.
94 - 'render_callback' => array( $this, 'render' ),
125 + 'render_callback' => array( $this, 'render' ),
95 126
96 127 // Shortcode: TinyMCE / QuickTags Modal Width and Height.
97 - 'modal' => array(
128 + 'modal' => array(
98 129 'width' => 500,
99 - 'height' => 352,
130 + 'height' => 282,
100 131 ),
101 132
102 133 // Shortcode: Include a closing [/shortcode] tag when using TinyMCE or QuickTag Modals.
103 - 'shortcode_include_closing_tag' => false,
134 + 'shortcode_include_closing_tag' => false,
104 135
105 136 // Gutenberg: Block Icon in Editor.
106 - 'gutenberg_icon' => convertkit_get_file_contents( CONVERTKIT_PLUGIN_PATH . '/resources/backend/images/block-icon-formtrigger.svg' ),
137 + 'gutenberg_icon' => convertkit_get_file_contents( CONVERTKIT_PLUGIN_PATH . '/resources/backend/images/block-icon-formtrigger.svg' ),
107 138
108 139 // Gutenberg: Example image showing how this block looks when choosing it in Gutenberg.
109 - 'gutenberg_example_image' => CONVERTKIT_PLUGIN_URL . 'resources/backend/images/block-example-formtrigger.png',
140 + 'gutenberg_example_image' => CONVERTKIT_PLUGIN_URL . 'resources/backend/images/block-example-formtrigger.png',
110 141
111 - // Gutenberg: Help description, displayed when no settings defined for a newly added Block.
112 - 'gutenberg_help_description' => __( 'Select a Form using the Form option in the Gutenberg sidebar.', 'convertkit' ),
142 + // Help descriptions, displayed when no API key / resources exist and this block/shortcode is added.
143 + 'no_access_token' => array(
144 + 'notice' => __( 'Not connected to Kit.', 'convertkit' ),
145 + 'link' => convertkit_get_setup_wizard_plugin_link(),
146 + 'link_text' => __( 'Click here to connect your Kit account.', 'convertkit' ),
147 + 'instruction_text' => __( 'Connect your Kit account at Settings > Kit, and then refresh this page to select a form.', 'convertkit' ),
148 + ),
149 + 'no_resources' => array(
150 + 'notice' => __( 'No modal, sticky bar or slide in forms exist in Kit.', 'convertkit' ),
151 + 'link' => convertkit_get_new_form_url(),
152 + 'link_text' => __( 'Click here to create a form.', 'convertkit' ),
153 + 'instruction_text' => __( 'Add a non-inline form to your Kit account, and then refresh this page to select a form.', 'convertkit' ),
154 + ),
113 155
114 - // Gutenberg: JS function to call when rendering the block preview in the Gutenberg editor.
115 - // If not defined, render_callback above will be used.
116 - 'gutenberg_preview_render_callback' => 'convertKitGutenbergFormTriggerBlockRenderPreview',
156 + // The attribute to check if a value exists when rendering the block in the editor,
157 + // and the message to display if no value exists.
158 + 'gutenberg_help_description' => __( 'Select a Form using the Form option in the Gutenberg sidebar.', 'convertkit' ),
159 + 'gutenberg_help_description_attribute' => 'form',
160 +
161 + // Whether an API Key exists in the Plugin, and are the required resources (non-inline forms) available.
162 + // If no API Key is specified in the Plugin's settings, render the "No API Key" output.
163 + 'has_access_token' => $settings->has_access_and_refresh_token(),
164 + 'has_resources' => $convertkit_forms->non_inline_exist(),
117 165 );
118 166
119 167 }
120 168
@@ -137,9 +185,12 @@
137 185 ),
138 186
139 187 // The below are built in Gutenberg attributes registered in get_supports().
140 188
141 - // Color.
189 + // get_supports() style, color and typography attributes.
190 + 'style' => array(
191 + 'type' => 'object',
192 + ),
142 193 'backgroundColor' => array(
143 194 'type' => 'string',
144 195 ),
145 196 'textColor' => array(
@@ -144,37 +195,12 @@
144 195 ),
145 196 'textColor' => array(
146 197 'type' => 'string',
147 198 ),
148 -
149 - // Typography.
150 199 'fontSize' => array(
151 200 'type' => 'string',
152 201 ),
153 202
154 - // Spacing/Dimensions > Padding.
155 - 'style' => array(
156 - 'type' => 'object',
157 - 'visualizers' => array(
158 - 'type' => 'object',
159 - 'padding' => array(
160 - 'type' => 'object',
161 - 'top' => array(
162 - 'type' => 'boolean',
163 - ),
164 - 'bottom' => array(
165 - 'type' => 'boolean',
166 - ),
167 - 'left' => array(
168 - 'type' => 'boolean',
169 - ),
170 - 'right' => array(
171 - 'type' => 'boolean',
172 - ),
173 - ),
174 - ),
175 - ),
176 -
177 203 // Always required for Gutenberg.
178 204 'is_gutenberg_example' => array(
179 205 'type' => 'boolean',
180 206 'default' => false,
@@ -194,19 +220,23 @@
194 220
195 221 return array(
196 222 'className' => true,
197 223 'color' => array(
198 - 'background' => true,
199 - 'text' => true,
224 + 'background' => true,
225 + 'text' => true,
226 +
227 + // Don't apply styles to the block editor's div element.
228 + // This ensures what's rendered in the Gutenberg editor matches the frontend output for styling.
229 + // See: https://github.com/WordPress/gutenberg/issues/32417.
230 + '__experimentalSkipSerialization' => true,
200 231 ),
201 232 'typography' => array(
202 - 'fontSize' => true,
233 + 'fontSize' => true,
234 + 'lineHeight' => true,
203 235 ),
204 236 'spacing' => array(
205 - 'padding' => array(
206 - 'horizontal',
207 - 'vertical',
208 - ),
237 + 'margin' => true,
238 + 'padding' => true,
209 239 ),
210 240 );
211 241
212 242 }
@@ -219,32 +249,19 @@
219 249 * @return bool|array
220 250 */
221 251 public function get_fields() {
222 252
223 - // Bail if the request is not for the WordPress Administration or frontend editor.
224 - if ( ! WP_ConvertKit()->is_admin_or_frontend_editor() ) {
225 - return false;
226 - }
227 -
228 - // Get ConvertKit Forms.
253 + // Get non-inline ConvertKit Forms.
229 254 $forms = array();
230 255 $convertkit_forms = new ConvertKit_Resource_Forms( 'block_edit' );
231 - if ( $convertkit_forms->exist() ) {
232 - foreach ( $convertkit_forms->get() as $form ) {
233 - // Ignore inline forms; this button link is only for modal, slide in and sticky bar forms.
234 - if ( ! array_key_exists( 'format', $form ) ) {
235 - continue;
236 - }
237 - if ( $form['format'] === 'inline' ) {
238 - continue;
239 - }
240 -
241 - // Ignore forms that are missing a uid.
242 - if ( ! array_key_exists( 'uid', $form ) ) {
243 - continue;
244 - }
245 -
246 - $forms[ absint( $form['id'] ) ] = sanitize_text_field( $form['name'] );
256 + if ( $convertkit_forms->non_inline_exist() ) {
257 + foreach ( $convertkit_forms->get_non_inline() as $form ) {
258 + // Legacy forms don't include a `format` key, so define them as inline.
259 + $forms[ absint( $form['id'] ) ] = sprintf(
260 + '%s [%s]',
261 + sanitize_text_field( $form['name'] ),
262 + ( ! empty( $form['format'] ) ? sanitize_text_field( $form['format'] ) : 'inline' )
263 + );
247 264 }
248 265 }
249 266
250 267 // Gutenberg's built-in fields (such as styling, padding etc) don't need to be defined here, as they'll be included
@@ -251,11 +268,12 @@
251 268 // automatically by Gutenberg.
252 269 return array(
253 270 'form' => array(
254 271 'label' => __( 'Form', 'convertkit' ),
255 - 'type' => 'select',
272 + 'type' => 'resource',
273 + 'resource' => 'forms',
256 274 'values' => $forms,
257 - 'description' => __( 'The modal, sticky bar or slide in form to display when the button is pressed. To embed a form, use the ConvertKit Form block instead.', 'convertkit' ),
275 + 'description' => __( 'The modal, sticky bar or slide in form to display when the button is pressed. To embed a form, use the Kit Form block instead.', 'convertkit' ),
258 276 ),
259 277 'text' => array(
260 278 'label' => __( 'Button Text', 'convertkit' ),
261 279 'type' => 'text',
@@ -284,13 +302,8 @@
284 302 * @return bool|array
285 303 */
286 304 public function get_panels() {
287 305
288 - // Bail if the request is not for the WordPress Administration or frontend editor.
289 - if ( ! WP_ConvertKit()->is_admin_or_frontend_editor() ) {
290 - return false;
291 - }
292 -
293 306 // Gutenberg's built-in fields (such as styling, padding etc) don't need to be defined here, as they'll be included
294 307 // automatically by Gutenberg.
295 308 return array(
296 309 'general' => array(
@@ -343,10 +356,10 @@
343 356 * Returns the block's output, based on the supplied configuration attributes.
344 357 *
345 358 * @since 2.2.0
346 359 *
347 - * @param array $atts Block / Shortcode Attributes.
348 - * @return string Output
360 + * @param array $atts Block / Shortcode / Page Builder Module Attributes.
361 + * @return string
349 362 */
350 363 public function render( $atts ) {
351 364
352 365 // Parse attributes, defining fallback defaults if required
@@ -356,11 +369,17 @@
356 369 // Setup Settings class.
357 370 $settings = new ConvertKit_Settings();
358 371
359 372 // Build HTML.
360 - $html = $this->get_html( $atts['form'], $atts['text'], $atts['_css_classes'], $atts['_css_styles'], $this->is_block_editor_request() );
373 + $html = $this->get_html(
374 + $atts['form'],
375 + $atts['text'],
376 + $this->get_css_classes( array( 'wp-block-button__link', 'wp-element-button' ) ),
377 + $this->get_css_styles( $atts ),
378 + $this->is_block_editor_request()
379 + );
361 380
362 - // Bail if an error occured.
381 + // Bail if an error occurred.
363 382 if ( is_wp_error( $html ) ) {
364 383 if ( $settings->debug_enabled() ) {
365 384 return '<!-- ' . $html->get_error_message() . ' -->';
366 385 }
@@ -389,9 +408,9 @@
389 408 *
390 409 * @param int $id Form ID.
391 410 * @param string $button_text Button Text.
392 411 * @param array $css_classes CSS classes to apply to link (typically included when using Gutenberg).
393 - * @param array $css_styles CSS inline styles to apply to link (typically included when using Gutenberg).
412 + * @param array $css_styles CSS inline styles to apply to link (typically included when using Shortcode or third party page builder module / widget).
394 413 * @param bool $return_as_span If true, returns a <span> instead of <a>. Useful for the block editor so that the element is interactible.
395 414 * @return WP_Error|string Button HTML
396 415 */
397 416 private function get_html( $id, $button_text, $css_classes = array(), $css_styles = array(), $return_as_span = false ) {
@@ -410,9 +429,9 @@
410 429 return new WP_Error(
411 430 'convertkit_block_form_trigger_get_html',
412 431 sprintf(
413 432 /* translators: ConvertKit Form ID */
414 - __( 'ConvertKit Form ID %s does not exist on ConvertKit.', 'convertkit' ),
433 + __( 'Kit Form ID %s does not exist on Kit.', 'convertkit' ),
415 434 $id
416 435 )
417 436 );
418 437 }
@@ -422,9 +441,9 @@
422 441 return new WP_Error(
423 442 'convertkit_block_form_trigger_get_html',
424 443 sprintf(
425 444 /* translators: ConvertKit Form ID */
426 - __( 'ConvertKit Form ID %s has no uid property.', 'convertkit' ),
445 + __( 'Kit Form ID %s has no uid property.', 'convertkit' ),
427 446 $id
428 447 )
429 448 );
430 449 }
@@ -432,9 +451,9 @@
432 451 return new WP_Error(
433 452 'convertkit_block_form_trigger_get_html',
434 453 sprintf(
435 454 /* translators: ConvertKit Form ID */
436 - __( 'ConvertKit Form ID %s has no embed_js property.', 'convertkit' ),
455 + __( 'Kit Form ID %s has no embed_js property.', 'convertkit' ),
437 456 $id
438 457 )
439 458 );
440 459 }
@@ -447,9 +466,9 @@
447 466 } else {
448 467 $html .= '<a data-formkit-toggle="' . esc_attr( $form['uid'] ) . '" href="' . esc_url( $form['embed_url'] ) . '"';
449 468 }
450 469
451 - $html .= ' class="wp-block-button__link ' . implode( ' ', map_deep( $css_classes, 'sanitize_html_class' ) ) . '" style="' . implode( ';', map_deep( $css_styles, 'esc_attr' ) ) . '">';
470 + $html .= ' class="' . implode( ' ', map_deep( $css_classes, 'sanitize_html_class' ) ) . '" style="' . implode( ';', map_deep( $css_styles, 'esc_attr' ) ) . '">';
452 471 $html .= esc_html( $button_text );
453 472
454 473 if ( $return_as_span ) {
455 474 $html .= '</span>';
@@ -461,9 +480,9 @@
461 480
462 481 // Register the script, so it's only loaded once for this non-inline form across the entire page.
463 482 add_filter(
464 483 'convertkit_output_scripts_footer',
465 - function( $scripts ) use ( $form ) {
484 + function ( $scripts ) use ( $form ) {
466 485
467 486 $scripts[] = array(
468 487 'async' => true,
469 488 'data-uid' => $form['uid'],