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 +80 -110 2.71.5 View file →
@@ -1,161 +1,131 @@
1 1 <?php
2 2
3 -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { // If uninstall not called from WordPress exit
4 - exit;
5 -}
3 +//if uninstall not called from WordPress exit
4 +if (!defined('WP_UNINSTALL_PLUGIN'))
5 + exit();
6 6
7 -/**
8 - * Manages Polylang uninstallation
9 - * 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
10 10 *
11 11 * @since 0.5
12 12 */
13 13 class PLL_Uninstall {
14 14
15 - /**
16 - * Constructor: manages uninstall for multisite
15 + /*
16 + * constructor: manages uninstall for multisite
17 17 *
18 18 * @since 0.5
19 19 */
20 - public function __construct() {
20 + function __construct() {
21 21 global $wpdb;
22 22
23 - // Don't do anything except if the constant PLL_REMOVE_ALL_DATA is explicitely defined and true.
24 - if ( ! defined( 'PLL_REMOVE_ALL_DATA' ) || ! PLL_REMOVE_ALL_DATA ) {
25 - return;
26 - }
27 -
28 - // Check if it is a multisite uninstall - if so, run the uninstall function for each blog id
29 - if ( is_multisite() ) {
30 - foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) {
31 - 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);
32 27 $this->uninstall();
33 28 }
34 29 restore_current_blog();
35 30 }
36 - else {
31 + else
37 32 $this->uninstall();
38 - }
39 33 }
40 34
41 - /**
42 - * Removes ALL plugin data
43 - * only when the relevant option is active
35 + /*
36 + * removes ALL plugin data
44 37 *
45 38 * @since 0.5
46 39 */
47 - 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
48 43 global $wpdb;
44 + $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb
49 45
50 - // Executes each module's uninstall script, if it exists
51 - $pll_modules_dir = dirname( __FILE__ ) . '/modules';
52 - opendir( $pll_modules_dir );
53 - while ( ( $module = readdir() ) != false ) {
54 - if ( substr( $module, 0, 1 ) !== '.' ) {
55 - $uninstall_script = $pll_modules_dir . '/' . $module . '/uninstall.php';
56 - if ( file_exists( $uninstall_script ) ) {
57 - require $uninstall_script; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
58 - }
59 - }
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'");
52 +
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;");
60 56 }
61 - closedir();
62 57
63 - // Suppress data of the old model < 1.2
64 - // FIXME: to remove when support for v1.1.6 will be dropped
65 - $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb
66 58
67 - // Do nothing if the termmeta table does not exists
68 - if ( count( $wpdb->get_results( "SHOW TABLES LIKE '$wpdb->termmeta'" ) ) ) {
69 - $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_translations'" );
70 - $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_language'" );
71 - $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_rtl'" );
72 - $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_translations'" );
73 - }
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));
74 63
75 - // Need to register the taxonomies
76 - $pll_taxonomies = array( 'language', 'term_language', 'post_translations', 'term_translations' );
77 - foreach ( $pll_taxonomies as $taxonomy ) {
78 - register_taxonomy( $taxonomy, null, array( 'label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false ) );
79 - }
80 64
81 - $languages = get_terms( 'language', array( 'hide_empty' => false ) );
65 + $languages = get_terms('language', array('hide_empty'=>false));
82 66
83 - // Delete users options
84 - foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) {
85 - delete_user_meta( $user_id, 'pll_filter_content' );
86 - delete_user_meta( $user_id, 'pll_dismissed_notices' ); // Legacy meta.
87 - foreach ( $languages as $lang ) {
88 - delete_user_meta( $user_id, 'description_' . $lang->slug );
89 - }
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);
90 73 }
91 74
92 - // Delete menu language switchers
93 - $ids = get_posts(
94 - array(
95 - 'post_type' => 'nav_menu_item',
96 - 'numberposts' => -1,
97 - 'nopaging' => true,
98 - 'fields' => 'ids',
99 - 'meta_key' => '_pll_menu_item',
100 - )
101 - );
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 + ));
102 83
103 - foreach ( $ids as $id ) {
104 - wp_delete_post( $id, true );
105 - }
84 + foreach ($ids as $id)
85 + wp_delete_post($id, true);
106 86
107 - // Delete the strings translations ( <1.2 )
87 + // delete the strings translations (<1.2)
108 88 // FIXME: to remove when support for v1.1.6 will be dropped
109 - foreach ( $languages as $lang ) {
110 - delete_option( 'polylang_mo' . $lang->term_id );
111 - }
89 + foreach ($languages as $lang)
90 + delete_option('polylang_mo'.$lang->term_id);
112 91
113 - // Delete the strings translations 1.2+
114 - register_post_type( 'polylang_mo', array( 'rewrite' => false, 'query_var' => false ) );
115 - $ids = get_posts(
116 - array(
117 - 'post_type' => 'polylang_mo',
118 - 'post_status' => 'any',
119 - 'numberposts' => -1,
120 - 'nopaging' => true,
121 - 'fields' => 'ids',
122 - )
123 - );
124 - foreach ( $ids as $id ) {
125 - wp_delete_post( $id, true );
126 - }
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);
127 102
128 - // Delete all what is related to languages and translations
129 - $term_ids = array();
130 - $tt_ids = array();
131 -
132 - 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) {
133 105 $term_ids[] = (int) $term->term_id;
134 106 $tt_ids[] = (int) $term->term_taxonomy_id;
135 107 }
136 108
137 - if ( ! empty( $term_ids ) ) {
138 - $term_ids = array_unique( $term_ids );
139 - $wpdb->query( "DELETE FROM {$wpdb->terms} WHERE term_id IN ( " . implode( ',', $term_ids ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
140 - $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) . ")");
141 113 }
142 114
143 - if ( ! empty( $tt_ids ) ) {
144 - $tt_ids = array_unique( $tt_ids );
145 - $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) . ")");
146 118 }
147 119
148 - // Delete options
149 - delete_option( 'polylang' );
150 - delete_option( 'widget_polylang' ); // Automatically created by WP
151 - delete_option( 'polylang_wpml_strings' ); // Strings registered with icl_register_string
152 - delete_option( 'polylang_licenses' );
153 - 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
154 124
155 - // Delete transients
156 - delete_transient( 'pll_languages_list' );
157 - delete_transient( 'pll_upgrade_1_4' );
125 + //delete transients
126 + delete_transient('pll_languages_list');
127 + delete_transient('pll_upgrade_1_4');
158 128 }
159 129 }
160 130
161 131 new PLL_Uninstall();