| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Handles action 'saveGscSettings': persists Google Search Console OAuth |
| 9 |
* credentials submitted from the GSC settings form. Returns the validation |
| 10 |
* error string from GoogleSearchConsole::saveSettings() (empty on success). |
| 11 |
* |
| 12 |
* Uses a custom nonce arg '_wpnonce_gsc' to scope the GSC form's nonce |
| 13 |
* separately from other admin actions on the same page. |
| 14 |
*/ |
| 15 |
class ABJ_404_Solution_SaveGscSettingsHandler implements ABJ_404_Solution_AdminActionHandlerInterface { |
| 16 |
|
| 17 |
public function nonceAction(): string { |
| 18 |
return 'abj404_gsc_save'; |
| 19 |
} |
| 20 |
|
| 21 |
public function nonceArg(): string { |
| 22 |
return '_wpnonce_gsc'; |
| 23 |
} |
| 24 |
|
| 25 |
public function useCheckAdminReferer(): bool { |
| 26 |
return true; |
| 27 |
} |
| 28 |
|
| 29 |
public function handle(string $action, string &$sub): string { |
| 30 |
$logger = abj_service('logging'); |
| 31 |
$gsc = new ABJ_404_Solution_GoogleSearchConsole($logger); |
| 32 |
$error = $gsc->oauthStore()->saveSettings($_POST); |
| 33 |
return ($error === '') |
| 34 |
? __('Google Search Console credentials saved.', '404-solution') |
| 35 |
: $error; |
| 36 |
} |
| 37 |
} |
| 38 |
|