PluginProbe
Polylang / trunk
Polylang vtrunk
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | uninstall.php +93 -53 2.8.3 → trunk View file →
@@ -2,15 +2,15 @@
2 2 /**
3 3 * @package Polylang
4 4 */
5 5
6 -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { // If uninstall not called from WordPress exit
6 +if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { // If uninstall not called from WordPress exit.
7 7 exit;
8 8 }
9 9
10 10 /**
11 - * Manages Polylang uninstallation
12 - * The goal is to remove ALL Polylang related data in db
11 + * Manages Polylang uninstallation.
12 + * The goal is to remove **all** Polylang related data in db.
13 13 *
14 14 * @since 0.5
15 15 */
16 16 class PLL_Uninstall {
@@ -15,9 +15,9 @@
15 15 */
16 16 class PLL_Uninstall {
17 17
18 18 /**
19 - * Constructor: manages uninstall for multisite
19 + * Constructor: manages uninstall for multisite.
20 20 *
21 21 * @since 0.5
22 22 */
23 23 public function __construct() {
@@ -22,14 +22,14 @@
22 22 */
23 23 public function __construct() {
24 24 global $wpdb;
25 25
26 - // Don't do anything except if the constant PLL_REMOVE_ALL_DATA is explicitely defined and true.
26 + // Don't do anything except if the constant PLL_REMOVE_ALL_DATA is explicitly defined and true.
27 27 if ( ! defined( 'PLL_REMOVE_ALL_DATA' ) || ! PLL_REMOVE_ALL_DATA ) {
28 28 return;
29 29 }
30 30
31 - // Check if it is a multisite uninstall - if so, run the uninstall function for each blog id
31 + // Check if it is a multisite uninstall - if so, run the uninstall function for each blog id.
32 32 if ( is_multisite() ) {
33 33 foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) {
34 34 switch_to_blog( $blog_id );
35 35 $this->uninstall();
@@ -34,17 +34,15 @@
34 34 switch_to_blog( $blog_id );
35 35 $this->uninstall();
36 36 }
37 37 restore_current_blog();
38 - }
39 - else {
38 + } else {
40 39 $this->uninstall();
41 40 }
42 41 }
43 42
44 43 /**
45 - * Removes ALL plugin data
46 - * only when the relevant option is active
44 + * Removes **all** plugin data.
47 45 *
48 46 * @since 0.5
49 47 */
50 48 public function uninstall() {
@@ -51,38 +49,44 @@
51 49 global $wpdb;
52 50
53 51 do_action( 'pll_uninstall' );
54 52
55 - // Suppress data of the old model < 1.2
56 - // FIXME: to remove when support for v1.1.6 will be dropped
57 - $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb
53 + // We need to register the taxonomies.
54 + $pll_taxonomies = array(
55 + 'language',
56 + 'term_language',
57 + 'post_translations',
58 + 'term_translations',
59 + );
58 60
59 - // Do nothing if the termmeta table does not exists
60 - if ( count( $wpdb->get_results( "SHOW TABLES LIKE '$wpdb->termmeta'" ) ) ) {
61 - $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_translations'" );
62 - $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_language'" );
63 - $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_rtl'" );
64 - $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_translations'" );
65 - }
66 -
67 - // Need to register the taxonomies
68 - $pll_taxonomies = array( 'language', 'term_language', 'post_translations', 'term_translations' );
69 61 foreach ( $pll_taxonomies as $taxonomy ) {
70 - register_taxonomy( $taxonomy, null, array( 'label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false ) );
62 + register_taxonomy(
63 + $taxonomy,
64 + null,
65 + array(
66 + 'label' => false,
67 + 'public' => false,
68 + 'query_var' => false,
69 + 'rewrite' => false,
70 + )
71 + );
71 72 }
72 73
73 - $languages = get_terms( 'language', array( 'hide_empty' => false ) );
74 + $languages = get_terms(
75 + array(
76 + 'taxonomy' => 'language',
77 + 'hide_empty' => false,
78 + )
79 + );
74 80
75 - // Delete users options
76 - foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) {
77 - delete_user_meta( $user_id, 'pll_filter_content' );
78 - delete_user_meta( $user_id, 'pll_dismissed_notices' ); // Legacy meta.
79 - foreach ( $languages as $lang ) {
80 - delete_user_meta( $user_id, 'description_' . $lang->slug );
81 - }
81 + // Delete users options.
82 + delete_metadata( 'user', 0, 'pll_filter_content', '', true );
83 + delete_metadata( 'user', 0, 'pll_dismissed_notices', '', true ); // Legacy meta.
84 + foreach ( $languages as $lang ) {
85 + delete_metadata( 'user', 0, "description_{$lang->slug}", '', true );
82 86 }
83 87
84 - // Delete menu language switchers
88 + // Delete menu language switchers.
85 89 $ids = get_posts(
86 90 array(
87 91 'post_type' => 'nav_menu_item',
88 92 'numberposts' => -1,
@@ -95,16 +99,19 @@
95 99 foreach ( $ids as $id ) {
96 100 wp_delete_post( $id, true );
97 101 }
98 102
99 - // Delete the strings translations ( <1.2 )
100 - // FIXME: to remove when support for v1.1.6 will be dropped
101 - foreach ( $languages as $lang ) {
102 - delete_option( 'polylang_mo' . $lang->term_id );
103 - }
104 -
105 - // Delete the strings translations 1.2+
106 - register_post_type( 'polylang_mo', array( 'rewrite' => false, 'query_var' => false ) );
103 + /*
104 + * Backward compatibility with Polylang < 3.4.
105 + * Delete the legacy strings translations.
106 + */
107 + register_post_type(
108 + 'polylang_mo',
109 + array(
110 + 'rewrite' => false,
111 + 'query_var' => false,
112 + )
113 + );
107 114 $ids = get_posts(
108 115 array(
109 116 'post_type' => 'polylang_mo',
110 117 'post_status' => 'any',
@@ -116,38 +123,71 @@
116 123 foreach ( $ids as $id ) {
117 124 wp_delete_post( $id, true );
118 125 }
119 126
120 - // Delete all what is related to languages and translations
127 + // Delete all what is related to languages and translations.
121 128 $term_ids = array();
122 129 $tt_ids = array();
123 130
124 - foreach ( get_terms( $pll_taxonomies, array( 'hide_empty' => false ) ) as $term ) {
131 + $terms = get_terms(
132 + array(
133 + 'taxonomy' => $pll_taxonomies,
134 + 'hide_empty' => false,
135 + )
136 + );
137 +
138 + foreach ( $terms as $term ) {
125 139 $term_ids[] = (int) $term->term_id;
126 - $tt_ids[] = (int) $term->term_taxonomy_id;
140 + $tt_ids[] = (int) $term->term_taxonomy_id;
127 141 }
128 142
129 143 if ( ! empty( $term_ids ) ) {
130 144 $term_ids = array_unique( $term_ids );
131 - $wpdb->query( "DELETE FROM {$wpdb->terms} WHERE term_id IN ( " . implode( ',', $term_ids ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
132 - $wpdb->query( "DELETE FROM {$wpdb->term_taxonomy} WHERE term_id IN ( " . implode( ',', $term_ids ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
145 + $wpdb->query(
146 + $wpdb->prepare(
147 + sprintf(
148 + "DELETE FROM {$wpdb->terms} WHERE term_id IN (%s)",
149 + implode( ',', array_fill( 0, count( $term_ids ), '%d' ) )
150 + ),
151 + $term_ids
152 + )
153 + );
154 + $wpdb->query(
155 + $wpdb->prepare(
156 + sprintf(
157 + "DELETE FROM {$wpdb->term_taxonomy} WHERE term_id IN (%s)",
158 + implode( ',', array_fill( 0, count( $term_ids ), '%d' ) )
159 + ),
160 + $term_ids
161 + )
162 + );
163 + $wpdb->query(
164 + $wpdb->prepare(
165 + sprintf(
166 + "DELETE FROM {$wpdb->termmeta} WHERE term_id IN (%s) AND meta_key='_pll_strings_translations'",
167 + implode( ',', array_fill( 0, count( $term_ids ), '%d' ) )
168 + ),
169 + $term_ids
170 + )
171 + );
133 172 }
134 173
135 174 if ( ! empty( $tt_ids ) ) {
136 175 $tt_ids = array_unique( $tt_ids );
137 - $wpdb->query( "DELETE FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ( " . implode( ',', $tt_ids ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
176 + $wpdb->query( $wpdb->prepare( sprintf( "DELETE FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN (%s)", implode( ',', array_fill( 0, count( $tt_ids ), '%d' ) ) ), $tt_ids ) );
138 177 }
139 178
140 - // Delete options
179 + // Delete options.
141 180 delete_option( 'polylang' );
142 - delete_option( 'widget_polylang' ); // Automatically created by WP
143 - delete_option( 'polylang_wpml_strings' ); // Strings registered with icl_register_string
181 + delete_option( 'widget_polylang' ); // Automatically created by WP.
182 + delete_option( 'polylang_wpml_strings' ); // Strings registered with icl_register_string.
144 183 delete_option( 'polylang_licenses' );
145 184 delete_option( 'pll_dismissed_notices' );
185 + delete_option( 'pll_language_from_content_available' );
186 + delete_option( 'pll_language_taxonomies' );
146 187
147 - // Delete transients
148 - delete_transient( 'pll_languages_list' );
149 - delete_transient( 'pll_upgrade_1_4' );
188 + // Delete transients.
189 + delete_option( '_transient_pll_languages_list' ); // Force deletion of the transient from the options table even in case external object cache is used.
150 190 }
151 191 }
152 192
153 193 new PLL_Uninstall();