Automattic\WooCommerce\Admin\API

ActivityPanelCounts::get_count_via │ private │ WC 1.0

Run one of the existing count endpoints internally and read its total off the response, so the counting logic itself (query building, permission checks) isn't duplicated here.

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

Хуков нет.

Возвращает

int|null. Null when the sub-request failed, so callers can tell "unknown" apart from a real zero count.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_count_via( $route, $params );
$route(строка) (обязательный)
REST route to call, e.g. '/wc-analytics/orders'.
$params(массив) (обязательный)
Query params for the sub-request.

Код ActivityPanelCounts::get_count_via() WC 11.2.2

private function get_count_via( $route, $params ) {
	$sub_request = new \WP_REST_Request( 'GET', $route );
	foreach ( $params as $key => $value ) {
		$sub_request->set_param( $key, $value );
	}

	$response = rest_do_request( $sub_request );

	if ( $response->is_error() ) {
		wc_get_logger()->warning(
			sprintf( 'Activity Panel counts sub-request to %s failed.', $route ),
			array( 'source' => 'activity-panel-counts' )
		);
		return null;
	}

	$headers = $response->get_headers();
	if ( isset( $headers['X-WP-Total'] ) ) {
		return (int) $headers['X-WP-Total'];
	}

	$data = $response->get_data();
	return isset( $data['total'] ) ? (int) $data['total'] : null;
}