| 1 |
<?php |
| 2 |
|
| 3 |
function bwp_is_ajax() { |
| 4 |
return |
| 5 |
(function_exists("wp_doing_ajax") && wp_doing_ajax()) || |
| 6 |
(defined('DOING_AJAX') && DOING_AJAX) || |
| 7 |
(!empty($_SERVER["HTTP_X_REQUESTED_WITH"]) && $_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest") || |
| 8 |
(!empty($_SERVER["REQUEST_URI"]) && basename($_SERVER["REQUEST_URI"]) == "admin-ajax.php") || |
| 9 |
!empty($_GET["wc-ajax"]); |
| 10 |
} |
| 11 |
|
| 12 |
function bwp_is_user_logged_in() { |
| 13 |
foreach ($_COOKIE as $key => $value) { |
| 14 |
if (strpos($key, 'wordpress_logged_in') === 0) { |
| 15 |
return true; |
| 16 |
} |
| 17 |
} |
| 18 |
return false; |
| 19 |
} |
| 20 |
|
| 21 |
function dropin_remove_ignore_params($slug) |
| 22 |
{ |
| 23 |
$tracking_params = ignoreParams::$query_params; |
| 24 |
|
| 25 |
// Parse the provided slug |
| 26 |
$url_parts = parse_url($slug); |
| 27 |
|
| 28 |
// Get the current URL parameters |
| 29 |
$url_params = array(); |
| 30 |
if (isset($url_parts['query'])) { |
| 31 |
parse_str($url_parts['query'], $url_params); |
| 32 |
} |
| 33 |
|
| 34 |
// Remove specified tracking parameters from the URL |
| 35 |
foreach ($tracking_params as $param) { |
| 36 |
$param = trim($param); |
| 37 |
if (isset($url_params[$param])) { |
| 38 |
unset($url_params[$param]); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
// Build the new query string |
| 43 |
$new_query_string = http_build_query($url_params); |
| 44 |
|
| 45 |
// Reconstruct the URL with the new query string |
| 46 |
$updated_url = $url_parts['scheme'] . "://" . $url_parts['host'] . $url_parts['path']; |
| 47 |
if (!empty($new_query_string)) { |
| 48 |
$updated_url .= '?' . $new_query_string; |
| 49 |
} |
| 50 |
|
| 51 |
return $updated_url; |
| 52 |
} |
| 53 |
|
| 54 |
function bwp_dropin_isGzipEncoded() { |
| 55 |
// Check if the Content-Encoding header is set to gzip |
| 56 |
if (isset($_SERVER['HTTP_CONTENT_ENCODING']) && strtolower($_SERVER['HTTP_CONTENT_ENCODING']) === 'gzip') { |
| 57 |
return true; |
| 58 |
} |
| 59 |
|
| 60 |
foreach (headers_list() as $header) { |
| 61 |
if (stripos($header, 'Content-Encoding: gzip') !== false) { |
| 62 |
return true; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
return false; |
| 67 |
} |
| 68 |
|
| 69 |
function berqwp_dropin_is_page_url_excluded($page_url) { |
| 70 |
if (empty($page_url)) { |
| 71 |
return false; |
| 72 |
} |
| 73 |
|
| 74 |
$berqconfigs = berqConfigs::getInstance(); |
| 75 |
$configs = $berqconfigs->get_configs(); |
| 76 |
$pages_to_exclude = $configs['exclude_urls']; |
| 77 |
|
| 78 |
if (strpos($page_url, '?') !== false) { |
| 79 |
$page_url = explode('?', $page_url)[0]; |
| 80 |
} |
| 81 |
|
| 82 |
if (in_array($page_url, $pages_to_exclude)) { |
| 83 |
return true; |
| 84 |
} |
| 85 |
|
| 86 |
if (!empty($pages_to_exclude)) { |
| 87 |
foreach ($pages_to_exclude as $single_page_url) { |
| 88 |
|
| 89 |
if (empty($single_page_url)) { |
| 90 |
continue; |
| 91 |
} |
| 92 |
|
| 93 |
if (substr($single_page_url, -1) !== '*') { |
| 94 |
continue; |
| 95 |
} |
| 96 |
|
| 97 |
$single_page_url = str_replace('*', '', $single_page_url); |
| 98 |
|
| 99 |
if (strpos($page_url, $single_page_url) !== false) { |
| 100 |
return true; |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
return false; |
| 106 |
} |
| 107 |
|