PluginProbe
Polylang / 1.4
Polylang v1.4
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.4, at uninstall.php

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