Automattic\WooCommerce\Admin\API\Reports\PerformanceIndicators

Controller::get_jetpack_modules_data()privateWC 1.0

Get active Jetpack modules and endpoints.

Method of the class: Controller{}

Return

null. Nothing (null).

Usage

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

Controller::get_jetpack_modules_data() code WC 9.3.3

private function get_jetpack_modules_data() {
	$active_modules = $this->get_active_jetpack_modules();

	if ( empty( $active_modules ) ) {
		return;
	}

	$items = apply_filters(
		'woocommerce_rest_performance_indicators_jetpack_items',
		array(
			'stats/visitors' => array(
				'label'      => __( 'Visitors', 'woocommerce' ),
				'permission' => 'view_stats',
				'format'     => 'number',
				'module'     => 'stats',
			),
			'stats/views'    => array(
				'label'      => __( 'Views', 'woocommerce' ),
				'permission' => 'view_stats',
				'format'     => 'number',
				'module'     => 'stats',
			),
		)
	);

	foreach ( $items as $item_key => $item ) {
		if ( ! in_array( $item['module'], $active_modules, true ) ) {
			return;
		}

		if ( $item['permission'] && ! current_user_can( $item['permission'] ) ) {
			return;
		}

		$stat                         = 'jetpack/' . $item_key;
		$endpoint                     = 'jetpack/' . $item['module'];
		$this->allowed_stats[]        = $stat;
		$this->labels[ $stat ]        = $item['label'];
		$this->endpoints[ $endpoint ] = '/jetpack/v4/module/' . $item['module'] . '/data';
		$this->formats[ $stat ]       = $item['format'];
	}

	$this->urls['jetpack/stats'] = '/jetpack';
}