| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Handles action 'updateOptions': either deletes the debug file (if |
| 9 |
* deleteDebugFile flag is set) or rewrites $sub to 'abj404_options' so the |
| 10 |
* settings page submission proceeds through the normal options pipeline. |
| 11 |
* |
| 12 |
* This is the one handler that uses wp_verify_nonce() against $_POST['nonce'] |
| 13 |
* (not check_admin_referer), preserving the pre-refactor behavior exactly. |
| 14 |
*/ |
| 15 |
class ABJ_404_Solution_UpdateOptionsHandler implements ABJ_404_Solution_AdminActionHandlerInterface { |
| 16 |
|
| 17 |
/** @var ABJ_404_Solution_PluginLogicAdminActions */ |
| 18 |
private $parent; |
| 19 |
|
| 20 |
public function __construct(ABJ_404_Solution_PluginLogicAdminActions $parent) { |
| 21 |
$this->parent = $parent; |
| 22 |
} |
| 23 |
|
| 24 |
public function nonceAction(): string { |
| 25 |
return 'abj404UpdateOptions'; |
| 26 |
} |
| 27 |
|
| 28 |
public function nonceArg(): string { |
| 29 |
return 'nonce'; |
| 30 |
} |
| 31 |
|
| 32 |
public function useCheckAdminReferer(): bool { |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
public function handle(string $action, string &$sub): string { |
| 37 |
$logger = $this->parent->getLogger(); |
| 38 |
|
| 39 |
if (array_key_exists('deleteDebugFile', $_POST) && $_POST['deleteDebugFile']) { |
| 40 |
$filepath = $logger->getDebugFilePath(); |
| 41 |
if (!file_exists($filepath)) { |
| 42 |
return sprintf(__("Debug file not found. (%s)", '404-solution'), $filepath); |
| 43 |
} else if ($logger->deleteDebugFile()) { |
| 44 |
return sprintf(__("Debug file(s) deleted. (%s)", '404-solution'), $filepath); |
| 45 |
} else { |
| 46 |
return sprintf(__("Issue deleting debug file. (%s)", '404-solution'), $filepath); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
$sub = 'abj404_options'; |
| 51 |
return ''; |
| 52 |
} |
| 53 |
} |
| 54 |
|