From f6b1e69b513ec0719754e1aa696ba33a42197fca Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Wed, 18 Dec 2024 17:16:19 +0100 Subject: [PATCH] Add an optional survey when deactivating --- friends-admin.js | 10 ++++++- includes/class-admin.php | 26 ++++++++++++++++- templates/admin/dialog-ask-why-deactivate.php | 28 +++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 templates/admin/dialog-ask-why-deactivate.php diff --git a/friends-admin.js b/friends-admin.js index 54684d8a..58886b6d 100644 --- a/friends-admin.js +++ b/friends-admin.js @@ -37,7 +37,6 @@ jQuery( function ( $ ) { } } ); - $( document ).on( 'click', 'a#show-details', function () { $( '.details' ).toggleClass( 'hidden' ).focus(); return false; @@ -427,4 +426,13 @@ jQuery( function ( $ ) { ); } }, 500 ); + + $( document ).on( 'click', 'a.friends-ask-why-deactivate', function() { + const dialog = document.getElementById( 'friends-why-deactivate-dialog' ); + console.log( dialog ); + if ( dialog ) { + dialog.showModal(); + return false; + } + }); } ); diff --git a/includes/class-admin.php b/includes/class-admin.php index 1250e5d3..59055f7f 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -71,7 +71,7 @@ private function register_hooks() { add_filter( 'debug_information', array( $this, 'site_health_debug' ) ); add_filter( 'friends_create_and_follow', array( $this, 'create_and_follow' ), 10, 4 ); add_filter( 'friends_admin_tabs', array( $this, 'maybe_remove_friendship_settings' ) ); - + add_filter( 'plugin_action_links_' . FRIENDS_PLUGIN_BASENAME, array( $this, 'plugin_action_links' ) ); if ( ! get_option( 'permalink_structure' ) ) { add_action( 'admin_notices', array( $this, 'admin_notice_unsupported_permalink_structure' ) ); } @@ -3794,4 +3794,28 @@ public function admin_friend_posts_query( $query ) { return $query; } + + public function output_ask_why_deactivate_dialog() { + Friends::template_loader()->get_template_part( 'admin/dialog-ask-why-deactivate' ); + } + + public function plugin_action_links( $links ) { + $links[] = '' . esc_html__( 'Settings', 'friends' ) . ''; + + if ( isset( $links['deactivate'] ) && 0 === strpos( $links['deactivate'], 'next_tag( 'a' ) ) { + $deactivate_link = $tags->get_attribute( 'href', true ); + $text = __( 'Deactivate and let us know why', 'friends' ); + add_action( 'admin_footer', array( $this, 'output_ask_why_deactivate_dialog' ) ); + array_unshift( + $links, + '' . esc_html( $text ) . '' + ); + } + } + + return $links; + } } diff --git a/templates/admin/dialog-ask-why-deactivate.php b/templates/admin/dialog-ask-why-deactivate.php new file mode 100644 index 00000000..13377efb --- /dev/null +++ b/templates/admin/dialog-ask-why-deactivate.php @@ -0,0 +1,28 @@ + +
+

+ +
    +
  • +
  • +
+ +

+ + please report it!', 'friends' ), + 'https://github.com/akirk/friends' + ), + array( 'a' => array( 'href' => array() ) ) + ); + ?> +

+

+ + +

+
+