: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace WPForms\Admin\Payments\Views\Overview;
use WPForms\Admin\Helpers\Datepicker;
use WPForms\Db\Payments\ValueValidator;
use WPForms\Admin\Payments\Payments;
use WPForms\Admin\Payments\Views\PaymentsViewsInterface;
use WPForms\Integrations\Stripe\Helpers as StripeHelpers;
* Payments Overview Page class.
class Page implements PaymentsViewsInterface {
if ( ! $this->has_any_mode_payment() ) {
$this->chart = new Chart();
$this->table = new Table();
$this->table->prepare_items();
$this->clean_request_uri();
private function hooks() {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
public function get_tab_label() {
return __( 'Overview', 'wpforms-lite' );
* Enqueue scripts and styles.
public function enqueue_assets() {
$min = wpforms_get_min_suffix();
WPFORMS_PLUGIN_URL . 'assets/lib/flatpickr/flatpickr.min.css',
WPFORMS_PLUGIN_URL . 'assets/lib/flatpickr/flatpickr.min.js',
'wpforms-multiselect-checkboxes',
WPFORMS_PLUGIN_URL . 'assets/lib/wpforms-multiselect/wpforms-multiselect-checkboxes.min.css',
'wpforms-multiselect-checkboxes',
WPFORMS_PLUGIN_URL . 'assets/lib/wpforms-multiselect/wpforms-multiselect-checkboxes.min.js',
WPFORMS_PLUGIN_URL . 'assets/lib/chart.min.js',
'wpforms-admin-payments-overview',
WPFORMS_PLUGIN_URL . "assets/js/admin/payments/overview{$min}.js",
[ 'jquery', 'wpforms-flatpickr', 'wpforms-chart' ],
'settings' => $this->chart->get_chart_settings(),
'locale' => sanitize_key( wpforms_get_language_code() ),
'nonce' => wp_create_nonce( 'wpforms_payments_overview_nonce' ),
'date_format' => sanitize_text_field( Datepicker::get_wp_date_format_for_momentjs() ),
'delimiter' => Datepicker::TIMESPAN_DELIMITER,
'report' => Chart::ACTIVE_REPORT,
'currency' => sanitize_text_field( wpforms_get_currency() ),
'decimals' => absint( wpforms_get_currency_decimals( wpforms_get_currency() ) ),
'label' => esc_html__( 'Payments', 'wpforms-lite' ),
'delete_button' => esc_html__( 'Delete', 'wpforms-lite' ),
'subscription_delete_confirm' => $this->get_subscription_delete_confirmation_message(),
'total_payments' => esc_html__( 'No payments for selected period', 'wpforms-lite' ),
'total_sales' => esc_html__( 'No sales for selected period', 'wpforms-lite' ),
'total_refunded' => esc_html__( 'No refunds for selected period', 'wpforms-lite' ),
'total_subscription' => esc_html__( 'No new subscriptions for selected period', 'wpforms-lite' ),
'total_renewal_subscription' => esc_html__( 'No subscription renewals for the selected period', 'wpforms-lite' ),
'total_coupons' => esc_html__( 'No coupons applied during the selected period', 'wpforms-lite' ),
'page_uri' => $this->get_current_uri(),
'wpforms-admin-payments-overview', // Script handle the data will be attached to.
'wpforms_admin_payments_overview', // Name for the JavaScript object.
* Retrieve a Payment Overview URI.
private function get_current_uri() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
unset( $query['mode'], $query['paged'] );
return add_query_arg( $query, self::get_url() );
* Determine whether the current user has the capability to view the page.
public function current_user_can() {
return wpforms_current_user_can();
public function heading() {
Helpers::get_default_heading();
public function display() {
// If there are no payments at all, display an empty state.
if ( ! $this->has_any_mode_payment() ) {
$this->display_empty_state();
// Display the page content, including the chart and the table.
* Get the URL of the page.
public static function get_url() {
'page' => Payments::SLUG,
* Use only for logged-in users. Returns mode from user meta data or from the $_GET['mode'] parameter.
public static function get_mode() {
if ( ! wpforms_is_admin_ajax() && ! wpforms_is_admin_page( 'payments' ) && ! wpforms_is_admin_page( 'entries' ) ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$mode = isset( $_GET['mode'] ) ? sanitize_key( $_GET['mode'] ) : '';
$user_id = get_current_user_id();
$meta_key = 'wpforms-payments-mode';
if ( ValueValidator::is_valid( $mode, 'mode' ) ) {
update_user_meta( $user_id, $meta_key, $mode );
$mode = get_user_meta( $user_id, $meta_key, true );
return ! empty( $mode ) ? $mode : $default_mode;
* Display one of the empty states.
private function display_empty_state() {
// If a payment gateway is configured, output no payments state.
if ( $this->is_gateway_configured() ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'admin/empty-states/payments/no-payments',
'cta_url' => add_query_arg(
'page' => 'wpforms-overview',
// Otherwise, output get started state.
$is_upgraded = StripeHelpers::is_allowed_license_type();
$message = __( "First you need to set up a payment gateway. We've partnered with <strong>Stripe</strong> to bring easy payment forms to everyone. ", 'wpforms-lite' );
? sprintf( /* translators: %s - WPForms Addons admin page URL. */
__( 'Other payment gateways such as <strong>PayPal</strong> and <strong>Square</strong> can be installed from the <a href="%s">Addons screen</a>.', 'wpforms-lite' ),
'page' => 'wpforms-addons',
: sprintf( /* translators: %s - WPForms.com Upgrade page URL. */
__( "If you'd like to use another payment gateway, please consider <a href='%s'>upgrading to WPForms Pro</a>.", 'wpforms-lite' ),
esc_url( wpforms_admin_upgrade_link( 'Payments Dashboard', 'Splash - Upgrade to Pro Text' ) )
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'admin/empty-states/payments/get-started',
'version' => $is_upgraded ? 'pro' : 'lite',
'cta_url' => add_query_arg(
'page' => 'wpforms-settings',
* Determine whether a payment gateway is configured.
private function is_gateway_configured() {
* Allow to modify a status whether a payment gateway is configured.
* @param bool $is_configured True if a payment gateway is configured.
return (bool) apply_filters( 'wpforms_admin_payments_views_overview_page_gateway_is_configured', StripeHelpers::has_stripe_keys() );
* Determine whether there are payments of any modes.
private function has_any_mode_payment() {
static $has_any_mode_payment;
if ( $has_any_mode_payment !== null ) {
return $has_any_mode_payment;
$has_any_mode_payment = count(
wpforms()->get( 'payment' )->get_payments(
// Check on trashed payments.
if ( ! $has_any_mode_payment ) {
$has_any_mode_payment = count(
wpforms()->get( 'payment' )->get_payments(
return $has_any_mode_payment;
* To avoid recursively, remove the previous variables from the REQUEST_URI.
private function clean_request_uri() {
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Recommended
$_SERVER['REQUEST_URI'] = remove_query_arg( [ '_wpnonce', '_wp_http_referer', 'action', 'action2', 'payment_id' ], wp_unslash( $_SERVER['REQUEST_URI'] ) );
if ( empty( $_GET['s'] ) ) {
$_SERVER['REQUEST_URI'] = remove_query_arg( [ 'search_where', 'search_mode', 's' ], wp_unslash( $_SERVER['REQUEST_URI'] ) );
// phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Recommended
* Get the subscription delete confirmation message.
* The returned message is used in the JavaScript file and shown in a "Heads up!" modal.
private function get_subscription_delete_confirmation_message() {
$help_link = wpforms_utm_link(
'https://wpforms.com/docs/viewing-and-managing-payments/#deleting-parent-subscription',
wp_kses( /* translators: WPForms.com docs page URL. */
__( 'Deleting one or more selected payments may prevent processing of future subscription renewals. Payment filtering may also be affected. <a href="%1$s" rel="noopener" target="_blank">Learn More</a>', 'wpforms-lite' ),