: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/* global wpforms_education, WPFormsBuilder, wpf */
* WPForms Education Core.
// noinspection ES6ConvertVarToLetConst
* @param wpforms_education.activate_confirm
* @param wpforms_education.activate_prompt
* @param wpforms_education.activating
* @param wpforms_education.addon_activated
* @param wpforms_education.addon_error
* @param wpforms_education.ajax_url
* @param wpforms_education.can_activate_addons
* @param wpforms_education.can_install_addons
* @param wpforms_education.cancel
* @param wpforms_education.close
* @param wpforms_education.install_confirm
* @param wpforms_education.install_prompt
* @param wpforms_education.installing
* @param wpforms_education.nonce
* @param wpforms_education.ok
* @param wpforms_education.plugin_activated
* @param wpforms_education.save_confirm
* @param wpforms_education.save_prompt
* @param wpforms_education.saving
* @param wpforms_education.thanks_for_interest
* @param wpforms_education.upgrade
* @param wpforms_education.upgrade.modal
* @param wpforms_education.upgrade.url
* @param wpforms_education.upgrade.url_template
var WPFormsEducation = window.WPFormsEducation || {}; // eslint-disable-line no-var
WPFormsEducation.core = window.WPFormsEducation.core || ( function( document, window, $ ) {
const spinner = '<i class="wpforms-loading-spinner wpforms-loading-white wpforms-loading-inline"></i>';
* Public functions and properties.
app.openModalButtonClick();
app.gotoAdvancedTabClick();
.on( 'click', '.education-modal:not(.wpforms-add-fields-button)', app.openModalButtonHandler )
.on( 'mousedown', '.education-modal.wpforms-add-fields-button', app.openModalButtonHandler );
* Open education modal handler.
* @param {Event} event Event.
openModalButtonHandler( event ) {
switch ( $this.data( 'action' ) ) {
app.activateModal( $this );
app.installModal( $this );
$( document ).on( 'click', '.wpforms-dismiss-container .wpforms-dismiss-button', function() {
$cont = $this.closest( '.wpforms-dismiss-container' ),
action: 'wpforms_education_dismiss',
nonce: wpforms_education.nonce,
section: $this.data( 'section' ),
page: typeof window.pagenow === 'string' ? window.pagenow : '',
let $out = $cont.find( '.wpforms-dismiss-out' );
if ( $cont.hasClass( 'wpforms-dismiss-out' ) ) {
$.post( wpforms_education.ajax_url, data );
* Calculate and dynamically set the DYK block cell colspan attribute.
const $dykCell = $( '.wpforms-dyk td' ),
colCount = $( '.wp-list-table thead .manage-column' ).not( '.hidden' ).length;
$dykCell.attr( 'colspan', colCount );
* Go to Advanced tab when click on the link in Calculations educational notice.
.on( 'click', '.wpforms-educational-alert.wpforms-calculations a', function( e ) {
if ( $a.attr( 'href' ) !== '#advanced-tab' ) {
$a.closest( '.wpforms-field-option' )
.find( '.wpforms-field-option-group-advanced .wpforms-field-option-group-toggle' )
* Get UTM content for different elements.
* @param {jQuery} $el Element.
* @return {string} UTM content string.
getUTMContentValue( $el ) {
// UTM content for Fields.
if ( $el.hasClass( 'wpforms-add-fields-button' ) ) {
return $el.data( 'utm-content' ) + ' Field';
// UTM content for Templates.
if ( $el.hasClass( 'wpforms-template-select' ) ) {
return app.slugToUTMContent( $el.data( 'slug' ) );
// UTM content for Addons (sidebar).
if ( $el.hasClass( 'wpforms-panel-sidebar-section' ) ) {
return app.slugToUTMContent( $el.data( 'slug' ) ) + ' Addon';
// UTM content by default with fallback `data-name`.
return $el.data( 'utm-content' ) || $el.data( 'name' );
* Convert slug to UTM content.
* @param {string} slug Slug.
* @return {string} UTM content string.
slugToUTMContent( slug ) {
// Replace all non-alphanumeric characters with space.
.replace( /[^a-z\d ]/gi, ' ' )
.replace( /\b[a-z]/g, function( char ) {
return char.toUpperCase();
* Get upgrade URL according to the UTM content and license type.
* @param {string} utmContent UTM content.
* @param {string} type Feature license type: pro or elite.
* @return {string} Upgrade URL.
getUpgradeURL( utmContent, type ) {
let baseURL = wpforms_education.upgrade[ type ].url;
if ( utmContent.toLowerCase().indexOf( 'template' ) > -1 ) {
baseURL = wpforms_education.upgrade[ type ].url_template;
// Test if the base URL already contains `?`.
let appendChar = /(\?)/.test( baseURL ) ? '&' : '?';
// If the upgrade link is changed by partners, appendChar has to be encoded.
if ( baseURL.indexOf( 'https://wpforms.com' ) === -1 ) {
appendChar = encodeURIComponent( appendChar );
return baseURL + appendChar + 'utm_content=' + encodeURIComponent( utmContent.trim() );
* Upgrade modal second state.
* @param {string} type Feature license type: pro or elite.
upgradeModalThankYou: ( type ) => {
title: wpforms_education.thanks_for_interest,
content: wpforms_education.upgrade[ type ].modal,
icon: 'fa fa-info-circle',
text: wpforms_education.ok,
* @return {string} Spinner markup.
* @param {jQuery} $button jQuery button element.
activateModal( $button ) {
const feature = $button.data( 'name' ),
message = $button.data( 'message' );
const canActivateAddons = wpforms_education.can_activate_addons;
content: message ? message : wpforms_education.activate_prompt.replace( /%name%/g, feature ),
icon: 'fa fa-info-circle',
text: wpforms_education.activate_confirm,
btnClass: 'btn-confirm' + ( ! canActivateAddons ? ' hidden' : '' ),
isHidden: ! canActivateAddons,
.prop( 'disabled', true )
.html( spinner + wpforms_education.activating );
.prop( 'disabled', true );
app.activateAddon( $button, this );
text: wpforms_education.cancel,
* Activate addon via AJAX.
* @param {jQuery} $button jQuery button element.
* @param {Object} previousModal Previous modal instance.
activateAddon( $button, previousModal ) {
const path = $button.data( 'path' ),
pluginType = $button.data( 'type' ),
nonce = $button.data( 'nonce' ),
hideOnSuccess = $button.data( 'hide-on-success' );
wpforms_education.ajax_url,
action: 'wpforms_activate_addon',
app.saveModal( pluginType === 'plugin' ? wpforms_education.plugin_activated : wpforms_education.addon_activated );
icon: 'fa fa-exclamation-circle',
text: wpforms_education.close,
* Ask user if they would like to save form and refresh form builder.
* @param {string} title Modal title.
* @param {string|boolean} content Modal content.
saveModal( title, content = false ) {
title = title || wpforms_education.addon_activated;
content = content || wpforms_education.save_prompt;
title: title.replace( /\.$/, '' ), // Remove a dot in the title end.
icon: 'fa fa-check-circle',
text: wpforms_education.save_confirm,
if ( typeof WPFormsBuilder === 'undefined' ) {
.prop( 'disabled', true )
.html( spinner + wpforms_education.saving );
.prop( 'disabled', true );
if ( WPFormsBuilder.formIsSaved() ) {
const saveForm = WPFormsBuilder.formSave( false );
saveForm.done( function() {
text: wpforms_education.close,
* @param {jQuery} $button jQuery button element.
installModal( $button ) {
const feature = $button.data( 'name' ),
url = $button.data( 'url' );
if ( ! url || '' === url ) {
wpf.debug( `Couldn't install the ${ feature } addon: Empty install URL.` );
const canInstallAddons = wpforms_education.can_install_addons,
message = $button.data( 'message' );
content: message ? message : wpforms_education.install_prompt.replace( /%name%/g, feature ),
icon: 'fa fa-info-circle',
text: wpforms_education.install_confirm,
btnClass: 'btn-confirm' + ( ! canInstallAddons ? ' hidden' : '' ),