: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/* global wpforms_admin_form_embed_wizard, WPFormsBuilder, ajaxurl, WPFormsChallenge, wpforms_builder, WPForms */
* Form Embed Wizard function.
var WPFormsFormEmbedWizard = window.WPFormsFormEmbedWizard || ( function( document, window, $ ) {
* @since 1.7.9 Added `lastEmbedSearchPageTerm` property.
isChallengeActive: false,
lastEmbedSearchPageTerm: '',
* Public functions and properties.
$( window ).on( 'load', function() {
// in case of jQuery 3.+ we need to wait for an `ready` event first.
if ( typeof $.ready.then === 'function' ) {
$.ready.then( app.load );
* @since 1.7.9 Initialize 'Select Pages' ChoicesJS.
// Initialize tooltip in page editor.
if ( wpforms_admin_form_embed_wizard.is_edit_page === '1' && ! vars.isChallengeActive ) {
// Initialize wizard state in the form builder only.
app.initialStateToggle();
app.initSelectPagesChoicesJS();
$( document ).on( 'wpformsWizardPopupClose', app.enableLetsGoButton );
// Caching some DOM elements for further use.
$wizardContainer: $( '#wpforms-admin-form-embed-wizard-container' ),
$wizard: $( '#wpforms-admin-form-embed-wizard' ),
$contentInitial: $( '#wpforms-admin-form-embed-wizard-content-initial' ),
$contentSelectPage: $( '#wpforms-admin-form-embed-wizard-content-select-page' ),
$contentCreatePage: $( '#wpforms-admin-form-embed-wizard-content-create-page' ),
$sectionBtns: $( '#wpforms-admin-form-embed-wizard-section-btns' ),
$sectionGo: $( '#wpforms-admin-form-embed-wizard-section-go' ),
$newPageTitle: $( '#wpforms-admin-form-embed-wizard-new-page-title' ),
$selectPage: $( '#wpforms-setting-form-embed-wizard-choicesjs-select-pages' ),
$videoTutorial: $( '#wpforms-admin-form-embed-wizard-tutorial' ),
$sectionToggles: $( '#wpforms-admin-form-embed-wizard-section-toggles' ),
$sectionGoBack: $( '#wpforms-admin-form-embed-wizard-section-goback' ),
$shortcode: $( '#wpforms-admin-form-embed-wizard-shortcode-wrap' ),
$shortcodeInput: $( '#wpforms-admin-form-embed-wizard-shortcode' ),
$shortcodeCopy: $( '#wpforms-admin-form-embed-wizard-shortcode-copy' ),
el.$selectPageContainer = el.$selectPage.parents( 'span.choicesjs-select-wrap' );
// Detect the form builder screen and store the flag.
vars.isBuilder = typeof WPFormsBuilder !== 'undefined';
// Detect the Challenge and store the flag.
vars.isChallengeActive = typeof WPFormsChallenge !== 'undefined';
vars.pagesExists = el.$wizard.data( 'pages-exists' ) === 1;
* Init ChoicesJS for "Select Pages" field in embed.
initSelectPagesChoicesJS: function() {
if ( el.$selectPage.length <= 0 ) {
const useAjax = el.$selectPage.data( 'use_ajax' ) === 1;
WPForms.Admin.Builder.WPFormsChoicesJS.setup(
action: 'wpforms_admin_form_embed_wizard_search_pages_choicesjs',
nonce: useAjax ? wpforms_admin_form_embed_wizard.nonce : null,
// Skip wizard events in the page editor.
if ( ! el.$wizard.length ) {
.on( 'click', 'button', app.popupButtonsClick )
.on( 'click', '.tutorial-toggle', app.tutorialToggle )
.on( 'click', '.shortcode-toggle', app.shortcodeToggle )
.on( 'click', '.initialstate-toggle', app.initialStateToggle )
.on( 'click', '.wpforms-admin-popup-close', app.closePopup )
.on( 'click', '#wpforms-admin-form-embed-wizard-shortcode-copy', app.copyShortcodeToClipboard )
.on( 'keyup', '#wpforms-admin-form-embed-wizard-new-page-title', app.enableLetsGoButton );
* Popup buttons events handler.
* @param {object} e Event object.
popupButtonsClick: function( e ) {
var $btn = $( e.target );
var $div = $btn.closest( 'div' ),
action = $btn.data( 'action' ) || '';
el.$contentInitial.hide();
el.$contentSelectPage.show();
el.$selectPageContainer.hide();
el.$contentCreatePage.show();
if ( el.$selectPageContainer.is( ':visible' ) && el.$selectPage.val() === '' ) {
$btn.prop( 'disabled', true );
app.saveFormAndRedirect();
el.$sectionToggles.hide();
el.$sectionGoBack.fadeIn();
// Set focus to the field that is currently displayed.
$.each( [ el.$selectPage, el.$newPageTitle ], function() {
if ( this.is( ':visible' ) ) {
app.tutorialControl( 'Stop' );
* Toggle video tutorial inside popup.
* @param {object} e Event object.
tutorialToggle: function( e ) {
el.$videoTutorial.toggle();
if ( el.$videoTutorial.attr( 'src' ) === 'about:blank' ) {
el.$videoTutorial.attr( 'src', wpforms_admin_form_embed_wizard.video_url );
if ( el.$videoTutorial[0].src.indexOf( '&autoplay=1' ) < 0 ) {
app.tutorialControl( 'Play' );
app.tutorialControl( 'Stop' );
* Toggle video tutorial inside popup.
* @param {string} action One of 'Play' or 'Stop'.
tutorialControl: function( action ) {
var iframe = el.$videoTutorial[0];
if ( typeof iframe === 'undefined' ) {
if ( action !== 'Stop' ) {
iframe.src += iframe.src.indexOf( '&autoplay=1' ) < 0 ? '&autoplay=1' : '';
iframe.src = iframe.src.replace( '&autoplay=1', '' );
* Toggle shortcode input field.
* @param {object} e Event object.
shortcodeToggle: function( e ) {
el.$videoTutorial.hide();
app.tutorialControl( 'Stop' );
el.$shortcodeInput.val( '[wpforms id="' + vars.formId + '" title="false"]' );
* Enable the "Let's Go!" button.
enableLetsGoButton: function() {
const $btn = el.$sectionGo.find( 'button' );
$btn.prop( 'disabled', false );
* Copies the shortcode embed code to the clipboard.
copyShortcodeToClipboard: function() {
// Remove disabled attribute, select the text, and re-add disabled attribute.
.prop( 'disabled', false )
.prop( 'disabled', true );
document.execCommand( 'copy' );
var $icon = el.$shortcodeCopy.find( 'i' );
// Add visual feedback to copy command.
$icon.removeClass( 'fa-files-o' ).addClass( 'fa-check' );
// Reset visual confirmation back to default state after 2.5 sec.
window.setTimeout( function() {
$icon.removeClass( 'fa-check' ).addClass( 'fa-files-o' );
* @param {object} e Event object.
initialStateToggle: function( e ) {
if ( vars.pagesExists ) {
el.$contentInitial.show();
el.$contentSelectPage.hide();
el.$contentCreatePage.hide();
el.$selectPageContainer.show();
el.$contentInitial.hide();
el.$contentSelectPage.hide();
el.$contentCreatePage.show();
el.$selectPageContainer.hide();
el.$videoTutorial.hide();
app.tutorialControl( 'Stop' );
el.$sectionToggles.show();
el.$sectionGoBack.hide();
* Save the form and redirect to form embed page.
saveFormAndRedirect: function() {
// Just redirect if no need to save the form.
if ( ! vars.isBuilder || WPFormsBuilder.formIsSaved() ) {
// Embedding in Challenge should save the form silently.
if ( vars.isBuilder && vars.isChallengeActive ) {
WPFormsBuilder.formSave().done( app.embedPageRedirect );
content: wpforms_builder.exit_confirm,
icon: 'fa fa-exclamation-circle',
text: wpforms_builder.save_embed,
WPFormsBuilder.formSave().done( app.embedPageRedirect );
text: wpforms_builder.embed,
WPFormsBuilder.setCloseConfirmation( false );
el.$sectionGo.find( 'button' ).prop( 'disabled', false );
* Prepare data for requesting redirect URL.
* @returns {object} AJAX data object.
embedPageRedirectAjaxData: function() {
action : 'wpforms_admin_form_embed_wizard_embed_page_url',
_wpnonce: wpforms_admin_form_embed_wizard.nonce,
if ( el.$selectPageContainer.is( ':visible' ) ) {
data.pageId = el.$selectPage.val();
if ( el.$newPageTitle.is( ':visible' ) ) {
data.pageTitle = el.$newPageTitle.val();
* Redirect to form embed page.
embedPageRedirect: function() {
var data = app.embedPageRedirectAjaxData();
// Exit if no one page is selected.
if ( typeof data.pageId !== 'undefined' && data.pageId === '' ) {
$.post( ajaxurl, data, function( response ) {
if ( response.success ) {
window.location = response.data;
* @param {numeric} openFormId Form ID to embed. Used only if called outside the form builder.
openPopup: function( openFormId ) {
openFormId = openFormId || 0;
vars.formId = vars.isBuilder ? $( '#wpforms-builder-form' ).data( 'id' ) : openFormId;
// Regular wizard and wizard in Challenge has differences.
el.$wizard.toggleClass( 'wpforms-challenge-popup', vars.isChallengeActive );
el.$wizard.find( '.wpforms-admin-popup-content-regular' ).toggle( ! vars.isChallengeActive );
el.$wizard.find( '.wpforms-admin-popup-content-challenge' ).toggle( vars.isChallengeActive );
if ( el.$selectPage.length === 0 ) {