/var/www/html_uk/wp-content/plugins/automatewoo/admin/Analytics/Rest_API.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php

namespace AutomateWoo\Admin\Analytics;

use 
AutomateWoo\Admin\Analytics;

/**
 * AutomateWoo Analytics.
 * Formerly AutomateWoo > Reports.
 *
 * @since 5.6.3
 */
class Rest_API {

    
/**
     * Init.
     */
    
public static function init() {
        
add_action'init', array( __CLASS__'setup' ) );
    }

    
/**
     * Setup Analytics.
     * Register controllers and data stores.
     */
    
public static function setup() {
        if ( 
self::is_enabled() ) {

            
// REST API Controllers.
            
add_filter'woocommerce_admin_rest_controllers', array( __CLASS__'add_rest_api_controllers' ) );

            
// Report CSV Exporter Controllers.
            
add_filter'woocommerce_export_report_controller_map', array( __CLASS__'add_csv_export_controllers' ) );

            
// Register data stores.
            
add_filter'woocommerce_data_stores', array( __CLASS__'register_data_stores' ) );

        }
    }

    
/**
     * Whether or not the Rest APIs for Analytic reports are enabled.
     *
     * @return bool
     */
    
public static function is_enabled() {
        return 
Analytics::is_enabled();
    }

    
/**
     * Add controllers for CSV exports.
     *
     * @since 6.1.9
     *
     * @param array $controllers Original list of controllers for CSV exports.
     *
     * @return array Updated list of controllers.
     */
    
public static function add_csv_export_controllers$controllers ) {
        
$controllers['conversions'] = 'AutomateWoo\Admin\Analytics\Rest_API\Conversions\Controller';

        return 
$controllers;
    }

    
/**
     * Adds Analytics REST contollers.
     * To be used with `woocommerce_admin_rest_controllers` filter.
     *
     * @param  array $controllers
     * @return array Extended with AW Analytics controllers.
     */
    
public static function add_rest_api_controllers$controllers ) {
        
$controllers[] = 'AutomateWoo\Admin\Analytics\Rest_API\Conversions\Controller';
        
$controllers[] = 'AutomateWoo\Admin\Analytics\Rest_API\Conversions\Stats\Controller';
        
$controllers[] = 'AutomateWoo\Admin\Analytics\Rest_API\Email_Tracking\Stats_Controller';
        
$controllers[] = 'AutomateWoo\Admin\Analytics\Rest_API\Unsubscribers\Stats_Controller';
        
$controllers[] = 'AutomateWoo\Admin\Analytics\Rest_API\Workflow_Runs\Stats_Controller';

        return 
$controllers;
    }

    
/**
     * Register Analytics data stores.
     * To be used with `woocommerce_data_stores` filter.
     *
     * @param  array $stores
     * @return array Extended with AW Analytics stores.
     */
    
public static function register_data_stores$stores ) {
        
$stores['report-conversions-list']     = 'AutomateWoo\Admin\Analytics\Rest_API\Conversions\Store';
        
$stores['report-conversions-stats']    = 'AutomateWoo\Admin\Analytics\Rest_API\Conversions\Stats\Store';
        
$stores['report-email-tracking-stats'] = 'AutomateWoo\Admin\Analytics\Rest_API\Email_Tracking\Data_Store';
        
$stores['report-unsubscribers-stats']  = 'AutomateWoo\Admin\Analytics\Rest_API\Unsubscribers\Data_Store';
        
$stores['report-workflow-runs-stats']  = 'AutomateWoo\Admin\Analytics\Rest_API\Workflow_Runs\Data_Store';

        return 
$stores;
    }
}