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 +29 -32 2.2.0 → 3.4.4 View file →
@@ -38,10 +38,14 @@
38 38 * @since 2.2.0
39 39 */
40 40 public function __construct() {
41 41
42 - // Register this as a Gutenberg block formatter in the ConvertKit Plugin.
43 - add_filter( 'convertkit_get_block_formatters', array( $this, 'register' ) );
42 + // Register this as a Gutenberg block formatter in the ConvertKit Plugin,
43 + // if non-inline forms exist on ConvertKit.
44 + $this->forms = new ConvertKit_Resource_Forms( 'block_formatter_register' );
45 + if ( $this->forms->non_inline_exist() ) {
46 + add_filter( 'convertkit_get_block_formatters', array( $this, 'register' ) );
47 + }
44 48
45 49 // Enqueue JS in footer if links exist in the content that have the formatter applied.
46 50 add_filter( 'the_content', array( $this, 'maybe_enqueue_scripts' ) );
47 51
@@ -69,14 +73,14 @@
69 73 */
70 74 public function get_overview() {
71 75
72 76 return array(
73 - 'title' => __( 'ConvertKit Form Trigger', 'convertkit' ),
77 + 'title' => __( 'Kit Form Trigger', 'convertkit' ),
74 78 'description' => __( 'Displays a modal, sticky bar or slide in form to display when the link is pressed.', 'convertkit' ),
75 - 'icon' => 'resources/backend/images/block-icon-formtrigger.png',
79 + 'icon' => 'resources/backend/images/block-icon-formtrigger.svg',
76 80
77 81 // Gutenberg: Block Icon in Editor.
78 - 'gutenberg_icon' => file_get_contents( CONVERTKIT_PLUGIN_PATH . '/resources/backend/images/block-icon-formtrigger.svg' ), /* phpcs:ignore */
82 + 'gutenberg_icon' => convertkit_get_file_contents( CONVERTKIT_PLUGIN_PATH . '/resources/backend/images/block-icon-formtrigger.svg' ),
79 83 );
80 84
81 85 }
82 86
@@ -112,24 +116,20 @@
112 116 if ( ! WP_ConvertKit()->is_admin_or_frontend_editor() ) {
113 117 return false;
114 118 }
115 119
116 - // Get ConvertKit Forms.
117 - $forms = array();
118 - $forms_data = array();
119 - $convertkit_forms = new ConvertKit_Resource_Forms( 'block_edit' );
120 - if ( $convertkit_forms->exist() ) {
121 - foreach ( $convertkit_forms->get() as $form ) {
122 - // Ignore inline forms; this formatter is only for modal, slide in and sticky bar forms.
123 - if ( ! array_key_exists( 'format', $form ) ) {
124 - continue;
125 - }
126 - if ( $form['format'] === 'inline' ) {
127 - continue;
128 - }
129 -
120 + // Get non-inline ConvertKit Forms.
121 + $forms = array();
122 + $forms_data = array();
123 + if ( $this->forms->exist() ) {
124 + foreach ( $this->forms->get_non_inline() as $form ) {
130 125 // Add this form's necessary to the attribute arrays.
131 - $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 + );
132 132 $forms_data[ absint( $form['id'] ) ] = array(
133 133 'data-id' => sanitize_text_field( $form['id'] ),
134 134 'data-formkit-toggle' => sanitize_text_field( $form['uid'] ),
135 135 'href' => $form['embed_url'],
@@ -173,11 +173,8 @@
173 173 if ( strpos( $content, 'data-formkit-toggle' ) === false ) {
174 174 return $content;
175 175 }
176 176
177 - // Get Forms.
178 - $this->forms = new ConvertKit_Resource_Forms();
179 -
180 177 // Return content, unedited, if no Forms exist.
181 178 if ( ! $this->forms->exist() ) {
182 179 return $content;
183 180 }
@@ -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 }