| @@ -2,10 +2,11 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Uninstall routine for CryptX. |
| 4 | 4 | * |
| 5 | 5 | * Runs when the plugin is deleted through the WordPress admin (not on |
| 6 | - * deactivation). It removes everything CryptX has stored: the option 'cryptX' | |
| 7 | - * and any transient whose name starts with 'cryptx_'. | |
| 6 | + * deactivation). It removes everything CryptX has stored: the option 'cryptX', | |
| 7 | + * any transient whose name starts with 'cryptx_', and the user meta that | |
| 8 | + * records who declined to write a review. | |
| 8 | 9 | * |
| 9 | 10 | * Deliberately uses the WordPress API (delete_option(), delete_transient(), |
| 10 | 11 | * delete_site_transient()) instead of raw DELETE statements, so object caches |
| 11 | 12 | * and the *_option hooks see the removal. Only *finding* the transients needs |
| @@ -78,12 +79,13 @@ | ||
| 78 | 79 | } |
| 79 | 80 | |
| 80 | 81 | if (!function_exists('cryptx_uninstall_clean_network')) { |
| 81 | 82 | /** |
| 82 | - * Removes network-wide CryptX site transients. | |
| 83 | + * Removes what CryptX stored for the network rather than for a site. | |
| 83 | 84 | * |
| 84 | - * These live in the sitemeta table, not in any site's options table, so the | |
| 85 | - * per-site pass would never see them. | |
| 85 | + * Both kinds live in the sitemeta table, not in any site's options table, | |
| 86 | + * so the per-site pass would never see them: the site transients, and the | |
| 87 | + * defaults a newly created site started from. | |
| 86 | 88 | * |
| 87 | 89 | * @return void |
| 88 | 90 | */ |
| 89 | 91 | function cryptx_uninstall_clean_network(): void |
| @@ -89,8 +91,20 @@ | ||
| 89 | 91 | function cryptx_uninstall_clean_network(): void |
| 90 | 92 | { |
| 91 | 93 | global $wpdb; |
| 92 | 94 | |
| 95 | + // The network defaults. Added in 4.2.0, and it was missed here at | |
| 96 | + // first -- which would have left the file's own opening promise | |
| 97 | + // ("removes everything CryptX has stored") untrue on exactly the kind | |
| 98 | + // of installation where somebody notices. | |
| 99 | + // | |
| 100 | + // Written out rather than taken from Admin\NetworkDefaults::OPTION: | |
| 101 | + // WordPress runs this file on its own, with the plugin unloaded, so | |
| 102 | + // there is no class to ask. If that constant is ever renamed, this | |
| 103 | + // line has to be renamed with it -- there is nothing that would | |
| 104 | + // notice on its own. | |
| 105 | + delete_site_option('cryptx_network_defaults'); | |
| 106 | + | |
| 93 | 107 | $valueLike = $wpdb->esc_like('_site_transient_' . CRYPTX_UNINSTALL_TRANSIENT_PREFIX) . '%'; |
| 94 | 108 | |
| 95 | 109 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 96 | 110 | $rows = $wpdb->get_col( |
| @@ -105,8 +119,33 @@ | ||
| 105 | 119 | delete_site_transient(substr($metaKey, strlen('_site_transient_'))); |
| 106 | 120 | } |
| 107 | 121 | } |
| 108 | 122 | } |
| 123 | + | |
| 124 | +if (!function_exists('cryptx_uninstall_clean_users')) { | |
| 125 | + /** | |
| 126 | + * Removes the "do not ask me for a review again" mark from every user. | |
| 127 | + * | |
| 128 | + * Runs exactly once, not once per site: user meta lives in one table for | |
| 129 | + * the whole network, so the per-site pass would delete the same rows over | |
| 130 | + * and over -- and on a network of a thousand sites, a thousand times. | |
| 131 | + * | |
| 132 | + * delete_metadata() with $delete_all rather than a loop over get_users(): | |
| 133 | + * the loop would pull every user of the installation into memory to find | |
| 134 | + * the few who ever saw the notice. | |
| 135 | + * | |
| 136 | + * @return void | |
| 137 | + */ | |
| 138 | + function cryptx_uninstall_clean_users(): void | |
| 139 | + { | |
| 140 | + // Spelled out rather than taken from Admin\ReviewNotice::USER_META, | |
| 141 | + // for the same reason as the network option below: WordPress runs this | |
| 142 | + // file with the plugin unloaded, so there is no class to ask. | |
| 143 | + delete_metadata('user', 0, 'cryptx_review_dismissed', '', true); | |
| 144 | + } | |
| 145 | +} | |
| 146 | + | |
| 147 | +cryptx_uninstall_clean_users(); | |
| 109 | 148 | |
| 110 | 149 | if (is_multisite()) { |
| 111 | 150 | // Work in batches instead of loading every site of a large network at once: |
| 112 | 151 | // get_sites() without a limit would pull all of them into memory. |