Skip to content

Commit

Permalink
Redirect to the actual page after finishing a bulk action.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Nov 11, 2024
1 parent 38c3fe4 commit 94fff3d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion assets/js/static/admin-shipments-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ window.shipments.admin = window.shipments.admin || {};
});

if ( self.params.bulk_actions.hasOwnProperty( action ) && ids.length > 0 ) {

var actionData = self.params.bulk_actions[ action ];

$( '.bulk-action-wrapper' ).find( '.bulk-title' ).text( actionData['title'] );
Expand All @@ -63,6 +62,7 @@ window.shipments.admin = window.shipments.admin || {};
bulk_action : action,
step : step,
type : type,
referer : window.location.href,
ids : ids,
security : actionData['nonce']
},
Expand Down
13 changes: 11 additions & 2 deletions src/Admin/BulkActionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@ public function set_shipment_type( $type ) {
$this->type = $type;
}

public function get_success_redirect_url() {
public function get_success_redirect_url( $referer = false ) {
$page = 'wc-gzd-shipments';

if ( 'simple' !== $this->get_shipment_type() ) {
$page = 'wc-gzd-' . $this->get_shipment_type() . '-shipments';
}

return admin_url( 'admin.php?page=' . $page . '&bulk_action_handling=finished&current_bulk_action=' . sanitize_key( $this->get_action() ) );
$base_url = $referer ? $referer : admin_url( 'admin.php?page=' . $page );
$base_url = add_query_arg(
array(
'bulk_action_handling' => 'finished',
'current_bulk_action' => sanitize_key( $this->get_action() ),
),
$base_url
);

return esc_url_raw( $base_url );
}

public function get_step() {
Expand Down
7 changes: 4 additions & 3 deletions src/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,9 @@ public static function sort_shipping_provider() {
}

public static function shipments_bulk_action_handle() {
$action = isset( $_POST['bulk_action'] ) ? wc_clean( wp_unslash( $_POST['bulk_action'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
$type = isset( $_POST['type'] ) ? wc_clean( wp_unslash( $_POST['type'] ) ) : 'simple'; // phpcs:ignore WordPress.Security.NonceVerification.Missing
$action = isset( $_POST['bulk_action'] ) ? wc_clean( wp_unslash( $_POST['bulk_action'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
$type = isset( $_POST['type'] ) ? wc_clean( wp_unslash( $_POST['type'] ) ) : 'simple'; // phpcs:ignore WordPress.Security.NonceVerification.Missing
$referer = isset( $_POST['referer'] ) ? wp_sanitize_redirect( wp_unslash( $_POST['referer'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing

check_ajax_referer( "woocommerce_gzd_shipments_{$action}", 'security' );

Expand Down Expand Up @@ -570,7 +571,7 @@ public static function shipments_bulk_action_handle() {
array(
'step' => 'done',
'percentage' => 100,
'url' => $handler->get_success_redirect_url(),
'url' => $handler->get_success_redirect_url( $referer ),
'type' => $handler->get_shipment_type(),
)
);
Expand Down

0 comments on commit 94fff3d

Please sign in to comment.