-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwoocommerce-springbot.php
191 lines (160 loc) · 6.85 KB
/
woocommerce-springbot.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
<?php
/**
* Plugin Name: Springbot
* Plugin URI: https://app.springbot.com/
* Description: Integration plugin for email marketing
* Version: 1.0.4
* Requires at least: 3.1
* Requires PHP: 7.1
* Author: Springbot
* Author URI: https://www.springbot.com/
* License: GPLv2
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* @package Woocommerce_Springbot
*/
require_once( __DIR__ . '/config/springbot_config.php' );
add_action( 'plugins_loaded', array( 'WooCommerce_Springbot', 'init' ) );
/**
* Helper function to determine if WooCommerce is active
*/
function springbot_check_if_woo_active() {
return in_array(
'woocommerce/woocommerce.php',
apply_filters( 'active_plugins', get_option( 'active_plugins' ) )
);
}
if ( ! class_exists( 'WooCommerce_Springbot' ) ) {
class WooCommerce_Springbot {
public static function init() {
return new WooCommerce_Springbot();
}
public function __construct() {
require_once( __DIR__ . '/classes/springbot_activation.php' );
require_once( __DIR__ . '/classes/springbot_cart.php' );
require_once( __DIR__ . '/classes/springbot_product.php' );
require_once( __DIR__ . '/classes/springbot_footer.php' );
require_once( __DIR__ . '/classes/springbot_options.php' );
require_once( __DIR__ . '/classes/springbot_user_options.php' );
require_once( __DIR__ . '/classes/springbot_redirect.php' );
require_once( __DIR__ . '/classes/springbot_webhooks.php' );
require_once( __DIR__ . '/classes/springbot_settings.php' );
if ( $this->springbot_requirements_met() ) {
if ( ! isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['HTTP_AUTH'] ) ) {
$headerParts = explode( ' ', sanitize_text_field($_SERVER['HTTP_AUTH']) );
if ( count( $headerParts ) === 2 ) {
$authParts = explode( ':', base64_decode( $headerParts[1] ) );
if ( count( $authParts ) === 2 ) {
$_SERVER['PHP_AUTH_USER'] = $authParts[0];
$_SERVER['PHP_AUTH_PW'] = $authParts[1];
$_SERVER['HTTP_AUTHORIZATION'] = sanitize_text_field($_SERVER['HTTP_AUTH']);
}
}
}
if ( class_exists( 'Springbot_Webhooks' ) ) {
$springbot_webhooks = new Springbot_Webhooks();
}
if ( is_admin() ) {
add_action( 'admin_menu', array( $this, 'springbot_menu_page' ) );
add_action( 'admin_menu', array( $this, 'springbot_options_page' ) );
add_action( 'pre_user_query', array( 'WooCommerce_Springbot', 'hide_springbot_api_user' ) );
if ( class_exists( 'Springbot_Settings' ) ) {
$springbot_settings = new Springbot_Settings;
add_filter( 'woocommerce_settings_tabs_array', array( $springbot_settings, 'add_settings_tab' ), 50 );
add_action( 'woocommerce_settings_tabs_settings_tab_springbot', array( $springbot_settings, 'settings_tab' ) );
add_action( 'woocommerce_update_options_settings_tab_springbot', array( $springbot_settings, 'update_settings' ) );
}
} else {
if ( class_exists( 'Springbot_Footer' ) ) {
$springbot_footer = new Springbot_Footer;
add_action( 'wp_footer', array( $springbot_footer, 'show_async_script' ) );
}
if ( class_exists( 'Springbot_Redirect' ) ) {
$springbot_redirect = new Springbot_Redirect;
add_action( 'wp_loaded', array( $springbot_redirect, 'handle_redirect_posts' ) );
}
if ( class_exists( 'Springbot_Product' ) ) {
$springbot_product = new Springbot_Product;
add_action( 'wp_loaded', array( $springbot_product, 'handle_product_endpoint' ) );
}
if ( class_exists( 'Springbot_Cart' ) ) {
$springbot_cart = new Springbot_Cart;
add_action( 'woocommerce_cart_loaded_from_session', array(
$springbot_cart,
'handle_cart_endpoint'
) );
if ( get_option( 'wc_settings_tab_springbot_subscribe_checkbox', true ) !== 'no' ) {
add_action( 'woocommerce_after_order_notes', array( $springbot_cart, 'show_subscribe_field') );
add_action( 'woocommerce_checkout_process', array( $springbot_cart, 'process_subscribe_field') );
}
}
}
} else {
require_once( dirname( __FILE__ ) . '/views/springbot-requirements-error.php' );
}
}
// Hide the springbot user that we need for API access, so that it doesn't get deleted or a session timeout
public static function hide_springbot_api_user( $user_search ) {
global $wpdb;
$user_search->query_where = str_replace( 'WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.user_login != '" . SPRINGBOT_WP_USER . "'", $user_search->query_where );
}
public function springbot_options_page() {
if ( class_exists( 'Springbot_Activation' ) ) {
$springbot_activation = new Springbot_Activation;
if ( class_exists( 'Springbot_User_Options' ) ) {
$springbot_options = new Springbot_User_Options( $springbot_activation );
add_submenu_page(
null,
'Springbot Sync Options',
'Options',
'manage_options',
'springbot-options',
array( $springbot_options, 'create_admin_page' )
);
}
}
}
public function springbot_menu_page() {
if ( class_exists( 'Springbot_Activation' ) ) {
$springbot_activation = new Springbot_Activation;
if ( class_exists( 'Springbot_Options' ) ) {
$springbot_options = new Springbot_Options( $springbot_activation );
add_menu_page(
'Springbot',
'Springbot',
'manage_options',
'springbot',
array( $springbot_options, 'create_admin_page' ),
'data:image/svg+xml;base64,' . base64_encode( '<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 46.8 40.9" style="enable-background:new 0 0 46.8 40.9;" xml:space="preserve">
<path id="Fill-15" class="st0" d="M18,15.1c-2.6,2.7-4.7,5.8-5.8,9.4c-1.5,4.7-1,9.5,1.4,12.2c1.2,1.3,2.5,1.8,4,1.5
c2.6-0.6,5.1-3.5,6.3-7.2c0.7-2.4,1.8-8.6-3.7-14.3C19.4,16,18.7,15.5,18,15.1 M16.7,40.9c-1.9,0-3.7-0.9-5.1-2.5
c-3-3.4-3.7-9-1.9-14.7c1.2-3.6,3.1-6.7,5.6-9.5c-1.3-0.1-2.4,0.1-3.4,0.5C6.6,16.6,2.1,22.3,1.6,29C1.5,30.9,0,30.4,0,29.7
c0.5-7.6,4.8-15.1,11-17.4c2.2-0.8,4.4-0.9,6.4-0.3C24.2,5.5,37.1,1.6,44.9,0.1C47.7-0.4,47.2,1,45,1.5c-5.8,1.2-19.1,5.8-24.9,11.6
c0.7,0.5,1.3,1.2,2,1.8c4.5,4.7,6.1,10.9,4.3,16.8c-1.4,4.6-4.7,8.2-8.2,8.9C17.6,40.8,17.2,40.9,16.7,40.9"/>
</svg>
' )
);
}
}
}
/**
* Check that the local system meets the minimum requirements for this plugin
*/
public function springbot_requirements_met() {
global $wp_version;
if ( version_compare( PHP_VERSION, SPRINGBOT_REQUIRED_PHP_VERSION, '<' ) ) {
return false;
}
if ( version_compare( $wp_version, SPRINGBOT_REQUIRED_WP_VERSION, '<' ) ) {
return false;
}
if ( ! springbot_check_if_woo_active() ) {
return false;
}
return true;
}
}
}