| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) exit; |
| 4 |
|
| 5 |
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_GET['berqwp_webhook']) && $_GET['berqwp_webhook'] == 'update_configs') { |
| 6 |
|
| 7 |
if (defined('DOING_CRON') && DOING_CRON) { |
| 8 |
return; |
| 9 |
} |
| 10 |
|
| 11 |
if (defined('DOING_AJAX') && DOING_AJAX) { |
| 12 |
return; |
| 13 |
} |
| 14 |
|
| 15 |
if (defined('REST_REQUEST') && REST_REQUEST) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
$jsonData = file_get_contents('php://input'); |
| 20 |
$data = json_decode($jsonData, true); |
| 21 |
|
| 22 |
if ($data == null) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
$settings = (array) $data['settings']; |
| 27 |
$license_key_hash = sanitize_text_field($data['license_key_hash']); |
| 28 |
$license_key = berqwp_get_license_key(); |
| 29 |
|
| 30 |
if (empty($license_key_hash) || empty($license_key) || $license_key_hash !== md5($license_key)) { |
| 31 |
echo json_encode(['status' => 'error']); |
| 32 |
http_response_code(403); |
| 33 |
exit; |
| 34 |
} |
| 35 |
|
| 36 |
if (empty($settings)) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
// Sanitize |
| 41 |
$valid_setting_names = [ |
| 42 |
'berqwp_fluid_images', |
| 43 |
'berqwp_can_use_fluid_images', |
| 44 |
'berqwp_license_key', |
| 45 |
]; |
| 46 |
|
| 47 |
foreach ($settings as $setting_name => $setting_value) { |
| 48 |
|
| 49 |
// skip invalid name |
| 50 |
if (!in_array($setting_name, $valid_setting_names)) { |
| 51 |
continue; |
| 52 |
} |
| 53 |
|
| 54 |
switch ($setting_name) { |
| 55 |
|
| 56 |
case 'berqwp_can_use_fluid_images': |
| 57 |
update_option($setting_name, $setting_value); |
| 58 |
update_option('bwp_require_flush_cache', 1); |
| 59 |
break; |
| 60 |
|
| 61 |
case 'berqwp_license_key': |
| 62 |
update_option($setting_name, $setting_value); |
| 63 |
break; |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
exit; |
| 72 |
} |