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