PluginProbe
BeyondWords – AI audio for publishers / 4.0.5
BeyondWords – AI audio for publishers v4.0.5
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 4.7.0 All 43 releases
speechkit / src / Core / Uninstaller.php

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

151 lines 4.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 <stu@beyondwords.io>
10 * @since 3.7.0
11 */
12
13 namespace Beyondwords\Wordpress\Core;
14
15 /**
16 * BeyondWords uninstaller.
17 *
18 * @since 3.7.0
19 */
20 class Uninstaller
21 {
22 /**
23 * Clean up (delete) all BeyondWords plugin options.
24 *
25 * @since 3.7.0
26 */
27 public static function cleanupPluginOptions()
28 {
29 $options = [
30 // v4.0.0
31 'beyondwords_languages',
32 'beyondwords_player_ui',
33 'beyondwords_player_version',
34 'beyondwords_settings_updated',
35 'beyondwords_valid_api_connection',
36 // v3.7.0 beyondwords_*
37 'beyondwords_version',
38 'beyondwords_api_key',
39 'beyondwords_project_id',
40 'beyondwords_preselect',
41 'beyondwords_prepend_excerpt',
42 // v3.0.0 speechkit_*
43 'speechkit_version',
44 'speechkit_api_key',
45 'speechkit_project_id',
46 'speechkit_preselect',
47 'speechkit_prepend_excerpt',
48 // deprecated < v3.0
49 'speechkit_settings',
50 'speechkit_enable',
51 'speechkit_id',
52 'speechkit_select_post_types',
53 'speechkit_selected_categories',
54 'speechkit_enable_telemetry',
55 'speechkit_rollbar_access_token',
56 'speechkit_rollbar_error_notice',
57 'speechkit_merge_excerpt',
58 'speechkit_enable_marfeel_comp',
59 'speechkit_wordpress_cron',
60 ];
61
62 $total = 0;
63
64 foreach ($options as $option) {
65 if (is_multisite()) {
66 $deleted = delete_site_option($option);
67 } else {
68 $deleted = delete_option($option);
69 }
70
71 if ($deleted) {
72 $total++;
73 }
74 }
75
76 return $total;
77 }
78
79 /**
80 * Clean up (delete) all BeyondWords custom fields.
81 *
82 * @since 3.7.0
83 */
84 public static function cleanupCustomFields()
85 {
86 global $wpdb;
87
88 $tableName = $wpdb->prefix . 'postmeta';
89
90 $fields = [
91 // > v4.0 beyondwords_content_id
92 'beyondwords_content_id',
93 'beyondwords_language_id',
94 'beyondwords_title_voice_id',
95 'beyondwords_body_voice_id',
96 'beyondwords_summary_voice_id',
97 // v3.7 `beyondwords_*`
98 'beyondwords_generate_audio',
99 'beyondwords_project_id',
100 'beyondwords_podcast_id',
101 'beyondwords_hash',
102 'beyondwords_error_message',
103 'beyondwords_disabled',
104 // v3.0 `speechkit_*`
105 'speechkit_generate_audio',
106 'speechkit_project_id',
107 'speechkit_podcast_id',
108 'speechkit_hash',
109 'speechkit_access_key',
110 'speechkit_error_message',
111 'speechkit_disabled',
112 'speechkit_updated_at',
113 // < v3.0 deprecated
114 'publish_post_to_speechkit',
115 'speechkit_error',
116 'speechkit_info',
117 'speechkit_response',
118 'speechkit_retries',
119 'speechkit_status',
120 '_speechkit_link',
121 '_speechkit_text',
122 ];
123
124 $total = 0;
125
126 /*
127 * Delete the custom fields one at a time to help prevent very slow
128 * individual MySQL DELETE queries on sites with 1,000s of posts.
129 */
130 foreach ($fields as $field) {
131 $query = $wpdb->prepare('SELECT `meta_id` FROM %1s WHERE `meta_key` = "%2s";', [$tableName, $field]);
132
133 $meta_ids = $wpdb->get_col($query); // phpcs:ignore
134
135 if (! count($meta_ids)) {
136 continue;
137 }
138
139 $query = "DELETE FROM `{$tableName}` WHERE `meta_id` IN ( " . implode(',', $meta_ids) . ' );';
140
141 $count = $wpdb->query($query); // phpcs:ignore
142
143 if ($count) {
144 $total += $count;
145 }
146 }
147
148 return $total;
149 }
150 }
151