: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/* global wpforms_challenge_admin, ajaxurl, WPFormsBuilder */
* WPForms Challenge Admin function.
* @since 1.6.2 Challenge v2
var WPFormsChallenge = window.WPFormsChallenge || {};
WPFormsChallenge.admin = window.WPFormsChallenge.admin || ( function( document, window, $ ) {
* Public functions and properties.
l10n: wpforms_challenge_admin,
$( '.wpforms-challenge-list-block' )
.on( 'click', '.challenge-skip', app.skipChallenge )
.on( 'click', '.challenge-cancel', app.cancelChallenge )
.on( 'click', '.toggle-list', app.toggleList );
* Toggle list icon click.
* @param {object} e Event object.
toggleList: function( e ) {
var $icon = $( e.target ),
$listBlock = $( '.wpforms-challenge-list-block' );
if ( ! $listBlock.length || ! $icon.length ) {
if ( $listBlock.hasClass( 'closed' ) ) {
wpforms_challenge_admin.option.window_closed = '0';
$listBlock.removeClass( 'closed' );
$listBlock.removeClass( 'transition-back' );
wpforms_challenge_admin.option.window_closed = '1';
$listBlock.addClass( 'closed' );
// Add `transition-back` class when the forward transition is completed.
// It is needed to properly implement transitions order for some elements.
$listBlock.addClass( 'transition-back' );
* Skip the Challenge without starting it.
skipChallenge: function() {
seconds_left : app.l10n.minutes_left * 60,
$( '.wpforms-challenge' ).remove();
// In the Form Builder, we must also make the Embed button clickable.
$( '#wpforms-embed' ).removeClass( 'wpforms-disabled' );
app.saveChallengeOption( optionData );
* Cancel Challenge after starting it.
cancelChallenge: function() {
var core = WPFormsChallenge.core;
/* eslint-disable camelcase */
seconds_spent: core.timer.getSecondsSpent(),
seconds_left : core.timer.getSecondsLeft(),
core.removeChallengeUI();
core.clearLocalStorage();
if ( typeof WPFormsBuilder !== 'undefined' ) {
WPFormsChallenge.admin.saveChallengeOption( optionData )
.done( function() { // Save the form before removing scripts if we're in a WPForms Builder.
if ( localStorage.getItem( 'wpformsChallengeStep' ) !== null ) {
WPFormsBuilder.formSave( false );
} ).done( // Remove scripts related to challenge.
$( '#wpforms-challenge-admin-js, #wpforms-challenge-core-js, #wpforms-challenge-admin-js-extra, #wpforms-challenge-builder-js' )
WPFormsChallenge.admin.saveChallengeOption( optionData )
.done( app.triggerPageSave ); // Assume we're on form embed page.
* Set Challenge parameter(s) to Challenge option.
* @param {object} optionData Query using option schema keys.
* @returns {promise} jQuery.post() promise interface.
saveChallengeOption: function( optionData ) {
action : 'wpforms_challenge_save_option',
_wpnonce : app.l10n.nonce,
// Save window closed (collapsed) state as well.
data.option_data.window_closed = wpforms_challenge_admin.option.window_closed;
$.extend( wpforms_challenge_admin.option, optionData );
return $.post( ajaxurl, data, function( response ) {
if ( ! response.success ) {
console.error( 'Error saving WPForms Challenge option.' );
// Provide access to public functions/properties.
}( document, window, jQuery ) );
WPFormsChallenge.admin.init();