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

69 lines 2.1 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 register_taxonomy('language', get_post_types(array('show_ui' => true)), array('label' => false, 'query_var'=>'lang')); // need to register the language taxonomy
25
26 $languages = get_terms('language', array('hide_empty'=>false));
27
28 $ids = get_posts(array('numberposts'=> -1, 'fields' => 'ids', 'post_type'=>'any', 'post_status'=>'any'));
29 foreach ($ids as $id) {
30 foreach ($languages as $lang)
31 delete_post_meta($id, '_lang-'.$lang->slug); //FIXME before 0.5
32
33 delete_post_meta($id, '_translations'); // V0.5+
34 }
35
36 $ids = get_terms(get_taxonomies(array('show_ui'=>true)), array('get'=>'all', 'fields'=>'ids'));
37 foreach ($ids as $id) {
38 foreach ($languages as $lang)
39 delete_metadata('term', $id, '_lang-'.$lang->slug); //FIXME before 0.5
40
41 delete_metadata('term', $id, '_translations'); // V0.5+
42 delete_metadata('term', $id, '_language');
43 }
44
45 // finally delete languages
46 foreach ($languages as $lang)
47 wp_delete_term($lang->term_id, 'language');
48
49 // delete the termmeta table only if it is empty as other plugins may use it
50 $table = $wpdb->termmeta;
51 $count = $wpdb->get_var("SELECT COUNT(*) FROM $table;");
52 if (!$count) {
53 $wpdb->query("DROP TABLE $table;");
54 unset($wpdb->termmeta);
55 }
56
57 // delete options
58 delete_option('polylang');
59 delete_option('polylang_nav_menus');
60 delete_option('polylang_widgets');
61 delete_option('polylang_widget'); // automatically created by WP
62 }
63 }
64
65 if (class_exists("Polylang_Uninstall"))
66 new Polylang_Uninstall();
67
68 ?>
69