export-tools.php
40 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Components\Export; |
| 5 | |
| 6 | // If this file is called directly, abort. |
| 7 | if ( ! defined( 'WPINC' ) ) { |
| 8 | die; |
| 9 | } |
| 10 | |
| 11 | class Export_Tools { |
| 12 | |
| 13 | /** |
| 14 | * @return Interfaces\Base_Export_It |
| 15 | */ |
| 16 | public static function get_exporter_by_format(): Interfaces\Base_Export_It { |
| 17 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 18 | $exporter = self::get_exporter( sanitize_key( $_GET['format'] ?? 'csv' ) ); |
| 19 | |
| 20 | return $exporter ?: self::get_exporter( 'csv' ); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @param string $format |
| 25 | * |
| 26 | * @return false|Interfaces\Base_Export_It |
| 27 | */ |
| 28 | public static function get_exporter( string $format ) { |
| 29 | $formats = apply_filters( |
| 30 | 'jet-form-builder/export/formats', |
| 31 | array( |
| 32 | 'csv' => new Csv\Service(), |
| 33 | ) |
| 34 | ); |
| 35 | |
| 36 | return array_key_exists( $format, $formats ) ? $formats[ $format ] : false; |
| 37 | } |
| 38 | |
| 39 | } |
| 40 |