From 6ef3b1d735b2bcdc29b7408c4bec1594a388f069 Mon Sep 17 00:00:00 2001 From: Nick Cernis Date: Wed, 1 May 2019 16:33:40 +0200 Subject: [PATCH] Prevent form creation attempts if WPForms Lite version is < 1.5.2 Creating a working form via the WPForms API requires 1.5.2 or higher. If the site already has WPForms Lite installed but it's an older version, form creation will fail, breaking the onboarding process. --- lib/wpforms.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/wpforms.php b/lib/wpforms.php index e0bb3d12..68df1260 100644 --- a/lib/wpforms.php +++ b/lib/wpforms.php @@ -24,6 +24,18 @@ function studiopress_maybe_create_wpforms_form() { // phpcs:ignore -- studiopres return; } + // Form creation requires WPForms 1.5.2 or higher. + // If the site already as an earlier version of the plugin installed, don't create a form. + // Plugins do not get upgraded during one-click theme setup. + if ( function_exists( 'get_plugins' ) ) { + $plugin_data = get_plugins(); + $wpforms_lite_version = isset( $plugin_data['wpforms-lite/wpforms.php']['Version'] ) ? $plugin_data['wpforms-lite/wpforms.php']['Version'] : ''; + + if ( version_compare( $wpforms_lite_version, '1.5.2', '<' ) ) { + return; + } + } + $existing_form_id = get_option( 'genesis_onboarding_wpforms_id' ); if ( $existing_form_id ) {