Amp-wp: Allow removing all data on uninstall

Created on 9 Sep 2019  路  11Comments  路  Source: ampproject/amp-wp

As reported in the forums: https://wordpress.org/support/topic/how-to-delete-plugin-including-data-left-behind/

When uninstalling the plugin, all the AMP options and custom post types are still in the database.

Suggestion:

  1. Add checkbox to AMP settings screen to enable data removal upon uninstall
  2. Use register_uninstall_hook or uninstall.php to remove all custom post types, taxonomies, and options upon uninstall.
Enhancement Groomed P2 Core

Most helpful comment

Yes, let's do it in v2.1.

All 11 comments

There's also the postmeta for controlling whether AMP is enabled for a given post.

Is the checkbox necessary? Doesn't uninstallation entail data removal? I'm not up on the best practices for plugin uninstallation.

A checkbox is common in many plugins as it prevents accidental data removal, for example when one wants to update a plugin via uploading a ZIP file. Because https://core.trac.wordpress.org/ticket/9757 is not solved yet, it would erase all data when deleting the AMP plugin and uploading the ZIP file of an RC. Which would be a bit annoying.

I can't comprehend why this wasn't built into the plugin from the get go. When you guys implement this, please also consider taking care of redirects (301) required after removing all AMP content. You don't want to leave your users with potentially thousands of 404's.

@cryptochrome What 404s are you referring to? Are you referring to /amp/ endpoint URLs? There would be no way for the AMP plugin to redirect those URLs if it is deactivated. WordPress has no persistent URL redirect system that it could write to upon deactivation.

The issue of /amp/ URLs 404ing will be mitigated by away from URL endpoints in favor of the ?amp=1 query var per https://github.com/ampproject/amp-wp/issues/2204.

@cryptochrome To redirect /amp/ URLs to non-AMP URLs after plugin deactivation, you can use this plugin: https://gist.github.com/westonruter/b7eb9cc7648b9a8b94b0015c79c8702e

Something that comes to mind with this issue is that if someone wants to try a pre-release build of the AMP plugin, currently the way to do that is to download a pre-release ZIP, uninstall the AMP plugin, and install the pre-release AMP plugin to then activate. However, if the uninstall process deletes data, then this would not work anymore.

@westonruter That鈥榮 why I mention the checkbox. Uninstall would only run if the user enables it.

Something that comes to mind with this issue is that if someone wants to try a pre-release build of the AMP plugin, currently the way to do that is to download a pre-release ZIP, uninstall the AMP plugin, and install the pre-release AMP plugin to then activate.

This is fixed in WordPress 5.5. Updating via upload is now possible.

Time to unblock?

Yes, let's do it in v2.1.

This needs an Implementation Brief or similar to that effect

Implementation brief:

Add an uninstall.php which does what @swissspidy outlined in the support topic.

  1. Remove AMP settings data: wp option delete amp-options
  2. Remove all amp_validated_url posts: wp post delete $(wp post list --post_type='amp_validated_url' --format=ids)
  3. Remove all amp_validation_error terms: wp term list amp_validation_error --field=term_id | xargs wp term delete amp_validation_error

We could also delete all transients associated with the plugin, when an external object cache is not being used.

See also Uninstall Methods in the Plugin Handbook.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

westonruter picture westonruter  路  5Comments

miina picture miina  路  5Comments

GitaStreet picture GitaStreet  路  4Comments

westonruter picture westonruter  路  4Comments

swissspidy picture swissspidy  路  5Comments