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; } ?>