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