PluginProbe
Embed Privacy / 1.10.7
Embed Privacy v1.10.7
1.14.0 1.13.0 trunk 0.1 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.10.0 1.10.1 1.10.10 1.10.2 1.10.3 1.10.4 1.10.5 1.10.6 1.10.7 1.10.8 1.10.9 1.11.0 1.11.1 1.11.2 All 68 releases
embed-privacy / uninstall.php

uninstall.php in Embed Privacy 1.10.7, at uninstall.php

140 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // // phpcs:disable SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified
3 namespace epiphyt\Embed_Privacy;
4
5 use epiphyt\Embed_Privacy\thumbnail\Thumbnail;
6
7 // if uninstall.php is not called by WordPress, die
8 if ( ! \defined( 'WP_UNINSTALL_PLUGIN' ) ) {
9 exit;
10 }
11
12 $GLOBALS['options'] = [
13 'embed_privacy_disable_link',
14 'embed_privacy_download_thumbnails',
15 'embed_privacy_is_migrating',
16 'embed_privacy_javascript_detection',
17 'embed_privacy_local_tweets',
18 'embed_privacy_migrate_version',
19 'embed_privacy_migration_count',
20 'embed_privacy_preserve_data_on_uninstall',
21 ];
22
23 if ( \is_multisite() ) {
24 $sites = \get_sites( [
25 'fields' => 'ids',
26 'number' => 99999,
27 ] );
28
29 foreach ( $sites as $site_blog_id ) {
30 \switch_to_blog( $site_blog_id );
31
32 // do nothing if option says so
33 if ( \get_option( 'embed_privacy_preserve_data_on_uninstall' ) ) {
34 continue;
35 }
36
37 delete_data();
38 \restore_current_blog();
39 }
40
41 // delete site options
42 foreach ( $GLOBALS['options'] as $option ) {
43 \delete_site_option( $option );
44 }
45 }
46 else if ( ! \get_option( 'embed_privacy_preserve_data_on_uninstall' ) ) {
47 delete_data();
48 }
49
50 /**
51 * Delete all data
52 *
53 * @since 1.5.0
54 */
55 function delete_data() {
56 global $options;
57
58 // delete options
59 foreach ( $options as $option ) {
60 \delete_option( $option );
61 }
62
63 // delete posts of custom post type
64 $post_args = [
65 'fields' => 'ids',
66 'no_found_rows' => true,
67 'post_status' => 'any',
68 'post_type' => 'epi_embed',
69 'update_post_meta_cache' => false,
70 'update_post_term_cache' => false,
71 ];
72 $embeds = \get_posts( $post_args );
73
74 while ( \count( $embeds ) ) {
75 foreach ( $embeds as $embed_id ) {
76 \wp_delete_post( $embed_id, true );
77 }
78
79 $embeds = \get_posts( $post_args );
80 }
81
82 $post_args = [
83 'fields' => 'ids',
84 'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
85 [
86 'compare' => '!=',
87 'compare_key' => 'LIKE',
88 'key' => 'embed_privacy_thumbnail_',
89 'value' => '',
90 ],
91 ],
92 'no_found_rows' => true,
93 'offset' => 0,
94 'post_type' => 'any',
95 'update_post_term_cache' => false,
96 ];
97 $posts = \get_posts( $post_args );
98
99 while ( \count( $posts ) ) {
100 foreach ( $posts as $post_id ) {
101 $metadata = \get_post_meta( $post_id );
102
103 foreach ( \array_keys( $metadata ) as $meta_key ) {
104 if ( ! \str_contains( $meta_key, 'embed_privacy_thumbnail_' ) ) {
105 continue;
106 }
107
108 \delete_post_meta( $post_id, $meta_key );
109 }
110 }
111
112 $post_args['offset'] += 5;
113 $posts = \get_posts( $post_args );
114 }
115
116 require_once __DIR__ . '/inc/thumbnail/class-thumbnail.php';
117
118 // delete thumbnail directory
119 delete_directory( Thumbnail::get_directory()['base_dir'] );
120 // delete old thumbnail directory
121 delete_directory( \WP_CONTENT_DIR . '/uploads/embed-privacy' );
122 }
123
124 /**
125 * Delete a directory recursively.
126 *
127 * @since 1.7.3
128 *
129 * @param string $directory The directory to delete
130 */
131 function delete_directory( $directory ) {
132 if ( ! \file_exists( $directory ) ) {
133 return;
134 }
135
136 require_once __DIR__ . '/inc/class-embed-privacy.php';
137
138 Embed_Privacy::get_wp_filesystem()->rmdir( $directory, true );
139 }
140