BulkAction
1 week ago
views
1 week ago
AdminNotices.php
1 week ago
BulkAction.php
1 week ago
DispatchLabelFile.php
1 week ago
FilterOrders.php
1 week ago
ModifyOrderTable.php
1 week ago
ModifyStatuses.php
1 week ago
SubscriptionsIntegration.php
1 week ago
DispatchLabelFile.php
51 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class DispatchLabelFile |
| 4 | */ |
| 5 | |
| 6 | namespace WPDesk\FS\Shipment; |
| 7 | |
| 8 | use FSVendor\WPDesk\FS\Shipment\Label\LabelsFileDispatcher; |
| 9 | use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 10 | |
| 11 | /** |
| 12 | * . |
| 13 | */ |
| 14 | class DispatchLabelFile implements Hookable { |
| 15 | |
| 16 | /** |
| 17 | * @return void |
| 18 | */ |
| 19 | public function hooks() { |
| 20 | add_action( 'admin_init', [ $this, 'dispatch_labels_file_if_expected' ], 1 ); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Dispatch labels file if requested. |
| 25 | */ |
| 26 | public function dispatch_labels_file_if_expected() { |
| 27 | if ( ! isset( $_GET['flexible_shipping_labels'], $_GET['tmp_file'], $_GET['nonce'] ) ) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | $file = trailingslashit( sys_get_temp_dir() ) . basename( sanitize_text_field( wp_unslash( $_GET['flexible_shipping_labels'] ) ) ); |
| 32 | $tmp_file = trailingslashit( sys_get_temp_dir() ) . basename( sanitize_text_field( wp_unslash( $_GET['tmp_file'] ) ) ); |
| 33 | |
| 34 | if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['nonce'] ) ), 'flexible_shipping_labels' . basename( $tmp_file ) ) ) { |
| 35 | wp_die( esc_html__( 'Nonce verification failed!', 'flexible-shipping' ) ); |
| 36 | } |
| 37 | |
| 38 | if ( ! current_user_can( 'manage_woocommerce' ) ) { |
| 39 | wp_die( esc_html__( 'You do not have permission to access this page!', 'flexible-shipping' ) ); |
| 40 | } |
| 41 | |
| 42 | if ( ! file_exists( $tmp_file ) ) { |
| 43 | wp_die( esc_html__( 'This file was already downloaded! Please retry bulk action!', 'flexible-shipping' ) ); |
| 44 | } |
| 45 | |
| 46 | $labels_file_dispatcher = new LabelsFileDispatcher(); |
| 47 | $labels_file_dispatcher->dispatch_and_delete_labels_file( $file, $tmp_file ); |
| 48 | die(); |
| 49 | } |
| 50 | } |
| 51 |