PluginProbe
Falang multilanguage for WordPress / trunk
Falang multilanguage for WordPress vtrunk
1.4.5 1.4.4 1.4.3 1.2.2 1.2.3 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.19 1.3.2 1.3.20 1.3.21 1.3.22 1.3.23 1.3.24 1.3.25 1.3.26 All 91 releases
falang / uninstall.php

uninstall.php in Falang multilanguage for WordPress trunk, at uninstall.php

188 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Fired when the plugin is uninstalled.
5 *
6 * When populating this file, consider the following flow
7 * of control:
8 *
9 * - This method should be static
10 * - Check if the $_REQUEST content actually is the plugin name
11 * - Run an admin referrer check to make sure it goes through authentication
12 * - Verify the output of $_GET makes sense
13 * - Repeat with other user roles. Best directly by using the links/query string parameters.
14 * - Repeat things for multisite. Once for a single site in the network, once sitewide.
15 *
16 * This file may be updated more in future version of the Boilerplate; however, this is the
17 * general skeleton and outline for how the file should work.
18 *
19 * For more information, see the following discussion:
20 * https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
21 *
22 * @link www.faboba.com
23 * @since 1.0.0
24 *
25 * @package Falang
26 */
27
28 // If uninstall not called from WordPress, then exit.
29 if (!defined('WP_UNINSTALL_PLUGIN')) {
30 exit;
31 }
32
33 /**
34 * Manages Falang uninstallation
35 * The goal is to remove ALL Falang related data in db if set to true
36 *
37 * @since 1.0
38 */
39 class Falang_Uninstall
40 {
41
42 /**
43 * Constructor: manages uninstall for multisite
44 *
45 * @since 0.5
46 */
47 public function __construct()
48 {
49 $this->uninstall();
50 }
51
52 /**
53 * Removes ALL plugin data
54 * only when the relevant option is active
55 *
56 * @since 0.5
57 */
58 public function uninstall()
59 {
60 global $wpdb;
61
62 $delete_trans = $this->get_option('delete_trans_on_uninstall', false);
63
64 if (!$delete_trans) {
65 return;
66 }
67
68 // Need to register the taxonomies
69 $falang_taxonomies = array('language', 'term_language');
70 foreach ($falang_taxonomies as $taxonomy) {
71 register_taxonomy($taxonomy, null, array('label' => false,
72 'public' => false,
73 'query_var' => false,
74 'rewrite' => false
75 ));
76 }
77
78 $languages = get_terms('language', array('hide_empty' => false));
79
80 // Delete the strings translations 1.2+
81 register_post_type('falang_mo', array('rewrite' => false, 'query_var' => false));
82 $ids = get_posts(
83 array(
84 'post_type' => 'falang_mo',
85 'post_status' => 'any',
86 'numberposts' => -1,
87 'nopaging' => true,
88 'fields' => 'ids',
89 )
90 );
91 foreach ($ids as $id) {
92 wp_delete_post($id, true);
93 }
94
95 foreach ($languages as $language) {
96 //local is in description
97 $description = maybe_unserialize($language->description);
98 foreach ($description as $prop => $value) {
99 $language->$prop = $value;
100 }
101
102 //check $prefix length can be only 2 caracteres
103 if (strlen($language->locale) < 2) {
104 continue;
105 }
106
107 //see create_prefix from Falang_Core
108 $prefix = '_' . $language->locale . '_';
109
110 //delete post meta
111 $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE meta_key like ( '" . $prefix . "%')"); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
112
113 //delete post locale
114 $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE meta_key = '_locale' AND meta_value = '" . $prefix . "%'"); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
115
116 //delete termmeta
117 // Do nothing if the termmeta table does not exists
118 if (count($wpdb->get_results("SHOW TABLES LIKE '$wpdb->termmeta'"))) {
119 $wpdb->query("DELETE FROM {$wpdb->termmeta} WHERE meta_key like ( '" . $prefix . "%')"); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
120
121 }
122 }
123
124 // Delete all what is related to languages and translations
125 foreach (get_terms($falang_taxonomies, array('hide_empty' => false)) as $term) {
126 $term_ids[] = (int)$term->term_id;
127 $tt_ids[] = (int)$term->term_taxonomy_id;
128 }
129
130 if (!empty($term_ids)) {
131 $term_ids = array_unique($term_ids);
132 $wpdb->query("DELETE FROM {$wpdb->terms} WHERE term_id IN ( " . implode(',', $term_ids) . ' )'); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
133 $wpdb->query("DELETE FROM {$wpdb->term_taxonomy} WHERE term_id IN ( " . implode(',', $term_ids) . ' )'); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
134 }
135
136 if (!empty($tt_ids)) {
137 $tt_ids = array_unique($tt_ids);
138 $wpdb->query("DELETE FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ( " . implode(',', $tt_ids) . ' )'); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared
139 }
140
141 // Delete options
142 delete_option('falang');
143 delete_option('widget_falang'); // Automatically created by WP
144 delete_option('falang_wpml_strings'); // Strings registered with icl_register_string
145 delete_option('falang_dismissed_notices');//delete dismissed notices options
146
147
148 }
149
150 /**
151 * Get option
152 *
153 * @param string $option_name . Option name
154 * @param mixed $default . Default value if option does not exist
155 * @return mixed
156 *
157 * @from 1.4.7
158 */
159 public function get_option($option_name, $default = false)
160 {
161 $options = get_option('falang');
162 if (isset($options[$option_name])) {
163
164 return $options[$option_name];
165
166 }
167
168 return $default;
169 }
170
171 /**
172 * Get prefix for translation meta keys
173 *
174 * @from 1.0
175 *
176 * @param string $language_locale
177 * @return string
178 */
179 public function get_prefix($locale)
180 {
181
182 return '_' . $locale . '_';
183
184 }
185 }
186
187 new Falang_Uninstall();
188