| @@ -1,5 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * @package Polylang | |
| 4 | + */ | |
| 2 | 5 | |
| 3 | 6 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { // If uninstall not called from WordPress exit |
| 4 | 7 | exit; |
| 5 | 8 | } |
| @@ -19,9 +22,9 @@ | ||
| 19 | 22 | */ |
| 20 | 23 | public function __construct() { |
| 21 | 24 | global $wpdb; |
| 22 | 25 | |
| 23 | - // Don't do anything except if the constant PLL_REMOVE_ALL_DATA is explicitely defined and true. | |
| 26 | + // Don't do anything except if the constant PLL_REMOVE_ALL_DATA is explicitly defined and true. | |
| 24 | 27 | if ( ! defined( 'PLL_REMOVE_ALL_DATA' ) || ! PLL_REMOVE_ALL_DATA ) { |
| 25 | 28 | return; |
| 26 | 29 | } |
| 27 | 30 | |
| @@ -46,33 +49,10 @@ | ||
| 46 | 49 | */ |
| 47 | 50 | public function uninstall() { |
| 48 | 51 | global $wpdb; |
| 49 | 52 | |
| 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 | - } | |
| 60 | - } | |
| 61 | - closedir(); | |
| 53 | + do_action( 'pll_uninstall' ); | |
| 62 | 54 | |
| 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 | - | |
| 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 | - } | |
| 74 | - | |
| 75 | 55 | // Need to register the taxonomies |
| 76 | 56 | $pll_taxonomies = array( 'language', 'term_language', 'post_translations', 'term_translations' ); |
| 77 | 57 | foreach ( $pll_taxonomies as $taxonomy ) { |
| 78 | 58 | register_taxonomy( $taxonomy, null, array( 'label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false ) ); |
| @@ -77,17 +57,15 @@ | ||
| 77 | 57 | foreach ( $pll_taxonomies as $taxonomy ) { |
| 78 | 58 | register_taxonomy( $taxonomy, null, array( 'label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false ) ); |
| 79 | 59 | } |
| 80 | 60 | |
| 81 | - $languages = get_terms( 'language', array( 'hide_empty' => false ) ); | |
| 61 | + $languages = get_terms( array( 'taxonomy' => 'language', 'hide_empty' => false ) ); | |
| 82 | 62 | |
| 83 | 63 | // 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 | - } | |
| 64 | + delete_metadata( 'user', 0, 'pll_filter_content', '', true ); | |
| 65 | + delete_metadata( 'user', 0, 'pll_dismissed_notices', '', true ); // Legacy meta. | |
| 66 | + foreach ( $languages as $lang ) { | |
| 67 | + delete_metadata( 'user', 0, "description_{$lang->slug}", '', true ); | |
| 90 | 68 | } |
| 91 | 69 | |
| 92 | 70 | // Delete menu language switchers |
| 93 | 71 | $ids = get_posts( |
| @@ -103,15 +81,12 @@ | ||
| 103 | 81 | foreach ( $ids as $id ) { |
| 104 | 82 | wp_delete_post( $id, true ); |
| 105 | 83 | } |
| 106 | 84 | |
| 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+ | |
| 85 | + /* | |
| 86 | + * Backward compatibility with Polylang < 3.4. | |
| 87 | + * Delete the legacy strings translations. | |
| 88 | + */ | |
| 114 | 89 | register_post_type( 'polylang_mo', array( 'rewrite' => false, 'query_var' => false ) ); |
| 115 | 90 | $ids = get_posts( |
| 116 | 91 | array( |
| 117 | 92 | 'post_type' => 'polylang_mo', |
| @@ -128,9 +103,9 @@ | ||
| 128 | 103 | // Delete all what is related to languages and translations |
| 129 | 104 | $term_ids = array(); |
| 130 | 105 | $tt_ids = array(); |
| 131 | 106 | |
| 132 | - foreach ( get_terms( $pll_taxonomies, array( 'hide_empty' => false ) ) as $term ) { | |
| 107 | + foreach ( get_terms( array( 'taxonomy' => $pll_taxonomies, 'hide_empty' => false ) ) as $term ) { | |
| 133 | 108 | $term_ids[] = (int) $term->term_id; |
| 134 | 109 | $tt_ids[] = (int) $term->term_taxonomy_id; |
| 135 | 110 | } |
| 136 | 111 | |
| @@ -137,8 +112,9 @@ | ||
| 137 | 112 | if ( ! empty( $term_ids ) ) { |
| 138 | 113 | $term_ids = array_unique( $term_ids ); |
| 139 | 114 | $wpdb->query( "DELETE FROM {$wpdb->terms} WHERE term_id IN ( " . implode( ',', $term_ids ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 140 | 115 | $wpdb->query( "DELETE FROM {$wpdb->term_taxonomy} WHERE term_id IN ( " . implode( ',', $term_ids ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 116 | + $wpdb->query( "DELETE FROM {$wpdb->termmeta} WHERE term_id IN ( " . implode( ',', $term_ids ) . " ) AND meta_key='_pll_strings_translations'" ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 141 | 117 | } |
| 142 | 118 | |
| 143 | 119 | if ( ! empty( $tt_ids ) ) { |
| 144 | 120 | $tt_ids = array_unique( $tt_ids ); |
| @@ -153,9 +129,8 @@ | ||
| 153 | 129 | delete_option( 'pll_dismissed_notices' ); |
| 154 | 130 | |
| 155 | 131 | // Delete transients |
| 156 | 132 | delete_transient( 'pll_languages_list' ); |
| 157 | - delete_transient( 'pll_upgrade_1_4' ); | |
| 158 | 133 | } |
| 159 | 134 | } |
| 160 | 135 | |
| 161 | 136 | new PLL_Uninstall(); |