: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/* global wpforms_edit_post_education */
* WPForms Edit Post Education function.
const WPFormsEditPostEducation = window.WPFormsEditPostEducation || ( function( document, window, $ ) {
* Public functions and properties.
* Determine if the notice was showed before.
$( window ).on( 'load', function() {
// In the case of jQuery 3.+, we need to wait for a ready event first.
if ( typeof $.ready.then === 'function' ) {
$.ready.then( app.load );
if ( ! app.isGutenbergEditor() ) {
app.maybeShowClassicNotice();
const blockLoadedInterval = setInterval( function() {
if ( ! document.querySelector( '.editor-post-title__input, iframe[name="editor-canvas"]' ) ) {
clearInterval( blockLoadedInterval );
app.maybeShowGutenbergNotice();
app.bindGutenbergEvents();
const iframe = document.querySelector( 'iframe[name="editor-canvas"]' );
const observer = new MutationObserver( function() {
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document || {};
if ( iframeDocument.readyState === 'complete' && iframeDocument.querySelector( '.editor-post-title__input' ) ) {
app.maybeShowGutenbergNotice();
observer.observe( document.body, { subtree: true, childList: true } );
* Bind events for Classic Editor.
bindClassicEvents: function() {
const $document = $( document );
if ( ! app.isNoticeVisible ) {
$document.on( 'input', '#title', app.maybeShowClassicNotice );
$document.on( 'click', '.wpforms-edit-post-education-notice-close', app.closeNotice );
* Bind events for Gutenberg Editor.
bindGutenbergEvents: function() {
const $document = $( document );
.on( 'DOMSubtreeModified', '.edit-post-layout', app.distractionFreeModeToggle );
if ( app.isNoticeVisible ) {
.on( 'input', '.editor-post-title__input', app.maybeShowGutenbergNotice )
.on( 'DOMSubtreeModified', '.editor-post-title__input', app.maybeShowGutenbergNotice );
* Bind events for Gutenberg Editor in FSE mode.
bindFseEvents: function() {
const $iframe = $( 'iframe[name="editor-canvas"]' );
.on( 'DOMSubtreeModified', '.edit-post-layout', app.distractionFreeModeToggle );
.on( 'DOMSubtreeModified', '.editor-post-title__input', app.maybeShowGutenbergNotice );
* Determine if the editor is Gutenberg.
* @returns {boolean} True if the editor is Gutenberg.
isGutenbergEditor: function() {
return typeof wp !== 'undefined' && typeof wp.blocks !== 'undefined';
* Determine if the editor is Gutenberg in FSE mode.
* @returns {boolean} True if the Gutenberg editor in FSE mode.
return Boolean( $( 'iframe[name="editor-canvas"]' ).length );
* Create a notice for Gutenberg.
showGutenbergNotice: function() {
wp.data.dispatch( 'core/notices' ).createInfoNotice(
wpforms_edit_post_education.gutenberg_notice.template,
app.getGutenbergNoticeSettings()
// The notice component doesn't have a way to add HTML id or class to the notice.
// Also, the notice became visible with a delay on old Gutenberg versions.
const hasNotice = setInterval( function() {
const noticeBody = $( '.wpforms-edit-post-education-notice-body' );
if ( ! noticeBody.length ) {
const $notice = noticeBody.closest( '.components-notice' );
$notice.addClass( 'wpforms-edit-post-education-notice' );
$notice.find( '.is-secondary, .is-link' ).removeClass( 'is-secondary' ).removeClass( 'is-link' ).addClass( 'is-primary' );
clearInterval( hasNotice );
* Get settings for the Gutenberg notice.
* @returns {object} Notice settings.
getGutenbergNoticeSettings: function() {
const pluginName = 'wpforms-edit-post-product-education-guide';
className: 'wpforms-edit-post-education-notice-guide-button',
label: wpforms_edit_post_education.gutenberg_notice.button,
if ( ! wpforms_edit_post_education.gutenberg_guide ) {
noticeSettings.actions[0].url = wpforms_edit_post_education.gutenberg_notice.url;
const Guide = wp.components.Guide;
const useState = wp.element.useState;
const registerPlugin = wp.plugins.registerPlugin;
const unregisterPlugin = wp.plugins.unregisterPlugin;
const GutenbergTutorial = function() {
const [ isOpen, setIsOpen ] = useState( true );
// eslint-disable-next-line react/react-in-jsx-scope
className="edit-post-welcome-guide"
unregisterPlugin( pluginName );
pages={ app.getGuidePages() }
noticeSettings.onDismiss = app.updateUserMeta;
noticeSettings.actions[0].onClick = () => registerPlugin( pluginName, { render: GutenbergTutorial } );
* Get Guide pages in proper format.
* @returns {Array} Guide Pages.
getGuidePages: function() {
wpforms_edit_post_education.gutenberg_guide.forEach( function( page ) {
/* eslint-disable react/react-in-jsx-scope */
<h1 className="edit-post-welcome-guide__heading">{ page.title }</h1>
<p className="edit-post-welcome-guide__text">{ page.content }</p>
image: <img className="edit-post-welcome-guide__image" src={ page.image } alt={ page.title } />,
/* eslint-enable react/react-in-jsx-scope */
* Show notice if the page title matches some keywords for Classic Editor.
maybeShowClassicNotice: function() {
if ( app.isNoticeVisible ) {
if ( app.isTitleMatchKeywords( $( '#title' ).val() ) ) {
app.isNoticeVisible = true;
$( '.wpforms-edit-post-education-notice' ).removeClass( 'wpforms-hidden' );
* Show notice if the page title matches some keywords for Gutenberg Editor.
maybeShowGutenbergNotice: function() {
if ( app.isNoticeVisible ) {
const $postTitle = app.isFse() ?
$( 'iframe[name="editor-canvas"]' ).contents().find( '.editor-post-title__input' ) :
$( '.editor-post-title__input' );
const tagName = $postTitle.prop( 'tagName' );
const title = tagName === 'TEXTAREA' ? $postTitle.val() : $postTitle.text();
if ( app.isTitleMatchKeywords( title ) ) {
app.isNoticeVisible = true;
app.showGutenbergNotice();
* Add notice class when the distraction mode is enabled.
distractionFreeModeToggle: function() {
if ( ! app.isNoticeVisible ) {
const $document = $( document );
const isDistractionFreeMode = Boolean( $document.find( '.is-distraction-free' ).length );
if ( ! isDistractionFreeMode ) {
const isNoticeHasClass = Boolean( $( '.wpforms-edit-post-education-notice' ).length );
if ( isNoticeHasClass ) {
const $noticeBody = $document.find( '.wpforms-edit-post-education-notice-body' );
const $notice = $noticeBody.closest( '.components-notice' );
$notice.addClass( 'wpforms-edit-post-education-notice' );
* Determine if the title matches keywords.
* @param {string} titleValue Page title value.
* @returns {boolean} True if the title matches some keywords.
isTitleMatchKeywords: function( titleValue ) {
const expectedTitleRegex = new RegExp( /\b(contact|form)\b/i );
return expectedTitleRegex.test( titleValue );
closeNotice: function() {
$( this ).closest( '.wpforms-edit-post-education-notice' ).remove();
* Update user meta and don't show the notice next time.
wpforms_edit_post_education.ajax_url,
action: 'wpforms_education_dismiss',
nonce: wpforms_edit_post_education.education_nonce,
section: 'edit-post-notice',
}( document, window, jQuery ) );
WPFormsEditPostEducation.init();