plugin_file = $_plugin_file; $this->plugin_name = $slug; //for translations $apiControl = ApiKeyController::getInstance(); $this->key = $apiControl->forceGetApiKey(); // Skip the feedback when constant. if (defined('SHORTPIXEL_SKIP_FEEDBACK') && true == SHORTPIXEL_SKIP_FEEDBACK) { return false; } // Deactivation add_filter( 'plugin_action_links_' . plugin_basename( $this->plugin_file ), array( $this, 'filterActionLinks') ); add_filter('network_admin_plugin_action_links_' . plugin_basename( $this->plugin_file ), array( $this, 'filterActionLinks')); add_action( 'admin_footer-plugins.php', array( $this, 'goodbyeAjax') ); add_action( 'wp_ajax_shortpixel_deactivate_plugin', array( $this, 'deactivatePluginCallback') ); } /** * Filter the deactivation link to allow us to present a form when the user deactivates the plugin * @since 1.0.0 */ public function filterActionLinks( $links ) { if( isset( $links['deactivate'] ) ) { $deactivation_link = $links['deactivate']; // Insert an onClick action to allow form before deactivating $deactivation_link = str_replace( ' getFormInfo(); // Build the HTML to go in the form $html = '
' . esc_html( $form['heading'] ) . '
'; $html .= '
'; if( is_array( $form['options'] ) ) { $html .= '
'; $html .= '

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

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

'; $html .= '
'; } $html .= '
'; $html .= '' . sprintf(__( 'If you want to completely uninstall ShortPIxel from your site, please go to %s Settings → ShortPixel → Tools %s.', 'shortpixel-image-optimiser' ),'
', '') . '
'; $html .= '
'; $html .= '
'; $html .= '

' . __( 'Submitting form', 'shortpixel-image-optimiser' ) . '

'; $html .= ''; ?>
__('Temporary deactivation', 'shortpixel-image-optimiser'), 'setup' => __( 'Set up is too difficult', 'shortpixel-image-optimiser' ), 'docs' => __( 'Lack of documentation', 'shortpixel-image-optimiser' ), 'features' => __( 'Not the features I wanted', 'shortpixel-image-optimiser' ), 'better-plugin' => __( 'Found a better plugin', 'shortpixel-image-optimiser' ), 'incompatibility' => __( 'Incompatible with theme or plugin', 'shortpixel-image-optimiser' ), 'maintenance' => __( 'Other', 'shortpixel-image-optimiser' ), ); $form['details'] = __( 'How could we improve ?', 'shortpixel-image-optimiser'); return $form; } public function deactivatePluginCallback() { check_ajax_referer( 'shortpixel_deactivate_plugin', 'security' ); Log::addDebug('Deactive Plugin Callback POST', $_POST); if ( isset($_POST['reason']) && isset($_POST['details']) && isset($_POST['anonymous']) ) { require_once(\WPSPIO()->plugin_path() . 'class/view/shortpixel-plugin-request.php'); $anonymous = (intval($_POST['anonymous']) == 1) ? true : false; $args = array( 'key' => $this->key, 'reason' => sanitize_text_field(wp_unslash($_POST['reason'])), 'details' => sanitize_text_field(wp_unslash($_POST['details'])), 'anonymous' => $anonymous ); $request = new ShortPixelPluginRequest( $this->plugin_file, 'http://' . SHORTPIXEL_API . '/v2/feedback.php', $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(); } }