Exporter
2 weeks ago
Importer
2 weeks ago
Exporter.php
2 weeks ago
ExporterData.php
2 weeks ago
ImporterData.php
2 weeks ago
ShippingClassTrait.php
2 weeks ago
Exporter.php
42 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Exporter. |
| 4 | * |
| 5 | * @package WPDesk\FS\TableRate\ImporterExporter |
| 6 | */ |
| 7 | |
| 8 | namespace WPDesk\FS\TableRate\ImporterExporter; |
| 9 | |
| 10 | use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 11 | use WPDesk\FS\TableRate\ImporterExporter\Exporter\JSON; |
| 12 | |
| 13 | /** |
| 14 | * Class Hooks |
| 15 | */ |
| 16 | class Exporter implements Hookable { |
| 17 | /** |
| 18 | * @return void|null |
| 19 | */ |
| 20 | public function hooks() { |
| 21 | add_action( 'wp_ajax_flexible_shipping_export', array( $this, 'flexible_shipping_export' ) ); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Preparing data to export. |
| 26 | */ |
| 27 | public function flexible_shipping_export() { |
| 28 | check_ajax_referer( 'flexible_shipping', 'flexible_shipping_nonce' ); |
| 29 | if ( ! current_user_can( 'manage_woocommerce' ) ) { |
| 30 | wp_send_json_error(); |
| 31 | } |
| 32 | |
| 33 | $instance_id = filter_input( INPUT_GET, 'instance_id' ); |
| 34 | $methods = array_filter( wp_parse_id_list( filter_input( INPUT_GET, 'methods' ) ) ); |
| 35 | |
| 36 | $exporter = new JSON( sanitize_key( $instance_id ), $methods ); |
| 37 | $export_data = $exporter->get_exported_data(); |
| 38 | |
| 39 | $exporter->download_file( $exporter->get_filename( $export_data ), $export_data ); |
| 40 | } |
| 41 | } |
| 42 |