Automattic\WooCommerce\Admin\API\Reports\PerformanceIndicators

Controller::get_stats_data()privateWC 1.0

Get report stats data, avoiding duplicate requests for stats that use the same endpoint.

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

Хуков нет.

Возвращает

WP_REST_Response|WP_Error. Report stats data.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_stats_data( $report, $query_args );
$report(строка) (обязательный)
Report slug to request data for.
$query_args(массив) (обязательный)
Report query args.

Код Controller::get_stats_data() WC 8.7.0

private function get_stats_data( $report, $query_args ) {
	// Return from cache if we've already requested these report stats.
	if ( isset( $this->stats_data[ $report ] ) ) {
		return $this->stats_data[ $report ];
	}

	// Request the report stats.
	$request_url = $this->endpoints[ $report ];
	$request     = new \WP_REST_Request( 'GET', $request_url );
	$request->set_param( 'before', $query_args['before'] );
	$request->set_param( 'after', $query_args['after'] );

	$response = rest_do_request( $request );

	// Cache the response.
	$this->stats_data[ $report ] = $response;

	return $response;
}