From e07c9b79c1094fbbbf430296ab881d790b69232c Mon Sep 17 00:00:00 2001 From: Timo Giese Date: Mon, 11 May 2026 15:48:31 +0200 Subject: [PATCH] feat: show deactivation dialog asking for feedback --- admin/class-spotmap-admin.php | 15 ++++++++++ admin/js/spotmap-deactivate.js | 55 ++++++++++++++++++++++++++++++++++ includes/class-spotmap.php | 1 + 3 files changed, 71 insertions(+) create mode 100644 admin/js/spotmap-deactivate.js diff --git a/admin/class-spotmap-admin.php b/admin/class-spotmap-admin.php index 68e5859..f237c61 100644 --- a/admin/class-spotmap-admin.php +++ b/admin/class-spotmap-admin.php @@ -282,6 +282,21 @@ public function get_maps() return $maps; } + public function enqueue_plugins_page_script($hook) + { + if ($hook !== 'plugins.php') { + return; + } + wp_enqueue_style('wp-jquery-ui-dialog'); + wp_enqueue_script( + 'spotmap-deactivate', + plugin_dir_url(__DIR__) . 'admin/js/spotmap-deactivate.js', + [ 'jquery', 'jquery-ui-dialog' ], + SPOTMAP_VERSION, + true + ); + } + public function allow_gpx_upload($mime_types) { $mime_types['gpx'] = 'text/xml'; diff --git a/admin/js/spotmap-deactivate.js b/admin/js/spotmap-deactivate.js new file mode 100644 index 0000000..1f23347 --- /dev/null +++ b/admin/js/spotmap-deactivate.js @@ -0,0 +1,55 @@ +(function ($) { + 'use strict'; + + var orig = document.getElementById('deactivate-spotmap'); + if (!orig) { + return; + } + var deactivateHref = orig.href; + + function openAndDeactivate(url) { + window.open(url, '_blank'); + window.location.href = deactivateHref; + } + + var $dialog = $( + '
' + + '

Spotmap is a hobby project I pour a lot of sweat and love into. It would mean the world to me to know why you\'re moving on.

' + + '

Would you mind leaving a quick note?

' + + '

Note: If you later delete the plugin, all tracked points and settings will be permanently removed.

' + + '
' + ); + + $dialog.dialog({ + autoOpen: false, + modal: true, + width: 510, + buttons: [ + { + text: 'Post on WordPress.org', + 'class': 'button button-primary', + click: function () { + openAndDeactivate('https://wordpress.org/support/plugin/spotmap/'); + }, + }, + { + text: 'Post on GitHub', + 'class': 'button button-primary', + click: function () { + openAndDeactivate('https://github.com/techtimo/spotmap/issues/new'); + }, + }, + { + text: 'Skip & Deactivate', + 'class': 'button', + click: function () { window.location.href = deactivateHref; }, + }, + ], + }); + + $(orig).on('click', function (e) { + e.preventDefault(); + $dialog.dialog('open'); + }); + +})(jQuery); diff --git a/includes/class-spotmap.php b/includes/class-spotmap.php index 836605b..59ac34a 100644 --- a/includes/class-spotmap.php +++ b/includes/class-spotmap.php @@ -84,6 +84,7 @@ private function define_admin_hooks() { $this->admin = new Spotmap_Admin(); $this->loader->add_action('admin_enqueue_scripts', $this->admin, 'enqueue_scripts'); + $this->loader->add_action('admin_enqueue_scripts', $this->admin, 'enqueue_plugins_page_script'); $this->loader->add_filter('cron_schedules', $this->admin, 'add_cron_schedule'); $this->loader->add_filter('plugin_action_links_' . SPOTMAP_PLUGIN_BASENAME, $this->admin, 'add_link_plugin_overview'); $this->loader->add_action('admin_menu', $this->admin, 'add_options_page');