PluginProbe
BeyondWords – AI audio for publishers / 4.6.1
BeyondWords – AI audio for publishers v4.6.1
7.2.0 7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 All 44 releases
speechkit / src / Core / Uninstaller.php

Uninstaller.php in BeyondWords – AI audio for publishers 4.6.1, at src/Core/Uninstaller.php

117 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 /**
6 * BeyondWords uninstaller.
7 *
8 * @package Beyondwords\Wordpress
9 * @author Stuart McAlpine <[email protected]>
10 * @since 3.7.0
11 */
12
13 namespace Beyondwords\Wordpress\Core;
14
15 use Beyondwords\Wordpress\Core\CoreUtils;
16
17 /**
18 * BeyondWords uninstaller.
19 *
20 * @since 3.7.0
21 */
22 class Uninstaller
23 {
24 /**
25 * Clean up (delete) all BeyondWords plugin options.
26 *
27 * @since 3.7.0
28 */
29 public static function cleanupPluginOptions()
30 {
31 $options = [
32 // v4.0.0
33 'beyondwords_languages',
34 'beyondwords_player_ui',
35 'beyondwords_player_style',
36 'beyondwords_player_version',
37 'beyondwords_settings_updated',
38 'beyondwords_valid_api_connection',
39 // v3.7.0 beyondwords_*
40 'beyondwords_version',
41 'beyondwords_api_key',
42 'beyondwords_project_id',
43 'beyondwords_preselect',
44 'beyondwords_prepend_excerpt',
45 // v3.0.0 speechkit_*
46 'speechkit_version',
47 'speechkit_api_key',
48 'speechkit_project_id',
49 'speechkit_preselect',
50 'speechkit_prepend_excerpt',
51 // deprecated < v3.0
52 'speechkit_settings',
53 'speechkit_enable',
54 'speechkit_id',
55 'speechkit_select_post_types',
56 'speechkit_selected_categories',
57 'speechkit_enable_telemetry',
58 'speechkit_rollbar_access_token',
59 'speechkit_rollbar_error_notice',
60 'speechkit_merge_excerpt',
61 'speechkit_enable_marfeel_comp',
62 'speechkit_wordpress_cron',
63 ];
64
65 $total = 0;
66
67 foreach ($options as $option) {
68 if (is_multisite()) {
69 $deleted = delete_site_option($option);
70 } else {
71 $deleted = delete_option($option);
72 }
73
74 if ($deleted) {
75 $total++;
76 }
77 }
78
79 return $total;
80 }
81
82 /**
83 * Clean up (delete) all BeyondWords custom fields.
84 *
85 * @since 3.7.0
86 * @since 4.6.1 Use $wpdb->postmeta variable for table name.
87 */
88 public static function cleanupCustomFields()
89 {
90 global $wpdb;
91
92 $fields = CoreUtils::getPostMetaKeys('all');
93
94 $total = 0;
95
96 /*
97 * Delete the custom fields one at a time to help prevent very slow
98 * individual MySQL DELETE queries on sites with 1,000s of posts.
99 */
100 foreach ($fields as $field) {
101 $metaIds = $wpdb->get_col($wpdb->prepare("SELECT `meta_id` FROM {$wpdb->postmeta} WHERE `meta_key` = %s;", $field)); // phpcs:ignore
102
103 if (! count($metaIds)) {
104 continue;
105 }
106
107 $count = $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE `meta_id` IN ( " . implode(',', $metaIds) . ' );'); // phpcs:ignore
108
109 if ($count) {
110 $total += $count;
111 }
112 }
113
114 return $total;
115 }
116 }
117