2019-04-11 18:31:31 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2019-05-08 16:10:05 +00:00
|
|
|
* WooCommerce Analytics Dashboard.
|
2019-04-11 18:31:31 +00:00
|
|
|
* NOTE: DO NOT edit this file in WooCommerce core, this is generated from woocommerce-admin.
|
|
|
|
*
|
|
|
|
* @package Woocommerce Admin
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains backend logic for the dashboard feature.
|
|
|
|
*/
|
2019-05-08 16:10:05 +00:00
|
|
|
class WC_Admin_Analytics_Dashboard {
|
2019-04-11 18:31:31 +00:00
|
|
|
/**
|
|
|
|
* Class instance.
|
|
|
|
*
|
2019-05-08 16:10:05 +00:00
|
|
|
* @var WC_Admin_Analytics_Dashboard instance
|
2019-04-11 18:31:31 +00:00
|
|
|
*/
|
|
|
|
protected static $instance = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get class instance.
|
|
|
|
*/
|
|
|
|
public static function get_instance() {
|
|
|
|
if ( ! self::$instance ) {
|
|
|
|
self::$instance = new self();
|
|
|
|
}
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook into WooCommerce.
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
add_filter( 'woocommerce_component_settings_preload_endpoints', array( $this, 'add_preload_endpoints' ) );
|
|
|
|
add_filter( 'wc_admin_get_user_data_fields', array( $this, 'add_user_data_fields' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-07 07:21:34 +00:00
|
|
|
* Preload data from the performance indicators endpoint.
|
2019-04-11 18:31:31 +00:00
|
|
|
*
|
|
|
|
* @param array $endpoints Array of preloaded endpoints.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function add_preload_endpoints( $endpoints ) {
|
|
|
|
$endpoints['performanceIndicators'] = '/wc/v4/reports/performance-indicators/allowed';
|
|
|
|
$endpoints['leaderboards'] = '/wc/v4/leaderboards/allowed';
|
|
|
|
return $endpoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-07 07:21:34 +00:00
|
|
|
* Adds fields so that we can store performance indicators, row settings, and chart type settings for users.
|
2019-04-11 18:31:31 +00:00
|
|
|
*
|
|
|
|
* @param array $user_data_fields User data fields.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function add_user_data_fields( $user_data_fields ) {
|
|
|
|
return array_merge(
|
|
|
|
$user_data_fields,
|
|
|
|
array(
|
2019-05-07 07:21:34 +00:00
|
|
|
'dashboard_sections',
|
2019-04-11 18:31:31 +00:00
|
|
|
'dashboard_chart_type',
|
|
|
|
'dashboard_chart_interval',
|
|
|
|
'dashboard_leaderboard_rows',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-08 16:10:05 +00:00
|
|
|
new WC_Admin_Analytics_Dashboard();
|