-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathechodash.php
executable file
·343 lines (289 loc) · 8.65 KB
/
echodash.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?php
/**
* EchoDash - Event Tracking and Activity Log
*
* @package EchoDash
* @author EchoDash
* @license GPL-3.0-or-later
* @link https://echodash.com
*
* @wordpress-plugin
* Plugin Name: EchoDash
* Plugin URI: https://echodash.com/
* Description: Track events from WordPress plugins as real-time activities in the EchoDash platform.
* Version: 1.1.2
* Author: EchoDash
* Text Domain: echodash
* Domain Path: /languages
* License: GPL-3.0-or-later
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
/**
* @copyright Copyright (c) 2024. All rights reserved.
*
* @license Released under the GPL license http://www.opensource.org/licenses/gpl-license.php
*
* **********************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* **********************************************************************
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
define( 'ECHODASH_VERSION', '1.1.2' );
/**
* Class EchoDash
*
* @since 1.0.0
*/
final class EchoDash {
/** Singleton *************************************************************/
/**
* The one true EchoDash.
*
* @var EchoDash
* @since 1.0.0
*/
private static $instance;
/**
* Allows interfacing with the main class.
*
* @var EchoDash_Public
* @since 1.0.0
*/
public $public;
/**
* Allows interfacing with the admin class.
*
* @var EchoDash_Admin
* @since 1.1.3
*/
public $admin;
/**
* Allows interfacing with integrations.
*
* For example echodash()->integration( 'woocommerce' )->get_events().
*
* @var object
* @since 1.0.0
*/
public $integrations;
/**
* Main EchoDash Instance
*
* Insures that only one instance of EchoDash exists in
* memory at any one time. Also prevents needing to define globals all over
* the place.
*
* @since 1.0.0
* @static var array $instance
*
* @return EchoDash The one true EchoDash
*/
public static function instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new EchoDash();
self::$instance->setup_constants();
if ( ! is_wp_error( self::$instance->check_install() ) ) {
self::$instance->includes();
// Initialize classes
self::$instance->public = new EchoDash_Public();
if ( is_admin() ) {
self::$instance->admin = new EchoDash_Admin();
}
self::$instance->integrations = new stdClass();
self::$instance->integrations_includes();
} else {
add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
}
}
return self::$instance;
}
/**
* Throw error on object clone.
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @access protected
*
* @since 1.0.0.
*/
public function __clone() {
// Cloning instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'echodash' ), '1.0.0' );
}
/**
* Disable unserializing of the class.
*
* @access protected
*
* @since 1.0.0
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'echodash' ), '1.0.0' );
}
/**
* If the method doesn't exist here, call it from the public class.
*
* @since 1.0.0
*
* @param string $name The method name.
* @param array $arguments The arguments.
* @return mixed The returned value.
*/
public function __call( $name, $arguments ) {
if ( ! method_exists( self::$instance, $name ) && method_exists( self::$instance->public, $name ) ) {
return call_user_func_array( array( self::$instance->public, $name ), $arguments );
}
}
/**
* Helper for accessing a single integration.
*
* @since 1.0.0
*
* @param string $integration_name The integration name.
* @return EchoDash_Integration|bool The integration class or false.
*/
public function integration( $integration_name ) {
if ( isset( self::$instance->integrations->{ $integration_name } ) ) {
return self::$instance->integrations->{ $integration_name };
} else {
return false;
}
}
/**
* Setup plugin constants.
*
* @access private
*
* @since 1.0.0
*/
private function setup_constants() {
if ( ! defined( 'ECHODASH_DIR_PATH' ) ) {
define( 'ECHODASH_DIR_PATH', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'ECHODASH_PLUGIN_PATH' ) ) {
define( 'ECHODASH_PLUGIN_PATH', plugin_basename( __FILE__ ) );
}
if ( ! defined( 'ECHODASH_DIR_URL' ) ) {
define( 'ECHODASH_DIR_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'ECHODASH_WP_PLUGIN_DIR' ) ) {
define( 'ECHODASH_WP_PLUGIN_DIR', dirname( plugin_dir_path( __FILE__ ) ) );
}
}
/**
* Include required files.
*
* @access private
*
* @since 1.0.0
*/
private function includes() {
require_once ECHODASH_DIR_PATH . 'includes/functions.php';
require_once ECHODASH_DIR_PATH . 'includes/public/class-echodash-public.php';
require_once ECHODASH_DIR_PATH . 'includes/integrations/class-echodash-integration.php';
if ( is_admin() ) {
require_once ECHODASH_DIR_PATH . 'includes/admin/class-echodash-admin.php';
require_once ECHODASH_DIR_PATH . 'includes/admin/admin-functions.php';
}
}
/**
* Include plugin integration classes.
*
* @access private
*
* @since 1.0.0
*/
private function integrations_includes() {
// Extend integrations for integrations that does not have files in WPF integrations folder.
$integrations = array(
'wordpress' => 'WP',
'user' => 'WP_User',
'presto-player' => 'PrestoPlayer\Core',
'abandoned-cart' => 'WP_Fusion_Abandoned_Cart',
'gravity-forms' => 'GFForms',
'affiliatewp' => 'AffWP',
'bbpress' => 'bbPress',
'buddypress' => 'BuddyPress',
'edd' => 'Easy_Digital_Downloads',
'edd-software-licensing' => 'EDD_Software_Licensing',
'edd-recurring' => 'EDD_Recurring',
'gamipress' => 'GamiPress',
'give' => 'Give',
'learndash' => 'SFWD_LMS',
'lifterlms' => 'LLMS',
'woocommerce' => 'WooCommerce',
'woo-subscriptions' => 'WC_Subscriptions_Product',
);
foreach ( $integrations as $filename => $dependency_class ) {
$filename = sanitize_file_name( $filename );
if ( class_exists( $dependency_class ) ) {
require_once ECHODASH_DIR_PATH . 'includes/integrations/' . $filename . '/class-echodash-' . $filename . '.php';
}
}
do_action( 'echodash_integrations_loaded' );
}
/**
* Show error message if install check failed.
*
* @since 1.0.0
*/
public function admin_notices() {
$return = self::$instance->check_install();
if ( is_wp_error( $return ) && 'error' === $return->get_error_code() ) {
printf(
'<div class="notice notice-error"><p>%s</p></div>',
wp_kses_post( $return->get_error_message() )
);
}
}
/**
* Check install.
*
* Checks if the minimum WordPress and PHP versions are met.
*
* @since 1.0.0
*
* @return mixed True on success, WP_Error on error
*/
public function check_install() {
if ( version_compare( PHP_VERSION, '7.0.0', '<' ) ) {
return new WP_Error( 'error', esc_html__( 'The EchoDash plugin requires PHP 7.0 or higher.', 'echodash' ) );
}
// Make sure WordPress is at least 6.0.
if ( version_compare( get_bloginfo( 'version' ), '6.0', '<' ) ) {
return new WP_Error( 'error', esc_html__( 'The EchoDash plugin requires WordPress 6.0 or higher.', 'echodash' ) );
}
return true;
}
}
/**
* The main function responsible for returning the one true EchoDash Instance
* to functions everywhere.
*
* Use this function like you would a global variable, except without needing to
* declare the global.
*
* @since 1.0.0
*
* @return object The one true EchoDash
*/
function echodash() {
return EchoDash::instance();
}
add_action( 'plugins_loaded', 'echodash' );