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