-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlpac.php
277 lines (259 loc) · 10.5 KB
/
lpac.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
<?php
/**
* Kikote - Location Picker at Checkout Plugin for WooCommerce.
*
* @link https://uriahsvictor.com
* @link https://github.com/UVLabs/location-picker-at-checkout-for-woocommerce
* @since 1.0.0
* @package Lpac
*
* @wordpress-plugin
* Plugin Name: Kikote - Location Picker at Checkout for WooCommerce
* Plugin URI: https://lpacwp.com
* Description: Allow customers to choose their shipping or pickup location using a map at checkout.
* Version: 1.7.4-lite
* Requires at least: 5.7
* Author: Uriahs Victor
* Author URI: https://lpacwp.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: map-location-picker-at-checkout-for-woocommerce
* Domain Path: /languages
* WC requires at least: 3.0
* WC tested up to: 7.5
* Requires PHP: 7.4
*/
// If this file is called directly, abort.
if ( !defined( 'WPINC' ) ) {
die;
}
if ( !defined( 'LPAC_VERSION' ) ) {
define( 'LPAC_VERSION', '1.7.4' );
}
/**
* Check PHP version
*/
if ( function_exists( 'phpversion' ) ) {
if ( version_compare( phpversion(), '7.4', '<' ) ) {
add_action( 'admin_notices', function () {
echo "<div class='notice notice-error is-dismissible'>" ;
/* translators: 1: Opening <p> HTML element 2: Opening <strong> HTML element 3: Closing <strong> HTML element 4: Closing <p> HTML element */
echo sprintf(
esc_html__( '%1$s%2$sKikote - Location Picker at Checkout for WooCommerce NOTICE:%3$s PHP version too low to use this plugin. Please change to at least PHP 7.4. You can contact your web host for assistance in updating your PHP version.%4$s', 'map-location-picker-at-checkout-for-woocommerce' ),
'<p>',
'<strong>',
'</strong>',
'</p>'
) ;
echo '</div>' ;
} );
return;
}
}
/**
* Check PHP versions
*/
if ( defined( 'PHP_VERSION' ) ) {
if ( version_compare( PHP_VERSION, '7.4', '<' ) ) {
add_action( 'admin_notices', function () {
echo "<div class='notice notice-error is-dismissible'>" ;
/* translators: 1: Opening <p> HTML element 2: Opening <strong> HTML element 3: Closing <strong> HTML element 4: Closing <p> HTML element */
echo sprintf(
esc_html__( '%1$s%2$sKikote - Location Picker at Checkout for WooCommerce NOTICE:%3$s PHP version too low to use this plugin. Please change to at least PHP 7.4. You can contact your web host for assistance in updating your PHP version.%4$s', 'map-location-picker-at-checkout-for-woocommerce' ),
'<p>',
'<strong>',
'</strong>',
'</p>'
) ;
echo '</div>' ;
} );
return;
}
}
/**
* Check that WooCommerce is active.
*
* This needs to happen before freemius does any work.
*
* @since 1.0.0
*/
if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
add_action( 'admin_notices', function () {
echo "<div class='notice notice-error is-dismissible'>" ;
/* translators: 1: Opening <p> HTML element 2: Opening <strong> HTML element 3: Closing <strong> HTML element 4: Closing <p> HTML element */
echo sprintf(
esc_html__( '%1$s%2$sKikote - Location Picker at Checkout for WooCommerce NOTICE:%3$s WooCommerce is not activated, please activate it to use the plugin.%4$s', 'map-location-picker-at-checkout-for-woocommerce' ),
'<p>',
'<strong>',
'</strong>',
'</p>'
) ;
echo '</div>' ;
} );
return;
}
if ( function_exists( 'lpac_fs' ) ) {
lpac_fs()->set_basename( false, __FILE__ );
} else {
// Setup Freemius.
if ( !function_exists( 'lpac_fs' ) ) {
/**
* Create a helper function for easy SDK access.
*
* @return mixed
* @throws Freemius_Exception Freemius Exception.
* @since 1.0.0
*/
function lpac_fs()
{
global $lpac_fs ;
if ( !isset( $lpac_fs ) ) {
// Include Freemius SDK.
require_once dirname( __FILE__ ) . '/vendor/freemius/wordpress-sdk/start.php';
$lpac_fs = fs_dynamic_init( array(
'id' => '8507',
'slug' => 'map-location-picker-at-checkout-for-woocommerce',
'premium_slug' => 'map-location-picker-at-checkout-for-woocommerce-pro',
'type' => 'plugin',
'public_key' => 'pk_da07de47a2bdd9391af9020cc646d',
'is_premium' => false,
'premium_suffix' => 'PRO',
'has_addons' => false,
'has_paid_plans' => true,
'trial' => array(
'days' => 14,
'is_require_payment' => true,
),
'has_affiliation' => 'selected',
'menu' => array(
'slug' => 'lpac-menu',
'parent' => array(
'slug' => 'sl-plugins-menu',
),
),
'is_live' => true,
) );
}
return $lpac_fs;
}
// Init Freemius.
lpac_fs();
/**
* Signal that SDK was initiated.
*
* @since 1.0.1
*/
do_action( 'lpac_fs_loaded' );
}
/**
* Composer autoload. DO NOT PLACE THIS LINE BEFORE FREEMIUS SDK RUNS.
*
* Doing that will cause the plugin to throw an error when trying to activate PRO when the Free version is active or vice versa.
* This is because both PRO and Free are generated from the same codebase, meaning composer autoloader file would already be
* present and throw an error when trying to be redefined.
*/
require_once dirname( __FILE__ ) . '/vendor/autoload.php';
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-lpac-activator.php
*/
if ( !function_exists( 'activate_lpac' ) ) {
/**
* Code that runs when the plugin is activated.
*
* @return void
* @since 1.0.0
*/
function activate_lpac()
{
require_once plugin_dir_path( __FILE__ ) . 'includes/class-lpac-activator.php';
Lpac_Activator::activate();
}
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-lpac-deactivator.php
*/
if ( !function_exists( 'deactivate_lpac' ) ) {
/**
* Code that runs when the plugin is deactivated.
*
* @return void
* @since 1.0.0
*/
function deactivate_lpac()
{
require_once plugin_dir_path( __FILE__ ) . 'includes/class-lpac-deactivator.php';
Lpac_Deactivator::deactivate();
}
}
register_activation_hook( __FILE__, 'activate_lpac' );
register_deactivation_hook( __FILE__, 'deactivate_lpac' );
/**
* Move this code to the main plugin file and then run it in an action hook when the SDK is initialized: lpac_fs_loaded.
*/
function lpac_redirect_to_map_builder()
{
wp_safe_redirect( admin_url( 'edit.php?post_type=kikote-maps' ) );
exit;
}
require __DIR__ . '/class-lpac-uninstall.php';
require __DIR__ . '/admin-pointers.php';
lpac_fs()->add_action( 'after_uninstall', array( new Lpac_Uninstall(), 'remove_plugin_settings' ) );
lpac_fs()->add_filter( 'show_deactivation_subscription_cancellation', '__return_false' );
lpac_fs()->add_filter( 'plugin_icon', function () {
return dirname( __FILE__ ) . '/assets/img/logo.png';
} );
define( 'LPAC_BASE_FILE', basename( plugin_dir_path( __FILE__ ) ) );
define( 'LPAC_PLUGIN_NAME', 'lpac' );
define( 'LPAC_PLUGIN_DIR', __DIR__ . '/' );
define( 'LPAC_PLUGIN_ASSETS_DIR', __DIR__ . '/assets/' );
define( 'LPAC_PLUGIN_ASSETS_PATH_URL', plugin_dir_url( __FILE__ ) . 'assets/' );
define( 'LPAC_PLUGIN_PATH_URL', plugin_dir_url( __FILE__ ) );
define( 'LPAC_INSTALLED_AT_VERSION', get_option( 'lpac_installed_at_version', constant( 'LPAC_VERSION' ) ) );
define( 'LPAC_IS_PREMIUM_VERSION', lpac_fs()->is_premium() );
define( 'LPAC_GOOGLE_MAPS_API_LINK', 'https://maps.googleapis.com/maps/api/js?key=' );
define( 'LPAC_GOOGLE_MAPS_API_KEY', get_option( 'lpac_google_maps_api_key', '' ) );
define( 'LPAC_GOOGLE_MAPS_DIRECTIONS_LINK', 'https://maps.google.com/maps?daddr=' );
define( 'LPAC_WAZE_DIRECTIONS_LINK', 'https://waze.com/ul?ll=' );
$debug = false;
if ( function_exists( 'wp_get_environment_type' ) ) {
/* File will only exist in local installation */
if ( wp_get_environment_type() === 'local' && file_exists( LPAC_PLUGIN_ASSETS_DIR . 'public/js/maps/base-map.js' ) ) {
$debug = true;
}
}
define( 'LPAC_DEBUG', $debug );
$version = ( LPAC_DEBUG ? 'weekly' : 'quarterly' );
$google_params = array( "v={$version}" );
$libraries = array();
$places_autocomplete = get_option( 'lpac_enable_places_autocomplete', 'no' );
if ( 'no' !== $places_autocomplete ) {
array_push( $libraries, 'places' );
}
if ( !empty($libraries) ) {
$libraries = implode( ',', $libraries );
array_push( $google_params, "libraries={$libraries}" );
}
// Map Region.
$region = get_option( 'lpac_google_map_region' );
if ( !empty($region) ) {
$google_params[] = "region={$region}";
}
// Callback parameter is required even though we're not making use of it.
$google_params[] = 'callback=GMapsScriptLoaded';
// Bring our parameters together.
$google_params = implode( '&', $google_params );
define( 'LPAC_GOOGLE_MAPS_PARAMS', $google_params );
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
*/
$main_plugin = new \Lpac\Bootstrap\Main();
$main_plugin->run();
}