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
RestoreSettingsRequest.php
77 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\RequestHandler\Ajax; |
| 6 | |
| 7 | use AC\Capabilities; |
| 8 | use AC\ListScreenRepository; |
| 9 | use AC\ListScreenRepositoryWritable; |
| 10 | use AC\Nonce; |
| 11 | use AC\Request; |
| 12 | use AC\RequestAjaxHandler; |
| 13 | use AC\Response; |
| 14 | |
| 15 | class RestoreSettingsRequest implements RequestAjaxHandler |
| 16 | { |
| 17 | private ListScreenRepository\Storage\ListScreenRepository $repository; |
| 18 | |
| 19 | public function __construct(ListScreenRepository\Storage\ListScreenRepository $repository) |
| 20 | { |
| 21 | $this->repository = $repository; |
| 22 | } |
| 23 | |
| 24 | public function handle(): void |
| 25 | { |
| 26 | if (! current_user_can(Capabilities::MANAGE)) { |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | $request = new Request(); |
| 31 | $response = new Response\Json(); |
| 32 | |
| 33 | if (! (new Nonce\Ajax())->verify($request)) { |
| 34 | $response->error(); |
| 35 | } |
| 36 | |
| 37 | $repository = $this->repository->get_list_screen_repository(); |
| 38 | |
| 39 | if (! $repository instanceof ListScreenRepositoryWritable) { |
| 40 | $response->error(); |
| 41 | } |
| 42 | |
| 43 | foreach ($repository->find_all() as $list_screen) { |
| 44 | $repository->delete($list_screen); |
| 45 | } |
| 46 | |
| 47 | $this->delete_options(); |
| 48 | $this->delete_user_preferences(); |
| 49 | |
| 50 | do_action('ac/settings/restore'); |
| 51 | |
| 52 | $response->set_parameter('message', __('Default settings successfully restored.', 'codepress-admin-columns')); |
| 53 | $response->success(); |
| 54 | } |
| 55 | |
| 56 | private function delete_user_preferences(): void |
| 57 | { |
| 58 | global $wpdb; |
| 59 | |
| 60 | $wpdb->query("DELETE FROM $wpdb->usermeta WHERE meta_key LIKE '{$wpdb->get_blog_prefix()}ac_preferences_%'"); |
| 61 | $wpdb->query("DELETE FROM $wpdb->usermeta WHERE meta_key LIKE 'ac_conditional_format_%'"); |
| 62 | } |
| 63 | |
| 64 | private function delete_options(): void |
| 65 | { |
| 66 | global $wpdb; |
| 67 | |
| 68 | $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'ac_api_request%'"); |
| 69 | $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'ac_cache_expires_%'"); |
| 70 | $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'ac_cache_data%'"); |
| 71 | $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'ac_sorting_%'"); |
| 72 | $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'cpac_options%__default'"); |
| 73 | $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'cpac_general_options'"); |
| 74 | } |
| 75 | |
| 76 | } |
| 77 |