PluginProbe
Polylang / 0.7
Polylang v0.7
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 +41 -110 3.00.7 View file →
@@ -1,134 +1,65 @@
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;
8 -}
3 +class Polylang_Uninstall {
9 4
10 -/**
11 - * Manages Polylang uninstallation
12 - * The goal is to remove ALL Polylang related data in db
13 - *
14 - * @since 0.5
15 - */
16 -class PLL_Uninstall {
17 -
18 - /**
19 - * Constructor: manages uninstall for multisite
20 - *
21 - * @since 0.5
22 - */
23 - public function __construct() {
5 + function __construct() {
24 6 global $wpdb;
25 7
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
32 - if ( is_multisite() ) {
33 - foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) {
34 - switch_to_blog( $blog_id );
8 + // check if it is a multisite uninstall - if so, run the uninstall function for each blog id
9 + if (is_multisite()) {
10 + foreach ($wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs")) as $blog_id) {
11 + switch_to_blog($blog_id);
35 12 $this->uninstall();
36 13 }
37 14 restore_current_blog();
38 15 }
39 - else {
16 + else
40 17 $this->uninstall();
41 - }
42 18 }
43 19
44 - /**
45 - * Removes ALL plugin data
46 - * only when the relevant option is active
47 - *
48 - * @since 0.5
49 - */
50 - public function uninstall() {
20 + // removes ALL plugin data (languages, translation, and the termmeta table if empty
21 + function uninstall() {
51 22 global $wpdb;
23 + $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb
24 + register_taxonomy('language', get_post_types(array('show_ui' => true)), array('label' => false, 'query_var'=>'lang')); // need to register the language taxonomy
52 25
53 - do_action( 'pll_uninstall' );
26 + $languages = get_terms('language', array('hide_empty'=>false));
54 27
55 - // Need to register the taxonomies
56 - $pll_taxonomies = array( 'language', 'term_language', 'post_translations', 'term_translations' );
57 - foreach ( $pll_taxonomies as $taxonomy ) {
58 - register_taxonomy( $taxonomy, null, array( 'label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false ) );
59 - }
28 + // delete posts translations
29 + $ids = get_posts(array('numberposts'=> -1, 'fields' => 'ids', 'meta_key'=>'_translations', 'post_type'=>'any', 'post_status'=>'any'));
30 + foreach ($ids as $id)
31 + delete_post_meta($id, '_translations');
60 32
61 - $languages = get_terms( 'language', array( 'hide_empty' => false ) );
62 -
63 - // Delete users options
64 - foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) {
65 - delete_user_meta( $user_id, 'pll_filter_content' );
66 - delete_user_meta( $user_id, 'pll_dismissed_notices' ); // Legacy meta.
67 - foreach ( $languages as $lang ) {
68 - delete_user_meta( $user_id, 'description_' . $lang->slug );
69 - }
33 + // delete terms translations
34 + $ids = get_terms(get_taxonomies(array('show_ui'=>true)), array('get'=>'all', 'fields'=>'ids'));
35 + foreach ($ids as $id) {
36 + delete_metadata('term', $id, '_translations');
37 + delete_metadata('term', $id, '_language');
70 38 }
71 -
72 - // 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 - );
82 -
83 - foreach ( $ids as $id ) {
84 - wp_delete_post( $id, true );
39 +
40 + foreach ($languages as $lang) {
41 + delete_metadata('term', $lang->term_id, '_rtl'); // delete rtl meta
42 + delete_option('polylang_mo'.$lang->term_id); // delete the string translations
43 + wp_delete_term($lang->term_id, 'language'); // finally delete languages
85 44 }
86 45
87 - // Delete the strings translations.
88 - 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 - );
98 - foreach ( $ids as $id ) {
99 - wp_delete_post( $id, true );
46 + // delete the termmeta table only if it is empty as other plugins may use it
47 + $table = $wpdb->termmeta;
48 + $count = $wpdb->get_var("SELECT COUNT(*) FROM $table;");
49 + if (!$count) {
50 + $wpdb->query($wpdb->prepare("DROP TABLE $table;"));
51 + unset($wpdb->termmeta);
100 52 }
101 53
102 - // Delete all what is related to languages and translations
103 - $term_ids = array();
104 - $tt_ids = array();
105 -
106 - foreach ( get_terms( $pll_taxonomies, array( 'hide_empty' => false ) ) as $term ) {
107 - $term_ids[] = (int) $term->term_id;
108 - $tt_ids[] = (int) $term->term_taxonomy_id;
109 - }
110 -
111 - if ( ! empty( $term_ids ) ) {
112 - $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
115 - }
116 -
117 - if ( ! empty( $tt_ids ) ) {
118 - $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
120 - }
121 -
122 - // Delete options
123 - delete_option( 'polylang' );
124 - delete_option( 'widget_polylang' ); // Automatically created by WP
125 - delete_option( 'polylang_wpml_strings' ); // Strings registered with icl_register_string
126 - delete_option( 'polylang_licenses' );
127 - delete_option( 'pll_dismissed_notices' );
128 -
129 - // Delete transients
130 - delete_transient( 'pll_languages_list' );
54 + // delete options
55 + delete_option('polylang');
56 + delete_option('polylang_nav_menus');
57 + delete_option('polylang_widgets');
58 + delete_option('polylang_widget'); // automatically created by WP
131 59 }
132 60 }
133 61
134 -new PLL_Uninstall();
62 +if (class_exists("Polylang_Uninstall"))
63 + new Polylang_Uninstall();
64 +
65 +?>