: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace WPForms\Admin\Payments\Views\Overview;
if ( ! defined( 'ABSPATH' ) ) {
use WPForms\Db\Payments\ValueValidator;
use WPForms\Db\Payments\Queries;
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
* Payments Overview Table class.
class Table extends \WP_List_Table {
* Trait for using notices.
* Payment type: one-time.
const ONE_TIME = 'one-time';
* Total number of payments.
private $table_query_args = [];
* Retrieve the table columns.
* @return array $columns Array of all the list table columns.
public function get_columns() {
if ( ! empty( $columns ) ) {
'cb' => '<input type="checkbox" />',
'title' => esc_html__( 'Payment', 'wpforms-lite' ),
'date' => esc_html__( 'Date', 'wpforms-lite' ),
if ( wpforms()->get( 'payment_queries' )->has_different_values( 'gateway' ) ) {
$columns['gateway'] = esc_html__( 'Gateway', 'wpforms-lite' );
if ( wpforms()->get( 'payment_queries' )->has_different_values( 'type' ) ) {
$columns['type'] = esc_html__( 'Type', 'wpforms-lite' );
if ( wpforms()->get( 'payment_meta' )->is_valid_meta_by_meta_key( 'coupon_id' ) ) {
$columns['coupon'] = esc_html__( 'Coupon', 'wpforms-lite' );
$columns['total'] = esc_html__( 'Total', 'wpforms-lite' );
if ( wpforms()->get( 'payment_queries' )->has_subscription() ) {
$columns['subscription'] = esc_html__( 'Subscription', 'wpforms-lite' );
$columns['form'] = esc_html__( 'Form', 'wpforms-lite' );
$columns['status'] = esc_html__( 'Status', 'wpforms-lite' );
* Filters the columns in the Payments Overview table.
* @param array $columns Array of columns.
return (array) apply_filters( 'wpforms_admin_payments_views_overview_table_get_columns', $columns );
* Determine whether it is a trash view.
private function is_trash_view() {
return $this->is_current_view( 'trash' );
* Define the table's sortable columns.
* @return array Array of all the sortable columns.
protected function get_sortable_columns() {
'title' => [ 'id', false ],
'date' => [ 'date', false ],
'total' => [ 'total', false ],
* Prepare the table with different parameters, pagination, columns and table elements.
public function prepare_items() {
$page = $this->get_pagenum();
$per_page = $this->get_items_per_page( 'wpforms_payments_per_page', 20 );
'offset' => $per_page * ( $page - 1 ),
'orderby' => $this->get_order_by(),
'search' => $this->get_search_query(),
'search_conditions' => $this->get_search_conditions(),
'status' => $this->get_valid_status_from_request(),
'is_published' => $this->is_trash_view() ? 0 : 1,
// Set the table query arguments for later use.
$this->table_query_args = $this->prepare_table_query_args( $data_args );
// Retrieve the payment records for the given data arguments.
$this->items = wpforms()->get( 'payment' )->get_payments( $this->table_query_args );
// Check if we can continue.
$this->can_prepare_records();
// Get the proper total number of records depending on the current status view.
$total_items = $this->get_valid_status_count_from_request();
$total_pages = ceil( $total_items / $per_page );
$this->set_pagination_args(
'total_items' => $total_items,
'total_pages' => $total_pages,
* Prepare the query arguments for the overview table.
* @param array $args Array of data arguments.
private function prepare_table_query_args( $args = [] ) {
// phpcs:disable WordPress.Security.NonceVerification.Recommended
'order' => isset( $_GET['order'] ) ? sanitize_key( $_GET['order'] ) : 'DESC',
'form_id' => isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : '',
'type' => isset( $_GET['type'] ) ? sanitize_text_field( wp_unslash( $_GET['type'] ) ) : '',
'gateway' => isset( $_GET['gateway'] ) ? sanitize_text_field( wp_unslash( $_GET['gateway'] ) ) : '',
'subscription_status' => isset( $_GET['subscription_status'] ) ? sanitize_text_field( wp_unslash( $_GET['subscription_status'] ) ) : '',
// phpcs:enable WordPress.Security.NonceVerification.Recommended
* Message to be displayed when there are no payments.
public function no_items() {
if ( $this->is_trash_view() ) {
esc_html_e( 'No payments found in the trash.', 'wpforms-lite' );
if ( $this->is_current_view( 'search' ) ) {
esc_html_e( 'No payments found, please try a different search.', 'wpforms-lite' );
esc_html_e( 'No payments found.', 'wpforms-lite' );
* Generates content for a single row of the table.
* @param array $item Item data.
public function single_row( $item ) {
// Leave the default row if the item is not a subscription.
if ( empty( $item['subscription_id'] ) || empty( $item['subscription_status'] ) ) {
parent::single_row( $item );
$has_renewal = wpforms()->get( 'payment_queries' )->if_subscription_has_renewal( $item['subscription_id'] );
// Leave the default row if the subscription has no renewal.
parent::single_row( $item );
echo '<tr class="subscription-has-renewal">';
$this->single_row_columns( $item );
* @param array $item Item data.
* @param string $column_name Column name.
protected function column_default( $item, $column_name ) {
if ( method_exists( $this, "get_column_{$column_name}" ) ) {
return $this->{"get_column_{$column_name}"}( $item );
if ( isset( $item[ $column_name ] ) ) {
return esc_html( $item[ $column_name ] );
* Allow to filter default column value.
* @param string $value Default column value.
* @param array $item Item data.
* @param string $column_name Column name.
return apply_filters( 'wpforms_admin_payments_views_overview_table_column_default_value', '', $item, $column_name );
* Define the checkbox column.
* @param array $item The current item.
protected function column_cb( $item ) {
return '<input type="checkbox" name="payment_id[]" value="' . absint( $item['id'] ) . '" />';
* Prepare the items and display the table.
public function display() {
<form id="wpforms-payments-table" method="GET" action="<?php echo esc_url( Page::get_url() ); ?>">
$this->display_hidden_fields();
$this->show_reset_filter();
$this->search_box( esc_html__( 'Search Payments', 'wpforms-lite' ), 'wpforms-payments-search-input' );
* Extra filtering controls to be displayed between bulk actions and pagination.
* @param string $which Position of the extra controls: 'top' or 'bottom'.
protected function extra_tablenav( $which ) {
// We only want to show the extra controls on the top.
if ( $which !== 'top' ) {
'data' => ValueValidator::get_allowed_types(),
'plural_label' => __( 'types', 'wpforms-lite' ),
'data' => ValueValidator::get_allowed_gateways(),
'plural_label' => __( 'gateways', 'wpforms-lite' ),
'subscription_status' => [
'data' => ValueValidator::get_allowed_subscription_statuses(),
'plural_label' => __( 'subscriptions', 'wpforms-lite' ),
// Special case for showing all available types, gateways and subscription statuses.
if ( ! $this->has_items() ) {
$this->table_query_args['type'],
$this->table_query_args['gateway'],
$this->table_query_args['subscription_status']
// Output the reset filter notice.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'admin/payments/tablenav-filters',
'filters' => $this->prepare_extra_tablenav_filters( $tablenav_data ),
* Iterate through each given filter option and remove the ones that don't have any records.
* @param array $tablenav_data Array of filter options.
private function prepare_extra_tablenav_filters( $tablenav_data ) {
foreach ( $tablenav_data as $nav_key => $nav_attributes ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$selected = isset( $_GET[ $nav_key ] ) ? explode( '|', wp_unslash( $_GET[ $nav_key ] ) ) : [];
foreach ( $nav_attributes['data'] as $attribute_key => $attribute_value ) {
$query_args = array_merge( $this->table_query_args, [ $nav_key => $attribute_key ] );
if ( in_array( $attribute_key, $selected, true ) || wpforms()->get( 'payment_queries' )->if_exists( $query_args ) ) {
$filtered_data[ $attribute_key ] = $attribute_value;
$selected = array_filter(
static function ( $value ) use ( $filtered_data ) {
return isset( $filtered_data[ $value ] );
if ( empty( $filtered_data ) || ( count( $filtered_data ) === 1 && empty( $selected ) ) ) {
$rendered_nav_data[] = wpforms_render(
'admin/payments/tablenav-filter-multiselect',
'options' => $filtered_data,
'multiple' => sprintf( /* translators: %s - plural label. */
__( 'Multiple %s selected', 'wpforms-lite' ),
esc_attr( $nav_attributes['plural_label'] )
'all' => sprintf( /* translators: %s - plural label. */
__( 'All %s', 'wpforms-lite' ),
esc_attr( $nav_attributes['plural_label'] )
return implode( '', $rendered_nav_data );
* Display the search box.
* @param string $text The 'submit' button label.
* @param string $input_id ID attribute value for the search input field.
public function search_box( $text, $input_id ) {
$search_where = $this->get_search_where_key();
$search_mode = $this->get_search_mode_key();
<label class="screen-reader-text" for="search_where"><?php esc_html_e( 'Select which field to use when searching for payments', 'wpforms-lite' ); ?></label>
<select name="search_where">
<option value="<?php echo esc_attr( Search::TITLE ); ?>" <?php selected( $search_where, Search::TITLE ); ?> ><?php echo esc_html( $this->get_search_where( Search::TITLE ) ); ?></option>
<option value="<?php echo esc_attr( Search::TRANSACTION_ID ); ?>" <?php selected( $search_where, Search::TRANSACTION_ID ); ?> ><?php echo esc_html( $this->get_search_where( Search::TRANSACTION_ID ) ); ?></option>
<option value="<?php echo esc_attr( Search::SUBSCRIPTION_ID ); ?>" <?php selected( $search_where, Search::SUBSCRIPTION_ID ); ?> ><?php echo esc_html( $this->get_search_where( Search::SUBSCRIPTION_ID ) ); ?></option>
<option value="<?php echo esc_attr( Search::EMAIL ); ?>" <?php selected( $search_where, Search::EMAIL ); ?> ><?php echo esc_html( $this->get_search_where( Search::EMAIL ) ); ?></option>
<option value="<?php echo esc_attr( Search::CREDIT_CARD ); ?>" <?php selected( $search_where, Search::CREDIT_CARD ); ?> ><?php echo esc_html( $this->get_search_where( Search::CREDIT_CARD ) ); ?></option>
<option value="<?php echo esc_attr( Search::ANY ); ?>" <?php selected( $search_where, Search::ANY ); ?> ><?php echo esc_html( $this->get_search_where( Search::ANY ) ); ?></option>
<label class="screen-reader-text" for="search_mode"><?php esc_html_e( 'Select which comparison method to use when searching for payments', 'wpforms-lite' ); ?></label>
<select name="search_mode">
<option value="<?php echo esc_attr( Search::MODE_CONTAINS ); ?>" <?php selected( $search_mode, Search::MODE_CONTAINS ); ?> ><?php echo esc_html( $this->get_search_mode( Search::MODE_CONTAINS ) ); ?></option>
<option value="<?php echo esc_attr( Search::MODE_EQUALS ); ?>" <?php selected( $search_mode, Search::MODE_EQUALS ); ?> ><?php echo esc_html( $this->get_search_mode( Search::MODE_EQUALS ) ); ?></option>
<option value="<?php echo esc_attr( Search::MODE_STARTS ); ?>" <?php selected( $search_mode, Search::MODE_STARTS ); ?> ><?php echo esc_html( $this->get_search_mode( Search::MODE_STARTS ) ); ?></option>
<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo esc_html( $text ); ?></label>
<input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s" value="<?php echo esc_attr( $this->get_search_query() ); ?>" />
<input type="submit" class="button" value="<?php echo esc_attr( $text ); ?>" />
* Get bulk actions to be displayed in bulk action dropdown.
protected function get_bulk_actions() {
if ( $this->is_trash_view() ) {
'restore' => esc_html__( 'Restore', 'wpforms-lite' ),
'delete' => esc_html__( 'Delete Permanently', 'wpforms-lite' ),