-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathingot_bootstrap.php
More file actions
165 lines (132 loc) · 3 KB
/
Copy pathingot_bootstrap.php
File metadata and controls
165 lines (132 loc) · 3 KB
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
<?php
/**
* Load up the Ingot
*
* @package ingot
* @author Josh Pollock <Josh@JoshPress.net>
* @license GPL-2.0+
* @link
* @copyright 2015 Josh Pollock
*/
class ingot_bootstrap {
/**
* Loads ingot if not already loaded.
*
* @since 0.0.5
*/
public static function maybe_load() {
if ( did_action( 'ingot_loaded' ) ) {
return;
}
if ( ! defined( 'INGOT_DEV_MODE' ) ){
/**
* Puts Ingot into dev mode
*
* Don't use on a live site -- makes API totally open
*
* @since 0.0.5
*/
define( 'INGOT_DEV_MODE', false );
}
$load = true;
if ( ! version_compare( PHP_VERSION, '5.5.0', '>=' ) ) {
$load = false;
}
$autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( ! file_exists( $autoloader ) ) {
$load = false;
}
if ( $load ) {
include_once( $autoloader );
$tables_existed = self::maybe_add_tables();
self::maybe_upgrade();
self::maybe_load_trial();
ingot_init_plan();
if( $tables_existed || \ingot\testing\db\delta::check_if_tables_exist() ) {
ingot\testing\ingot::instance();
//make admin go in admin
if ( is_admin() ) {
new ingot\ui\make();
}
if ( ingot_is_front_end() || ingot_is_admin_ajax() ) {
//setup destination tests
$destination_tests = \ingot\testing\tests\click\destination\init::set_tracking();
//run cookies
add_action( 'ingot_loaded', function () {
/**
* Disable running cookies
*
* @since 1.1.0
*
* @param bool $run
*/
if ( true == (bool) apply_filters( 'ingot_run_cookies', true ) && ! did_action( 'ingot_cookies_set' ) ) {
if ( ! empty( $destination_tests ) ) {
\ingot\testing\tests\click\destination\init::setup_cookies( $destination_tests );
}
\ingot\testing\cookies\set::run();
}
});
}
/**
* Runs when Ingot has loaded.
*
* @since 0.0.5
*/
do_action( 'ingot_loaded' );
}else{
if ( is_admin() ) {
printf( '<div class="error"><p>%s</p></div>', __( 'Ingot Not Loaded', 'ingot' ) );
}
/**
* Runs if Ingot failed to load
*
* @since 0.3.0
*
*/
do_action( 'ingot_loaded_failed' );
return;
}
}
}
/**
* Add tables to DB if needed
*
* @since 1.1.0
*
* @access protected
*
* @return bool
*/
protected static function maybe_add_tables(){
if( false == \ingot\testing\db\delta::check_if_tables_exist() ){
\ingot\testing\db\delta::add_tables();
return false;
}
return true;
}
/**
* Maybe run DB updater
*
* @access protected
*
* @since 1.0.1
*/
protected static function maybe_upgrade(){
if( INGOT_VER != get_option( 'ingot_version', 0 ) ) {
$updater = new \ingot\testing\db\upgrade( INGOT_VER );
$updater->run();
update_option( 'ingot_version', INGOT_VER, false );
}
}
/**
* If trial mode is a thing, load the trial system
*
* @since 1.1.0
*
* @return bool
*/
public static function maybe_load_trial(){
return false;
}
}