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
convertkit / includes / integrations / contactform7 / class-convertkit-contactform7-admin-section.php

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

260 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Contact Form 7 Admin Settings class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Registers Contact Form 7 Settings that can be edited at Settings > Kit > Contact Form 7.
11 *
12 * @package ConvertKit
13 * @author ConvertKit
14 */
15 class ConvertKit_ContactForm7_Admin_Section extends ConvertKit_Admin_Section_Base {
16
17 /**
18 * Constructor
19 */
20 public function __construct() {
21
22 // Define the class that reads/writes settings.
23 $this->settings = new ConvertKit_ContactForm7_Settings();
24
25 // Define the settings key.
26 $this->settings_key = $this->settings::SETTINGS_NAME;
27
28 // Define the programmatic name, Title and Tab Text.
29 $this->name = 'contactform7';
30 $this->title = __( 'Contact Form 7 Integration Settings', 'convertkit' );
31 $this->tab_text = __( 'Contact Form 7', 'convertkit' );
32
33 // Define settings sections.
34 $this->settings_sections = array(
35 'general' => array(
36 'title' => $this->title,
37 'callback' => array( $this, 'print_section_info' ),
38 'wrap' => false,
39 ),
40 );
41
42 parent::__construct();
43
44 }
45
46 /**
47 * Register fields for this section
48 */
49 public function register_fields() {
50
51 // No fields are registered, because they are output in a WP_List_Table
52 // in this class' render() function.
53 // This function is deliberately blank.
54 }
55
56 /**
57 * Prints help info for this section.
58 */
59 public function print_section_info() {
60
61 ?>
62 <p>
63 <?php
64 esc_html_e( 'Kit seamlessly integrates with Contact Form 7 to let you add subscribers using Contact Form 7 forms.', 'convertkit' );
65 ?>
66 </p>
67 <p>
68 <?php
69 printf(
70 '%s <code>text*</code> %s <code>your-name</code> %s <code>email*</code> %s <code>your-email</code>%s',
71 esc_html__( 'The Contact Form 7 form must have a', 'convertkit' ),
72 esc_html__( 'field named', 'convertkit' ),
73 esc_html__( 'and an', 'convertkit' ),
74 esc_html__( 'field named', 'convertkit' ),
75 esc_html__( '. These fields will be sent to Kit for the subscription.', 'convertkit' )
76 );
77 ?>
78 </p>
79 <p>
80 <?php esc_html_e( 'Each Contact Form 7 Form has the following Kit options:', 'convertkit' ); ?>
81 <br />
82 <code><?php esc_html_e( 'Do not subscribe', 'convertkit' ); ?></code>: <?php esc_html_e( 'Do not subscribe the email address to Kit', 'convertkit' ); ?>
83 <br />
84 <code><?php esc_html_e( 'Subscribe', 'convertkit' ); ?></code>: <?php esc_html_e( 'Subscribes the email address to Kit', 'convertkit' ); ?>
85 <br />
86 <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' ); ?>
87 <br />
88 <code><?php esc_html_e( 'Tag', 'convertkit' ); ?></code>: <?php esc_html_e( 'Subscribes the email address to Kit, tagging the subscriber', 'convertkit' ); ?>
89 <br />
90 <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' ); ?>
91 </p>
92 <?php
93
94 }
95
96 /**
97 * Returns the URL for the ConvertKit documentation for this setting section.
98 *
99 * @since 2.0.8
100 *
101 * @return string Documentation URL.
102 */
103 public function documentation_url() {
104
105 return 'https://help.kit.com/en/articles/2502591-how-to-set-up-the-kit-plugin-on-your-wordpress-website';
106
107 }
108
109 /**
110 * Outputs the section as a WP_List_Table of Contact Form 7 Forms, with options to choose
111 * a ConvertKit Form mapping for each.
112 *
113 * @since 1.9.6
114 */
115 public function render() {
116
117 // Render opening container.
118 $this->render_container_start();
119
120 do_settings_sections( $this->settings_key );
121
122 // Get Contact Form 7 Forms.
123 $cf7_forms = $this->get_cf7_forms();
124
125 // Bail with an error if no Contact Form 7 Forms exist.
126 if ( ! $cf7_forms ) {
127 $this->output_error( __( 'No Contact Form 7 Forms exist in the Contact Form 7 Plugin.', 'convertkit' ) );
128 $this->render_container_end();
129 return;
130 }
131
132 // Get Creator Network Recommendations script.
133 $creator_network_recommendations = new ConvertKit_Resource_Creator_Network_Recommendations( 'contact_form_7' );
134 $creator_network_recommendations_enabled = $creator_network_recommendations->enabled();
135
136 // Setup WP_List_Table.
137 $table = new ConvertKit_WP_List_Table();
138 $table->add_column( 'title', __( 'Contact Form 7 Form', 'convertkit' ), true );
139 $table->add_column( 'form', __( 'Kit', 'convertkit' ), false );
140 $table->add_column( 'email', __( 'Contact Form 7 Email Field', 'convertkit' ), false );
141 $table->add_column( 'name', __( 'Contact Form 7 Name Field', 'convertkit' ), false );
142 $table->add_column( 'creator_network_recommendations', __( 'Enable Creator Network Recommendations', 'convertkit' ), false );
143
144 // Iterate through Contact Form 7 Forms, building table array.
145 $table_rows = array();
146 foreach ( $cf7_forms as $cf7_form ) {
147 // Build row.
148 $table_row = array(
149 'title' => $cf7_form['name'],
150 'form' => convertkit_get_subscription_dropdown_field(
151 '_wp_convertkit_integration_contactform7_settings[' . $cf7_form['id'] . ']',
152 (string) $this->settings->get_convertkit_subscribe_setting_by_cf7_form_id( $cf7_form['id'] ),
153 '_wp_convertkit_integration_contactform7_settings_' . $cf7_form['id'],
154 'widefat',
155 'contact_form_7'
156 ),
157 'email' => 'your-email',
158 'name' => 'your-name',
159 );
160
161 // Add Creator Network Recommendations table column.
162 if ( $creator_network_recommendations_enabled ) {
163 // Show checkbox to enable Creator Network Recommendations for this Contact Form 7 Form.
164 $table_row['creator_network_recommendations'] = $this->get_checkbox_field(
165 'creator_network_recommendations_' . $cf7_form['id'],
166 '1',
167 $this->settings->get_creator_network_recommendations_enabled_by_cf7_form_id( $cf7_form['id'] )
168 );
169 } else {
170 // Show a link to the ConvertKit billing page, as a paid plan is required for Creator Network Recommendations.
171 $table_row['creator_network_recommendations'] = sprintf(
172 '%s <a href="%s" target="_blank">%s</a>',
173 esc_html__( 'Creator Network Recommendations requires a', 'convertkit' ),
174 convertkit_get_billing_url(),
175 esc_html__( 'paid Kit Plan', 'convertkit' )
176 );
177 }
178
179 // Add row to table of settings.
180 $table_rows[] = $table_row;
181 }
182
183 // Sort table rows.
184 $table_rows = $table->reorder( $table_rows );
185
186 // Set items.
187 $table->add_items( $table_rows );
188 $table->set_total_items( count( $table_rows ) );
189
190 // Prepare and display WP_List_Table.
191 $table->prepare_items();
192 $table->display();
193
194 // Register settings field.
195 settings_fields( $this->settings_key );
196
197 // Render closing container.
198 $this->render_container_end();
199
200 // Render submit button.
201 submit_button();
202
203 }
204
205 /**
206 * Gets available forms from CF7
207 */
208 private function get_cf7_forms() {
209
210 $forms = array();
211
212 $result = new WP_Query(
213 array(
214 'post_type' => 'wpcf7_contact_form',
215 'posts_per_page' => -1,
216 'orderby' => 'ID',
217 'order' => 'ASC',
218 )
219 );
220
221 if ( ! count( $result->posts ) ) {
222 return false;
223 }
224
225 foreach ( $result->posts as $post ) {
226 $forms[] = array(
227 'id' => $post->ID,
228 'name' => $post->post_title,
229 );
230 }
231
232 return $forms;
233
234 }
235
236 }
237
238 // Register Admin Settings section.
239 add_filter(
240 'convertkit_admin_settings_register_sections',
241 /**
242 * Register WishList Member as a section at Settings > Kit.
243 *
244 * @param array $sections Settings Sections.
245 * @return array
246 */
247 function ( $sections ) {
248
249 // Bail if Contact Form 7 isn't enabled.
250 if ( ! defined( 'WPCF7_VERSION' ) ) {
251 return $sections;
252 }
253
254 // Register this class as a section at Settings > Kit.
255 $sections['contactform7'] = new ConvertKit_ContactForm7_Admin_Section();
256 return $sections;
257
258 }
259 );
260