PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.1.0
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.1.0
3.4.6 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 All 199 releases
← All changes | admin/section/class-convertkit-admin-section-tools.php +49 -47 3.4.1 → 3.1.0 View file →
@@ -18,8 +18,12 @@
18 18 * Constructor
19 19 */
20 20 public function __construct() {
21 21
22 + // Initialize WP_Filesystem.
23 + require_once ABSPATH . 'wp-admin/includes/file.php';
24 + WP_Filesystem();
25 +
22 26 $this->settings_key = '_wp_convertkit_tools'; // Required for ConvertKit_Settings_Base, but we don't save settings on the Tools screen.
23 27 $this->name = 'tools';
24 28 $this->title = __( 'Tools', 'convertkit' );
25 29 $this->tab_text = __( 'Tools', 'convertkit' );
@@ -48,19 +52,13 @@
48 52
49 53 return array_merge(
50 54 $notices,
51 55 array(
52 - 'import_configuration_upload_error' => __( 'An error occured uploading the configuration file.', 'convertkit' ),
53 - 'import_configuration_invalid_file_type' => __( 'The uploaded configuration file isn\'t valid.', 'convertkit' ),
54 - 'import_configuration_empty' => __( 'The uploaded configuration file contains no settings.', 'convertkit' ),
55 - 'import_configuration_success' => __( 'Configuration imported successfully.', 'convertkit' ),
56 - 'migrate_activecampaign_configuration_success' => __( 'ActiveCampaign forms migrated successfully.', 'convertkit' ),
57 - 'migrate_aweber_configuration_success' => __( 'AWeber forms migrated successfully.', 'convertkit' ),
58 - 'migrate_campaignmonitor_configuration_success' => __( 'Campaign Monitor forms migrated successfully.', 'convertkit' ),
59 - 'migrate_convertkit_legacy_forms_configuration_success' => __( 'Kit Legacy Forms migrated successfully.', 'convertkit' ),
60 - 'migrate_mc4wp_configuration_success' => __( 'MC4WP forms migrated successfully.', 'convertkit' ),
61 - 'migrate_mailpoet_configuration_success' => __( 'MailPoet forms migrated successfully.', 'convertkit' ),
62 - 'migrate_newsletter_configuration_success' => __( 'Newsletter forms migrated successfully.', 'convertkit' ),
56 + 'import_configuration_upload_error' => __( 'An error occured uploading the configuration file.', 'convertkit' ),
57 + 'import_configuration_invalid_file_type' => __( 'The uploaded configuration file isn\'t valid.', 'convertkit' ),
58 + 'import_configuration_empty' => __( 'The uploaded configuration file contains no settings.', 'convertkit' ),
59 + 'import_configuration_success' => __( 'Configuration imported successfully.', 'convertkit' ),
60 + 'migrate_mc4wp_configuration_success' => __( 'MC4WP forms migrated successfully.', 'convertkit' ),
63 61 )
64 62 );
65 63
66 64 }
@@ -77,9 +75,9 @@
77 75 $this->maybe_download_log();
78 76 $this->maybe_download_system_info();
79 77 $this->maybe_export_configuration();
80 78 $this->maybe_import_configuration();
81 - $this->maybe_migrate_forms();
79 + $this->maybe_migrate_mc4wp_configuration();
82 80
83 81 }
84 82
85 83 /**
@@ -120,8 +118,10 @@
120 118 * @since 1.9.6
121 119 */
122 120 private function maybe_download_log() {
123 121
122 + global $wp_filesystem;
123 +
124 124 // Bail if nonce verification fails.
125 125 if ( ! isset( $_REQUEST['_convertkit_settings_tools_nonce'] ) ) {
126 126 return;
127 127 }
@@ -142,10 +142,9 @@
142 142 header( 'Content-type: application/octet-stream' );
143 143 header( 'Content-Disposition: attachment; filename=convertkit-log.txt' );
144 144 header( 'Pragma: no-cache' );
145 145 header( 'Expires: 0' );
146 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
147 - echo esc_html( (string) file_get_contents( $log->get_filename() ) );
146 + echo esc_html( $wp_filesystem->get_contents( $log->get_filename() ) );
148 147 exit();
149 148
150 149 }
151 150
@@ -156,8 +155,10 @@
156 155 * @since 1.9.6
157 156 */
158 157 private function maybe_download_system_info() {
159 158
159 + global $wp_filesystem;
160 +
160 161 // Bail if nonce verification fails.
161 162 if ( ! isset( $_REQUEST['_convertkit_settings_tools_nonce'] ) ) {
162 163 return;
163 164 }
@@ -173,14 +174,23 @@
173 174
174 175 // Get System Info.
175 176 $system_info = $this->get_system_info();
176 177
178 + // Write contents to temporary file.
179 + $tmpfile = tmpfile();
180 + $filename = stream_get_meta_data( $tmpfile )['uri'];
181 + $wp_filesystem->put_contents(
182 + $filename,
183 + esc_attr( $system_info )
184 + );
185 +
177 186 // Download.
178 187 header( 'Content-type: application/octet-stream' );
179 188 header( 'Content-Disposition: attachment; filename=convertkit-system-info.txt' );
180 189 header( 'Pragma: no-cache' );
181 190 header( 'Expires: 0' );
182 - echo esc_html( $system_info );
191 + echo esc_html( $wp_filesystem->get_contents( $filename ) );
192 + $wp_filesystem->delete( $filename );
183 193 exit();
184 194
185 195 }
186 196
@@ -246,8 +256,13 @@
246 256 if ( ! wp_verify_nonce( sanitize_key( $_REQUEST['_convertkit_settings_tools_nonce'] ), 'convertkit-settings-tools' ) ) {
247 257 return;
248 258 }
249 259
260 + // Allow us to easily interact with the filesystem.
261 + require_once ABSPATH . 'wp-admin/includes/file.php';
262 + WP_Filesystem();
263 + global $wp_filesystem;
264 +
250 265 // Bail if the submit button for importing the configuration was not clicked.
251 266 if ( ! array_key_exists( 'convertkit-import', $_REQUEST ) ) {
252 267 return;
253 268 }
@@ -262,10 +277,9 @@
262 277 $this->redirect_with_error_notice( 'import_configuration_upload_error' );
263 278 }
264 279
265 280 // Read file.
266 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
267 - $json = file_get_contents( sanitize_text_field( wp_unslash( $_FILES['import']['tmp_name'] ) ) );
281 + $json = $wp_filesystem->get_contents( sanitize_text_field( wp_unslash( $_FILES['import']['tmp_name'] ) ) );
268 282
269 283 // Decode.
270 284 $import = json_decode( $json, true );
271 285
@@ -302,14 +316,14 @@
302 316
303 317 }
304 318
305 319 /**
306 - * Replaces ActiveCampaign Form Shortcodes and Blocks with Kit Form Shortcodes and Blocks, if the user submitted the
307 - * ActiveCampaign Migrate Configuration section.
320 + * Replaces MC4WP Form Shortcodes with Kit Form Shortcodes, if the user submitted the
321 + * MC4WP Migrate Configuration section.
308 322 *
309 - * @since 3.1.7
323 + * @since 3.1.0
310 324 */
311 - private function maybe_migrate_forms() {
325 + private function maybe_migrate_mc4wp_configuration() {
312 326
313 327 // Bail if nonce verification fails.
314 328 if ( ! isset( $_REQUEST['_convertkit_settings_tools_nonce'] ) ) {
315 329 return;
@@ -318,33 +332,24 @@
318 332 if ( ! wp_verify_nonce( sanitize_key( $_REQUEST['_convertkit_settings_tools_nonce'] ), 'convertkit-settings-tools' ) ) {
319 333 return;
320 334 }
321 335
322 - // Get importers.
323 - $importers = convertkit_get_form_importers();
336 + // Bail if no MC4WP Form IDs were submitted.
337 + if ( ! isset( $_REQUEST['_wp_convertkit_integration_mc4wp_settings'] ) ) {
338 + return;
339 + }
324 340
325 - // Find the importer that was used for the form submission.
326 - foreach ( $importers as $importer ) {
327 - // Skip if this importer was not used.
328 - if ( ! isset( $_REQUEST[ 'convertkit-import-' . $importer['name'] ] ) ) {
329 - continue;
330 - }
341 + // Initialise the importer.
342 + $mc4wp = new ConvertKit_Admin_Importer_MC4WP();
331 343
332 - // Skip if no mappings were submitted for the importer.
333 - if ( ! isset( $_REQUEST[ '_wp_convertkit_integration_' . $importer['name'] . '_settings' ] ) ) {
334 - continue;
335 - }
344 + // Iterate through the MC4WP Form IDs and replace the shortcodes with the Kit Form Shortcodes.
345 + foreach ( array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['_wp_convertkit_integration_mc4wp_settings'] ) ) as $mc4wp_form_id => $kit_form_id ) {
346 + $mc4wp->replace_shortcodes_in_posts( (int) $mc4wp_form_id, (int) $kit_form_id );
347 + }
336 348
337 - // Sanitize mappings.
338 - $mappings = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST[ '_wp_convertkit_integration_' . $importer['name'] . '_settings' ] ) );
349 + // Redirect to Tools screen.
350 + $this->redirect_with_success_notice( 'migrate_mc4wp_configuration_success' );
339 351
340 - // Replace third party form shortcodes and blocks with Kit form shortcodes and blocks.
341 - WP_ConvertKit()->get_class( 'admin_importer_' . $importer['name'] )->import( $mappings );
342 -
343 - // Redirect to Tools screen.
344 - $this->redirect_with_success_notice( 'migrate_' . $importer['name'] . '_configuration_success' );
345 - }
346 -
347 352 }
348 353
349 354 /**
350 355 * Outputs the Debug Log and System Info view.
@@ -366,13 +371,10 @@
366 371
367 372 // Get Forms.
368 373 $forms = new ConvertKit_Resource_Forms();
369 374
370 - // Get Importers, if Kit Forms exist.
371 - $importers = array();
372 - if ( $forms->exist() ) {
373 - $importers = convertkit_get_form_importers();
374 - }
375 + // Get Importers.
376 + $mc4wp = new ConvertKit_Admin_Importer_MC4WP();
375 377
376 378 // Output view.
377 379 require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/settings/tools.php';
378 380