PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.5
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.5
3.4.5 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 All 198 releases
convertkit / includes / integrations / forminator / class-convertkit-forminator-admin-section.php

class-convertkit-forminator-admin-section.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.5, at includes/integrations/forminator/class-convertkit-forminator-admin-section.php

340 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Forminator Admin Settings class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Registers Forminator Settings that can be edited at Settings > Kit > Forminator.
11 *
12 * @package ConvertKit
13 * @author ConvertKit
14 */
15 class ConvertKit_Forminator_Admin_Section extends ConvertKit_Admin_Section_Base {
16
17 /**
18 * Constructor
19 *
20 * @since 2.3.0
21 */
22 public function __construct() {
23
24 // Define the class that reads/writes settings.
25 $this->settings = new ConvertKit_Forminator_Settings();
26
27 // Define the settings key.
28 $this->settings_key = $this->settings::SETTINGS_NAME;
29
30 // Define the programmatic name, Title and Tab Text.
31 $this->name = 'forminator';
32 $this->title = __( 'Forminator Integration Settings', 'convertkit' );
33 $this->tab_text = __( 'Forminator', 'convertkit' );
34
35 // Define settings sections.
36 $this->settings_sections = array(
37 'general' => array(
38 'title' => $this->title,
39 'callback' => array( $this, 'print_section_info' ),
40 'wrap' => false,
41 ),
42 );
43
44 parent::__construct();
45
46 }
47
48 /**
49 * Prints help info for this section.
50 *
51 * @since 2.3.0
52 */
53 public function print_section_info() {
54
55 ?>
56 <p>
57 <?php
58 esc_html_e( 'Kit seamlessly integrates with Forminator to let you add subscribers using Forminator forms.', 'convertkit' );
59 ?>
60 </p>
61 <p>
62 <?php
63 esc_html_e( 'The Forminator form must have Name and Email fields. These fields will be sent to Kit for the subscription', 'convertkit' );
64 ?>
65 </p>
66 <p>
67 <?php esc_html_e( 'Each Forminator form and quiz has the following Kit options:', 'convertkit' ); ?>
68 <br />
69 <code><?php esc_html_e( 'Do not subscribe', 'convertkit' ); ?></code>: <?php esc_html_e( 'Do not subscribe the email address to Kit', 'convertkit' ); ?>
70 <br />
71 <code><?php esc_html_e( 'Subscribe', 'convertkit' ); ?></code>: <?php esc_html_e( 'Subscribes the email address to Kit', 'convertkit' ); ?>
72 <br />
73 <code><?php esc_html_e( 'Form', 'convertkit' ); ?></code>: <?php esc_html_e( 'Subscribes the email address to Kit, and adds the subscriber to the Kit form', 'convertkit' ); ?>
74 <br />
75 <code><?php esc_html_e( 'Tag', 'convertkit' ); ?></code>: <?php esc_html_e( 'Subscribes the email address to Kit, tagging the subscriber', 'convertkit' ); ?>
76 <br />
77 <code><?php esc_html_e( 'Sequence', 'convertkit' ); ?></code>: <?php esc_html_e( 'Subscribes the email address to Kit, and adds the subscriber to the Kit sequence', 'convertkit' ); ?>
78 </p>
79 <?php
80
81 }
82
83 /**
84 * Returns the URL for the ConvertKit documentation for this setting section.
85 *
86 * @since 2.3.0
87 *
88 * @return string Documentation URL.
89 */
90 public function documentation_url() {
91
92 return 'https://help.kit.com/en/articles/2502591-how-to-set-up-the-kit-plugin-on-your-wordpress-website';
93
94 }
95
96 /**
97 * Outputs the section as a WP_List_Table of Forminator Forms, with options to choose
98 * a ConvertKit Form mapping for each.
99 *
100 * @since 2.3.0
101 */
102 public function render() {
103
104 // Render opening container.
105 $this->render_container_start();
106
107 do_settings_sections( $this->settings_key );
108
109 // Get Forminator Forms.
110 $forminator_forms = $this->get_forminator_forms();
111
112 // Bail with an error if no Forminator Forms exist.
113 if ( ! $forminator_forms ) {
114 $this->output_error( __( 'No Forminator Forms or Quizzes exist in the Forminator Plugin.', 'convertkit' ) );
115 $this->render_container_end();
116 return;
117 }
118
119 // Warn the user if any Forminator Form subscribes to Kit, and has no Captcha field.
120 $this->maybe_output_spam_protection_warning( $forminator_forms );
121
122 // Get Creator Network Recommendations script.
123 $creator_network_recommendations = new ConvertKit_Resource_Creator_Network_Recommendations( 'forminator' );
124 $creator_network_recommendations_enabled = $creator_network_recommendations->enabled();
125
126 // Setup WP_List_Table.
127 $table = new ConvertKit_WP_List_Table();
128 $table->add_column( 'title', __( 'Forminator Form', 'convertkit' ), true );
129 $table->add_column( 'form', __( 'Kit', 'convertkit' ), false );
130 $table->add_column( 'creator_network_recommendations', __( 'Enable Creator Network Recommendations', 'convertkit' ), false );
131
132 // Iterate through Forminator Forms, building table array.
133 $table_rows = array();
134 foreach ( $forminator_forms as $forminator_form ) {
135 // Build row.
136 $table_row = array(
137 'title' => $forminator_form['name'],
138 'form' => convertkit_get_subscription_dropdown_field(
139 '_wp_convertkit_integration_forminator_settings[' . $forminator_form['id'] . ']',
140 (string) $this->settings->get_convertkit_subscribe_setting_by_forminator_form_id( $forminator_form['id'] ),
141 '_wp_convertkit_integration_forminator_settings_' . $forminator_form['id'],
142 'widefat',
143 'forminator'
144 ),
145 );
146
147 // Add Creator Network Recommendations table column.
148 if ( $creator_network_recommendations_enabled ) {
149 // Show checkbox to enable Creator Network Recommendations for this Forminator Form.
150 $table_row['creator_network_recommendations'] = $this->get_checkbox_field(
151 'creator_network_recommendations_' . $forminator_form['id'],
152 '1',
153 $this->settings->get_creator_network_recommendations_enabled_by_forminator_form_id( $forminator_form['id'] )
154 );
155 } else {
156 // Show a link to the ConvertKit billing page, as a paid plan is required for Creator Network Recommendations.
157 $table_row['creator_network_recommendations'] = sprintf(
158 '%s <a href="%s" target="_blank">%s</a>',
159 esc_html__( 'Creator Network Recommendations requires a', 'convertkit' ),
160 convertkit_get_billing_url(),
161 esc_html__( 'paid Kit Plan', 'convertkit' )
162 );
163 }
164
165 // Add row to table of settings.
166 $table_rows[] = $table_row;
167 }
168
169 // Sort table rows.
170 $table_rows = $table->reorder( $table_rows );
171
172 // Set items.
173 $table->add_items( $table_rows );
174 $table->set_total_items( count( $table_rows ) );
175
176 // Prepare and display WP_List_Table.
177 $table->prepare_items();
178 $table->display();
179
180 // Register settings field.
181 settings_fields( $this->settings_key );
182
183 // Render closing container.
184 $this->render_container_end();
185
186 // Render submit button.
187 submit_button();
188
189 }
190
191 /**
192 * Outputs a warning if one or more Forminator Forms subscribe email addresses
193 * to Kit, and have no Captcha field.
194 *
195 * @since 3.4.5
196 *
197 * @param array $forminator_forms Forminator Forms.
198 */
199 private function maybe_output_spam_protection_warning( $forminator_forms ) {
200
201 // Build a list of Forminator Forms that subscribe to Kit, with no Captcha field.
202 $unprotected_forms = array();
203 foreach ( $forminator_forms as $forminator_form ) {
204 if ( ! $this->settings->get_convertkit_subscribe_setting_by_forminator_form_id( $forminator_form['id'] ) ) {
205 continue;
206 }
207
208 if ( $this->form_has_spam_protection( $forminator_form['id'] ) ) {
209 continue;
210 }
211
212 $unprotected_forms[] = $forminator_form['name'];
213 }
214
215 // Bail if all Forminator Forms subscribing to Kit have a Captcha field.
216 if ( ! count( $unprotected_forms ) ) {
217 return;
218 }
219
220 $this->output_warning(
221 sprintf(
222 '%s <strong>%s</strong>. %s <a href="%s" target="_blank">%s</a>',
223 esc_html__( 'The following Forminator Forms subscribe email addresses to Kit, but have no spam protection:', 'convertkit' ),
224 esc_html( implode( ', ', $unprotected_forms ) ),
225 esc_html__( 'Bots may submit fake email addresses, which are then added to your Kit account.', 'convertkit' ),
226 'https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#captcha-field',
227 esc_html__( 'Add a Captcha field, or enable honeypot protection, in Forminator.', 'convertkit' )
228 ),
229 'convertkit-spam-protection-warning'
230 );
231
232 }
233
234 /**
235 * Determines if the given Forminator Form has spam protection, by way of a
236 * Captcha field or Forminator's honeypot setting.
237 *
238 * @since 3.4.5
239 *
240 * @param int $forminator_form_id Forminator Form ID.
241 * @return bool
242 */
243 private function form_has_spam_protection( $forminator_form_id ) {
244
245 if ( ! class_exists( 'Forminator_API' ) ) {
246 return false;
247 }
248
249 $form = Forminator_API::get_form( $forminator_form_id );
250
251 // Assume the form is protected if it can't be read, so we don't warn incorrectly.
252 if ( is_wp_error( $form ) ) {
253 return true;
254 }
255
256 // Determine if the form has honeypot protection enabled.
257 if ( isset( $form->settings['honeypot'] ) && filter_var( $form->settings['honeypot'], FILTER_VALIDATE_BOOLEAN ) ) {
258 return true;
259 }
260
261 // Determine if the form has a Captcha field.
262 foreach ( $form->get_fields() as $field ) {
263 $field_array = $field->to_formatted_array();
264 if ( ! empty( $field_array['type'] ) && $field_array['type'] === 'captcha' ) {
265 return true;
266 }
267 }
268
269 return false;
270
271 }
272
273 /**
274 * Gets available forms from Forminator
275 *
276 * @since 2.3.0
277 *
278 * @return bool|array
279 */
280 private function get_forminator_forms() {
281
282 $forms = array();
283
284 // Get all forms using Forminator API class.
285 foreach ( Forminator_API::get_forms( null, 1, -1 ) as $forminator_form ) {
286 $forms[] = array(
287 'id' => $forminator_form->id,
288 'name' => sprintf(
289 '%s: %s',
290 esc_html__( 'Form', 'convertkit' ),
291 $forminator_form->name
292 ),
293 );
294 }
295
296 foreach ( Forminator_API::get_quizzes( null, 1, -1 ) as $forminator_form ) {
297 $forms[] = array(
298 'id' => $forminator_form->id,
299 'name' => sprintf(
300 '%s: %s',
301 esc_html__( 'Quiz', 'convertkit' ),
302 $forminator_form->name
303 ),
304 );
305 }
306
307 // If no Forms or Quizzes were found in Forminator, return false.
308 if ( ! count( $forms ) ) {
309 return false;
310 }
311
312 return $forms;
313
314 }
315
316 }
317
318 // Register Admin Settings section.
319 add_filter(
320 'convertkit_admin_settings_register_sections',
321 /**
322 * Register Forminator as a settings section at Settings > Kit.
323 *
324 * @param array $sections Settings Sections.
325 * @return array
326 */
327 function ( $sections ) {
328
329 // Bail if Forminator isn't enabled.
330 if ( ! defined( 'FORMINATOR_VERSION' ) ) {
331 return $sections;
332 }
333
334 // Register this class as a section at Settings > Kit.
335 $sections['forminator'] = new ConvertKit_Forminator_Admin_Section();
336 return $sections;
337
338 }
339 );
340