| @@ -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,12 +39,41 @@ | ||
| 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 | + | |
| 51 | 49 | global $wpdb; |
| 52 | 50 | |
| 53 | - do_action( 'pll_uninstall' ); | |
| 51 | + // Executes each module's uninstall script, if it exists | |
| 52 | + $pll_modules_dir = dirname( __FILE__ ) . '/modules'; | |
| 53 | + opendir( $pll_modules_dir ); | |
| 54 | + while ( ( $module = readdir() ) != false ) { | |
| 55 | + if ( substr( $module, 0, 1 ) !== '.' ) { | |
| 56 | + $uninstall_script = $pll_modules_dir . '/' . $module . '/uninstall.php'; | |
| 57 | + if ( file_exists( $uninstall_script ) ) { | |
| 58 | + require $uninstall_script; | |
| 59 | + } | |
| 60 | + } | |
| 61 | + } | |
| 62 | + closedir(); | |
| 54 | 63 | |
| 64 | + // Suppress data of the old model < 1.2 | |
| 65 | + // FIXME: to remove when support for v1.1.6 will be dropped | |
| 66 | + $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb | |
| 67 | + | |
| 68 | + // Do nothing if the termmeta table does not exists | |
| 69 | + if ( count( $wpdb->get_results( "SHOW TABLES LIKE '$wpdb->termmeta'" ) ) ) { | |
| 70 | + $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_translations'" ); | |
| 71 | + $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_language'" ); | |
| 72 | + $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_rtl'" ); | |
| 73 | + $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_translations'" ); | |
| 74 | + } | |
| 75 | + | |
| 55 | 76 | // Need to register the taxonomies |
| 56 | 77 | $pll_taxonomies = array( 'language', 'term_language', 'post_translations', 'term_translations' ); |
| 57 | 78 | foreach ( $pll_taxonomies as $taxonomy ) { |
| 58 | 79 | register_taxonomy( $taxonomy, null, array( 'label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false ) ); |
| @@ -62,9 +83,8 @@ | ||
| 62 | 83 | |
| 63 | 84 | // Delete users options |
| 64 | 85 | foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) { |
| 65 | 86 | delete_user_meta( $user_id, 'pll_filter_content' ); |
| 66 | - delete_user_meta( $user_id, 'pll_dismissed_notices' ); // Legacy meta. | |
| 67 | 87 | foreach ( $languages as $lang ) { |
| 68 | 88 | delete_user_meta( $user_id, 'description_' . $lang->slug ); |
| 69 | 89 | } |
| 70 | 90 | } |
| @@ -83,9 +103,15 @@ | ||
| 83 | 103 | foreach ( $ids as $id ) { |
| 84 | 104 | wp_delete_post( $id, true ); |
| 85 | 105 | } |
| 86 | 106 | |
| 87 | - // Delete the strings translations. | |
| 107 | + // Delete the strings translations ( <1.2 ) | |
| 108 | + // 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 | + } | |
| 112 | + | |
| 113 | + // Delete the strings translations 1.2+ | |
| 88 | 114 | register_post_type( 'polylang_mo', array( 'rewrite' => false, 'query_var' => false ) ); |
| 89 | 115 | $ids = get_posts( |
| 90 | 116 | array( |
| 91 | 117 | 'post_type' => 'polylang_mo', |
| @@ -99,11 +125,8 @@ | ||
| 99 | 125 | wp_delete_post( $id, true ); |
| 100 | 126 | } |
| 101 | 127 | |
| 102 | 128 | // Delete all what is related to languages and translations |
| 103 | - $term_ids = array(); | |
| 104 | - $tt_ids = array(); | |
| 105 | - | |
| 106 | 129 | foreach ( get_terms( $pll_taxonomies, array( 'hide_empty' => false ) ) as $term ) { |
| 107 | 130 | $term_ids[] = (int) $term->term_id; |
| 108 | 131 | $tt_ids[] = (int) $term->term_taxonomy_id; |
| 109 | 132 | } |
| @@ -123,12 +146,12 @@ | ||
| 123 | 146 | delete_option( 'polylang' ); |
| 124 | 147 | delete_option( 'widget_polylang' ); // Automatically created by WP |
| 125 | 148 | delete_option( 'polylang_wpml_strings' ); // Strings registered with icl_register_string |
| 126 | 149 | delete_option( 'polylang_licenses' ); |
| 127 | - delete_option( 'pll_dismissed_notices' ); | |
| 128 | 150 | |
| 129 | 151 | // Delete transients |
| 130 | 152 | delete_transient( 'pll_languages_list' ); |
| 153 | + delete_transient( 'pll_upgrade_1_4' ); | |
| 131 | 154 | } |
| 132 | 155 | } |
| 133 | 156 | |
| 134 | 157 | new PLL_Uninstall(); |