| @@ -1,11 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { // If uninstall not called from WordPress exit |
| 7 | - exit; | |
| 4 | + exit(); | |
| 8 | 5 | } |
| 9 | 6 | |
| 10 | 7 | /** |
| 11 | 8 | * Manages Polylang uninstallation |
| @@ -22,13 +19,8 @@ | ||
| 22 | 19 | */ |
| 23 | 20 | public 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 | 23 | // Check if it is a multisite uninstall - if so, run the uninstall function for each blog id |
| 32 | 24 | if ( is_multisite() ) { |
| 33 | 25 | foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) { |
| 34 | 26 | switch_to_blog( $blog_id ); |
| @@ -47,11 +39,26 @@ | ||
| 47 | 39 | * |
| 48 | 40 | * @since 0.5 |
| 49 | 41 | */ |
| 50 | 42 | public function uninstall() { |
| 43 | + $options = get_option( 'polylang' ); | |
| 44 | + | |
| 45 | + if ( empty( $options['uninstall'] ) ) { | |
| 46 | + return; | |
| 47 | + } | |
| 48 | + | |
| 49 | + // Suppress data of the old model < 1.2 | |
| 50 | + // FIXME: to remove when support for v1.1.6 will be dropped | |
| 51 | 51 | global $wpdb; |
| 52 | + $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb | |
| 52 | 53 | |
| 53 | - do_action( 'pll_uninstall' ); | |
| 54 | + // Do nothing if the termmeta table does not exists | |
| 55 | + if ( count( $wpdb->get_results( "SHOW TABLES LIKE '$wpdb->termmeta'" ) ) ) { | |
| 56 | + $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_translations'" ); | |
| 57 | + $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_language'" ); | |
| 58 | + $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_rtl'" ); | |
| 59 | + $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_translations'" ); | |
| 60 | + } | |
| 54 | 61 | |
| 55 | 62 | // Need to register the taxonomies |
| 56 | 63 | $pll_taxonomies = array( 'language', 'term_language', 'post_translations', 'term_translations' ); |
| 57 | 64 | foreach ( $pll_taxonomies as $taxonomy ) { |
| @@ -62,9 +69,9 @@ | ||
| 62 | 69 | |
| 63 | 70 | // Delete users options |
| 64 | 71 | foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) { |
| 65 | 72 | delete_user_meta( $user_id, 'pll_filter_content' ); |
| 66 | - delete_user_meta( $user_id, 'pll_dismissed_notices' ); // Legacy meta. | |
| 73 | + delete_user_meta( $user_id, 'pll_duplicate_content' ); | |
| 67 | 74 | foreach ( $languages as $lang ) { |
| 68 | 75 | delete_user_meta( $user_id, 'description_' . $lang->slug ); |
| 69 | 76 | } |
| 70 | 77 | } |
| @@ -83,9 +90,15 @@ | ||
| 83 | 90 | foreach ( $ids as $id ) { |
| 84 | 91 | wp_delete_post( $id, true ); |
| 85 | 92 | } |
| 86 | 93 | |
| 87 | - // Delete the strings translations. | |
| 94 | + // Delete the strings translations ( <1.2 ) | |
| 95 | + // FIXME: to remove when support for v1.1.6 will be dropped | |
| 96 | + foreach ( $languages as $lang ) { | |
| 97 | + delete_option( 'polylang_mo' . $lang->term_id ); | |
| 98 | + } | |
| 99 | + | |
| 100 | + // Delete the strings translations 1.2+ | |
| 88 | 101 | register_post_type( 'polylang_mo', array( 'rewrite' => false, 'query_var' => false ) ); |
| 89 | 102 | $ids = get_posts( |
| 90 | 103 | array( |
| 91 | 104 | 'post_type' => 'polylang_mo', |
| @@ -99,11 +112,8 @@ | ||
| 99 | 112 | wp_delete_post( $id, true ); |
| 100 | 113 | } |
| 101 | 114 | |
| 102 | 115 | // Delete all what is related to languages and translations |
| 103 | - $term_ids = array(); | |
| 104 | - $tt_ids = array(); | |
| 105 | - | |
| 106 | 116 | foreach ( get_terms( $pll_taxonomies, array( 'hide_empty' => false ) ) as $term ) { |
| 107 | 117 | $term_ids[] = (int) $term->term_id; |
| 108 | 118 | $tt_ids[] = (int) $term->term_taxonomy_id; |
| 109 | 119 | } |
| @@ -123,12 +133,13 @@ | ||
| 123 | 133 | delete_option( 'polylang' ); |
| 124 | 134 | delete_option( 'widget_polylang' ); // Automatically created by WP |
| 125 | 135 | delete_option( 'polylang_wpml_strings' ); // Strings registered with icl_register_string |
| 126 | 136 | delete_option( 'polylang_licenses' ); |
| 127 | - delete_option( 'pll_dismissed_notices' ); | |
| 128 | 137 | |
| 129 | 138 | // Delete transients |
| 130 | 139 | delete_transient( 'pll_languages_list' ); |
| 140 | + delete_transient( 'pll_upgrade_1_4' ); | |
| 141 | + delete_transient( 'pll_translated_slugs' ); | |
| 131 | 142 | } |
| 132 | 143 | } |
| 133 | 144 | |
| 134 | 145 | new PLL_Uninstall(); |