| 1 |
<?php |
| 2 |
namespace WPAdminify\Inc\Classes; |
| 3 |
|
| 4 |
use WPAdminify\Inc\Classes\Notifications\Base\User_Data; |
| 5 |
|
| 6 |
// No, Direct access Sir !!! |
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Feedback |
| 13 |
* |
| 14 |
* @author Jewel Theme <support@jeweltheme.com> |
| 15 |
*/ |
| 16 |
class Feedback { |
| 17 |
|
| 18 |
use User_Data; |
| 19 |
|
| 20 |
/** |
| 21 |
* Construct Method |
| 22 |
* |
| 23 |
* @return void |
| 24 |
* @author Jewel Theme <support@jeweltheme.com> |
| 25 |
*/ |
| 26 |
public function __construct() { |
| 27 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_suvery_scripts' ) ); |
| 28 |
add_action( 'admin_footer', array( $this, 'deactivation_footer' ) ); |
| 29 |
add_action( 'wp_ajax_jltwp_adminify_deactivation_survey', array( $this, 'jltwp_adminify_deactivation_survey' ) ); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
public function proceed() { |
| 34 |
|
| 35 |
global $current_screen; |
| 36 |
if ( |
| 37 |
isset( $current_screen->parent_file ) |
| 38 |
&& $current_screen->parent_file == 'plugins.php' |
| 39 |
&& isset( $current_screen->id ) |
| 40 |
&& $current_screen->id == 'plugins' |
| 41 |
) { |
| 42 |
return true; |
| 43 |
} |
| 44 |
return false; |
| 45 |
} |
| 46 |
|
| 47 |
public function admin_suvery_scripts( $handle ) { |
| 48 |
if ( 'plugins.php' === $handle ) { |
| 49 |
wp_enqueue_style( 'jltwp_adminify-survey', WP_ADMINIFY_ASSETS . 'css/plugin-survey.css' ); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Deactivation Survey |
| 55 |
*/ |
| 56 |
public function jltwp_adminify_deactivation_survey() { |
| 57 |
check_ajax_referer( 'jltwp_adminify_deactivation_nonce' ); |
| 58 |
|
| 59 |
$deactivation_reason = ! empty( $_POST['deactivation_reason'] ) ? sanitize_text_field( wp_unslash( $_POST['deactivation_reason'] ) ) : ''; |
| 60 |
|
| 61 |
if ( empty( $deactivation_reason ) ) { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
$email = get_bloginfo( 'admin_email' ); |
| 66 |
$author_obj = get_user_by( 'email', $email ); |
| 67 |
$user_id = $author_obj->ID; |
| 68 |
$full_name = $author_obj->display_name; |
| 69 |
|
| 70 |
$response = $this->get_collect_data( |
| 71 |
$user_id, |
| 72 |
array( |
| 73 |
'first_name' => $full_name, |
| 74 |
'email' => $email, |
| 75 |
'deactivation_reason' => $deactivation_reason, |
| 76 |
) |
| 77 |
); |
| 78 |
|
| 79 |
return $response; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
public function get_survey_questions() { |
| 84 |
|
| 85 |
return array( |
| 86 |
'no_longer_needed' => array( |
| 87 |
'title' => esc_html__( 'I no longer need the plugin', 'adminify' ), |
| 88 |
'input_placeholder' => '', |
| 89 |
), |
| 90 |
'found_a_better_plugin' => array( |
| 91 |
'title' => esc_html__( 'I found a better plugin', 'adminify' ), |
| 92 |
'input_placeholder' => esc_html__( 'Please share which plugin', 'adminify' ), |
| 93 |
), |
| 94 |
'couldnt_get_the_plugin_to_work' => array( |
| 95 |
'title' => esc_html__( 'I couldn\'t get the plugin to work', 'adminify' ), |
| 96 |
'input_placeholder' => '', |
| 97 |
), |
| 98 |
'temporary_deactivation' => array( |
| 99 |
'title' => esc_html__( 'It\'s a temporary deactivation', 'adminify' ), |
| 100 |
'input_placeholder' => '', |
| 101 |
), |
| 102 |
'jltwp_adminify_pro' => array( |
| 103 |
'title' => sprintf( esc_html__( 'I have %1$s Pro', 'adminify' ), WP_ADMINIFY ), |
| 104 |
'input_placeholder' => '', |
| 105 |
'alert' => sprintf( esc_html__( 'Wait! Don\'t deactivate %1$s. You have to activate both %1$s and %1$s Pro in order for the plugin to work.', 'adminify' ), WP_ADMINIFY ), |
| 106 |
), |
| 107 |
'need_better_design' => array( |
| 108 |
'title' => esc_html__( 'I need better design and presets', 'adminify' ), |
| 109 |
'input_placeholder' => esc_html__( 'Let us know your thoughts', 'adminify' ), |
| 110 |
), |
| 111 |
'other' => array( |
| 112 |
'title' => esc_html__( 'Other', 'adminify' ), |
| 113 |
'input_placeholder' => esc_html__( 'Please share the reason', 'adminify' ), |
| 114 |
), |
| 115 |
); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
/** |
| 120 |
* Deactivation Footer |
| 121 |
*/ |
| 122 |
public function deactivation_footer() { |
| 123 |
|
| 124 |
if ( ! $this->proceed() ) { |
| 125 |
return; |
| 126 |
} |
| 127 |
|
| 128 |
?> |
| 129 |
<div class="wp-adminify-deactivate-survey-overlay" id="wp-adminify-deactivate-survey-overlay"></div> |
| 130 |
<div class="wp-adminify-deactivate-survey-modal" id="wp-adminify-deactivate-survey-modal"> |
| 131 |
<header> |
| 132 |
<div class="wp-adminify-deactivate-survey-header"> |
| 133 |
<img src="<?php echo esc_url( WP_ADMINIFY_ASSETS_IMAGE . 'logos/menu-icon.svg' ); ?>" /> |
| 134 |
<h3><?php echo wp_sprintf( '%1$s <strong>%2$s</strong>', WP_ADMINIFY, __( '- Feedback', 'adminify' ) ); ?></h3> |
| 135 |
</div> |
| 136 |
</header> |
| 137 |
<div class="wp-adminify-deactivate-info"> |
| 138 |
<?php echo wp_sprintf( '%1$s %2$s', __( 'If you have a moment, please share why you are deactivating', 'adminify' ), WP_ADMINIFY ); ?> |
| 139 |
</div> |
| 140 |
<div class="wp-adminify-deactivate-content-wrapper"> |
| 141 |
<form action="#" class="wp-adminify-deactivate-form-wrapper"> |
| 142 |
<?php foreach ( $this->get_survey_questions() as $reason_key => $reason ) { ?> |
| 143 |
<div class="wp-adminify-deactivate-input-wrapper"> |
| 144 |
<input id="wp-adminify-deactivate-feedback-<?php echo esc_attr( $reason_key ); ?>" class="wp-adminify-deactivate-feedback-dialog-input" type="radio" name="reason_key" value="<?php echo $reason_key; ?>"> |
| 145 |
<label for="wp-adminify-deactivate-feedback-<?php echo esc_attr( $reason_key ); ?>" class="wp-adminify-deactivate-feedback-dialog-label"><?php echo esc_html( $reason['title'] ); ?></label> |
| 146 |
<?php if ( ! empty( $reason['input_placeholder'] ) ) : ?> |
| 147 |
<input class="wp-adminify-deactivate-feedback-text" type="text" name="reason_<?php echo esc_attr( $reason_key ); ?>" placeholder="<?php echo esc_attr( $reason['input_placeholder'] ); ?>" /> |
| 148 |
<?php endif; ?> |
| 149 |
</div> |
| 150 |
<?php } ?> |
| 151 |
<div class="wp-adminify-deactivate-footer"> |
| 152 |
<button id="wp-adminify-dialog-lightbox-submit" class="wp-adminify-dialog-lightbox-submit"><?php echo esc_html__( 'Submit & Deactivate', 'adminify' ); ?></button> |
| 153 |
<button id="wp-adminify-dialog-lightbox-skip" class="wp-adminify-dialog-lightbox-skip"><?php echo esc_html__( 'Skip & Deactivate', 'adminify' ); ?></button> |
| 154 |
</div> |
| 155 |
</form> |
| 156 |
</div> |
| 157 |
</div> |
| 158 |
|
| 159 |
<script> |
| 160 |
var deactivate_url = '#'; |
| 161 |
|
| 162 |
jQuery(document).on('click', '#deactivate-adminify', function(e) { |
| 163 |
e.preventDefault(); |
| 164 |
deactivate_url = e.target.href; |
| 165 |
jQuery('#wp-adminify-deactivate-survey-overlay').addClass('wp-adminify-deactivate-survey-is-visible'); |
| 166 |
jQuery('#wp-adminify-deactivate-survey-modal').addClass('wp-adminify-deactivate-survey-is-visible'); |
| 167 |
}); |
| 168 |
|
| 169 |
jQuery('#wp-adminify-dialog-lightbox-skip').on('click', function (e) { |
| 170 |
e.preventDefault(); |
| 171 |
window.location.replace(deactivate_url); |
| 172 |
}); |
| 173 |
|
| 174 |
|
| 175 |
jQuery(document).on('click', '#wp-adminify-dialog-lightbox-submit', async function(e) { |
| 176 |
e.preventDefault(); |
| 177 |
|
| 178 |
jQuery('#wp-adminify-dialog-lightbox-submit').addClass('wp-adminify-loading'); |
| 179 |
|
| 180 |
var $dialogModal = jQuery('.wp-adminify-deactivate-input-wrapper'), |
| 181 |
radioSelector = '.wp-adminify-deactivate-feedback-dialog-input'; |
| 182 |
$dialogModal.find(radioSelector).on('change', function () { |
| 183 |
$dialogModal.attr('data-feedback-selected', jQuery(this).val()); |
| 184 |
}); |
| 185 |
$dialogModal.find(radioSelector + ':checked').trigger('change'); |
| 186 |
|
| 187 |
|
| 188 |
// Reasons for deactivation |
| 189 |
var deactivation_reason = ''; |
| 190 |
var reasonData = jQuery('.wp-adminify-deactivate-form-wrapper').serializeArray(); |
| 191 |
|
| 192 |
jQuery.each(reasonData, function (reason_index, reason_value) { |
| 193 |
if ('reason_key' == reason_value.name && reason_value.value != '') { |
| 194 |
const reason_input_id = '#wp-adminify-deactivate-feedback-' + reason_value.value, |
| 195 |
reason_title = jQuery(reason_input_id).siblings('label').text(), |
| 196 |
reason_placeholder_input = jQuery(reason_input_id).siblings('input').val(), |
| 197 |
format_title_with_key = reason_value.value + ' - ' + reason_placeholder_input, |
| 198 |
format_title = reason_title + ' - ' + reason_placeholder_input; |
| 199 |
|
| 200 |
deactivation_reason = reason_value.value; |
| 201 |
|
| 202 |
if ('found_a_better_plugin' == reason_value.value ) { |
| 203 |
deactivation_reason = format_title_with_key; |
| 204 |
} |
| 205 |
|
| 206 |
if ('need_better_design' == reason_value.value ) { |
| 207 |
deactivation_reason = format_title_with_key; |
| 208 |
} |
| 209 |
|
| 210 |
if ('other' == reason_value.value) { |
| 211 |
deactivation_reason = format_title_with_key; |
| 212 |
} |
| 213 |
} |
| 214 |
}); |
| 215 |
|
| 216 |
await jQuery.ajax({ |
| 217 |
url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', |
| 218 |
method: 'POST', |
| 219 |
// crossDomain: true, |
| 220 |
async: true, |
| 221 |
// dataType: 'jsonp', |
| 222 |
data: { |
| 223 |
action: 'jltwp_adminify_deactivation_survey', |
| 224 |
_wpnonce: '<?php echo esc_js( wp_create_nonce( 'jltwp_adminify_deactivation_nonce' ) ); ?>', |
| 225 |
deactivation_reason: deactivation_reason |
| 226 |
}, |
| 227 |
success:function(response){ |
| 228 |
window.location.replace(deactivate_url); |
| 229 |
} |
| 230 |
}); |
| 231 |
return true; |
| 232 |
}); |
| 233 |
|
| 234 |
jQuery('#wp-adminify-deactivate-survey-overlay').on('click', function () { |
| 235 |
jQuery('#wp-adminify-deactivate-survey-overlay').removeClass('wp-adminify-deactivate-survey-is-visible'); |
| 236 |
jQuery('#wp-adminify-deactivate-survey-modal').removeClass('wp-adminify-deactivate-survey-is-visible'); |
| 237 |
}); |
| 238 |
</script> |
| 239 |
<?php |
| 240 |
} |
| 241 |
} |
| 242 |
|