: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
} ).fail( function( jqXHR, textStatus, errorThrown ) {
app.alertModal( errorThrown, {} );
if ( typeof always === 'function' ) {
* Update all tags choices storage.
* @param {Array} allTagsChoices New all tags choices.
updateAllTagsChoices: function( allTagsChoices ) {
if ( ! allTagsChoices ) {
wpforms_admin_forms_overview.all_tags_choices = allTagsChoices;
// Update Tags Filter items.
el.$tagsFilterSelect.each( function() {
app.initChoicesJS( $( this ) );
// Show Tags Filter and Manage Tags button if at least one tag exists.
if ( wpforms_admin_forms_overview.all_tags_choices.length > 0 ) {
$( '.wpforms-tags-filter, .wpforms-manage-tags' ).removeClass( 'wpforms-hidden' );
* Init Choices.js on the given select input element.
* @param {jQuery} $select Select input.
* @returns {Choices} Choices.js instance.
initChoicesJS: function( $select ) {
// Skip in certain cases.
! wpforms_admin_forms_overview.choicesjs_config ||
typeof window.Choices !== 'function'
config = wpforms_admin_forms_overview.choicesjs_config;
if ( ! $select.data( 'tags-filter' ) ) {
config.noResultsText = wpforms_admin_forms_overview.strings.add_new_tag;
// Add arrow placeholder.
// It is needed to catch the arrow click event in the specific case
// when Tags Filter has many selected tags which overflow the Choices.js control.
config.callbackOnInit = function() {
$select.closest( '.choices__inner' ).append( '<div class="choices__arrow"></div>' );
wpf.initMultipleSelectWithSearch( this );
wpf.showMoreButtonForChoices( this.containerOuter.element );
// Init or get Choices.js object instance.
if ( $select.data( 'choice' ) === 'active' ) {
choicesObj = $select.data( 'choicesjs' );
choicesObj = new Choices( $select[0], config );
var currentValue = choicesObj.getValue( true );
// Update all tags choices. We need to do it evey time, since tags could be added dynamically.
wpforms_admin_forms_overview.all_tags_choices,
.setChoiceByValue( currentValue );
* Init Edit Tags Bulk Action item.
initEditTagsBulkActionItem: function() {
if ( wpforms_admin_forms_overview.strings.is_tags_column_hidden ) {
$( '.bulkactions option[value="edit_tags"]' ).addClass( 'wpforms-hidden' );
initTagsFilter: function() {
el.$tagsFilterSelect.each( function() {
app.initChoicesJS( $( this ) );
* Click the tags "Filter" button.
* @param {object} event Event object.
tagsFilterClick: function( event ) {
$select = $button.closest( '.wpforms-tags-filter' ).find( 'select' ),
choicesObj = $select.data( 'choicesjs' ),
url = new URL( wpforms_admin_forms_overview.strings.base_url ),
tagsIds = choicesObj.getValue( true ),
tags = wpforms_admin_forms_overview.all_tags_choices.filter( function( choice ) {
return tagsIds.indexOf( choice.value ) > -1;
_.map( tags, 'slug' ).join( ',' )
window.location.href = url.href;
* Click the "Manage Tags" button.
* @param {object} event Event object.
manageTagsClick: function( event ) {
title: wpforms_admin_forms_overview.strings.manage_tags_title,
content: app.getManageTagsContent(),
text: wpforms_admin.cancel,
onOpenBefore: function() {
this.$$confirm && this.$$confirm.prop( 'disabled', true );
$( 'body' ).addClass( 'wpforms-manage-tags-modal' );
$( 'body' ).removeClass( 'wpforms-manage-tags-modal' );
var confirm = app.getManageTagsConfirmSettings();
cancel: options.buttons.cancel,
* Get Manage Tags modal content.
* @returns {string} Content of the modal.
getManageTagsContent: function() {
var allTags = wpforms_admin_forms_overview.all_tags_choices;
if ( allTags.length === 0 ) {
return wpforms_admin_forms_overview.strings.manage_tags_no_tags;
var content = wpforms_admin_forms_overview.strings.manage_tags_desc,
for ( var i = 0; i < allTags.length; i++ ) {
`<input type="checkbox" value="${ allTags[ i ].value }" id="wpforms-tag-${ allTags[ i ].value }">
<label for="wpforms-tag-${ allTags[ i ].value }">
<span>(${ allTags[ i ].count })</span>
content += `<div class="wpforms-manage-tags-items">${ tags.join( '' ) }</div>
<div class="wpforms-manage-tags-notice wpforms-hidden"></div>`;
* Get Manage Tags modal confirm button settings.
* @returns {object} Confirm button settings.
getManageTagsConfirmSettings: function() {
if ( wpforms_admin_forms_overview.all_tags_choices.length === 0 ) {
text: wpforms_admin_forms_overview.strings.manage_tags_save,
$( '.wpforms-manage-tags-items input:checked' ).each( function() {
checkedTags.push( $( this ).val() );
action: 'wpforms_admin_forms_overview_delete_tags',
nonce: wpforms_admin_forms_overview.strings.nonce,
).done( function( res ) {
if ( ! res.success || ! res.data ) {
app.alertModal( res.data || '', {} );
app.manageTagsResultModal( res.data.deleted );
} ).fail( function( jqXHR, textStatus, errorThrown ) {
app.alertModal( errorThrown, {} );
* Change the Tag item hidden checkbox in the Manage Tags modal.
manageTagsItemChange: function() {
var checkedCount = $( '.wpforms-manage-tags-items input:checked' ).length,
$saveButton = $( this ).closest( '.jconfirm-box' ).find( '.btn-confirm' ),
$notice = $( '.wpforms-manage-tags-notice' ),
noticeHtml = checkedCount > 1 ?
wpforms_admin_forms_overview.strings.manage_tags_n_tags.replace( '%d', checkedCount ) :
wpforms_admin_forms_overview.strings.manage_tags_one_tag;
$saveButton.prop( 'disabled', checkedCount === 0 );
.toggleClass( 'wpforms-hidden', checkedCount === 0 );
* Open modal when the tags were deleted.
* @param {int} deletedCount Deleted tags count.
manageTagsResultModal: function( deletedCount ) {
var deleted = deletedCount === 1 ?
wpforms_admin_forms_overview.strings.manage_tags_one_deleted :
wpforms_admin_forms_overview.strings.manage_tags_n_deleted.replace( '%d', deletedCount );
title: wpforms_admin_forms_overview.strings.manage_tags_result_title,
content: `<p>${ deleted }</p><p>${ wpforms_admin_forms_overview.strings.manage_tags_result_text }</p>`,
icon: 'fa fa-exclamation-circle',
text: wpforms_admin_forms_overview.strings.manage_tags_btn_refresh,
window.location.href = wpforms_admin_forms_overview.strings.base_url;
openBulkEditTags: function() {
// Iterate checked forms.
el.$listTableRows.find( 'input:checked' ).each( function( i ) {
$tr = $input.closest( 'tr' ),
$name = $tr.find( '.column-name > a:first-child' ),
$tags = $tr.find( '.wpforms-column-tags-links' ),
formTags = $tags.data( 'tags' ).toString() || '';
if ( $tags.data( 'is-editable' ) !== 1 ) {
label: _.escape( $name.text() ),
formsValue.push( $input.val() );
formTags = formTags.length ? formTags.split( ',' ) : [];
tagsValue = _.union( tagsValue, formTags );
if ( forms.length === 0 ) {
el.$bulkEditTagsRows.removeClass( 'wpforms-hidden' );
// Init Choices.js instance for forms.
app.initChoicesJS( el.$bulkEditTagsForms )
.setChoiceByValue( formsValue );
// Init Choices.js instance for tags.
app.initChoicesJS( el.$bulkEditTagsTags )
.setChoiceByValue( tagsValue );
app.updateBulkEditTagsFormMessage( formsValue );
* Update the message below the Bulk Edit Tags form.
* @param {Array} formsValue Forms value.
updateBulkEditTagsFormMessage: function( formsValue ) {
var msg = wpforms_admin_forms_overview.strings.bulk_edit_n_forms;
if ( formsValue.length === 1 ) {
msg = wpforms_admin_forms_overview.strings.bulk_edit_one_form;
el.$bulkEditTagsMessage.html(
msg.replace( '%d', formsValue.length )
* Remove form from the Bulk Edit Tags form.
* @param {object} event Event object.
bulkEditTagsFormRemoveItem: function( event ) {
var formsValue = $( event.target ).data( 'choicesjs' ).getValue( true );
if ( formsValue.length === 0 ) {
app.cancelBulkEditTagsClick();
app.updateBulkEditTagsFormMessage( formsValue );
* Remove tag from Tags editor event handler.
* @param {object} event Event object.
editTagsRemoveItem: function( event ) {
var allValues = _.map( wpforms_admin_forms_overview.all_tags_choices, 'value' );
if ( allValues.indexOf( event.detail.value ) >= 0 ) {
// We should remove new tag from the list of choices.
var choicesObj = $( event.target ).data( 'choicesjs' ),
currentValue = choicesObj.getValue( true ),
choices = _.filter( choicesObj._currentState.choices, function( item ) {
return item.value !== event.detail.value;
.setChoiceByValue( currentValue );
* Calculate and set the bulk edit tags form attributes and styles.
adjustBulkEditTagsForm() {
const $table = $( '.wp-list-table' ),
$columns = $table.find( 'thead .manage-column' ).not( '.hidden' ),
$formCells = $( '.wpforms-bulk-edit-tags td' );
// Update colspan attributes.
$formCells.attr( 'colspan', $columns.length );
let nameWidth = $table.find( '.column-name' ).outerWidth();
nameWidth = nameWidth < 300 ? 300 : nameWidth;
const cellsWidth = $table.outerWidth() - nameWidth -
$table.find( '.check-column' ).outerWidth() - 10;
const formsInputWidth = `calc( 100% - ${ cellsWidth }px )`;
// Update width property of the forms input element.
el.$bulkEditTagsForms.closest( '.wpforms-edit-forms' ).css( 'width', formsInputWidth );
* Click toggle Tags column checkbox event handler.