Automattic\WooCommerce\Internal\Admin\Orders

PostsRedirectionController::maybe_redirect_to_edit_order_page()privateWC 1.0

If needed, performs a redirection to the edit order page.

Method of the class: PostsRedirectionController{}

No Hooks.

Return

null. Nothing.

Usage

// private - for code of main (parent) class only
$result = $this->maybe_redirect_to_edit_order_page(): void;

PostsRedirectionController::maybe_redirect_to_edit_order_page() code WC 7.1.0

private function maybe_redirect_to_edit_order_page(): void {
	$post_id = absint( $_GET['post'] ?? 0 );

	if ( ! $post_id || ! in_array( get_post_type( $post_id ), array( 'shop_order_placehold', 'shop_order' ), true ) || ! isset( $_GET['action'] ) ) {
		return;
	}

	// Respect query args, except for 'post'.
	$query_args = wp_unslash( $_GET );
	$action     = $query_args['action'];
	unset( $query_args['post'], $query_args['_wpnonce'], $query_args['_wp_http_referer'], $query_args['action'] );

	$new_url = '';

	switch ( $action ) {
		case 'edit':
			$new_url = $this->page_controller->get_edit_url( $post_id );
			break;

		case 'trash':
		case 'untrash':
		case 'delete':
			// Re-generate nonce if validation passes.
			check_admin_referer( $action . '-post_' . $post_id );

			$new_url = add_query_arg(
				array(
					'action'           => $action,
					'order'            => array( $post_id ),
					'_wp_http_referer' => $this->page_controller->get_orders_url(),
					'_wpnonce'         => wp_create_nonce( 'bulk-orders' ),
				),
				$this->page_controller->get_orders_url()
			);

			break;

		default:
			break;
	}

	if ( ! $new_url ) {
		return;
	}

	$new_url = add_query_arg( $query_args, $new_url );

	wp_safe_redirect( $new_url, 301 );
	exit;
}