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
AdminNotices.php
96 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class AdminNotices |
| 4 | */ |
| 5 | |
| 6 | namespace WPDesk\FS\Shipment; |
| 7 | |
| 8 | use FSVendor\WPDesk\Notice\Notice; |
| 9 | use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 10 | use FSVendor\WPDesk\Session\SessionFactory; |
| 11 | |
| 12 | /** |
| 13 | * Display admin notices. |
| 14 | */ |
| 15 | class AdminNotices implements Hookable { |
| 16 | |
| 17 | /** |
| 18 | * @var SessionFactory |
| 19 | */ |
| 20 | private $session_factory; |
| 21 | |
| 22 | /** |
| 23 | * @param SessionFactory $session_factory . |
| 24 | */ |
| 25 | public function __construct( SessionFactory $session_factory ) { |
| 26 | $this->session_factory = $session_factory; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @return void |
| 31 | */ |
| 32 | public function hooks() { |
| 33 | add_action( 'admin_notices', [ $this, 'admin_notices' ] ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * . |
| 38 | */ |
| 39 | public function admin_notices() { |
| 40 | if ( ! empty( $_REQUEST['bulk_flexible_shipping_send'] ) ) { |
| 41 | $bulk_flexible_shipping_send_count = (int) sanitize_text_field( wp_unslash( $_REQUEST['bulk_flexible_shipping_send'] ) ); |
| 42 | |
| 43 | new Notice( |
| 44 | sprintf( __( 'Bulk send shipment - processed orders: %d', 'flexible-shipping' ), $bulk_flexible_shipping_send_count ) // phpcs:ignore |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | if ( ! empty( $_REQUEST['bulk_flexible_shipping_labels'] ) ) { |
| 49 | $bulk_flexible_shipping_labels_count = (int) sanitize_text_field( wp_unslash( $_REQUEST['bulk_flexible_shipping_labels'] ) ); |
| 50 | |
| 51 | if ( ! empty( $_REQUEST['bulk_flexible_shipping_no_labels_created'] ) ) { |
| 52 | new Notice( |
| 53 | sprintf( __( 'Bulk labels - processed orders: %d. No labels for processed orders.', 'flexible-shipping' ), $bulk_flexible_shipping_labels_count ) // phpcs:ignore |
| 54 | ); |
| 55 | } else { |
| 56 | $labels = $this->session_factory->get_woocommerce_session_adapter()->get( 'flexible_shipping_bulk_labels' ); |
| 57 | if ( is_array( $labels ) ) { |
| 58 | if ( isset( $labels['error'] ) ) { |
| 59 | new Notice( $labels['error'], Notice::NOTICE_TYPE_ERROR, true, 20 ); |
| 60 | } else { |
| 61 | $nonce = wp_create_nonce( 'flexible_shipping_labels' . basename( $labels['tmp_file'] ) ); |
| 62 | new Notice( |
| 63 | sprintf( |
| 64 | __( 'Bulk labels - processed orders: %d. If download not start automatically click %shere%s.', 'flexible-shipping' ), // phpcs:ignore |
| 65 | $bulk_flexible_shipping_labels_count, |
| 66 | '<a id="flexible_shipping_labels_url" target="_blank" href=' . esc_url( admin_url( 'admin.php?flexible_shipping_labels=' . basename( $labels['client_file'] ) . '&tmp_file=' . basename( $labels['tmp_file'] ) . '&nonce=' . $nonce ) ) . '>', |
| 67 | '</a>' |
| 68 | ) |
| 69 | ); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | if ( ! empty( $_REQUEST['bulk_flexible_shipping_manifests'] ) ) { |
| 76 | $bulk_flexible_shipping_manifest_count = (int) sanitize_text_field( wp_unslash( $_REQUEST['bulk_flexible_shipping_manifests'] ) ); |
| 77 | new Notice( |
| 78 | sprintf( __( 'Bulk shipping manifest - processed orders: %d', 'flexible-shipping' ), $bulk_flexible_shipping_manifest_count ) // phpcs:ignore |
| 79 | ); |
| 80 | |
| 81 | if ( $this->session_factory->get_woocommerce_session_adapter()->get( 'flexible_shipping_bulk_manifests' ) ) { |
| 82 | $messages = $this->session_factory->get_woocommerce_session_adapter()->get( 'flexible_shipping_bulk_manifests' ); |
| 83 | |
| 84 | foreach ( $messages as $message ) { |
| 85 | new Notice( |
| 86 | $message['message'], |
| 87 | $message['type'] |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | $this->session_factory->get_woocommerce_session_adapter()->set( 'flexible_shipping_bulk_manifests', null ); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 |