: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// Update filter button label when date range specified.
el.$filterBtn.text( instance.altInput.value );
// Determine if a custom date range was provided or selected.
this.handleOnUpdateDatepicker( {}, el.$filterForm.find( 'input[value="custom"]' ).prop( 'checked' ) );
* Callback which is called when the filter form gets submitted.
handleOnSubmitDatepicker() {
// Exclude radio inputs from the form submission.
$( this ).find( 'input[type="radio"]' ).attr( 'name', '' );
// Remove the popover from the view.
// When the dropdown is closed, aria-expended="false".
app.hideElm( el.$filterBtn.next() );
* Callback for the bulk action.
* @param {Object} event An event which takes place in the DOM.
handleOnBulkAction( event ) {
// Get the selected value for the name="action" select element.
const $action = el.$wrapper.find( 'select[name="action"]' );
const selectedAction = $action.val();
const actionsToExclude = [ 'trash', 'delete' ];
// Leave early if delete/trash is not selected.
// Trash is happening when you move payment to the trash. Delete is when you delete it permanently.
if ( ! actionsToExclude.includes( selectedAction ) ) {
// Get the selected checkboxes.
const $checkboxes = el.$wrapper.find( 'input[name="payment_id[]"]:checked' );
// Leave early if no checkboxes are selected.
if ( ! $checkboxes.length ) {
// Determine whether the selected payment has a renewal.
const hasRenewal = $checkboxes.closest( 'tr' ).hasClass( 'subscription-has-renewal' );
const { i18n: { subscription_delete_confirm: message, delete_button: buttonText } } = vars;
// Warn the user that the selected payment has a renewal.
title: wpforms_admin.heads_up,
icon: 'fa fa-exclamation-circle',
text: wpforms_admin.cancel,
el.$form.trigger( 'reset' );
* Callback which is called when the overview table gets submitted.
handleOnSubmitOverviewTable() {
// Leave early if the multi-select element is not present.
if ( ! el.$multiSelect.length ) {
// Prevent empty or unspecified values from being submitted.
// This is to avoid having empty values in the $_GET array for aesthetic reasons.
$( '.wpforms-multiselect-checkbox-input[value=""]' ).removeAttr( 'name' );
* Callback which is called when the datepicker "Cancel" button clicked.
* @param {Object} event An event which takes place in the DOM.
handleOnResetDatepicker( event ) {
// To return the form to its original state, manually reset it.
el.$filterForm.get( 0 ).reset();
// Remove the popover from the view.
// When the dropdown is closed, aria-expended="false".
app.hideElm( el.$filterBtn.next() );
app.handleOnUpdateDatepicker();
* Callback which is called when the filter form elements change.
* @param {Object} event An event which takes place in the DOM.
* @param {boolean} isCustomDates Determine whether a custom date range is provided.
// eslint-disable-next-line no-unused-vars
handleOnUpdateDatepicker( event = {}, isCustomDates = false ) {
const $selected = el.$filterForm.find( 'input:checked' );
const $parent = $selected.parent();
const $target = isCustomDates ? el.$datepicker : $selected;
const dates = $target.val().split( vars.delimiter );
el.$filterBtn.text( isCustomDates ? $target.next().val() : $parent.text() );
app.selectDatepickerChoice( $parent );
if ( Array.isArray( dates ) && dates.length === 2 ) {
// Sets the current selected date(s).
vars.datepicker.setDate( dates );
vars.datepicker.clear(); // Reset the datepicker.
* Create an instance of chart.
if ( ! el.$canvas.length ) {
const elm = el.$canvas.get( 0 ).getContext( '2d' );
const $selected = el.$reports.find( `.${ vars.classNames.selected }` );
vars.report = $selected.data( 'stats' );
vars.isAmount = $selected.hasClass( 'is-amount' );
vars.chart = new Chart( elm, vars.settings );
this.updateChartByReport();
* Create instances of multi-select.
// Check if multi-select elements and required class are present
if ( ! el.$multiSelect.length || ! window.WPFormsMultiSelectCheckbox ) {
// Initialize each multi-select element.
el.$multiSelect.each( function() {
const multiSelectCheckbox = new window.WPFormsMultiSelectCheckbox(
multiSelectCheckbox.init();
* Updates main chart stats when user switches between different stat card.
* @param {Object} event An event which takes place in the DOM.
handleOnChangeStatCard( event ) {
// If the already selected stat card is clicked, don't process the dataset.
if ( $this.hasClass( vars.classNames.selected ) || $this.hasClass( 'disabled' ) ) {
vars.report = $this.data( 'stats' );
vars.isAmount = $this.hasClass( 'is-amount' );
el.$reports.find( 'button' ).removeClass( vars.classNames.selected );
$this.addClass( vars.classNames.selected );
// If the `statcard` field is not present, create it.
if ( ! el.$activeStat.length ) {
// Append a hidden input field for the statcard.
el.$filterForm.append( '<input type="hidden" name="statcard">' );
// Update the reference to the activeStat element.
el.$activeStat = el.$filterForm.find( 'input[name="statcard"]' );
// Update the value of the statcard field with the selected report.
el.$activeStat.val( vars.report );
// Update the chart stats with consideration to possible form stats being viewed.
app.updateChartByReport();
* Save the user's preferred graph style and color scheme.
* @param {Object} event An event which takes place in the DOM.
handleOnSaveSettings( event ) {
const $wrapper = $( this ).closest( '.wpforms-dash-widget-settings-container' );
const graphStyle = $wrapper.find( 'input[name="wpforms-style"]:checked' ).val();
vars.type = Number( graphStyle ) === 1 ? 'bar' : 'line';
const options = Object.assign( {}, vars.settings );
options.data.labels = vars.chart.data.labels;
options.data.datasets[ 0 ].data = vars.chart.data.datasets[ 0 ].data;
const elm = el.$canvas.get( 0 ).getContext( '2d' );
vars.chart = new Chart( elm, options );
action: 'wpforms_payments_overview_save_chart_preference_settings',
el.$wrapper.find( '.wpforms-dash-widget-settings-menu' ).hide();
* Callback which is called when the "Toggle Mode" button clicked.
const { currentPageUri: url } = vars;
url.searchParams.set( 'mode', this.checked ? 'test' : 'live' );
window.location.href = url.href;
* Display or hide the matched elements.
* @param {Object} event An event which takes place in the DOM.
handleOnToggle( event ) {
const { data: { selector, hide } } = event;
// Toggle the visibility of the matched element.
el.$wrapper.find( selector ).toggle( 0, function() {
const $selector = $( selector );
// When the dropdown is open, aria-expended="true".
$selector.attr( 'aria-expanded', $selector.is( ':visible' ) );
// In case the other popover is open, let’s hide it to avoid clutter.
// When the dropdown is closed, aria-expended="false".
app.hideElm( el.$wrapper.find( hide ) );
* Hide the matched elements when clicked outside their container.
* @param {Object} event An event which takes place in the DOM.
handleOnClickOutside( event ) {
const { target, data: { selectors } } = event;
$.each( selectors, function( index, selector ) {
if ( ! $( target ).closest( `${ selector }:visible` ).length ) {
app.hideElm( el.$wrapper.find( selector ) );
* Either fills the container with placeholder data or determines
* whether actual data is available to process the chart dataset.
* @param {Object} data Chart dataset data.
* @return {Object} Labels and dataset data object.
processDatasetData( data ) {
if ( $.isPlainObject( data ) && Object.keys( data ).length > 0 ) {
el.$notice.addClass( vars.classNames.hide );
$.each( data || [], function( index, item ) {
const date = moment( item.day );
return { labels, datasets };
const { i18n: { no_dataset: placeholderText } } = vars;
// If there is a placeholder text for the current report, use it.
if ( placeholderText?.[ vars.report ] ) {
el.$notice.find( 'h2' ).text( placeholderText[ vars.report ] );
el.$notice.removeClass( vars.classNames.hide );
const end = moment().startOf( 'day' );
for ( let i = 1; i <= days; i++ ) {
date = end.clone().subtract( i, 'days' );
y: Math.floor( Math.random() * ( maxY - minY + 1 ) ) + minY, // NOSONAR not used in secure contexts.
return { labels, datasets };
* Populate the chart with a fresh set of dataset data.
* @param {Array} data Chart dataset data.
const { labels, datasets } = app.processDatasetData( data || [] );
vars.chart.data.labels = labels;
vars.chart.data.datasets[ 0 ] = vars.settings.data.datasets[ 0 ];
vars.chart.data.datasets[ 0 ].data = datasets;
el.$spinner.addClass( vars.classNames.hide );
* Fetch and process the chart dataset data for the selected stat card.
* @param {Object} args Optional. Additional arguments provided for the Ajax request.
updateChartByReport( args ) {
// Cache dataset of payments for the chart stats.
if ( vars.report && Object.hasOwn( vars.data, vars.report ) ) {
app.updateChart( vars.data[ vars.report ]?.data || [] );
// Add a class name indicating that the chart is fetching data.
// This is mainly to avoid fast clicking on the stat cards to avoid multiple Ajax requests.
el.$reports.addClass( vars.classNames.fetching );
action: 'wpforms_payments_overview_refresh_chart_dataset_data',
vars.data = Object.assign( { [ vars.report ]: data }, vars.data );
app.updateChart( data?.data || [] );
app.updateReports( data?.reports || {} );
el.$reports.addClass( vars.classNames.ready );
el.$reports.removeClass( vars.classNames.fetching );
* Reflect payments summary stats in their corresponding areas (elements).
* @param {Object} reports Reports summary stats queried from the database.
updateReports( reports ) {
// Bail early, in case given reports object is empty.
if ( $.isEmptyObject( reports ) ) {
// eslint-disable-next-line complexity
const $button = $this.find( 'button' );
// Skip iterating over stat cards that are disabled.
if ( $button.hasClass( 'disabled' ) ) {
return true; // This is the same as 'continue'.
const stats = $button.data( 'stats' );
const value = reports[ stats ] || 0;
const delta = Number( reports[ `${ stats }_delta` ] ) || 0;
const $value = $this.find( '.statcard-value' );
const $delta = $this.find( '.statcard-delta' );
$value.addClass( vars.classNames.calculated ).html( value );
$delta.addClass( vars.classNames.calculated ).html( Math.abs( delta ) );
$delta.addClass( Number( delta > 0 ) ? 'is-upward' : 'is-downward' );
// Skip iterating over stat cards that do not represent an amount.
if ( ! $button.hasClass( 'is-amount' ) ) {
return; // This is the same as 'continue'.
// Add a title attribute to the stat card value if it does not have one.
$value.attr( 'title', $value.text() );