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

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