get = isset( $_GET ) && is_array( $_GET ) ? $this->normalize_deep( wp_unslash( $_GET ) ) : array(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $this->post = isset( $_POST ) && is_array( $_POST ) ? $this->normalize_deep( wp_unslash( $_POST ) ) : array(); } private function normalize_deep( $value ) { if ( is_array( $value ) ) { return array_map( array( $this, 'normalize_deep' ), $value ); } if ( is_string( $value ) ) { return sanitize_text_field( $value ); } return $value; } private function source( string $type ): array { return match ( $type ) { 'get' => $this->get, 'post' => $this->post, default => $this->post, }; } public function input( string $key, string $type = 'post', $default = null, ?callable $sanitizer = null ) { $data = $this->source( $type ); $value = $data[ $key ] ?? $default; if ( null !== $sanitizer ) { return call_user_func( $sanitizer, $value ); } return $value; } public function all( string $type = 'post' ): array { return $this->source( $type ); } public function only( array $keys, string $type = 'post' ): array { return array_intersect_key( $this->source( $type ), array_flip( $keys ) ); } public function except( array $keys, string $type = 'post' ): array { return array_diff_key( $this->source( $type ), array_flip( $keys ) ); } }