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

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