plugin_file = $_plugin_file;
$this->home_url = 'webbuilders03@gmail.com';
$this->plugin_name = basename( $this->plugin_file, '.php' );
$this->require_optin = $_require_optin;
$this->include_goodbye_form = $_include_goodbye_form;
// Deactivation hook
register_deactivation_hook( $this->plugin_file, array( $this, 'deactivate_this_plugin' ) );
// Get it going
$this->init();
}
public function init() {
global $pagenow;
// Deactivation
add_filter( 'plugin_action_links_' . plugin_basename( $this->plugin_file ), array( $this, 'filter_action_links' ) );
add_action( 'admin_footer-plugins.php', array( $this, 'goodbye_ajax' ) );
add_action( 'wp_ajax_pd_alm_goodbye_form', array( $this, 'goodbye_form_callback' ) );
if( $pagenow == 'plugins.php' ){
add_action('admin_enqueue_scripts',array($this, 'admin_enqueue_scripts'));
}
}
public function admin_enqueue_scripts(){
wp_enqueue_style('pdalm-admin-style', PD_ALM_URL . 'admin/assets/css/admin.css', array(), PD_ALM_VERSION, 'all');
$css='';
$css .= '.button.pd_alm-promo-link {
color: #ff0000;
font-weight: normal;
margin-left: 0;
margin-top: 1px !important;
}
.clear{ clear: both; }';
$css .= ".wpb-form-active .pd_alm-goodbye-form-bg{background:rgba(0,0,0,.5);position:fixed;top:0;left:0;width:100%;height:100%}.wpb-goodbye-form-wrapper{position:relative;z-index:999;display:none}.wpb-form-active .wpb-goodbye-form-wrapper{display:block}.wpb-goodbye-form{display:none}.wpb-form-active .wpb-goodbye-form{position:fixed;max-width:400px;background:#fff;white-space:normal;z-index:99;top:50%;left:50%;transform:translate(-50%,-50%);border-radius:5px}.wpb-goodbye-form-head{background:#7a00aa;color:#fff;padding:8px 18px;text-align:center;border-radius:5px 5px 0 0}.wpb-goodbye-form-body{padding:8px 18px;color:#444}.deactivating-spinner{display:none}.deactivating-spinner .spinner{float:none;margin:4px 4px 0 18px;vertical-align:bottom;visibility:visible}.wpb-goodbye-form-footer{padding:8px 18px}";
wp_add_inline_style( 'pdalm-admin-style', $css );
}
// In theme's functions.php or plug-in code:
function set_content_type(){
return "text/html";
}
/**
* Send the data to the home site
*
* @since 1.0.0
*/
public function send_data( $body ) {
$message = '';
foreach($body as $key=>$value){
if($key=='active_plugins'){
$message .='
'.$key.': '.(implode(', ',$value)).'
';
}
elseif($key=='inactive_plugins'){
$message .=' '.$key.': '.(implode(', ',$value)).'
';
}else{
$message .=' '.$key.': '.$value.'
';
}
}
$title = esc_html('Elementor Ajax Load More Plugin Deactivation Notice');
$headers = array('From: Elementor Ajax Load More ');
add_filter( 'wp_mail_content_type', array($this, 'set_content_type') );
$email = wp_mail($this->home_url, $title, $message, $headers);
remove_filter('wp_mail_content_type', array($this, 'set_content_type'));
return $email;
}
/**
* Here we collect most of the data
*
* @since 1.0.0
*/
public function get_data() {
// Use this to pass error messages back if necessary
$body['message'] = '';
// Use this array to send data back
$body = array();
/**
* Get our plugin data
* Currently we grab plugin name and version
* Or, return a message if the plugin data is not available
* @since 1.0.0
*/
$plugin = $this->plugin_data();
if( empty( $plugin ) ) {
// We can't find the plugin data
// Send a message back to our home site
$body['message'] .= esc_html__( 'We can\'t detect any plugin information. This is most probably because you have not included the code in the plugin main file.', 'wpchatbot' );
$body['status'] = esc_html('Data not found'); // Never translated
} else {
if( isset( $plugin['Name'] ) ) {
$body['plugin'] = sanitize_text_field( $plugin['Name'] );
}
if( isset( $plugin['Version'] ) ) {
$body['version'] = sanitize_text_field( $plugin['Version'] );
}
}
// Return the data
return $body;
}
/**
* Return plugin data
* @since 1.0.0
*/
public function plugin_data() {
// Being cautious here
if( ! function_exists( 'get_plugin_data' ) ) {
include ABSPATH . '/wp-admin/includes/plugin.php';
}
// Retrieve current plugin information
$plugin = get_plugin_data( $this->plugin_file );
return $plugin;
}
/**
* Deactivating plugin
* @since 1.0.0
*/
public function deactivate_this_plugin() {
$body = $this->get_data();
$body['status'] = 'Deactivated'; // Never translated
$body['deactivated_date'] = date('Y-m-d');
$body['url'] = home_url();
$body['contact1'] = get_option( 'admin_email' );
// Add deactivation form data
if( false !== get_option( 'pd_alm_deactivation_reason_' . $this->plugin_name ) ) {
$body['deactivation_reason'] = get_option( 'pd_alm_deactivation_reason_' . $this->plugin_name );
delete_option('pd_alm_deactivation_reason_' . $this->plugin_name);
}
if( false !== get_option( 'pd_alm_deactivation_details_' . $this->plugin_name ) ) {
$body['deactivation_details'] = get_option( 'pd_alm_deactivation_details_' . $this->plugin_name );
delete_option('pd_alm_deactivation_details_' . $this->plugin_name);
}
if( false !== get_option( 'pd_alm_deactivation_email_' . $this->plugin_name ) ) {
$body['deactivation_email'] = get_option( 'pd_alm_deactivation_email_' . $this->plugin_name );
delete_option('pd_alm_deactivation_email_' . $this->plugin_name);
}
if( false !== get_option( 'pd_alm_deactivation_main_reason_' . $this->plugin_name ) ) {
$body['deactivation_main_reason'] = get_option( 'pd_alm_deactivation_main_reason_' . $this->plugin_name );
delete_option('pd_alm_deactivation_main_reason_' . $this->plugin_name);
}
if(isset($body['deactivation_reason']) or isset($body['deactivation_details']))
$this->send_data( $body );
}
/**
* Filter the deactivation link to allow us to present a form when the user deactivates the plugin
* @since 1.0.0
*/
public function filter_action_links( $links ) {
if( isset( $links['deactivate'] ) && $this->include_goodbye_form ) {
$deactivation_link = $links['deactivate'];
// Insert an onClick action to allow form before deactivating
$deactivation_link = str_replace( 'form_default_text();
return apply_filters( 'pd_alm_form_text_' . esc_attr( $this->plugin_name ), $form );
}
/**
* Form text strings
* These can be filtered
* @since 1.0.0
*/
public function goodbye_ajax() {
// Get our strings for the form
$form = $this->form_filterable_text();
if( ! isset( $form['heading'] ) || ! isset( $form['body'] ) || ! isset( $form['options'] ) || ! is_array( $form['options'] ) || ! isset( $form['details'] ) ) {
// If the form hasn't been filtered correctly, we revert to the default form
$form = $this->form_default_text();
}
// Build the HTML to go in the form
$html = '' . esc_html( $form['heading'] ) . '
';
$html .= '' . esc_html( $form['body'] ) . '
';
if( is_array( $form['options'] ) ) {
$html .= '
';
}
$html .= '
';
$html .= ' ' . __( 'Submitting form', 'wpbot-plugin' ) . '
';
?>
plugin_name, $values );
}
if( isset( $_POST['details'] ) ) {
$details = sanitize_text_field( $_POST['details'] );
update_option( 'pd_alm_deactivation_details_' . $this->plugin_name, $details );
}
if( isset( $_POST['email'] ) ) {
$email = sanitize_text_field( $_POST['email'] );
update_option( 'pd_alm_deactivation_email_' . $this->plugin_name, $email );
}
if( isset( $_POST['main_reason'] ) ) {
$main_reason = sanitize_text_field( $_POST['main_reason'] );
update_option( 'pd_alm_deactivation_main_reason_' . $this->plugin_name, $main_reason );
}
echo 'success';
wp_die();
}
}
}