PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.4
3.4.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 All 197 releases
← All changes | includes/block-formatters/class-convertkit-block-formatter-form-link.php +21 -24 2.2.2 → 3.4.4 View file →
@@ -39,11 +39,11 @@
39 39 */
40 40 public function __construct() {
41 41
42 42 // Register this as a Gutenberg block formatter in the ConvertKit Plugin,
43 - // if forms exist on ConvertKit.
43 + // if non-inline forms exist on ConvertKit.
44 44 $this->forms = new ConvertKit_Resource_Forms( 'block_formatter_register' );
45 - if ( $this->forms->exist() ) {
45 + if ( $this->forms->non_inline_exist() ) {
46 46 add_filter( 'convertkit_get_block_formatters', array( $this, 'register' ) );
47 47 }
48 48
49 49 // Enqueue JS in footer if links exist in the content that have the formatter applied.
@@ -73,11 +73,11 @@
73 73 */
74 74 public function get_overview() {
75 75
76 76 return array(
77 - 'title' => __( 'ConvertKit Form Trigger', 'convertkit' ),
77 + 'title' => __( 'Kit Form Trigger', 'convertkit' ),
78 78 'description' => __( 'Displays a modal, sticky bar or slide in form to display when the link is pressed.', 'convertkit' ),
79 - 'icon' => 'resources/backend/images/block-icon-formtrigger.png',
79 + 'icon' => 'resources/backend/images/block-icon-formtrigger.svg',
80 80
81 81 // Gutenberg: Block Icon in Editor.
82 82 'gutenberg_icon' => convertkit_get_file_contents( CONVERTKIT_PLUGIN_PATH . '/resources/backend/images/block-icon-formtrigger.svg' ),
83 83 );
@@ -116,23 +116,20 @@
116 116 if ( ! WP_ConvertKit()->is_admin_or_frontend_editor() ) {
117 117 return false;
118 118 }
119 119
120 - // Get ConvertKit Forms.
120 + // Get non-inline ConvertKit Forms.
121 121 $forms = array();
122 122 $forms_data = array();
123 123 if ( $this->forms->exist() ) {
124 - foreach ( $this->forms->get() as $form ) {
125 - // Ignore inline forms; this formatter is only for modal, slide in and sticky bar forms.
126 - if ( ! array_key_exists( 'format', $form ) ) {
127 - continue;
128 - }
129 - if ( $form['format'] === 'inline' ) {
130 - continue;
131 - }
132 -
124 + foreach ( $this->forms->get_non_inline() as $form ) {
133 125 // Add this form's necessary to the attribute arrays.
134 - $forms[ absint( $form['id'] ) ] = sanitize_text_field( $form['name'] );
126 + // Legacy forms don't include a `format` key, so define them as inline.
127 + $forms[ absint( $form['id'] ) ] = sprintf(
128 + '%s [%s]',
129 + sanitize_text_field( $form['name'] ),
130 + ( ! empty( $form['format'] ) ? sanitize_text_field( $form['format'] ) : 'inline' )
131 + );
135 132 $forms_data[ absint( $form['id'] ) ] = array(
136 133 'data-id' => sanitize_text_field( $form['id'] ),
137 134 'data-formkit-toggle' => sanitize_text_field( $form['uid'] ),
138 135 'href' => $form['embed_url'],
@@ -198,34 +195,34 @@
198 195 * Callback function to enqueue a script to a matching link.
199 196 *
200 197 * @since 2.2.0
201 198 *
202 - * @param array $match preg_replace_callback() match.
203 - * @return string Link with script appended
199 + * @param array $preg_match preg_replace_callback() match.
200 + * @return string Link with script appended
204 201 */
205 - public function enqueue_scripts( $match ) {
202 + public function enqueue_scripts( $preg_match ) {
206 203
207 204 // Get Form by its ID.
208 - $form = $this->forms->get_by_id( absint( $match[1] ) );
205 + $form = $this->forms->get_by_id( absint( $preg_match[1] ) );
209 206
210 207 // Just return the original element, unedited, if the Form could not be found.
211 208 if ( ! $form ) {
212 - return $match[0];
209 + return $preg_match[0];
213 210 }
214 211
215 212 // Return the original link, unedited, if the Form doesn't have a UID or JS embed.
216 213 // This prevents issues with legacy modal forms.
217 214 if ( ! array_key_exists( 'uid', $form ) ) {
218 - return $match[0];
215 + return $preg_match[0];
219 216 }
220 217 if ( ! array_key_exists( 'embed_js', $form ) ) {
221 - return $match[0];
218 + return $preg_match[0];
222 219 }
223 220
224 221 // Register the script, so it's only loaded once for this non-inline form across the entire page.
225 222 add_filter(
226 223 'convertkit_output_scripts_footer',
227 - function( $scripts ) use ( $form ) {
224 + function ( $scripts ) use ( $form ) {
228 225
229 226 $scripts[] = array(
230 227 'async' => true,
231 228 'data-uid' => $form['uid'],
@@ -237,9 +234,9 @@
237 234 }
238 235 );
239 236
240 237 // Return original link.
241 - return $match[0];
238 + return $preg_match[0];
242 239
243 240 }
244 241
245 242 }