PluginProbe
Polylang / 2.0.3
Polylang v2.0.3
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 +46 -58 2.92.0.3 View file →
@@ -1,16 +1,14 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { // If uninstall not called from WordPress exit
7 - exit;
3 +// if uninstall not called from WordPress exit
4 +if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
5 + exit();
8 6 }
9 7
10 8 /**
11 - * Manages Polylang uninstallation
12 - * The goal is to remove ALL Polylang related data in db
9 + * manages Polylang uninstallation
10 + * the goal is to remove ALL Polylang related data in db
13 11 *
14 12 * @since 0.5
15 13 */
16 14 class PLL_Uninstall {
@@ -15,21 +13,16 @@
15 13 */
16 14 class PLL_Uninstall {
17 15
18 16 /**
19 - * Constructor: manages uninstall for multisite
17 + * constructor: manages uninstall for multisite
20 18 *
21 19 * @since 0.5
22 20 */
23 - public function __construct() {
21 + function __construct() {
24 22 global $wpdb;
25 23
26 - // Don't do anything except if the constant PLL_REMOVE_ALL_DATA is explicitely defined and true.
27 - if ( ! defined( 'PLL_REMOVE_ALL_DATA' ) || ! PLL_REMOVE_ALL_DATA ) {
28 - return;
29 - }
30 -
31 - // Check if it is a multisite uninstall - if so, run the uninstall function for each blog id
24 + // check if it is a multisite uninstall - if so, run the uninstall function for each blog id
32 25 if ( is_multisite() ) {
33 26 foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) {
34 27 switch_to_blog( $blog_id );
35 28 $this->uninstall();
@@ -41,23 +34,26 @@
41 34 }
42 35 }
43 36
44 37 /**
45 - * Removes ALL plugin data
38 + * removes ALL plugin data
46 39 * only when the relevant option is active
47 40 *
48 41 * @since 0.5
49 42 */
50 - public function uninstall() {
51 - global $wpdb;
43 + function uninstall() {
44 + $options = get_option( 'polylang' );
52 45
53 - do_action( 'pll_uninstall' );
46 + if ( empty( $options['uninstall'] ) ) {
47 + return;
48 + }
54 49
55 - // Suppress data of the old model < 1.2
50 + // suppress data of the old model < 1.2
56 51 // FIXME: to remove when support for v1.1.6 will be dropped
52 + global $wpdb;
57 53 $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb
58 54
59 - // Do nothing if the termmeta table does not exists
55 + // do nothing if the termmeta table does not exists
60 56 if ( count( $wpdb->get_results( "SHOW TABLES LIKE '$wpdb->termmeta'" ) ) ) {
61 57 $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_translations'" );
62 58 $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_language'" );
63 59 $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_rtl'" );
@@ -63,65 +59,57 @@
63 59 $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_rtl'" );
64 60 $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_translations'" );
65 61 }
66 62
67 - // Need to register the taxonomies
63 + // need to register the taxonomies
68 64 $pll_taxonomies = array( 'language', 'term_language', 'post_translations', 'term_translations' );
69 65 foreach ( $pll_taxonomies as $taxonomy ) {
70 - register_taxonomy( $taxonomy, null, array( 'label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false ) );
66 + register_taxonomy( $taxonomy, null , array( 'label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false ) );
71 67 }
72 68
73 69 $languages = get_terms( 'language', array( 'hide_empty' => false ) );
74 70
75 - // Delete users options
71 + // delete users options
76 72 foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) {
73 + delete_user_meta( $user_id, 'user_lang' );
77 74 delete_user_meta( $user_id, 'pll_filter_content' );
78 - delete_user_meta( $user_id, 'pll_dismissed_notices' ); // Legacy meta.
79 75 foreach ( $languages as $lang ) {
80 76 delete_user_meta( $user_id, 'description_' . $lang->slug );
81 77 }
82 78 }
83 79
84 - // Delete menu language switchers
85 - $ids = get_posts(
86 - array(
87 - 'post_type' => 'nav_menu_item',
88 - 'numberposts' => -1,
89 - 'nopaging' => true,
90 - 'fields' => 'ids',
91 - 'meta_key' => '_pll_menu_item',
92 - )
93 - );
80 + // delete menu language switchers
81 + $ids = get_posts( array(
82 + 'post_type' => 'nav_menu_item',
83 + 'numberposts' => -1,
84 + 'nopaging' => true,
85 + 'fields' => 'ids',
86 + 'meta_key' => '_pll_menu_item',
87 + ) );
94 88
95 89 foreach ( $ids as $id ) {
96 90 wp_delete_post( $id, true );
97 91 }
98 92
99 - // Delete the strings translations ( <1.2 )
93 + // delete the strings translations ( <1.2 )
100 94 // FIXME: to remove when support for v1.1.6 will be dropped
101 95 foreach ( $languages as $lang ) {
102 96 delete_option( 'polylang_mo' . $lang->term_id );
103 97 }
104 98
105 - // Delete the strings translations 1.2+
99 + // delete the strings translations 1.2+
106 100 register_post_type( 'polylang_mo', array( 'rewrite' => false, 'query_var' => false ) );
107 - $ids = get_posts(
108 - array(
109 - 'post_type' => 'polylang_mo',
110 - 'post_status' => 'any',
111 - 'numberposts' => -1,
112 - 'nopaging' => true,
113 - 'fields' => 'ids',
114 - )
115 - );
101 + $ids = get_posts( array(
102 + 'post_type' => 'polylang_mo',
103 + 'numberposts' => -1,
104 + 'nopaging' => true,
105 + 'fields' => 'ids',
106 + ) );
116 107 foreach ( $ids as $id ) {
117 108 wp_delete_post( $id, true );
118 109 }
119 110
120 - // Delete all what is related to languages and translations
121 - $term_ids = array();
122 - $tt_ids = array();
123 -
111 + // delete all what is related to languages and translations
124 112 foreach ( get_terms( $pll_taxonomies, array( 'hide_empty' => false ) ) as $term ) {
125 113 $term_ids[] = (int) $term->term_id;
126 114 $tt_ids[] = (int) $term->term_taxonomy_id;
127 115 }
@@ -127,27 +115,27 @@
127 115 }
128 116
129 117 if ( ! empty( $term_ids ) ) {
130 118 $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
119 + $wpdb->query( "DELETE FROM $wpdb->terms WHERE term_id IN ( " . implode( ',', $term_ids ) . " )" );
120 + $wpdb->query( "DELETE FROM $wpdb->term_taxonomy WHERE term_id IN ( " . implode( ',', $term_ids ) . " )" );
133 121 }
134 122
135 123 if ( ! empty( $tt_ids ) ) {
136 124 $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
125 + $wpdb->query( "DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ( " . implode( ',', $tt_ids ) . " )" );
138 126 }
139 127
140 - // Delete options
128 + // delete options
141 129 delete_option( 'polylang' );
142 - delete_option( 'widget_polylang' ); // Automatically created by WP
143 - delete_option( 'polylang_wpml_strings' ); // Strings registered with icl_register_string
130 + delete_option( 'widget_polylang' ); // automatically created by WP
131 + delete_option( 'polylang_wpml_strings' ); // strings registered with icl_register_string
144 132 delete_option( 'polylang_licenses' );
145 - delete_option( 'pll_dismissed_notices' );
146 133
147 - // Delete transients
134 + //delete transients
148 135 delete_transient( 'pll_languages_list' );
149 136 delete_transient( 'pll_upgrade_1_4' );
137 + delete_transient( 'pll_translated_slugs' );
150 138 }
151 139 }
152 140
153 141 new PLL_Uninstall();