AdminGeneralOptionsGet.php
2 days ago
AdminGeneralOptionsPersist.php
2 days ago
CustomFieldKeys.php
2 days ago
EditorMenuFavorites.php
2 days ago
EditorMenuStatus.php
2 days ago
ExtendedValue.php
2 days ago
IntegrationToggle.php
2 days ago
Integrations.php
2 days ago
ListScreenAddColumn.php
2 days ago
ListScreenDelete.php
2 days ago
ListScreenOriginalColumns.php
2 days ago
ListScreenSave.php
2 days ago
ListScreenSelectColumn.php
2 days ago
ListScreenSettings.php
2 days ago
NetworkPostStati.php
2 days ago
NumberFormat.php
2 days ago
RestoreSettingsRequest.php
2 days ago
ScreenOptions.php
2 days ago
IntegrationToggle.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\RequestHandler\Ajax; |
| 6 | |
| 7 | use AC\Capabilities; |
| 8 | use AC\Nonce; |
| 9 | use AC\Request; |
| 10 | use AC\RequestAjaxHandler; |
| 11 | use AC\Storage\Repository\IntegrationStatus; |
| 12 | |
| 13 | class IntegrationToggle implements RequestAjaxHandler |
| 14 | { |
| 15 | private IntegrationStatus $repository; |
| 16 | |
| 17 | public function __construct(IntegrationStatus $repository) |
| 18 | { |
| 19 | $this->repository = $repository; |
| 20 | } |
| 21 | |
| 22 | public function handle(): void |
| 23 | { |
| 24 | if (! current_user_can(Capabilities::MANAGE)) { |
| 25 | wp_send_json_error(); |
| 26 | } |
| 27 | |
| 28 | $request = new Request(); |
| 29 | |
| 30 | if (! (new Nonce\Ajax())->verify($request)) { |
| 31 | wp_send_json_error(); |
| 32 | } |
| 33 | |
| 34 | $integration = $request->get('integration'); |
| 35 | |
| 36 | if (! $integration) { |
| 37 | wp_send_json_error(); |
| 38 | } |
| 39 | |
| 40 | $is_active = (bool)$request->get('status'); |
| 41 | |
| 42 | $is_active |
| 43 | ? $this->repository->set_active($integration) |
| 44 | : $this->repository->set_inactive($integration); |
| 45 | |
| 46 | wp_send_json_success(__('Settings saved successfully.', 'codepress-admin-columns')); |
| 47 | } |
| 48 | |
| 49 | } |
| 50 |