Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an exit survey when the plugin is deactivated #3205

Draft
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions assets/css/admin/deactivation-survey/deactivation-survey.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#sensei_deactivation_form_wrapper {
display: none;
border-radius: 0;
font-family: Futura, sans-serif;
border: 7px solid #00ace6;
font-size: 16px; }
#sensei_deactivation_form_wrapper p, #sensei_deactivation_form_wrapper input, #sensei_deactivation_form_wrapper button, #sensei_deactivation_form_wrapper a {
font-size: 16px; }
#sensei_deactivation_form_wrapper h2 {
text-transform: uppercase;
margin-bottom: 2em;
font-size: 23px;
line-height: 1em; }
#sensei_deactivation_form_wrapper .buttons {
margin-top: 2em;
margin-bottom: 2em;
text-align: right; }
#sensei_deactivation_form_wrapper .buttons .button, #sensei_deactivation_form_wrapper .buttons .button-primary {
border: none;
text-shadow: none;
box-shadow: none; }
#sensei_deactivation_form_wrapper .buttons .button-primary {
background: #00ace6; }
#sensei_deactivation_form_wrapper .buttons .button {
background: rgba(255, 255, 255, 0); }
42 changes: 42 additions & 0 deletions assets/css/admin/deactivation-survey/deactivation-survey.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
$email_signup_blue: #00ace6;

#sensei_deactivation_form_wrapper {
display: none;
border-radius: 0;
font-family: Futura, sans-serif;
border: 7px solid $email_signup_blue;
font-size: 16px;

p, input, button, a {
font-size: 16px;
}

h2 {
text-transform: uppercase;
margin-bottom: 2em;
font-size: 23px;
line-height: 1em;
}

.buttons {
margin-top: 2em;
margin-bottom: 2em;
text-align: right;
}

.buttons {
.button, .button-primary {
border: none;
text-shadow: none;
box-shadow: none;
}

.button-primary {
background: $email_signup_blue;
}

.button {
background: rgba( 255, 255, 255, 0 );
}
}
}
32 changes: 32 additions & 0 deletions assets/js/admin/deactivation-survey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
jQuery( document ).ready( function( $ ) {

// Get the Deactivate link for the Sensei LMS plugin in the plugins page.
$deactivation_link = jQuery('#the-list').find('[data-slug="sensei-lms"] span.deactivate a');

// When Deactivate button clicked, instead of deactivating plugin, show survey modal.
$deactivation_link.on('click', function ( event ) {
event.preventDefault();

$( '#sensei_deactivation_form_wrapper' ).modal( {
fadeDuration: 250,
showClose: false,
} );

} );

// When submitting survey modal, send survey data and continue with plugin deactivation.
jQuery( 'body' ).on( 'submit', '#sensei_deactivation_form_wrapper', function( event ) {

jQuery.modal.close();
location.href = $deactivation_link.attr('href');

} );

// If user skips submission, continue with plugin deactivation.
jQuery( '#sensei_deactivation_form_cancel' ).on('click', function ( event ) {

location.href = $deactivation_link.attr('href');

});

} );
1 change: 1 addition & 0 deletions includes/class-sensei-autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public function initialize_class_file_map() {
'Sensei_Email_Signup_Form' => 'email-signup/class-sensei-email-signup-form.php', // @deprecated since 3.1.0
'Sensei_Onboarding' => 'admin/class-sensei-onboarding.php',
'Sensei_Onboarding_Pages' => 'admin/class-sensei-onboarding-pages.php',
'Sensei_Deactivation_Survey_Form' => 'deactivation-survey/class-sensei-deactivation-survey-form.php',

/**
* Shortcodes
Expand Down
12 changes: 12 additions & 0 deletions includes/class-sensei-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2513,6 +2513,18 @@ public static function show_course_lessons( $course_id ) {
*/
return apply_filters( 'sensei_course_show_lessons', true, $course_id );
}

/**
* Determine whether the current page is the plugins page.
*
* @since 3.0.2
*
* @return bool Whether the current page is the plugins page.
*/
public static function sensei_is_plugins_page() {
return in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true );
}

} // End Class

