: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* WPForms Challenge function.
* @since 1.6.2 Challenge v2.
var WPFormsChallenge = window.WPFormsChallenge || {};
WPFormsChallenge.embed = window.WPFormsChallenge.embed || ( function( document, window, $ ) {
* 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 );
app.observeFullscreenMode();
// If the page is Add new page.
if ( window.location.href.indexOf( 'post-new.php' ) > -1 ) {
$( '.wpforms-challenge-dot-completed' ).hide();
if ( WPFormsChallenge.core.isGutenberg() ) {
WPFormsChallenge.core.initTooltips( 5, '.block-editor .edit-post-header', { side: 'bottom' } );
app.updateTooltipVisibility();
WPFormsChallenge.core.initTooltips( 5, '.wpforms-insert-form-button', { side: 'right' } );
WPFormsChallenge.core.updateTooltipUI();
if ( 5 === WPFormsChallenge.core.loadStep() ) {
$( '.wpforms-challenge' ).addClass( 'wpforms-challenge-completed' );
$( '.wpforms-challenge' ).show();
$( '.wpforms-challenge-step5-done' )
.on( 'click', app.lastStep );
$( '.wpforms-challenge-popup-close, .wpforms-challenge-end' )
.on( 'click', app.completeChallenge );
$( '#wpforms-challenge-contact-form .wpforms-challenge-popup-contact-btn' )
.on( 'click', app.submitContactForm );
* Last step done routine.
WPFormsChallenge.core.timer.pause();
WPFormsChallenge.core.stepCompleted( 5 );
$( '.wpforms-challenge' ).addClass( 'wpforms-challenge-completed' );
* Show either 'Congratulations' or 'Contact Us' popup.
var secondsLeft = WPFormsChallenge.core.timer.getSecondsLeft();
$( '.wpforms-challenge-popup-container' ).show();
var secondsSpent = WPFormsChallenge.core.timer.getSecondsSpent( secondsLeft );
$( '#wpforms-challenge-congrats-minutes' )
.text( WPFormsChallenge.core.timer.getMinutesFormatted( secondsSpent ) );
$( '#wpforms-challenge-congrats-seconds' )
.text( WPFormsChallenge.core.timer.getSecondsFormatted( secondsSpent ) );
$( '#wpforms-challenge-congrats-popup' ).show();
$( '#wpforms-challenge-contact-popup' ).show();
$( '.wpforms-challenge-popup-container' ).hide();
$( '.wpforms-challenge-popup' ).hide();
completeChallenge: function() {
seconds_spent: WPFormsChallenge.core.timer.getSecondsSpent(),
seconds_left : WPFormsChallenge.core.timer.getSecondsLeft(),
WPFormsChallenge.core.removeChallengeUI();
WPFormsChallenge.core.clearLocalStorage();
WPFormsChallenge.admin.saveChallengeOption( optionData )
.done( WPFormsChallenge.core.triggerPageSave ); // Save and reload the page to remove WPForms Challenge JS.
* Submit contact form button click event handler.
* @param {object} e Event object.
submitContactForm: function( e ) {
$form = $btn.closest( '#wpforms-challenge-contact-form' );
/* eslint-disable camelcase */
action : 'wpforms_challenge_send_contact_form',
_wpnonce : WPFormsChallenge.admin.l10n.nonce,
message : $form.find( '.wpforms-challenge-contact-message' ).val(),
contact_me: $form.find( '.wpforms-challenge-contact-permission' ).prop( 'checked' ),
$btn.prop( 'disabled', true );
$.post( ajaxurl, data, function( response ) {
if ( ! response.success ) {
console.error( 'Error sending WPForms Challenge Contact Form.' );
} ).done( app.completeChallenge );
* Observe Gutenberg's Fullscreen Mode state to adjust tooltip positioning.
observeFullscreenMode: function() {
isFullScreenPrev = $body.hasClass( 'is-fullscreen-mode' );
// MutationObserver configuration and callback.
obs.callback = function( mutationsList, observer ) {
$step5 = $( '.wpforms-challenge-tooltip-step5' ),
$step5Arrow = $step5.find( '.tooltipster-arrow' );
for ( var i in mutationsList ) {
mutation = mutationsList[ i ];
if ( mutation.type !== 'attributes' || mutation.attributeName !== 'class' ) {
isFullScreen = $body.hasClass( 'is-fullscreen-mode' );
if ( isFullScreen === isFullScreenPrev ) {
isFullScreenPrev = isFullScreen;
$step5Arrow.css( 'left', '91px' );
$step5Arrow.css( 'left', '130px' );
obs.observer = new MutationObserver( obs.callback );
obs.observer.observe( obs.targetNode, obs.config );
* Update tooltip z-index when Gutenberg sidebar is open.
* @returns {Function} Default function.
updateTooltipVisibility: function() {
var targetNode = document.querySelector( '.interface-interface-skeleton__body' );
if ( targetNode === null ) {
return app.updateTooltipVisibilityDefault();
var observer = new MutationObserver( function( mutationsList ) {
var $step5 = $( '.wpforms-challenge-tooltip-step5' );
for ( var mutation of mutationsList ) {
if ( mutation.type === 'childList' ) {
$step5.toggleClass( 'wpforms-challenge-tooltip-step5-hide' );
observer.observe( targetNode, { attributes: true, childList: true } );
* Update tooltip visibility for WP 5.6 version.
updateTooltipVisibilityDefault: function() {
$( '.editor-inserter__toggle' ).on( 'click', function() {
$( '.wpforms-challenge-tooltip-step5' ).toggleClass( 'wpforms-challenge-tooltip-step5-hide' );
// Provide access to public functions/properties.
}( document, window, jQuery ) );
WPFormsChallenge.embed.init();