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

80 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Polylang_Uninstall {
4
5 function __construct() {
6 global $wpdb;
7
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("SELECT blog_id FROM $wpdb->blogs") as $blog_id) {
11 switch_to_blog($blog_id);
12 $this->uninstall();
13 }
14 restore_current_blog();
15 }
16 else
17 $this->uninstall();
18 }
19
20 // removes ALL plugin data (languages, translation, and the termmeta table if empty
21 function uninstall() {
22 global $wpdb;
23 $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb
24
25 // need to register the language taxonomy
26 register_taxonomy('language', apply_filters('pll_get_post_types', get_post_types(array('show_ui' => true))),
27 array('label' => false, 'query_var'=>'lang'));
28
29 $languages = get_terms('language', array('hide_empty'=>false));
30
31 // delete users options
32 foreach (get_users(array('fields' => 'ID')) as $user_id) {
33 delete_user_meta($user_id, 'user_lang');
34 delete_user_meta($user_id, 'pll_filter_content');
35 foreach ($languages as $lang)
36 delete_user_meta($user_id, 'description_'.$lang->slug);
37 }
38
39 // delete posts translations
40 $ids = get_posts(array(
41 'numberposts'=> -1,
42 'fields' => 'ids',
43 'meta_key'=>'_translations',
44 'post_type'=>'any',
45 'post_status'=>'any'
46 ));
47
48 foreach ($ids as $id)
49 delete_post_meta($id, '_translations');
50
51 // delete terms translations
52 $ids = get_terms(apply_filters('pll_get_taxonomies', get_taxonomies(array('show_ui'=>true))), array('get'=>'all', 'fields'=>'ids'));
53 foreach ($ids as $id) {
54 delete_metadata('term', $id, '_translations');
55 delete_metadata('term', $id, '_language');
56 }
57
58 foreach ($languages as $lang) {
59 delete_metadata('term', $lang->term_id, '_rtl'); // delete rtl meta
60 delete_option('polylang_mo'.$lang->term_id); // delete the string translations
61 wp_delete_term($lang->term_id, 'language'); // finally delete languages
62 }
63
64 // delete the termmeta table only if it is empty as other plugins may use it
65 $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->termmeta;");
66 if (!$count) {
67 $wpdb->query("DROP TABLE $wpdb->termmeta;");
68 unset($wpdb->termmeta);
69 }
70
71 // delete options
72 delete_option('polylang');
73 delete_option('polylang_nav_menus');
74 delete_option('polylang_widgets');
75 delete_option('widget_polylang'); // automatically created by WP
76 }
77 }
78
79 new Polylang_Uninstall();
80