| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('WPINC')) { |
| 4 |
die; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Determine whether telemetry is disabled before initializing handlers or sending. |
| 9 |
*/ |
| 10 |
function metasync_telemetry_is_disabled() |
| 11 |
{ |
| 12 |
if (defined('METASYNC_DISABLE_TELEMETRY') && constant('METASYNC_DISABLE_TELEMETRY')) { |
| 13 |
return true; |
| 14 |
} |
| 15 |
|
| 16 |
if (function_exists('get_option')) { |
| 17 |
$options = get_option('metasync_options', array()); |
| 18 |
if (is_array($options) && !empty($options['disable_telemetry'])) { |
| 19 |
return true; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
return false; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Return only the path component of a request URI or URL. |
| 28 |
*/ |
| 29 |
function metasync_telemetry_request_path($request_uri = null) |
| 30 |
{ |
| 31 |
if ($request_uri === null) { |
| 32 |
$request_uri = $_SERVER['REQUEST_URI'] ?? ''; |
| 33 |
} |
| 34 |
|
| 35 |
if (!is_string($request_uri) || $request_uri === '') { |
| 36 |
return 'unknown'; |
| 37 |
} |
| 38 |
|
| 39 |
$path = parse_url($request_uri, PHP_URL_PATH); |
| 40 |
|
| 41 |
return is_string($path) && $path !== '' ? $path : '/'; |
| 42 |
} |
| 43 |
|