: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace WPForms\Admin\Payments;
use WPForms\Admin\Payments\Views\Coupons\Education;
use WPForms\Admin\Payments\Views\Overview\BulkActions;
use WPForms\Admin\Payments\Views\Single;
use WPForms\Admin\Payments\Views\Overview\Page;
use WPForms\Admin\Payments\Views\Overview\Coupon;
use WPForms\Admin\Payments\Views\Overview\Filters;
use WPForms\Admin\Payments\Views\Overview\Search;
const SLUG = 'wpforms-payments';
* Available views (pages).
private $active_view_slug;
* @var null|\WPForms\Admin\Payments\Views\PaymentsViewsInterface
if ( ! wpforms_is_admin_page( 'payments' ) ) {
$this->update_request_uri();
( new ScreenOptions() )->init();
( new Coupon() )->init();
( new Filters() )->init();
( new Search() )->init();
( new BulkActions() )->init();
* Initialize the active view.
public function init_view() {
$view_ids = array_keys( $this->get_views() );
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$this->active_view_slug = isset( $_GET['view'] ) ? sanitize_key( $_GET['view'] ) : 'payments';
// If the user tries to load an invalid view - fallback to the first available.
if ( ! in_array( $this->active_view_slug, $view_ids, true ) ) {
$this->active_view_slug = reset( $view_ids );
if ( ! isset( $this->views[ $this->active_view_slug ] ) ) {
$this->view = $this->views[ $this->active_view_slug ];
private function get_views() {
if ( ! empty( $this->views ) ) {
'coupons' => new Education(),
* Allow to extend payment views.
* @param array $views Array of views where key is slug.
$this->views = (array) apply_filters( 'wpforms_admin_payments_payments_get_views', $views );
$this->views['payments'] = new Page();
$this->views['payment'] = new Single();
// Payments view should be the first one.
$this->views = array_merge( [ 'payments' => $this->views['payments'] ], $this->views );
$this->views = array_filter(
static function ( $view ) {
return $view->current_user_can();
private function hooks() {
add_action( 'wpforms_admin_page', [ $this, 'output' ] );
add_action( 'current_screen', [ $this, 'init_view' ] );
add_filter( 'wpforms_db_payments_payment_add_secondary_where_conditions_args', [ $this, 'modify_secondary_where_conditions_args' ] );
public function output() {
if ( empty( $this->view ) ) {
<div id="wpforms-payments" class="wrap wpforms-admin-wrap wpforms-payments-wrap wpforms-payments-wrap-<?php echo esc_attr( $this->active_view_slug ); ?>">
<?php esc_html_e( 'Payments', 'wpforms-lite' ); ?>
<?php $this->view->heading(); ?>
<?php if ( ! empty( $this->view->get_tab_label() ) ) : ?>
<div class="wpforms-tabs-wrapper">
<?php $this->display_tabs(); ?>
<div class="wpforms-admin-content wpforms-admin-settings">
<?php $this->view->display(); ?>
private function display_tabs() {
$views = $this->get_views();
// Remove views that should not be displayed.
static function ( $view ) {
return ! empty( $view->get_tab_label() );
// If there is only one view - no need to display tabs.
if ( count( $views ) === 1 ) {
<nav class="nav-tab-wrapper">
<?php foreach ( $views as $slug => $view ) : ?>
<a href="<?php echo esc_url( $this->get_tab_url( $slug ) ); ?>" class="nav-tab <?php echo $slug === $this->active_view_slug ? 'nav-tab-active' : ''; ?>">
<?php echo esc_html( $view->get_tab_label() ); ?>
* @param string $tab Tab slug.
private function get_tab_url( $tab ) {
* Modify arguments of secondary where clauses.
* @param array $args Query arguments.
public function modify_secondary_where_conditions_args( $args ) {
if ( ! isset( $args['mode'] ) ) {
$args['mode'] = Page::get_mode();
* Update view param in request URI.
* Backward compatibility for old URLs.
private function update_request_uri() {
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
if ( ! isset( $_GET['view'], $_SERVER['REQUEST_URI'] ) ) {
'overview' => 'payments',
! array_key_exists( $_GET['view'], $old_new )
|| in_array( $_GET['view'], $old_new, true )
'view=' . $old_new[ $_GET['view'] ],
esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) )
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash