PluginProbe
BeyondWords – AI audio for publishers / 4.1.0
BeyondWords – AI audio for publishers v4.1.0
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.1.0, at src/Core/Uninstaller.php

121 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_version',
36 'beyondwords_settings_updated',
37 'beyondwords_valid_api_connection',
38 // v3.7.0 beyondwords_*
39 'beyondwords_version',
40 'beyondwords_api_key',
41 'beyondwords_project_id',
42 'beyondwords_preselect',
43 'beyondwords_prepend_excerpt',
44 // v3.0.0 speechkit_*
45 'speechkit_version',
46 'speechkit_api_key',
47 'speechkit_project_id',
48 'speechkit_preselect',
49 'speechkit_prepend_excerpt',
50 // deprecated < v3.0
51 'speechkit_settings',
52 'speechkit_enable',
53 'speechkit_id',
54 'speechkit_select_post_types',
55 'speechkit_selected_categories',
56 'speechkit_enable_telemetry',
57 'speechkit_rollbar_access_token',
58 'speechkit_rollbar_error_notice',
59 'speechkit_merge_excerpt',
60 'speechkit_enable_marfeel_comp',
61 'speechkit_wordpress_cron',
62 ];
63
64 $total = 0;
65
66 foreach ($options as $option) {
67 if (is_multisite()) {
68 $deleted = delete_site_option($option);
69 } else {
70 $deleted = delete_option($option);
71 }
72
73 if ($deleted) {
74 $total++;
75 }
76 }
77
78 return $total;
79 }
80
81 /**
82 * Clean up (delete) all BeyondWords custom fields.
83 *
84 * @since 3.7.0
85 */
86 public static function cleanupCustomFields()
87 {
88 global $wpdb;
89
90 $tableName = $wpdb->prefix . 'postmeta';
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 $query = $wpdb->prepare('SELECT `meta_id` FROM %1s WHERE `meta_key` = "%2s";', [$tableName, $field]);
102
103 $meta_ids = $wpdb->get_col($query); // phpcs:ignore
104
105 if (! count($meta_ids)) {
106 continue;
107 }
108
109 $query = "DELETE FROM `{$tableName}` WHERE `meta_id` IN ( " . implode(',', $meta_ids) . ' );';
110
111 $count = $wpdb->query($query); // phpcs:ignore
112
113 if ($count) {
114 $total += $count;
115 }
116 }
117
118 return $total;
119 }
120 }
121