| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { // If uninstall not called from WordPress exit |
| 4 | - exit; | |
| 4 | + exit(); | |
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * Manages Polylang uninstallation |
| @@ -19,13 +19,8 @@ | ||
| 19 | 19 | */ |
| 20 | 20 | public 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 | 23 | // Check if it is a multisite uninstall - if so, run the uninstall function for each blog id |
| 29 | 24 | if ( is_multisite() ) { |
| 30 | 25 | foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) { |
| 31 | 26 | switch_to_blog( $blog_id ); |
| @@ -44,25 +39,17 @@ | ||
| 44 | 39 | * |
| 45 | 40 | * @since 0.5 |
| 46 | 41 | */ |
| 47 | 42 | public function uninstall() { |
| 48 | - global $wpdb; | |
| 43 | + $options = get_option( 'polylang' ); | |
| 49 | 44 | |
| 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 | - } | |
| 45 | + if ( empty( $options['uninstall'] ) ) { | |
| 46 | + return; | |
| 60 | 47 | } |
| 61 | - closedir(); | |
| 62 | 48 | |
| 63 | 49 | // Suppress data of the old model < 1.2 |
| 64 | 50 | // FIXME: to remove when support for v1.1.6 will be dropped |
| 51 | + global $wpdb; | |
| 65 | 52 | $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb |
| 66 | 53 | |
| 67 | 54 | // Do nothing if the termmeta table does not exists |
| 68 | 55 | if ( count( $wpdb->get_results( "SHOW TABLES LIKE '$wpdb->termmeta'" ) ) ) { |
| @@ -82,9 +69,9 @@ | ||
| 82 | 69 | |
| 83 | 70 | // Delete users options |
| 84 | 71 | foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) { |
| 85 | 72 | delete_user_meta( $user_id, 'pll_filter_content' ); |
| 86 | - delete_user_meta( $user_id, 'pll_dismissed_notices' ); // Legacy meta. | |
| 73 | + delete_user_meta( $user_id, 'pll_duplicate_content' ); | |
| 87 | 74 | foreach ( $languages as $lang ) { |
| 88 | 75 | delete_user_meta( $user_id, 'description_' . $lang->slug ); |
| 89 | 76 | } |
| 90 | 77 | } |
| @@ -125,11 +112,8 @@ | ||
| 125 | 112 | wp_delete_post( $id, true ); |
| 126 | 113 | } |
| 127 | 114 | |
| 128 | 115 | // Delete all what is related to languages and translations |
| 129 | - $term_ids = array(); | |
| 130 | - $tt_ids = array(); | |
| 131 | - | |
| 132 | 116 | foreach ( get_terms( $pll_taxonomies, array( 'hide_empty' => false ) ) as $term ) { |
| 133 | 117 | $term_ids[] = (int) $term->term_id; |
| 134 | 118 | $tt_ids[] = (int) $term->term_taxonomy_id; |
| 135 | 119 | } |
| @@ -149,13 +133,13 @@ | ||
| 149 | 133 | delete_option( 'polylang' ); |
| 150 | 134 | delete_option( 'widget_polylang' ); // Automatically created by WP |
| 151 | 135 | delete_option( 'polylang_wpml_strings' ); // Strings registered with icl_register_string |
| 152 | 136 | delete_option( 'polylang_licenses' ); |
| 153 | - delete_option( 'pll_dismissed_notices' ); | |
| 154 | 137 | |
| 155 | 138 | // Delete transients |
| 156 | 139 | delete_transient( 'pll_languages_list' ); |
| 157 | 140 | delete_transient( 'pll_upgrade_1_4' ); |
| 141 | + delete_transient( 'pll_translated_slugs' ); | |
| 158 | 142 | } |
| 159 | 143 | } |
| 160 | 144 | |
| 161 | 145 | new PLL_Uninstall(); |