PluginProbe
Polylang / 2.5.4
Polylang v2.5.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 2.5.4, at uninstall.php

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