From 080b56212126675e748294914bd18124e66eff76 Mon Sep 17 00:00:00 2001 From: ahuseyn Date: Thu, 27 Nov 2025 16:57:09 +0100 Subject: [PATCH 1/2] add uninstallation hook --- docs/plugins/hwp-previews/index.md | 13 ++++++ plugins/hwp-previews/README.md | 13 ++++++ .../tests/wpunit/Core/UninstallTest.php | 44 +++++++++++++++++++ plugins/hwp-previews/uninstall.php | 33 ++++++++++++++ 4 files changed, 103 insertions(+) create mode 100755 plugins/hwp-previews/tests/wpunit/Core/UninstallTest.php create mode 100644 plugins/hwp-previews/uninstall.php diff --git a/docs/plugins/hwp-previews/index.md b/docs/plugins/hwp-previews/index.md index 5ea0d1fb..f1d973a3 100644 --- a/docs/plugins/hwp-previews/index.md +++ b/docs/plugins/hwp-previews/index.md @@ -17,6 +17,7 @@ This plugin bridges the preview gap in headless WordPress architectures, allowin * [Configuration](#configuration) * [Front-End Integration](#front-end-integration) * [Using With Faust.js](#using-with-faustjs) +* [Uninstallation](#uninstallation) * [Documentation](#documentation) * [Contributing](#contributing) @@ -132,6 +133,18 @@ To implement previews from scratch, refer to your framework's documentation: HWP Previews automatically integrates with [Faust.js](https://faustjs.org/) when both plugins are active. See the [Integrate with Faust.js](how-to/integrate-with-faust/index.md) guide for details. +## Uninstallation + +By default, HWP Previews preserves all settings when the plugin is deactivated to prevent accidental data loss. + +If you would like to remove all plugin settings and data, you must set the PHP constant before you uninstall the plugin: + +```php +define( 'HWP_PREVIEWS_UNINSTALL_PLUGIN', true ); +``` + +You can add this constant to your `wp-config.php` file if you want to enable automatic cleanup during uninstallation. + ## Documentation ### How-to guides diff --git a/plugins/hwp-previews/README.md b/plugins/hwp-previews/README.md index c70113e5..2615921b 100644 --- a/plugins/hwp-previews/README.md +++ b/plugins/hwp-previews/README.md @@ -35,6 +35,7 @@ - [Using With Faust.js](#using-with-faustjs) - [Extending the Functionality](#extending-the-functionality) - [Testing](#testing) +- [Uninstallation](#uninstallation) ## Overview @@ -171,6 +172,18 @@ See the [Actions & Filters documentation](ACTIONS_AND_FILTERS.md) for a comprehe See [Testing.md](TESTING.md) for details on how to test the plugin. +## Uninstallation + +By default, HWP Previews preserves all settings when the plugin is deactivated to prevent accidental data loss. + +If you would like to remove all plugin settings and data, you must set the PHP constant before you uninstall the plugin: + +```php +define( 'HWP_PREVIEWS_UNINSTALL_PLUGIN', true ); +``` + +You can add this constant to your `wp-config.php` file if you want to enable automatic cleanup during uninstallation. + ## Screenshots
diff --git a/plugins/hwp-previews/tests/wpunit/Core/UninstallTest.php b/plugins/hwp-previews/tests/wpunit/Core/UninstallTest.php new file mode 100755 index 00000000..35904ccd --- /dev/null +++ b/plugins/hwp-previews/tests/wpunit/Core/UninstallTest.php @@ -0,0 +1,44 @@ +assertFileExists( $uninstall_file, 'uninstall.php file should exist' ); + } + + public function test_option_can_be_deleted(): void { + // Test that delete_option works (simulating what uninstall.php does). + $option_key = HWP_PREVIEWS_SETTINGS_KEY; + $test_data = [ 'test' => 'data' ]; + + update_option( $option_key, $test_data ); + $this->assertEquals( $test_data, get_option( $option_key ) ); + + delete_option( $option_key ); + $this->assertFalse( get_option( $option_key ) ); + } + + public function test_uninstall_action_hook_exists(): void { + // Verify the action hook can be registered. + $called = false; + + add_action( 'hwp_previews_after_uninstall', function () use ( &$called ) { + $called = true; + } ); + + do_action( 'hwp_previews_after_uninstall' ); + + $this->assertTrue( $called, 'hwp_previews_after_uninstall action should fire' ); + } +} + diff --git a/plugins/hwp-previews/uninstall.php b/plugins/hwp-previews/uninstall.php new file mode 100644 index 00000000..4f94f231 --- /dev/null +++ b/plugins/hwp-previews/uninstall.php @@ -0,0 +1,33 @@ + Date: Thu, 27 Nov 2025 17:27:11 +0100 Subject: [PATCH 2/2] minor fix on uninstall.php, add changeset --- .changeset/tall-wasps-bathe.md | 5 +++++ plugins/hwp-previews/uninstall.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/tall-wasps-bathe.md diff --git a/.changeset/tall-wasps-bathe.md b/.changeset/tall-wasps-bathe.md new file mode 100644 index 00000000..9d81bcfc --- /dev/null +++ b/.changeset/tall-wasps-bathe.md @@ -0,0 +1,5 @@ +--- +"@wpengine/hwp-previews-wordpress-plugin": patch +--- + +Add optional data cleanup on uninstall via HWP_PREVIEWS_UNINSTALL_PLUGIN constant \ No newline at end of file diff --git a/plugins/hwp-previews/uninstall.php b/plugins/hwp-previews/uninstall.php index 4f94f231..b5546985 100644 --- a/plugins/hwp-previews/uninstall.php +++ b/plugins/hwp-previews/uninstall.php @@ -17,7 +17,7 @@ // Only proceed if the uninstall constant is defined. if ( ! defined( 'HWP_PREVIEWS_UNINSTALL_PLUGIN' ) || ! HWP_PREVIEWS_UNINSTALL_PLUGIN ) { - exit; + return; } // Define constants if not already defined.