PluginProbe
Polylang / 1.5.5
Polylang v1.5.5
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
polylang / uninstall.php

uninstall.php in Polylang 1.5.5, at uninstall.php

132 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 //if uninstall not called from WordPress exit
4 if (!defined('WP_UNINSTALL_PLUGIN'))
5 exit();
6
7 /*
8 * manages Polylang uninstallation
9 * the goal is to remove ALL Polylang related data in db
10 *
11 * @since 0.5
12 */
13 class PLL_Uninstall {
14
15 /*
16 * constructor: manages uninstall for multisite
17 *
18 * @since 0.5
19 */
20 function __construct() {
21 global $wpdb;
22
23 // check if it is a multisite uninstall - if so, run the uninstall function for each blog id
24 if (is_multisite()) {
25 foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs") as $blog_id) {
26 switch_to_blog($blog_id);
27 $this->uninstall();
28 }
29 restore_current_blog();
30 }
31 else
32 $this->uninstall();
33 }
34
35 /*
36 * removes ALL plugin data
37 *
38 * @since 0.5
39 */
40 function uninstall() {
41 // suppress data of the old model < 1.2
42 // FIXME: to remove when support for v1.1.6 will be dropped
43 global $wpdb;
44 $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb
45
46 // do nothing if the termmeta table does not exists
47 if (count($wpdb->get_results("SHOW TABLES LIKE '$wpdb->termmeta'"))) {
48 $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = '_translations'");
49 $wpdb->query("DELETE FROM $wpdb->termmeta WHERE meta_key = '_language'");
50 $wpdb->query("DELETE FROM $wpdb->termmeta WHERE meta_key = '_rtl'");
51 $wpdb->query("DELETE FROM $wpdb->termmeta WHERE meta_key = '_translations'");
52
53 // delete the termmeta table only if it is empty as other plugins may use it
54 if (!$wpdb->get_var("SELECT COUNT(*) FROM $wpdb->termmeta;"))
55 $wpdb->query("DROP TABLE $wpdb->termmeta;");
56 }
57
58
59 // need to register the taxonomies
60 $pll_taxonomies = array('language', 'term_language', 'post_translations', 'term_translations');
61 foreach ($pll_taxonomies as $taxonomy)
62 register_taxonomy($taxonomy, null , array('label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false));
63
64
65 $languages = get_terms('language', array('hide_empty'=>false));
66
67 // delete users options
68 foreach (get_users(array('fields' => 'ID')) as $user_id) {
69 delete_user_meta($user_id, 'user_lang');
70 delete_user_meta($user_id, 'pll_filter_content');
71 foreach ($languages as $lang)
72 delete_user_meta($user_id, 'description_'.$lang->slug);
73 }
74
75 // delete menu language switchers
76 $ids = get_posts(array(
77 'post_type' => 'nav_menu_item',
78 'numberposts' => -1,
79 'nopaging' => true,
80 'fields' => 'ids',
81 'meta_key' => '_pll_menu_item'
82 ));
83
84 foreach ($ids as $id)
85 wp_delete_post($id, true);
86
87 // delete the strings translations (<1.2)
88 // FIXME: to remove when support for v1.1.6 will be dropped
89 foreach ($languages as $lang)
90 delete_option('polylang_mo'.$lang->term_id);
91
92 // delete the strings translations 1.2+
93 register_post_type('polylang_mo', array('rewrite' => false, 'query_var' => false));
94 $ids = get_posts(array(
95 'post_type' => 'polylang_mo',
96 'numberposts' => -1,
97 'nopaging' => true,
98 'fields' => 'ids',
99 ));
100 foreach ($ids as $id)
101 wp_delete_post($id, true);
102
103 // delete all what is related to languages and translations
104 foreach (get_terms($pll_taxonomies, array('hide_empty'=>false)) as $term) {
105 $term_ids[] = (int) $term->term_id;
106 $tt_ids[] = (int) $term->term_taxonomy_id;
107 }
108
109 if (!empty($term_ids)) {
110 $term_ids = array_unique($term_ids);
111 $wpdb->query("DELETE FROM $wpdb->terms WHERE term_id IN (" . implode(',', $term_ids) . ")");
112 $wpdb->query("DELETE FROM $wpdb->term_taxonomy WHERE term_id IN (" . implode(',', $term_ids) . ")");
113 }
114
115 if (!empty($tt_ids)) {
116 $tt_ids = array_unique($tt_ids);
117 $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . implode(',', $tt_ids) . ")");
118 }
119
120 // delete options
121 delete_option('polylang');
122 delete_option('widget_polylang'); // automatically created by WP
123 delete_option('polylang_wpml_strings'); // strings registered with icl_register_string
124
125 //delete transients
126 delete_transient('pll_languages_list');
127 delete_transient('pll_upgrade_1_4');
128 }
129 }
130
131 new PLL_Uninstall();
132