-
Notifications
You must be signed in to change notification settings - Fork 0
/
gainwp.php
274 lines (226 loc) · 6.85 KB
/
gainwp.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?php
/**
* Plugin Name: GAinWP Google Analytics Integration for WordPress
* Plugin URI: https://intelligencewp.com/google-analytics-in-wordpress
* Description: Automatically adds Google Analytics tracking to your site and displays Google Analytics reports and real-time statistics in your dashboard.
* Author: IntelligenceWP
* Version: 5.4.0
* Author URI: https://intelligencewp.com
* Text Domain: ga-in
* Domain Path: /languages
*
* This plugin was originally created as the Google Analytics Dashboard for WordPress (GADWP) by Alin Marcu (https://deconf.com).
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) )
exit();
// Plugin Version
if ( ! defined( 'GAINWP_CURRENT_VERSION' ) ) {
define( 'GAINWP_CURRENT_VERSION', '5.4.0' );
}
if ( ! defined( 'GAINWP_ENDPOINT_URL' ) ) {
define( 'GAINWP_ENDPOINT_URL', '' );
}
if ( ! class_exists( 'GAINWP_Manager' ) ) {
final class GAINWP_Manager {
private static $instance = null;
public $config = null;
public $frontend_actions = null;
public $common_actions = null;
public $backend_actions = null;
public $tracking = null;
public $frontend_item_reports = null;
public $backend_setup = null;
public $frontend_setup = null;
public $backend_widgets = null;
public $backend_item_reports = null;
public $gapi_controller = null;
/**
* Construct forbidden
*/
private function __construct() {
if ( null !== self::$instance ) {
_doing_it_wrong( __FUNCTION__, __( "This is not allowed, read the documentation!", 'ga-in' ), '4.6' );
}
}
/**
* Clone warning
*/
private function __clone() {
_doing_it_wrong( __FUNCTION__, __( "This is not allowed, read the documentation!", 'ga-in' ), '4.6' );
}
/**
* Wakeup warning
*/
private function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( "This is not allowed, read the documentation!", 'ga-in' ), '4.6' );
}
/**
* Creates a single instance for GAINWP and makes sure only one instance is present in memory.
*
* @return GAINWP_Manager
*/
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
self::$instance->setup();
self::$instance->config = new GAINWP_Config();
}
return self::$instance;
}
/**
* Defines constants and loads required resources
*/
private function setup() {
// Plugin Path
if ( ! defined( 'GAINWP_DIR' ) ) {
define( 'GAINWP_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin URL
if ( ! defined( 'GAINWP_URL' ) ) {
define( 'GAINWP_URL', plugin_dir_url( __FILE__ ) );
}
// Plugin main File
if ( ! defined( 'GAINWP_FILE' ) ) {
define( 'GAINWP_FILE', __FILE__ );
}
/*
* Load Tools class
*/
include_once ( GAINWP_DIR . 'tools/tools.php' );
/*
* Load Config class
*/
include_once ( GAINWP_DIR . 'config.php' );
/*
* Load GAPI Controller class
*/
include_once ( GAINWP_DIR . 'tools/gapi.php' );
/*
* Plugin i18n
*/
add_action( 'init', array( self::$instance, 'load_i18n' ) );
/*
* Plugin Init
*/
add_action( 'init', array( self::$instance, 'load' ) );
/*
* Include Install
*/
include_once ( GAINWP_DIR . 'install/install.php' );
register_activation_hook( GAINWP_FILE, array( 'GAINWP_Install', 'install' ) );
/*
* Include Uninstall
*/
include_once ( GAINWP_DIR . 'install/uninstall.php' );
register_uninstall_hook( GAINWP_FILE, array( 'GAINWP_Uninstall', 'uninstall' ) );
/*
* Load Frontend Widgets
* (needed during ajax)
*/
include_once ( GAINWP_DIR . 'front/widgets.php' );
/*
* Add Frontend Widgets
* (needed during ajax)
*/
add_action( 'widgets_init', array( self::$instance, 'add_frontend_widget' ) );
}
/**
* Load i18n
*/
public function load_i18n() {
load_plugin_textdomain( 'ga-in', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Register Frontend Widgets
*/
public function add_frontend_widget() {
register_widget( 'GAINWP_Frontend_Widget' );
}
/**
* Conditional load
*/
public function load() {
if ( is_admin() ) {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
if ( GAINWP_Tools::check_roles( self::$instance->config->options['access_back'] ) ) {
/*
* Load Backend ajax actions
*/
include_once ( GAINWP_DIR . 'admin/ajax-actions.php' );
self::$instance->backend_actions = new GAINWP_Backend_Ajax();
}
/*
* Load Frontend ajax actions
*/
include_once ( GAINWP_DIR . 'front/ajax-actions.php' );
self::$instance->frontend_actions = new GAINWP_Frontend_Ajax();
/*
* Load Common ajax actions
*/
include_once ( GAINWP_DIR . 'common/ajax-actions.php' );
self::$instance->common_actions = new GAINWP_Common_Ajax();
if ( self::$instance->config->options['backend_item_reports'] ) {
/*
* Load Backend Item Reports for Quick Edit
*/
include_once ( GAINWP_DIR . 'admin/item-reports.php' );
self::$instance->backend_item_reports = new GAINWP_Backend_Item_Reports();
}
} else if ( GAINWP_Tools::check_roles( self::$instance->config->options['access_back'] ) ) {
/*
* Load Backend Setup
*/
include_once ( GAINWP_DIR . 'admin/setup.php' );
self::$instance->backend_setup = new GAINWP_Backend_Setup();
if ( self::$instance->config->options['dashboard_widget'] ) {
/*
* Load Backend Widget
*/
include_once ( GAINWP_DIR . 'admin/widgets.php' );
self::$instance->backend_widgets = new GAINWP_Backend_Widgets();
}
if ( self::$instance->config->options['backend_item_reports'] ) {
/*
* Load Backend Item Reports
*/
include_once ( GAINWP_DIR . 'admin/item-reports.php' );
self::$instance->backend_item_reports = new GAINWP_Backend_Item_Reports();
}
}
} else {
if ( GAINWP_Tools::check_roles( self::$instance->config->options['access_front'] ) ) {
/*
* Load Frontend Setup
*/
include_once ( GAINWP_DIR . 'front/setup.php' );
self::$instance->frontend_setup = new GAINWP_Frontend_Setup();
if ( self::$instance->config->options['frontend_item_reports'] ) {
/*
* Load Frontend Item Reports
*/
include_once ( GAINWP_DIR . 'front/item-reports.php' );
self::$instance->frontend_item_reports = new GAINWP_Frontend_Item_Reports();
}
}
if ( ! GAINWP_Tools::check_roles( self::$instance->config->options['track_exclude'], true ) && 'disabled' != self::$instance->config->options['tracking_type'] ) {
/*
* Load tracking class
*/
include_once ( GAINWP_DIR . 'front/tracking.php' );
self::$instance->tracking = new GAINWP_Tracking();
}
}
}
}
}
/**
* Returns a unique instance of GAINWP
*/
function GAINWP() {
return GAINWP_Manager::instance();
}
/*
* Start GAINWP
*/
GAINWP();