/**
Expand Down
20 changes: 20 additions & 0 deletions includes/class-sensei.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ protected function init() {

$this->initialize_global_objects();

$this->maybe_init_email_deactivation_survey_modal();

}

/**
Expand All @@ -267,6 +269,24 @@ public function load_email_signup_modal() {
_deprecated_function( __METHOD__, '3.1.0' );
}

/**
* Load the deactivation survey form in plugins screen.
*/
public function maybe_init_email_deactivation_survey_modal() {
add_action( 'current_screen', array( $this, 'load_deactivation_survey_modal' ) );
}

/**
* Load the deactivation survey modal.
*/
public function load_deactivation_survey_modal() {
if ( ! Sensei_Utils::sensei_is_plugins_page() ) {
return;
}

Sensei_Deactivation_Survey_Form::instance()->init();
}

/**
* Global Sensei Instance
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* File containing the class Sensei_Deactivation_Survey_Form.
*
* @package sensei
* @since 3.0.2
*/

/**
* Class for displaying the modal deactivation survey form.
*
* @class Sensei_Deactivation_Survey_Form
*/
class Sensei_Deactivation_Survey_Form {

/**
* Instance of class.
*
* @var self
*/
private static $instance;

/**
* Sensei_Deactivation_Survey_Form constructor. Prevents other instances from being
* created outside of `Sensei_Deactivation_Survey_Form::instance()`.
*/
private function __construct() {}

/**
* Initializes the class and adds all filters and actions.
*
* @access public
*/
public function init() {
// Add actions for displaying the deactivation survey modal.
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
add_action( 'admin_footer', array( $this, 'output_modal' ) );
}

/**
* Enqueue the required JS assets for the modal dialog.
*
* @access public
*/
public function enqueue_scripts() {
wp_enqueue_script( 'jquery-modal' );

// Load JS for the form.
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script(
'sensei-deactivation-survey-js',
Sensei()->plugin_url . 'assets/js/admin/deactivation-survey' . $suffix . '.js',
[ 'jquery-modal' ],
Sensei()->version,
false
);
}

/**
* Enqueue the required CSS assets for the modal dialog.
*
* @access public
*/
public function enqueue_styles() {
wp_enqueue_style( 'jquery-modal' );

// Load CSS for the form.
wp_enqueue_style(
'sensei-deactivation-survey-css',
Sensei()->plugin_url . 'assets/css/admin/deactivation-survey.css',
[ 'jquery-modal' ],
Sensei()->version
);
}

/**
* Load and output the code for the modal window.
*
* @access public
*/
public function output_modal() {
include dirname( __FILE__ ) . '/template.php';
}

/**
* Fetches an instance of the class.
*
* @return self
*/
public static function instance() {
if ( ! self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
}
48 changes: 48 additions & 0 deletions includes/deactivation-survey/template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* File containing the PHP template for the deactivation survey form.
*
* @package sensei
* @since 3.0.2
*/

?>
<div id="sensei_deactivation_form_wrapper">
<!--
WORK IN PROGRESS. TBD:
- Action URL
- Modal Title
- Data to send
- Format (color, arrangement, etc)
-->
<form
action="https://SENSEI_URL_WITH_ENDPOINT_FOR_DEACTIVATION_SURVEY_FORM"
method="post"
id="sensei_deactivation_form"
name="sensei_deactivation_form"
class="validate"
target="_blank"
novalidate
>

<input type="hidden" name="ADMIN_EMAIL" value="<?php echo esc_attr( get_option( 'admin_email', '' ) ); ?>">
<input type="hidden" name="SITE_URL" value="<?php echo esc_attr( get_option( 'siteurl', '' ) ); ?>">

<div id="sensei_deactivation_form_scroll">
<h2><?php esc_html_e( 'Sensei LMS Feedback', 'sensei-lms' ); ?></h2>
<p>
<?php esc_html_e( 'Please share why you are deactivating Sensei LMS.', 'sensei-lms' ); ?>
</p>

<!--
WORK IN PROGRESS:
- Data to send (checkboxes, textfields, etc...)
-->

<div class="buttons clear">
<a href="#close" id="sensei_deactivation_form_cancel" class="button" rel="modal:close"><?php esc_html_e( 'Skip and Continue', 'sensei-lms' ); ?></a>
<input type="submit" value="<?php esc_attr_e( 'Submit and Continue', 'sensei-lms' ); ?>" name="send_survey" id="sensei_deactivation_form_send_survey" class="button-primary">
</div>
</div>
</form>
</div>