AdminGeneralOptionsGet.php
3 months ago
AdminGeneralOptionsPersist.php
3 months ago
CustomFieldKeys.php
3 months ago
EditorMenuFavorites.php
3 months ago
EditorMenuStatus.php
3 months ago
ExtendedValue.php
3 months ago
IntegrationToggle.php
3 months ago
Integrations.php
3 months ago
ListScreenAddColumn.php
3 months ago
ListScreenDelete.php
3 months ago
ListScreenOriginalColumns.php
3 months ago
ListScreenSave.php
3 months ago
ListScreenSelectColumn.php
3 months ago
ListScreenSettings.php
3 months ago
NetworkPostStati.php
3 months ago
NumberFormat.php
3 months ago
RestoreSettingsRequest.php
3 months ago
ScreenOptions.php
3 months ago
ListScreenDelete.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\RequestHandler\Ajax; |
| 6 | |
| 7 | use AC\Capabilities; |
| 8 | use AC\ListScreenRepository\Storage; |
| 9 | use AC\Nonce; |
| 10 | use AC\Request; |
| 11 | use AC\RequestAjaxHandler; |
| 12 | use AC\Response; |
| 13 | use AC\Type\ListScreenId; |
| 14 | |
| 15 | class ListScreenDelete implements RequestAjaxHandler |
| 16 | { |
| 17 | |
| 18 | private Storage $storage; |
| 19 | |
| 20 | public function __construct(Storage $storage) |
| 21 | { |
| 22 | $this->storage = $storage; |
| 23 | } |
| 24 | |
| 25 | public function handle(): void |
| 26 | { |
| 27 | if ( ! current_user_can(Capabilities::MANAGE)) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | $request = new Request(); |
| 32 | $response = new Response\Json(); |
| 33 | |
| 34 | if ( ! (new Nonce\Ajax())->verify($request)) { |
| 35 | $response->error(); |
| 36 | } |
| 37 | |
| 38 | $list_screen = $this->storage->find(new ListScreenId($request->get('list_id'))); |
| 39 | |
| 40 | if ( ! $list_screen) { |
| 41 | $response->error(); |
| 42 | } |
| 43 | |
| 44 | $this->storage->delete($list_screen); |
| 45 | |
| 46 | do_action('ac/list_screen/deleted', $list_screen); |
| 47 | |
| 48 | $response->set_message( |
| 49 | sprintf( |
| 50 | __('Table view %s successfully deleted.', 'codepress-admin-columns'), |
| 51 | sprintf('<strong>"%s"</strong>', esc_html($list_screen->get_title() ?: $list_screen->get_label())) |
| 52 | ) |
| 53 | )->success(); |
| 54 | } |
| 55 | |
| 56 | } |