/home/techb158/public_html/wp-content/plugins/wpforms-lite/src/Admin/Payments
Edit: /home/techb158/public_html/wp-content/plugins/wpforms-lite/src/Admin/Payments/Payments.php (6195B)
update_request_uri();
( new ScreenOptions() )->init();
( new Coupon() )->init();
( new Filters() )->init();
( new Search() )->init();
( new BulkActions() )->init();
$this->hooks();
}
/**
* Initialize the active view.
*
* @since 1.8.2
*/
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 ] ) ) {
return;
}
$this->view = $this->views[ $this->active_view_slug ];
$this->view->init();
}
/**
* Get available views.
*
* @since 1.8.2
*
* @return array
*/
private function get_views() {
if ( ! empty( $this->views ) ) {
return $this->views;
}
$views = [
'coupons' => new Education(),
];
/**
* Allow to extend payment views.
*
* @since 1.8.2
*
* @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(
$this->views,
static function ( $view ) {
return $view->current_user_can();
}
);
return $this->views;
}
/**
* Register hooks.
*
* @since 1.8.2
*/
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' ] );
}
/**
* Output the page.
*
* @since 1.8.2
*/
public function output() {
if ( empty( $this->view ) ) {
return;
}
?>
get_views();
// Remove views that should not be displayed.
$views = array_filter(
$views,
static function ( $view ) {
return ! empty( $view->get_tab_label() );
}
);
// If there is only one view - no need to display tabs.
if ( count( $views ) === 1 ) {
return;
}
?>
self::SLUG,
'view' => $tab,
],
admin_url( 'admin.php' )
);
}
/**
* Modify arguments of secondary where clauses.
*
* @since 1.8.2
*
* @param array $args Query arguments.
*
* @return array
*/
public function modify_secondary_where_conditions_args( $args ) {
// Set a current mode.
if ( ! isset( $args['mode'] ) ) {
$args['mode'] = Page::get_mode();
}
return $args;
}
/**
* Update view param in request URI.
*
* Backward compatibility for old URLs.
*
* @since 1.8.4
*/
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'] ) ) {
return;
}
$old_new = [
'single' => 'payment',
'overview' => 'payments',
];
if (
! array_key_exists( $_GET['view'], $old_new )
|| in_array( $_GET['view'], $old_new, true )
) {
return;
}
wp_safe_redirect(
str_replace(
'view=' . $_GET['view'],
'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
exit;
}
}