plugin_file = $_plugin_file; $this->plugin_name = basename( $this->plugin_file, '.php' ); // 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_epsilon_deactivate_plugin', array( $this, 'epsilon_deactivate_plugin_callback' ) ); } /** * 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'] ) ) { $deactivation_link = $links['deactivate']; // Insert an onClick action to allow form before deactivating $deactivation_link = str_replace( 'get_form_info(); // Build the HTML to go in the form $html = '
' . esc_html( $form['heading'] ) . '
'; $html .= '

' . esc_html( $form['body'] ) . '

'; if ( is_array( $form['options'] ) ) { $html .= '

'; foreach ( $form['options'] as $key => $option ) { if ( 'features' == $key ) { $html .= '
'; } else { $html .= '
'; } } $html .= '

'; $html .= '
'; $html .= '
'; } $html .= '
'; $html .= '

' . __( 'Submitting form', 'saboxplugin' ) . '

'; $html .= '
' ?>
__( 'Set up is too difficult', 'saboxplugin' ), 'documentation' => __( 'Lack of documentation', 'saboxplugin' ), 'features' => __( 'Not the features I wanted', 'saboxplugin' ), 'better-plugin' => __( 'Found a better plugin', 'saboxplugin' ), 'incompatibility' => __( 'Incompatible with theme or plugin', 'saboxplugin' ), ); $form['details'] = __( 'How could we improve ?', 'saboxplugin' ); return $form; } public function epsilon_deactivate_plugin_callback() { check_ajax_referer( 'epsilon_deactivate_plugin', 'security' ); if ( isset( $_POST['reason'] ) && isset( $_POST['details'] ) && isset( $_POST['tracking'] ) ) { require_once 'class-epsilon-plugin-request-sab.php'; $args = array( 'reason' => $_POST['reason'], 'details' => $_POST['details'], 'tracking' => $_POST['tracking'], ); $request = new Epsilon_Plugin_Request_SAB( $this->plugin_file, $args ); if ( $request->request_successful ) { echo json_encode( array( 'status' => 'ok', ) ); } else { echo json_encode( array( 'status' => 'nok', ) ); } } else { echo json_encode( array( 'status' => 'ok', ) ); } die(); } }