-
Notifications
You must be signed in to change notification settings - Fork 0
/
inboxwp.php
189 lines (165 loc) · 4.35 KB
/
inboxwp.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
<?php
/**
* Plugin Name: InboxWP
* Plugin URI: https://inboxwp.com
* Description: Send transactional emails with this plugin in the easiest way.
* Version: 1.0.0
* Author: weDevs
* Author URI: https://inboxwp.com/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: inboxwp
* Domain Path: /languages
*/
use WeDevs\Inboxwp\Admin;
use WeDevs\Inboxwp\API;
use WeDevs\Inboxwp\Assets;
use WeDevs\Inboxwp\Hooks;
// don't call the file directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
require_once __DIR__ . '/vendor/autoload.php';
/**
* The main inboxWP plugin class
*/
final class InboxWP {
/**
* @var $inboxWP
*/
private static $instance;
/**
* Plugin version
*
* @var string
*/
const VERSION = '0.0.1';
/**
* InboxWP constructor.
*/
private function __construct() {
$this->define_constants();
$this->includes();
register_activation_hook( __FILE__, [ $this, 'activate' ] );
add_action( 'plugins_loaded', [ $this, 'init_plugin' ] );
add_action( 'admin_init', [ $this, 'inboxwp_redirect' ] );
}
/**
* Initializes a singleton instance
*
* @return InboxWP
*/
public static function init() { if ( ! self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Required constants
*
* @return void
*/
public function define_constants() {
define( 'INBOX_WP_VERSION', self::VERSION );
define( 'INBOX_WP_FILE', __FILE__ );
define( 'INBOX_WP_PATH', __DIR__ );
define( 'INBOX_WP_INCLUDES', INBOX_WP_PATH . '/includes' );
define( 'INBOX_WP_CORE', INBOX_WP_INCLUDES . '/Core' );
define( 'INBOX_WP_URL', plugins_url( '', INBOX_WP_FILE ) );
define( 'INBOX_WP_ASSETS', INBOX_WP_URL . '/assets' );
define( 'INBOX_WP_APP_URL', $this->getAppUrl() );
}
/**
* Do something when plugin active
*
* @return void
*/
public function activate() {
if ( ! get_option( 'inbox_wp_installed' ) ) {
update_option( 'inbox_wp_installed', time() );
}
update_option( 'inbox_wp_version', INBOX_WP_VERSION );
if ( ! inboxwp_site_hash() ) {
inboxwp_set_site_hash();
}
update_option( 'inbox_wp_activated', true );
}
/**
* Initialize the plugin
*/
public function init_plugin() {
new Assets();
new API();
new Hooks();
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
new WeDevs\Inboxwp\Ajax();
}
if ( is_admin() ) {
new Admin();
}
}
/**
* Includes core files
*
* @return void
*/
public function includes() {
require_once INBOX_WP_PATH . '/includes/Functions.php';
$this->include_cors();
}
/**
* Serve app url
*
* @return string
*/
protected function getAppUrl() {
$app_url = apply_filters( 'inboxwp_app_url', 'https://app.inboxwp.com' );
return untrailingslashit( $app_url );
}
/**
* Redirect to inboxwp admin page
*
* @return void
*/
public function inboxwp_redirect() {
if ( get_option( 'inbox_wp_activated' ) ) {
delete_option( 'inbox_wp_activated' );
wp_safe_redirect( inboxwp_get_admin_url() );
}
}
/**
* init the core classes
*
* @return void
*/
private function include_cors() {
$class_dirs = glob( INBOX_WP_CORE . '/*', GLOB_ONLYDIR );
foreach ( $class_dirs as $dir ) {
$className = str_replace( INBOX_WP_CORE . '/', '', $dir );
$class = "\\WeDevs\\Inboxwp\Core\\$className\\Menu";
if ( class_exists( $class ) ) {
new $class();
}
}
}
}
/**
* Initializes the main plugin
*
* @return InboxWP
*/
function inbox_wp() {
return InboxWP::init();
}
inbox_wp();
/**
* Initialize the plugin tracker
*
* @return void
*/
function appsero_init_tracker_inboxwp() {
$client = new Appsero\Client( 'd76c3855-3b47-48f8-a7e0-4e7e38d63de1', 'InboxWP', __FILE__ );
// Active insights
$client->insights()->init();
}
appsero_init_tracker_inboxwp();