| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @package Freemius |
| 5 |
* @copyright Copyright (c) 2015, Freemius, Inc. |
| 6 |
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 |
| 7 |
* @since 1.0.4 |
| 8 |
*/ |
| 9 |
|
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
if (!defined('WP_FS__SLUG')) { |
| 15 |
define('WP_FS__SLUG', 'freemius'); |
| 16 |
} |
| 17 |
if (!defined('WP_FS__DEV_MODE')) { |
| 18 |
define('WP_FS__DEV_MODE', false); |
| 19 |
} |
| 20 |
|
| 21 |
#-------------------------------------------------------------------------------- |
| 22 |
#region API Connectivity Issues Simulation |
| 23 |
#-------------------------------------------------------------------------------- |
| 24 |
|
| 25 |
if (!defined('WP_FS__SIMULATE_NO_API_CONNECTIVITY')) { |
| 26 |
define('WP_FS__SIMULATE_NO_API_CONNECTIVITY', false); |
| 27 |
} |
| 28 |
if (!defined('WP_FS__SIMULATE_NO_CURL')) { |
| 29 |
define('WP_FS__SIMULATE_NO_CURL', false); |
| 30 |
} |
| 31 |
if (!defined('WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE')) { |
| 32 |
define('WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', false); |
| 33 |
} |
| 34 |
if (!defined('WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL')) { |
| 35 |
define('WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', false); |
| 36 |
} |
| 37 |
if (WP_FS__SIMULATE_NO_CURL) { |
| 38 |
define('FS_SDK__SIMULATE_NO_CURL', true); |
| 39 |
} |
| 40 |
if (WP_FS__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE) { |
| 41 |
define('FS_SDK__SIMULATE_NO_API_CONNECTIVITY_CLOUDFLARE', true); |
| 42 |
} |
| 43 |
if (WP_FS__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL) { |
| 44 |
define('FS_SDK__SIMULATE_NO_API_CONNECTIVITY_SQUID_ACL', true); |
| 45 |
} |
| 46 |
|
| 47 |
#endregion |
| 48 |
|
| 49 |
if (!defined('WP_FS__SIMULATE_FREEMIUS_OFF')) { |
| 50 |
define('WP_FS__SIMULATE_FREEMIUS_OFF', false); |
| 51 |
} |
| 52 |
|
| 53 |
if (!defined('WP_FS__PING_API_ON_IP_OR_HOST_CHANGES')) { |
| 54 |
/** |
| 55 |
* @since 1.1.7.3 |
| 56 |
* @author Vova Feldman (@svovaf) |
| 57 |
* |
| 58 |
* I'm not sure if shared servers periodically change IP, or the subdomain of the |
| 59 |
* admin dashboard. Also, I've seen sites that have strange loop of switching |
| 60 |
* between domains on a daily basis. Therefore, to eliminate the risk of |
| 61 |
* multiple unwanted connectivity test pings, temporary ignore domain or |
| 62 |
* server IP changes. |
| 63 |
*/ |
| 64 |
define('WP_FS__PING_API_ON_IP_OR_HOST_CHANGES', false); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* If your dev environment supports custom public network IP setup |
| 69 |
* like VVV, please update WP_FS__LOCALHOST_IP with your public IP |
| 70 |
* and uncomment it during dev. |
| 71 |
*/ |
| 72 |
if (!defined('WP_FS__LOCALHOST_IP')) { |
| 73 |
// VVV default public network IP. |
| 74 |
define('WP_FS__VVV_DEFAULT_PUBLIC_IP', '192.168.50.4'); |
| 75 |
|
| 76 |
// define( 'WP_FS__LOCALHOST_IP', WP_FS__VVV_DEFAULT_PUBLIC_IP ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* If true and running with secret key, the opt-in process |
| 81 |
* will skip the email activation process which is invoked |
| 82 |
* when the email of the context user already exist in Freemius |
| 83 |
* database (as a security precaution, to prevent sharing user |
| 84 |
* secret with unauthorized entity). |
| 85 |
* |
| 86 |
* IMPORTANT: |
| 87 |
* AS A SECURITY PRECAUTION, WE VALIDATE THE TIMESTAMP OF THE OPT-IN REQUEST. |
| 88 |
* THEREFORE, MAKE SURE THAT WHEN USING THIS PARAMETER,YOUR TESTING ENVIRONMENT'S |
| 89 |
* CLOCK IS SYNCED. |
| 90 |
*/ |
| 91 |
if (!defined('WP_FS__SKIP_EMAIL_ACTIVATION')) { |
| 92 |
define('WP_FS__SKIP_EMAIL_ACTIVATION', false); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
#-------------------------------------------------------------------------------- |
| 97 |
#region Directories |
| 98 |
#-------------------------------------------------------------------------------- |
| 99 |
|
| 100 |
if (!defined('WP_FS__DIR')) { |
| 101 |
define('WP_FS__DIR', dirname(__FILE__)); |
| 102 |
} |
| 103 |
if (!defined('WP_FS__DIR_INCLUDES')) { |
| 104 |
define('WP_FS__DIR_INCLUDES', WP_FS__DIR . '/includes'); |
| 105 |
} |
| 106 |
if (!defined('WP_FS__DIR_TEMPLATES')) { |
| 107 |
define('WP_FS__DIR_TEMPLATES', WP_FS__DIR . '/templates'); |
| 108 |
} |
| 109 |
if (!defined('WP_FS__DIR_ASSETS')) { |
| 110 |
define('WP_FS__DIR_ASSETS', WP_FS__DIR . '/assets'); |
| 111 |
} |
| 112 |
if (!defined('WP_FS__DIR_CSS')) { |
| 113 |
define('WP_FS__DIR_CSS', WP_FS__DIR_ASSETS . '/css'); |
| 114 |
} |
| 115 |
if (!defined('WP_FS__DIR_JS')) { |
| 116 |
define('WP_FS__DIR_JS', WP_FS__DIR_ASSETS . '/js'); |
| 117 |
} |
| 118 |
if (!defined('WP_FS__DIR_IMG')) { |
| 119 |
define('WP_FS__DIR_IMG', WP_FS__DIR_ASSETS . '/img'); |
| 120 |
} |
| 121 |
if (!defined('WP_FS__DIR_SDK')) { |
| 122 |
define('WP_FS__DIR_SDK', WP_FS__DIR_INCLUDES . '/sdk'); |
| 123 |
} |
| 124 |
|
| 125 |
#endregion |
| 126 |
|
| 127 |
/** |
| 128 |
* Domain / URL / Address |
| 129 |
*/ |
| 130 |
define('WP_FS__ROOT_DOMAIN_PRODUCTION', 'freemius.com'); |
| 131 |
define('WP_FS__DOMAIN_PRODUCTION', 'wp.freemius.com'); |
| 132 |
define('WP_FS__ADDRESS_PRODUCTION', 'https://' . WP_FS__DOMAIN_PRODUCTION); |
| 133 |
|
| 134 |
if (!defined('WP_FS__DOMAIN_LOCALHOST')) { |
| 135 |
define('WP_FS__DOMAIN_LOCALHOST', 'wp.freemius'); |
| 136 |
} |
| 137 |
if (!defined('WP_FS__ADDRESS_LOCALHOST')) { |
| 138 |
define('WP_FS__ADDRESS_LOCALHOST', 'http://' . WP_FS__DOMAIN_LOCALHOST . ':8080'); |
| 139 |
} |
| 140 |
|
| 141 |
if (!defined('WP_FS__TESTING_DOMAIN')) { |
| 142 |
define('WP_FS__TESTING_DOMAIN', 'fswp'); |
| 143 |
} |
| 144 |
|
| 145 |
#-------------------------------------------------------------------------------- |
| 146 |
#region HTTP |
| 147 |
#-------------------------------------------------------------------------------- |
| 148 |
|
| 149 |
if (!defined('WP_FS__IS_HTTP_REQUEST')) { |
| 150 |
define('WP_FS__IS_HTTP_REQUEST', isset($_SERVER['HTTP_HOST'])); |
| 151 |
} |
| 152 |
|
| 153 |
if (!defined('WP_FS__IS_HTTPS')) { |
| 154 |
define( |
| 155 |
'WP_FS__IS_HTTPS', |
| 156 |
(WP_FS__IS_HTTP_REQUEST && |
| 157 |
// Checks if CloudFlare's HTTPS (Flexible SSL support). |
| 158 |
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && |
| 159 |
'https' === strtolower($_SERVER['HTTP_X_FORWARDED_PROTO'])) || |
| 160 |
// Check if HTTPS request. |
| 161 |
(isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS']) || |
| 162 |
(isset($_SERVER['SERVER_PORT']) && 443 == $_SERVER['SERVER_PORT']) |
| 163 |
); |
| 164 |
} |
| 165 |
|
| 166 |
if (!defined('WP_FS__IS_POST_REQUEST')) { |
| 167 |
define('WP_FS__IS_POST_REQUEST', (WP_FS__IS_HTTP_REQUEST && |
| 168 |
strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')); |
| 169 |
} |
| 170 |
|
| 171 |
if (!defined('WP_FS__REMOTE_ADDR')) { |
| 172 |
define('WP_FS__REMOTE_ADDR', fs_get_ip()); |
| 173 |
} |
| 174 |
|
| 175 |
if (!defined('WP_FS__IS_LOCALHOST')) { |
| 176 |
if (defined('WP_FS__LOCALHOST_IP')) { |
| 177 |
define('WP_FS__IS_LOCALHOST', (WP_FS__LOCALHOST_IP === WP_FS__REMOTE_ADDR)); |
| 178 |
} else { |
| 179 |
define( |
| 180 |
'WP_FS__IS_LOCALHOST', |
| 181 |
WP_FS__IS_HTTP_REQUEST && |
| 182 |
is_string(WP_FS__REMOTE_ADDR) && |
| 183 |
(substr(WP_FS__REMOTE_ADDR, 0, 4) === '127.' || |
| 184 |
WP_FS__REMOTE_ADDR === '::1') |
| 185 |
); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
if (!defined('WP_FS__IS_LOCALHOST_FOR_SERVER')) { |
| 190 |
define('WP_FS__IS_LOCALHOST_FOR_SERVER', (!WP_FS__IS_HTTP_REQUEST || |
| 191 |
false !== strpos($_SERVER['HTTP_HOST'], 'localhost'))); |
| 192 |
} |
| 193 |
|
| 194 |
#endregion |
| 195 |
|
| 196 |
if (!defined('WP_FS__IS_PRODUCTION_MODE')) { |
| 197 |
// By default, run with Freemius production servers. |
| 198 |
define('WP_FS__IS_PRODUCTION_MODE', true); |
| 199 |
} |
| 200 |
|
| 201 |
if (!defined('WP_FS__ADDRESS')) { |
| 202 |
define('WP_FS__ADDRESS', (WP_FS__IS_PRODUCTION_MODE ? WP_FS__ADDRESS_PRODUCTION : WP_FS__ADDRESS_LOCALHOST)); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
#-------------------------------------------------------------------------------- |
| 207 |
#region API |
| 208 |
#-------------------------------------------------------------------------------- |
| 209 |
|
| 210 |
if (!defined('WP_FS__API_ADDRESS_LOCALHOST')) { |
| 211 |
define('WP_FS__API_ADDRESS_LOCALHOST', 'http://api.freemius-local.com:8080'); |
| 212 |
} |
| 213 |
if (!defined('WP_FS__API_SANDBOX_ADDRESS_LOCALHOST')) { |
| 214 |
define('WP_FS__API_SANDBOX_ADDRESS_LOCALHOST', 'http://sandbox-api.freemius:8080'); |
| 215 |
} |
| 216 |
|
| 217 |
// Set API address for local testing. |
| 218 |
if (!WP_FS__IS_PRODUCTION_MODE) { |
| 219 |
if (!defined('FS_API__ADDRESS')) { |
| 220 |
define('FS_API__ADDRESS', WP_FS__API_ADDRESS_LOCALHOST); |
| 221 |
} |
| 222 |
if (!defined('FS_API__SANDBOX_ADDRESS')) { |
| 223 |
define('FS_API__SANDBOX_ADDRESS', WP_FS__API_SANDBOX_ADDRESS_LOCALHOST); |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
#endregion |
| 228 |
|
| 229 |
#-------------------------------------------------------------------------------- |
| 230 |
#region Checkout |
| 231 |
#-------------------------------------------------------------------------------- |
| 232 |
|
| 233 |
if (!defined('FS_CHECKOUT__ADDRESS_PRODUCTION')) { |
| 234 |
define('FS_CHECKOUT__ADDRESS_PRODUCTION', 'https://checkout.freemius.com'); |
| 235 |
} |
| 236 |
|
| 237 |
if (!defined('FS_CHECKOUT__ADDRESS_LOCALHOST')) { |
| 238 |
define('FS_CHECKOUT__ADDRESS_LOCALHOST', 'http://checkout.freemius-local.com:8080'); |
| 239 |
} |
| 240 |
|
| 241 |
if (!defined('FS_CHECKOUT__ADDRESS')) { |
| 242 |
define('FS_CHECKOUT__ADDRESS', (WP_FS__IS_PRODUCTION_MODE ? FS_CHECKOUT__ADDRESS_PRODUCTION : FS_CHECKOUT__ADDRESS_LOCALHOST)); |
| 243 |
} |
| 244 |
|
| 245 |
#endregion |
| 246 |
|
| 247 |
define('WP_FS___OPTION_PREFIX', 'fs' . (WP_FS__IS_PRODUCTION_MODE ? '' : '_dbg') . '_'); |
| 248 |
|
| 249 |
if (!defined('WP_FS__ACCOUNTS_OPTION_NAME')) { |
| 250 |
define('WP_FS__ACCOUNTS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'accounts'); |
| 251 |
} |
| 252 |
if (!defined('WP_FS__API_CACHE_OPTION_NAME')) { |
| 253 |
define('WP_FS__API_CACHE_OPTION_NAME', WP_FS___OPTION_PREFIX . 'api_cache'); |
| 254 |
} |
| 255 |
if (!defined('WP_FS__GDPR_OPTION_NAME')) { |
| 256 |
define('WP_FS__GDPR_OPTION_NAME', WP_FS___OPTION_PREFIX . 'gdpr'); |
| 257 |
} |
| 258 |
define('WP_FS__OPTIONS_OPTION_NAME', WP_FS___OPTION_PREFIX . 'options'); |
| 259 |
|
| 260 |
/** |
| 261 |
* Module types |
| 262 |
* |
| 263 |
* @since 1.2.2 |
| 264 |
*/ |
| 265 |
define('WP_FS__MODULE_TYPE_PLUGIN', 'plugin'); |
| 266 |
define('WP_FS__MODULE_TYPE_THEME', 'theme'); |
| 267 |
|
| 268 |
/** |
| 269 |
* Billing Frequencies |
| 270 |
*/ |
| 271 |
define('WP_FS__PERIOD_ANNUALLY', 'annual'); |
| 272 |
define('WP_FS__PERIOD_MONTHLY', 'monthly'); |
| 273 |
define('WP_FS__PERIOD_LIFETIME', 'lifetime'); |
| 274 |
|
| 275 |
/** |
| 276 |
* Plans |
| 277 |
*/ |
| 278 |
define('WP_FS__PLAN_DEFAULT_PAID', false); |
| 279 |
define('WP_FS__PLAN_FREE', 'free'); |
| 280 |
define('WP_FS__PLAN_TRIAL', 'trial'); |
| 281 |
|
| 282 |
/** |
| 283 |
* Times in seconds |
| 284 |
*/ |
| 285 |
if (!defined('WP_FS__TIME_5_MIN_IN_SEC')) { |
| 286 |
define('WP_FS__TIME_5_MIN_IN_SEC', 300); |
| 287 |
} |
| 288 |
if (!defined('WP_FS__TIME_10_MIN_IN_SEC')) { |
| 289 |
define('WP_FS__TIME_10_MIN_IN_SEC', 600); |
| 290 |
} |
| 291 |
// define( 'WP_FS__TIME_15_MIN_IN_SEC', 900 ); |
| 292 |
if (!defined('WP_FS__TIME_12_HOURS_IN_SEC')) { |
| 293 |
define('WP_FS__TIME_12_HOURS_IN_SEC', 43200); |
| 294 |
} |
| 295 |
if (!defined('WP_FS__TIME_24_HOURS_IN_SEC')) { |
| 296 |
define('WP_FS__TIME_24_HOURS_IN_SEC', WP_FS__TIME_12_HOURS_IN_SEC * 2); |
| 297 |
} |
| 298 |
if (!defined('WP_FS__TIME_WEEK_IN_SEC')) { |
| 299 |
define('WP_FS__TIME_WEEK_IN_SEC', 7 * WP_FS__TIME_24_HOURS_IN_SEC); |
| 300 |
} |
| 301 |
|
| 302 |
#-------------------------------------------------------------------------------- |
| 303 |
#region Debugging |
| 304 |
#-------------------------------------------------------------------------------- |
| 305 |
|
| 306 |
if (!defined('WP_FS__DEBUG_SDK')) { |
| 307 |
$debug_mode = get_option('fs_debug_mode', null); |
| 308 |
|
| 309 |
if ($debug_mode === null) { |
| 310 |
$debug_mode = false; |
| 311 |
add_option('fs_debug_mode', $debug_mode); |
| 312 |
} |
| 313 |
|
| 314 |
define('WP_FS__DEBUG_SDK', is_numeric($debug_mode) ? (0 < $debug_mode) : WP_FS__DEV_MODE); |
| 315 |
} |
| 316 |
|
| 317 |
if (!defined('WP_FS__ECHO_DEBUG_SDK')) { |
| 318 |
define('WP_FS__ECHO_DEBUG_SDK', WP_FS__DEV_MODE && !empty($_GET['fs_dbg_echo'])); |
| 319 |
} |
| 320 |
if (!defined('WP_FS__LOG_DATETIME_FORMAT')) { |
| 321 |
define('WP_FS__LOG_DATETIME_FORMAT', 'Y-m-d H:i:s'); |
| 322 |
} |
| 323 |
if (!defined('FS_API__LOGGER_ON')) { |
| 324 |
define('FS_API__LOGGER_ON', WP_FS__DEBUG_SDK); |
| 325 |
} |
| 326 |
|
| 327 |
if (WP_FS__ECHO_DEBUG_SDK) { |
| 328 |
error_reporting(E_ALL); |
| 329 |
} |
| 330 |
|
| 331 |
#endregion |
| 332 |
|
| 333 |
if (!defined('WP_FS__SCRIPT_START_TIME')) { |
| 334 |
define('WP_FS__SCRIPT_START_TIME', time()); |
| 335 |
} |
| 336 |
if (!defined('WP_FS__DEFAULT_PRIORITY')) { |
| 337 |
define('WP_FS__DEFAULT_PRIORITY', 10); |
| 338 |
} |
| 339 |
if (!defined('WP_FS__LOWEST_PRIORITY')) { |
| 340 |
define('WP_FS__LOWEST_PRIORITY', 999999999); |
| 341 |
} |
| 342 |
|
| 343 |
#-------------------------------------------------------------------------------- |
| 344 |
#region Multisite Network |
| 345 |
#-------------------------------------------------------------------------------- |
| 346 |
|
| 347 |
/** |
| 348 |
* Do not use this define directly, it will have the wrong value |
| 349 |
* during plugin uninstall/deletion when the inclusion of the plugin |
| 350 |
* is triggered due to registration with register_uninstall_hook(). |
| 351 |
* |
| 352 |
* Instead, use fs_is_network_admin(). |
| 353 |
* |
| 354 |
* @author Vova Feldman (@svovaf) |
| 355 |
*/ |
| 356 |
if (!defined('WP_FS__IS_NETWORK_ADMIN')) { |
| 357 |
define( |
| 358 |
'WP_FS__IS_NETWORK_ADMIN', |
| 359 |
is_multisite() && |
| 360 |
(is_network_admin() || |
| 361 |
((defined('DOING_AJAX') && DOING_AJAX && |
| 362 |
(isset($_REQUEST['_fs_network_admin']) /*|| |
| 363 |
( ! empty( $_REQUEST['action'] ) && 'delete-plugin' === $_REQUEST['action'] )*/)) || |
| 364 |
// Plugin uninstall. |
| 365 |
defined('WP_UNINSTALL_PLUGIN'))) |
| 366 |
); |
| 367 |
} |
| 368 |
|
| 369 |
/** |
| 370 |
* Do not use this define directly, it will have the wrong value |
| 371 |
* during plugin uninstall/deletion when the inclusion of the plugin |
| 372 |
* is triggered due to registration with register_uninstall_hook(). |
| 373 |
* |
| 374 |
* Instead, use fs_is_blog_admin(). |
| 375 |
* |
| 376 |
* @author Vova Feldman (@svovaf) |
| 377 |
*/ |
| 378 |
if (!defined('WP_FS__IS_BLOG_ADMIN')) { |
| 379 |
define('WP_FS__IS_BLOG_ADMIN', is_blog_admin() || (defined('DOING_AJAX') && DOING_AJAX && isset($_REQUEST['_fs_blog_admin']))); |
| 380 |
} |
| 381 |
|
| 382 |
if (!defined('WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED')) { |
| 383 |
// Set to true to show network level settings even if delegated to site admins. |
| 384 |
define('WP_FS__SHOW_NETWORK_EVEN_WHEN_DELEGATED', false); |
| 385 |
} |
| 386 |
|
| 387 |
#endregion |
| 388 |
|
| 389 |
if (!defined('WP_FS__DEMO_MODE')) { |
| 390 |
define('WP_FS__DEMO_MODE', false); |
| 391 |
} |
| 392 |
if (!defined('FS_SDK__SSLVERIFY')) { |
| 393 |
define('FS_SDK__SSLVERIFY', false); |
| 394 |
} |
| 395 |
|