Automattic\WooCommerce\Internal\Admin\Orders

COTRedirectionController::handle_hpos_admin_requests()privateWC 1.0

Listen for denied admin requests and, if they appear to relate to HPOS admin screens, potentially redirect the user to the equivalent CPT-driven screens.

Метод класса: COTRedirectionController{}

Хуков нет.

Возвращает

null. Ничего.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->handle_hpos_admin_requests( $query_params );
$query_params(массив|null)
The query parameters to use when determining the redirect. If not provided, the $_GET superglobal will be used.
По умолчанию: null

Код COTRedirectionController::handle_hpos_admin_requests() WC 7.3.0

private function handle_hpos_admin_requests( $query_params = null ) {
	$query_params = is_array( $query_params ) ? $query_params : $_GET;

	if ( ! isset( $query_params['page'] ) || 'wc-orders' !== $query_params['page'] ) {
		return;
	}

	$params = wp_unslash( $query_params );
	$action = $params['action'] ?? '';
	unset( $params['page'] );

	if ( 'edit' === $action && isset( $params['id'] ) ) {
		$params['post'] = $params['id'];
		unset( $params['id'] );
		$new_url = add_query_arg( $params, get_admin_url( null, 'post.php' ) );
	} elseif ( 'new' === $action ) {
		unset( $params['action'] );
		$params['post_type'] = 'shop_order';
		$new_url             = add_query_arg( $params, get_admin_url( null, 'post-new.php' ) );
	} else {
		// If nonce parameters are present and valid, rebuild them for the CPT admin list table.
		if ( isset( $params['_wpnonce'] ) && check_admin_referer( 'bulk-orders' ) ) {
			$params['_wp_http_referer'] = get_admin_url( null, 'edit.php?post_type=shop_order' );
			$params['_wpnonce']         = wp_create_nonce( 'bulk-posts' );
		}

		// If an `order` array parameter is present, rename as `post`.
		if ( isset( $params['order'] ) && is_array( $params['order'] ) ) {
			$params['post'] = $params['order'];
			unset( $params['order'] );
		}

		$params['post_type'] = 'shop_order';
		$new_url             = add_query_arg( $params, get_admin_url( null, 'edit.php' ) );
	}

	if ( ! empty( $new_url ) && wp_safe_redirect( $new_url, 301 ) ) {
		exit;
	}
}