: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Element bindings for general and global items.
bindUIActionsGeneral() { // eslint-disable-line max-lines-per-function
$builder.on( 'click', '.toggle-smart-tag-display', app.smartTagToggle );
$builder.on( 'click', '.smart-tags-list-display a', app.smartTagInsert );
// Toggle unfoldable group of fields
$builder.on( 'click', '.wpforms-panel-fields-group.unfoldable .wpforms-panel-fields-group-title', app.toggleUnfoldableGroup );
// Hide field preview helper box.
$builder.on( 'click', '.wpforms-field-helper-hide ', app.hideFieldHelper );
// Field map table, update key source
$builder.on( 'input', '.wpforms-field-map-table .key-source', function() {
const value = $( this ).val(),
$dest = $( this ).parent().parent().find( '.key-destination' ),
name = $dest.data( 'name' );
$dest.attr( 'name', name.replace( '{source}', value.replace( /[^0-9a-zA-Z_-]/gi, '' ) ) );
// Field map table, delete row
$builder.on( 'click', '.wpforms-field-map-table .remove', function( e ) {
app.fieldMapTableDeleteRow( e, $( this ) );
// Field map table, Add row
$builder.on( 'click', '.wpforms-field-map-table .add', function( e ) {
app.fieldMapTableAddRow( e, $( this ) );
// Global select field mapping
$( document ).on( 'wpformsFieldUpdate', app.fieldMapSelect );
// Restrict user money input fields
$builder.on( 'input', '.wpforms-money-input', function( event ) { // eslint-disable-line no-unused-vars
start = $this[ 0 ].selectionStart,
end = $this[ 0 ].selectionEnd;
$this.val( amount.replace( /[^0-9.,]/g, '' ) );
$this[ 0 ].setSelectionRange( start, end );
// Format user money input fields
$builder.on( 'focusout', '.wpforms-money-input', function( event ) { // eslint-disable-line no-unused-vars
const sanitized = wpf.amountSanitize( amount ),
formatted = wpf.amountFormat( sanitized );
// Show/hide a group of options.
$builder.on( 'change', '.wpforms-panel-field-toggle', function() {
const $input = $( this );
if ( $input.prop( 'disabled' ) ) {
$input.prop( 'disabled', true );
app.toggleOptionsGroup( $input );
// Don't allow users to enable payments if storing entries has
// been disabled in the General settings.
$builder.on( 'change', app.getPaymentsTogglesSelector(), function( event ) { // eslint-disable-line no-unused-vars
gateway = $this.attr( 'id' ).replace( /wpforms-panel-field-|-enable|_one_time|_recurring/gi, '' ),
$notificationWrap = $( '.wpforms-panel-content-section-notifications [id*="-' + gateway + '-wrap"]' ),
gatewayEnabled = $this.prop( 'checked' ) || $( '#wpforms-panel-field-' + gateway + '-enable_one_time' ).prop( 'checked' ) || $( '#wpforms-panel-field-' + gateway + '-enable_recurring' ).prop( 'checked' );
const disabled = $( '#wpforms-panel-field-settings-disable_entries' ).prop( 'checked' );
title: wpforms_builder.heads_up,
content: wpforms_builder.payments_entries_off,
icon: 'fa fa-exclamation-circle',
text: wpforms_builder.ok,
$this.prop( 'checked', false );
$notificationWrap.removeClass( 'wpforms-hidden' );
$notificationWrap.addClass( 'wpforms-hidden' );
$notificationWrap.find( 'input[id*="-' + gateway + '"]' ).prop( 'checked', false );
// Disable entries toggle.
$builder.on( 'change', '#wpforms-panel-field-settings-disable_entries', function( event ) { // eslint-disable-line no-unused-vars
// Toggle the store spam entries toggle.
$( '#wpforms-panel-field-settings-store_spam_entries-wrap' ).toggleClass( 'wpforms-hidden', $this.prop( 'checked' ) );
// Don't allow users to disable entries if payments have been enabled.
if ( $this.prop( 'checked' ) ) {
if ( app.isPaymentsEnabled() ) {
title: wpforms_builder.heads_up,
content: wpforms_builder.payments_on_entries_off,
icon: 'fa fa-exclamation-circle',
text: wpforms_builder.ok,
$this.prop( 'checked', false );
title: wpforms_builder.heads_up,
content: wpforms_builder.disable_entries,
icon: 'fa fa-exclamation-circle',
text: wpforms_builder.ok,
// Upload or add an image.
$builder.on( 'click', '.wpforms-image-upload-add', function( event ) {
const $container = $this.parent();
const mediaFrame = wpf.initMediaLibrary( {
title: wpforms_builder.upload_image_title,
extensions: wpforms_builder.upload_image_extensions,
extensionsError: wpforms_builder.upload_image_extensions_error,
buttonText: wpforms_builder.upload_image_button,
mediaFrame.on( 'select', function() {
const mediaAttachment = mediaFrame.state().get( 'selection' ).first().toJSON();
const $preview = $container.find( '.preview' );
$container.find( '.source' ).val( mediaAttachment.url );
$preview.prepend( '<img src="' + mediaAttachment.url + '" alt=""><a href="#" title="' + wpforms_builder.upload_image_remove + '" class="wpforms-image-upload-remove"><i class="fa fa-trash-o"></i></a>' );
if ( $this.data( 'after-upload' ) === 'hide' ) {
$builder.trigger( 'wpformsImageUploadAdd', [ $this, $container ] );
} ).on( 'close', function() {
mediaFrame.off( 'library:selection:add' );
// Now that everything has been set, let's open up the frame.
// Remove and uploaded image.
$builder.on( 'click', '.wpforms-image-upload-remove', function( event ) {
const $container = $( this ).parent().parent();
$container.find( '.preview' ).empty();
$container.find( '.wpforms-image-upload-add' ).show();
$container.find( '.source' ).val( '' );
$builder.trigger( 'wpformsImageUploadRemove', [ $( this ), $container ] );
// Validate email smart tags in Notifications fields.
$builder.on( 'blur', '.wpforms-notification .wpforms-panel-field-text input', function() {
app.validateEmailSmartTags( $( this ) );
$builder.on( 'blur', '.wpforms-notification .wpforms-panel-field-textarea textarea', function() {
app.validateEmailSmartTags( $( this ) );
// Validate From Email in Notification settings.
$builder.on( 'focusout', '.wpforms-notification .wpforms-panel-field.js-wpforms-from-email-validation input', app.validateFromEmail );
$builder.on( 'wpformsPanelSectionSwitch', app.notificationsPanelSectionSwitch );
// Mobile notice primary button / close icon click.
$builder.on( 'click', '#wpforms-builder-mobile-notice .wpforms-fullscreen-notice-button-primary, #wpforms-builder-mobile-notice .close', function() {
window.location.href = wpforms_builder.exit_url;
// Mobile notice secondary button click.
$builder.on( 'click', '#wpforms-builder-mobile-notice .wpforms-fullscreen-notice-button-secondary', function() {
window.location.href = wpf.updateQueryString( 'force_desktop_view', 1, window.location.href );
// License Alert close button click.
$( '#wpforms-builder-license-alert .close' ).on( 'click', function() {
window.location.href = wpforms_builder.exit_url;
// License Alert dismiss button click.
$( '#wpforms-builder-license-alert .dismiss' ).on( 'click', function( event ) {
$( '#wpforms-builder-license-alert' ).remove();
wpCookies.set( 'wpforms-builder-license-alert', 'true', 3600 );
// Don't allow the Akismet setting to be enabled if the Akismet plugin isn't available.
$builder.on( 'change', '#wpforms-panel-field-settings-akismet.wpforms-akismet-disabled', function( event ) { // eslint-disable-line no-unused-vars
akismetStatus = $this.data( 'akismet-status' );
if ( $this.prop( 'checked' ) ) {
title: wpforms_builder.heads_up,
content: wpforms_builder[ akismetStatus ],
icon: 'fa fa-exclamation-circle',
text: wpforms_builder.ok,
$this.prop( 'checked', false );
* Notification section switch event handler.
* @param {Object} e Event object.
* @param {string} panel Panel name.
notificationsPanelSectionSwitch( e, panel ) {
if ( panel !== 'notifications' ) {
$( '.wpforms-notification .wpforms-panel-field.js-wpforms-from-email-validation input' ).trigger( 'focusout' );
* Check if one of the payment addons payments enabled.
* @return {boolean} True if one of the payment addons payment enabled.
let paymentEnabled = false;
$( app.getPaymentsTogglesSelector() ).each( function() {
if ( $( this ).prop( 'checked' ) ) {
* Get Payments toggles selector.
* @return {string} List of selectors.
getPaymentsTogglesSelector() {
return `.wpforms-panel-content-section-payment-toggle-one-time input,
.wpforms-panel-content-section-payment-toggle-recurring input,
#wpforms-panel-field-stripe-enable,
#wpforms-panel-field-paypal_standard-enable,
#wpforms-panel-field-authorize_net-enable,
#wpforms-panel-field-square-enable`;
* Toggle an options group.
* @param {Object} $input Toggled field.
toggleOptionsGroup( $input ) {
const name = $input.attr( 'name' );
const $body = $( '.wpforms-panel-field-toggle-body[data-toggle="' + name + '"]' ),
enableInput = function() {
$input.prop( 'disabled', false );
if ( $body.length === 0 ) {
const type = $input.attr( 'type' );
if ( 'checkbox' === type || 'radio' === type ) {
value = $input.prop( 'checked' ) ? $input.val() : '0';
// eslint-disable-next-line no-unused-expressions
$this.attr( 'data-toggle-value' ).toString() === value.toString()
? $this.slideDown( '', enableInput )
: $this.slideUp( '', enableInput );
* Toggle all option groups.
* @param {jQuery} $context Context container jQuery object.
toggleAllOptionGroups( $context ) {
$context = $context || $builder || $( '#wpforms-builder' ) || $( 'body' );
// Show a toggled bodies.
$context.find( '.wpforms-panel-field-toggle' ).each( function() {
const $input = $( this );
$input.prop( 'disabled', true );
app.toggleOptionsGroup( $input );
* Toggle unfoldable group of fields.
* @param {Object} e Event object.
toggleUnfoldableGroup( e ) {
const $title = $( e.target ),
$group = $title.closest( '.wpforms-panel-fields-group' ),
$inner = $group.find( '.wpforms-panel-fields-group-inner' ),
cookieName = 'wpforms_fields_group_' + $group.data( 'group' );
if ( $group.hasClass( 'opened' ) ) {
wpCookies.remove( cookieName );
$inner.stop().slideUp( 150, function() {
$group.removeClass( 'opened' );
wpCookies.set( cookieName, 'true', 2592000 ); // 1 month.
$group.addClass( 'opened' );
$inner.stop().slideDown( 150 );
* Hide field preview helper box.
* @param {Object} e Event object.
const $helpers = $( '.wpforms-field-helper' ),
cookieName = 'wpforms_field_helper_hide';
wpCookies.set( cookieName, 'true', 30 * 24 * 60 * 60 ); // 1 month.
* @since 1.6.9 Simplify method.
* @param {Event} e Event.
// Prevent ajax to validate the default email queued on focusout event.
elements.$focusOutTarget = null;
$wrapper = $this.closest( '.wpforms-panel-field,.wpforms-field-option-row' );
if ( $wrapper.hasClass( 'smart-tags-toggling' ) ) {
$wrapper.addClass( 'smart-tags-toggling' );
if ( $this.hasClass( 'smart-tag-showing' ) ) {
app.removeSmartTagsList( $this );
app.insertSmartTagsList( $this );
* @param {jQuery} $el Toggle element.
removeSmartTagsList( $el ) {
const $wrapper = $el.closest( '.wpforms-panel-field,.wpforms-field-option-row' ),
$list = $wrapper.find( '.smart-tags-list-display' );
$el.find( 'span' ).text( wpforms_builder.smart_tags_show );
$list.slideUp( '', function() {
$el.removeClass( 'smart-tag-showing' );
$wrapper.removeClass( 'smart-tags-toggling' );
* @param {jQuery} $el Toggle element.
insertSmartTagsList( $el ) {
const $wrapper = $el.closest( '.wpforms-panel-field,.wpforms-field-option-row' );
let $label = $el.closest( 'label' ),
$label = $wrapper.find( 'label' );
const smartTagList = app.getSmartTagsList( $el, $label.attr( 'for' ).indexOf( 'wpforms-field-option-' ) !== -1 );
// eslint-disable-next-line no-unused-expressions