Skip to content

Commit

Permalink
Add an optional survey when deactivating
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Dec 18, 2024
1 parent e152be2 commit f6b1e69
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
10 changes: 9 additions & 1 deletion friends-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jQuery( function ( $ ) {
}
} );


$( document ).on( 'click', 'a#show-details', function () {
$( '.details' ).toggleClass( 'hidden' ).focus();
return false;
Expand Down Expand Up @@ -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;
}
});
} );
26 changes: 25 additions & 1 deletion includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
}
Expand Down Expand Up @@ -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[] = '<a href="' . self_admin_url( 'admin.php?page=friends-settings' ) . '">' . esc_html__( 'Settings', 'friends' ) . '</a>';

if ( isset( $links['deactivate'] ) && 0 === strpos( $links['deactivate'], '<a' ) ) {
// get the link to deactivate the plugin.
$tags = new \WP_HTML_Tag_Processor( $links['deactivate'] );
if ( $tags->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,
'<a href="x' . esc_url( $deactivate_link ) . '" class="friends-ask-why-deactivate">' . esc_html( $text ) . '</a>'
);
}
}

return $links;
}
}
28 changes: 28 additions & 0 deletions templates/admin/dialog-ask-why-deactivate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<dialog id="friends-why-deactivate-dialog">
<form action="">
<h1><?php esc_html_e( 'Deactivating the Friends Plugin', 'friends' ); ?></h1>
<label for="why-deactivate"><?php esc_html_e( 'Thank you for tell us why you are deactivating this plugin:', 'friends' ); ?></label>
<ul>
<li><label><input type="checkbox" name="reason[]" value="complicated"> <?php esc_html_e( 'Too complicated', 'friends' ); ?></label></li>
<li><label><input type="checkbox" name="reason[]" value="ugly"> <?php esc_html_e( 'Too Ugly', 'friends' ); ?></label></li>
</ul>
<textarea id="why-deactivate" name="why-deactivate" placeholder="Something else"></textarea>
<p>
<?php esc_html_e( 'Your response will be submitted anonymously.', 'friends' ); ?>
<?php
echo wp_kses(
sprintf(
// translators: %s: URL to the GitHub issue tracker.
__( 'If you encountered a bug, <a href="%s">please report it</a>!', 'friends' ),
'https://github.com/akirk/friends'
),
array( 'a' => array( 'href' => array() ) )
);
?>
</p>
<p>
<button type="submit" class="button btn-primary"><?php esc_html_e( 'Deactivate', 'friends' ); ?></button>
<button type="button" class="button btn-secondary"><?php esc_html_e( 'Cancel', 'friends' ); ?></button>
</p>
</form>
</dialog>

0 comments on commit f6b1e69

Please sign in to comment.