PluginProbe
Polylang / 0.9
Polylang v0.9
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 0.9, at uninstall.php

77 lines 2.5 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($wpdb->prepare("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))), array('label' => false, 'query_var'=>'lang'));
27
28 $languages = get_terms('language', array('hide_empty'=>false));
29
30 // delete users options
31 foreach (get_users(array('fields' => 'ID')) as $user_id) {
32 delete_user_meta($user_id, 'user_lang');
33 delete_user_meta($user_id, 'pll_filter_content');
34 foreach ($languages as $lang)
35 delete_user_meta($user_id, 'description_'.$lang->slug);
36 }
37
38 // delete posts translations
39 $ids = get_posts(array('numberposts'=> -1, 'fields' => 'ids', 'meta_key'=>'_translations', 'post_type'=>'any', 'post_status'=>'any'));
40 foreach ($ids as $id)
41 delete_post_meta($id, '_translations');
42
43 // delete terms translations
44 $ids = get_terms(apply_filters('pll_get_taxonomies', get_taxonomies(array('show_ui'=>true))), array('get'=>'all', 'fields'=>'ids'));
45 foreach ($ids as $id) {
46 delete_metadata('term', $id, '_translations');
47 delete_metadata('term', $id, '_language');
48 }
49
50 foreach ($languages as $lang) {
51 delete_metadata('term', $lang->term_id, '_rtl'); // delete rtl meta
52 delete_option('polylang_mo'.$lang->term_id); // delete the string translations
53 wp_delete_term($lang->term_id, 'language'); // finally delete languages
54 }
55
56 // delete the termmeta table only if it is empty as other plugins may use it
57 $table = $wpdb->termmeta;
58 $count = $wpdb->get_var("SELECT COUNT(*) FROM $table;");
59 if (!$count) {
60 $wpdb->query($wpdb->prepare("DROP TABLE $table;"));
61 unset($wpdb->termmeta);
62 }
63
64
65 // delete options
66 delete_option('polylang');
67 delete_option('polylang_nav_menus');
68 delete_option('polylang_widgets');
69 delete_option('widget_polylang'); // automatically created by WP
70 }
71 }
72
73 if (class_exists("Polylang_Uninstall"))
74 new Polylang_Uninstall();
75
76 ?>
77