| 1 |
<?php |
| 2 |
|
| 3 |
function iwp_compat_is_rest_request() |
| 4 |
{ |
| 5 |
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; |
| 6 |
|
| 7 |
if (preg_match('/iwp\/v1\/(?:importer|exporter)\/[\d]+\/(?:init|run|status)/', $request_uri) === 1) { |
| 8 |
return true; |
| 9 |
} |
| 10 |
|
| 11 |
if (defined('IWP_CRON_TOKEN') && isset($_GET['iwp_cron_token']) && $_GET['iwp_cron_token'] === IWP_CRON_TOKEN) { |
| 12 |
return true; |
| 13 |
} |
| 14 |
|
| 15 |
return false; |
| 16 |
} |
| 17 |
|
| 18 |
function iwp_compat_is_importer_request() |
| 19 |
{ |
| 20 |
$rest_request = iwp_compat_is_rest_request(); |
| 21 |
if ($rest_request) { |
| 22 |
return true; |
| 23 |
} |
| 24 |
|
| 25 |
return false; |
| 26 |
} |
| 27 |
|
| 28 |
add_filter('option_active_plugins', function ($plugins) { |
| 29 |
|
| 30 |
if (!is_array($plugins) || empty($plugins) || !iwp_compat_is_importer_request()) { |
| 31 |
return $plugins; |
| 32 |
} |
| 33 |
|
| 34 |
$blacklist = (array)get_option('iwp_compat_blacklist', []); |
| 35 |
|
| 36 |
if (is_array($blacklist) && !empty($blacklist)) { |
| 37 |
foreach ($plugins as $key => $plugin) { |
| 38 |
if (in_array($plugin, $blacklist)) { |
| 39 |
unset($plugins[$key]); |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
return $plugins; |
| 45 |
}); |
| 46 |
|