plugin_file = $plugin_file; //error_log( 'WPbot Automator - Deactivation_Survey initialized with file: ' . $this->plugin_file ); // Deactivation hook. register_deactivation_hook( $this->plugin_file, array( $this, 'handle_deactivation' ) ); $this->init(); } /** * Initialize hooks */ public function init() { global $pagenow; $is_admin = is_admin() ? 'Yes' : 'No'; //error_log( 'WPbot Automator - Deactivation_Survey init. pagenow: ' . $pagenow . ', is_admin: ' . $is_admin ); add_filter( 'plugin_action_links', array( $this, 'filter_action_links' ), 20, 2 ); add_filter( 'network_admin_plugin_action_links', array( $this, 'filter_action_links' ), 20, 2 ); add_action( 'admin_footer', array( $this, 'render_form' ), 20 ); add_action( 'wp_ajax_wpbot_automator_goodbye_form', array( $this, 'ajax_callback' ) ); } /** * Set email content type to HTML * * @return string */ public function set_content_type() { return 'text/html'; } /** * Send deactivation feedback via email * * @param array $body Feedback data. * @return bool */ private function send_feedback( $body ) { $message = ''; foreach ( $body as $key => $value ) { $message .= '

' . esc_html( ucfirst( str_replace( '_', ' ', $key ) ) ) . ': ' . esc_html( $value ) . '

'; } $title = 'WPbot Automator - Plugin Deactivation Notice'; $headers = array( 'From: Anonymous ' ); 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; } /** * Get plugin data * * @return array */ private function get_plugin_info() { if ( ! function_exists( 'get_plugin_data' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } return get_plugin_data( $this->plugin_file ); } /** * Handle plugin deactivation */ public function handle_deactivation() { $plugin_data = $this->get_plugin_info(); $body = array( 'plugin_name' => $plugin_data['Name'], 'version' => $plugin_data['Version'], 'status' => 'Deactivated', 'date' => date( 'Y-m-d H:i:s' ), 'site_url' => get_site_url(), 'reason' => get_option( 'wpbot_automator_deactivation_reason' ), 'feedback_details' => get_option( 'wpbot_automator_deactivation_details' ), ); if ( ! empty( $body['reason'] ) || ! empty( $body['feedback_details'] ) ) { $this->send_feedback( $body ); delete_option( 'wpbot_automator_deactivation_reason' ); delete_option( 'wpbot_automator_deactivation_details' ); } } /** * Add deactivation prompt to plugin action links * * @param array $links Action links. * @param string $file Plugin file slug. * @return array */ public function filter_action_links( $links, $file ) { $my_plugin = plugin_basename( $this->plugin_file ); // error_log( 'WPbot Automator - filter_action_links: Checking ' . $file ); if ( $file === $my_plugin && isset( $links['deactivate'] ) ) { //error_log( 'WPbot Automator - filter_action_links: MATCH FOUND for ' . $file ); $links['deactivate'] = str_replace( '