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

122 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 <stu@beyondwords.io>
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 */
87 public static function cleanupCustomFields()
88 {
89 global $wpdb;
90
91 $tableName = $wpdb->prefix . 'postmeta';
92
93 $fields = CoreUtils::getPostMetaKeys('all');
94
95 $total = 0;
96
97 /*
98 * Delete the custom fields one at a time to help prevent very slow
99 * individual MySQL DELETE queries on sites with 1,000s of posts.
100 */
101 foreach ($fields as $field) {
102 $query = $wpdb->prepare('SELECT `meta_id` FROM %1s WHERE `meta_key` = "%2s";', [$tableName, $field]);
103
104 $meta_ids = $wpdb->get_col($query); // phpcs:ignore
105
106 if (! count($meta_ids)) {
107 continue;
108 }
109
110 $query = "DELETE FROM `{$tableName}` WHERE `meta_id` IN ( " . implode(',', $meta_ids) . ' );';
111
112 $count = $wpdb->query($query); // phpcs:ignore
113
114 if ($count) {
115 $total += $count;
116 }
117 }
118
119 return $total;
120 }
121 }
122