芝麻web文件管理V1.00
编辑当前文件:/home/dcqnetm/novia/wp-content/plugins/image-optimization/modules/deactivation/module.php
should_show_feedback() ) { return; } // Enqueue thickbox for modal add_thickbox(); wp_enqueue_script( 'deactivation-io', $this->get_js_assets_url( 'deactivation' ), [], IMAGE_OPTIMIZATION_VERSION, true ); wp_enqueue_style( 'deactivation-io', $this->get_css_assets_url( 'style-deactivation' ), [], IMAGE_OPTIMIZATION_VERSION, ); wp_localize_script( 'deactivation-io', 'imageOptimizationDeactivationFeedback', [ 'nonce' => wp_create_nonce( 'image_optimization_deactivation_feedback' ), 'ajaxurl' => admin_url( 'admin-ajax.php' ), ] ); } /** * Add deactivation feedback modal HTML to footer */ public function add_deactivation_modal(): void { if ( ! $this->should_show_feedback() ) { return; } ?>
</textarea>
</textarea>
'No reason provided' ] ); return; } // Send feedback to external service $feedback_sent = $this->send_feedback_to_service( $reason, $additional_data ); if ( $feedback_sent ) { wp_send_json_success( [ 'message' => 'Feedback sent successfully' ] ); } else { // Still return success to not block deactivation, but log the error Logger::log( Logger::LEVEL_ERROR, 'Failed to send deactivation feedback to service' ); wp_send_json_success( [ 'message' => 'Feedback logged locally' ] ); } } /** * Send feedback to external service * * @param string $reason The deactivation reason * @param string $additional_data Additional feedback data from text fields * @return bool Whether the feedback was sent successfully */ private function send_feedback_to_service( string $reason, string $additional_data = '' ): bool { $feedback_data = $this->prepare_feedback_data( $reason, $additional_data ); $response = Client::get_instance()->make_request( 'POST', self::SERVICE_ENDPOINT, $feedback_data ); if ( empty( $response ) || is_wp_error( $response ) ) { $error_message = is_wp_error( $response ) ? $response->get_error_message() : 'Unknown error'; Logger::log( Logger::LEVEL_ERROR, 'Failed to post feedback: ' . $error_message ); return false; } return true; } /** * Prepare feedback data for the service * * @param string $reason The deactivation reason * @param string $additional_data Additional feedback data from text fields * @return array Formatted feedback data */ private function prepare_feedback_data( string $reason, string $additional_data = '' ): array { $data = [ 'app' => 'image-optimizer', 'app_version' => IMAGE_OPTIMIZATION_VERSION, 'selected_answer' => $reason, 'site_url' => home_url(), 'wp_version' => get_bloginfo( 'version' ), 'php_version' => PHP_VERSION, 'timestamp' => current_time( 'mysql' ), 'user_agent' => sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ?? '' ) ), 'locale' => get_locale(), ]; // Add additional data if provided if ( ! empty( $additional_data ) ) { $data['feedback_text'] = $additional_data; } return $data; } /** * Constructor */ public function __construct() { add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_deactivation_assets' ] ); add_action( 'admin_footer', [ $this, 'add_deactivation_modal' ] ); add_action( 'wp_ajax_image_optimization_deactivation_feedback', [ $this, 'handle_deactivation_feedback' ] ); } }