: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/* global wpforms_education_lite_connect, WPFormsChallenge */
* WPForms Education for Lite.
// eslint-disable-next-line no-var
var WPFormsEducation = window.WPFormsEducation || {};
WPFormsEducation.liteConnect = window.WPFormsEducation.liteConnect || ( function( document, window, $ ) {
* Public functions and properties.
$( window ).on( 'load', function() {
// In the case of jQuery 3.+, we need to wait for a ready event first.
if ( typeof $.ready.then === 'function' ) {
$.ready.then( app.load );
app.initLiteConnectToggle();
app.maybeRevealBuilderTopBar();
app.enableLiteConnectToggleClick();
app.enableLiteConnectButtonClick();
app.dismissBuilderTopBarClick();
app.autoSaveToggleChange();
* Init Lite Connect toggle.
initLiteConnectToggle() {
$( '.wpforms-toggle-control.wpforms-setting-lite-connect-auto-save-toggle input' ).prop( 'disabled', false );
* Enable Lite Connect toggle mousedown handler.
enableLiteConnectToggleClick() {
'#wpforms-setting-row-lite-connect-enabled label, .wpforms-setting-lite-connect-auto-save-toggle label',
const isTouchDevice = 'ontouchstart' in document.documentElement;
const wrapper = $( this ).closest( '#wpforms-setting-row-lite-connect-enabled, .wpforms-setting-lite-connect-auto-save-toggle' );
const $input = wrapper.find( '#wpforms-setting-lite-connect-enabled' );
if ( $input.prop( 'disabled' ) ) {
const isEnabled = $input.is( ':checked' );
app.openSettingsLiteConnectModal( isEnabled, function() {
.prop( 'disabled', true );
* Enable Lite Connect button click handler.
enableLiteConnectButtonClick() {
'.wpforms-dyk-lite-connect .button-primary',
const $button = $( this );
if ( $button.hasClass( 'wpforms-is-enabled' ) ) {
window.open( $button.attr( 'href' ) );
app.openSettingsLiteConnectModal(
app.enableLiteConnectButtonModalConfirm
* Enable Lite Connect button modal confirm Callback.
enableLiteConnectButtonModalConfirm() {
const $toggle = $( '.wpforms-dyk-lite-connect .button-primary' );
app.saveSettingAjaxPost( true, $toggle, function() {
app.switchSettingView( true, $toggle );
* Form Entry Backups information modal.
* @param {boolean} isEnabled Current setting state.
* @param {Function} confirmCallback Confirm button action.
openSettingsLiteConnectModal( isEnabled, confirmCallback ) {
app.openSettingsLiteConnectDisableModal( confirmCallback );
app.openSettingsLiteConnectEnableModal( confirmCallback );
* Form Entry Backups enable information modal.
* @param {Function} confirmCallback Confirm button action.
openSettingsLiteConnectEnableModal( confirmCallback ) {
content: wp.template( 'wpforms-settings-lite-connect-modal-content' )(),
scrollToPreviousElement: false,
text: wpforms_education_lite_connect.enable_modal.confirm,
if ( typeof confirmCallback === 'function' ) {
// Maybe close Challenge popup.
if ( window.WPFormsChallenge ) {
// eslint-disable-next-line no-var
var completeChallenge = WPFormsChallenge.embed && WPFormsChallenge.embed.completeChallenge;
if ( typeof completeChallenge === 'function' ) {
text: wpforms_education_lite_connect.enable_modal.cancel,
$( '.wpforms-challenge-popup-container' ).removeClass( 'wpforms-invisible' );
$( 'body' ).addClass( 'wpforms-setting-lite-connect-modal' );
$( '.wpforms-challenge-popup-container' ).addClass( 'wpforms-invisible' );
$( 'body' ).removeClass( 'wpforms-setting-lite-connect-modal' );
* Form Entry Backups disable information modal.
* @param {Function} confirmCallback Confirm button action.
openSettingsLiteConnectDisableModal( confirmCallback ) {
title: wpforms_education_lite_connect.disable_modal.title,
content: wpforms_education_lite_connect.disable_modal.content,
icon: 'fa fa-exclamation-circle',
animateFromElement: false,
scrollToPreviousElement: false,
text: wpforms_education_lite_connect.disable_modal.cancel,
text: wpforms_education_lite_connect.disable_modal.confirm,
if ( typeof confirmCallback === 'function' ) {
* Save Lite Connect Enabled setting AJAX post call.
* @param {boolean} isEnabled Lite Connect setting flag.
* @param {jQuery|undefined} $toggle Toggle control outer element.
* @param {Function} successCallback Success result callback.
saveSettingAjaxPost( isEnabled, $toggle, successCallback ) {
$toggle = $toggle || $();
const $input = $toggle.find( 'input' );
wpforms_education_lite_connect.ajax_url,
action: 'wpforms_update_lite_connect_enabled_setting',
value: isEnabled ? 1 : 0,
nonce: wpforms_education_lite_connect.nonce,
).done( function( res ) {
$input.prop( 'checked', ! isEnabled );
app.updateResultModal( 'error' );
app.updateResultModal( isEnabled ? 'enabled' : 'disabled' );
if ( typeof successCallback === 'function' ) {
$input.prop( 'checked', ! isEnabled );
app.updateResultModal( 'error' );
$input.prop( 'disabled', false );
* Lite Connect toggle `change` event handler with "auto save" feature.
'.wpforms-toggle-control.wpforms-setting-lite-connect-auto-save-toggle input',
const $input = $( this ),
$toggle = $input.closest( '.wpforms-toggle-control' ),
isEnabled = $input.is( ':checked' );
app.saveSettingAjaxPost( isEnabled, $toggle, function() {
app.switchSettingView( isEnabled, $toggle );
* After updating setting via AJAX we should hide toggle container and show info container.
* @param {boolean} isEnabled Toggle state.
* @param {jQuery} $toggle Toggle control.
switchSettingView( isEnabled, $toggle ) {
const $wrapper = $toggle.closest( '.wpforms-education-lite-connect-wrapper' ),
$setting = $wrapper.find( '.wpforms-education-lite-connect-setting' ),
$enabledInfo = $wrapper.find( '.wpforms-education-lite-connect-enabled-info' );
$setting.toggleClass( 'wpforms-hidden', isEnabled );
$enabledInfo.toggleClass( 'wpforms-hidden', ! isEnabled );
* Update result message modal.
* @param {string} msg Message slug.
updateResultModal( msg ) {
if ( ! wpforms_education_lite_connect.update_result[ msg ] ) {
title: wpforms_education_lite_connect.update_result[ msg + '_title' ],
content: wpforms_education_lite_connect.update_result[ msg ],
icon: 'fa fa-check-circle',
type: msg === 'error' ? 'red' : 'green',
animateFromElement: false,
scrollToPreviousElement: false,
text : wpforms_education_lite_connect.update_result.close,
* Reveal top bar in the Form Builder.
maybeRevealBuilderTopBar() {
// Skip it is not Form Builder or Entry Backups is already enabled or top bar is dismissed.
! window.wpforms_builder ||
wpforms_education_lite_connect.is_enabled === '1' ||
$( '#wpforms-builder-lite-connect-top-bar' ).length === 0
app.toggleBuilderTopBar( true );
* Toggle top bar in the Form Builder.
* @param {boolean} open True for open, false for close.
toggleBuilderTopBar( open ) {
const cssVar = '--wpforms-admin-bar-height';
const root = document.documentElement;
let adminBarHeight = parseInt( getComputedStyle( root ).getPropertyValue( cssVar ), 10 );
adminBarHeight += open ? topBarHeight : -topBarHeight;
cssVar + ': ' + ( adminBarHeight ) + 'px!important;'
* Dismiss top bar in the Form Builder.
dismissBuilderTopBarClick() {
'#wpforms-builder-lite-connect-top-bar .wpforms-dismiss-button',
app.toggleBuilderTopBar( false );
// Provide access to public functions/properties.
}( document, window, jQuery ) );
WPFormsEducation.liteConnect.init();