Skip to content

Commit 6749ab9

Browse files
authored
Merge pull request #3324 from Strategy11/fix_license_status_displayed_when_connecting
Fix license status displayed when connecting
2 parents 3a4e635 + c4837fb commit 6749ab9

3 files changed

Lines changed: 51 additions & 1 deletion

File tree

classes/models/FrmAddon.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,26 @@ private function activate_license( $license ) {
11741174

11751175
$this->update_last_checked( (bool) $is_valid );
11761176

1177+
if ( $is_valid ) {
1178+
// Setting the license active clears the license caches, so the new license details are available here.
1179+
$response = $this->add_activation_response_data( $response );
1180+
}
1181+
1182+
return $response;
1183+
}
1184+
1185+
/**
1186+
* Add extra details to the response for a license that just activated.
1187+
* Pro overrides this to include the license type, so the license message
1188+
* can be updated without reloading the page.
1189+
*
1190+
* @since x.x
1191+
*
1192+
* @param array $response The activation response.
1193+
*
1194+
* @return array
1195+
*/
1196+
protected function add_activation_response_data( $response ) {
11771197
return $response;
11781198
}
11791199

js/formidable_admin.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/src/admin/admin.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ window.FrmFormsConnect = window.FrmFormsConnect || ( function( document, window,
119119

120120
if ( msg.success === true ) {
121121
app.showAuthorized( true );
122+
app.showLicenseType( msg );
122123
app.showInlineSuccess();
123124

124125
/**
@@ -157,6 +158,35 @@ window.FrmFormsConnect = window.FrmFormsConnect || ( function( document, window,
157158
}
158159
},
159160

161+
/**
162+
* Update the license type message with the license that was just activated.
163+
* The message is printed before the license is known, so it would otherwise
164+
* keep showing the Lite copy until the page is reloaded.
165+
*
166+
* @since x.x
167+
*
168+
* @param {Object} msg The response from the authorize request.
169+
* @return {void}
170+
*/
171+
showLicenseType( msg ) {
172+
if ( ! msg.license_type_info ) {
173+
return;
174+
}
175+
176+
document.querySelectorAll( '.frm_license_type_info' ).forEach( function( element ) {
177+
element.textContent = msg.license_type_info;
178+
} );
179+
180+
if ( msg.license_type !== 'Elite' ) {
181+
return;
182+
}
183+
184+
// There is nothing left to upgrade to.
185+
document.querySelectorAll( '.frm_license_upgrade_cta' ).forEach( function( element ) {
186+
element.remove();
187+
} );
188+
},
189+
160190
/**
161191
* Use the data-success element to replace the element content.
162192
*/

0 commit comments

Comments
 (0)