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 (null).

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 9.4.2

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

	$redirect_from_types   = wc_get_order_types( 'admin-menu' );
	$redirect_from_types[] = 'shop_order_placehold';

	$post_type  = get_post_type( $post_id );
	$order_type = $post_type ? $post_type : OrderUtil::get_order_type( $post_id );
	if ( ! in_array( $order_type, $redirect_from_types, 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;
}