admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'schema_ai_deactivation_feedback' ), 'pluginFile' => SCHEMA_AI_PLUGIN_BASENAME, 'pluginName' => 'AI Schema Gen', 'strings' => array( 'title' => __( 'Quick Feedback', 'ai-schema-gen' ), 'question' => __( 'If you have a moment, please share why you are deactivating %s:', 'ai-schema-gen' ), 'otherPlaceholder' => __( 'Please share the reason', 'ai-schema-gen' ), 'submit' => __( 'Submit & Deactivate', 'ai-schema-gen' ), 'skip' => __( 'Skip & Deactivate', 'ai-schema-gen' ), ), 'reasons' => array( array( 'value' => 'no_longer_need', 'label' => __( 'I no longer need the plugin', 'ai-schema-gen' ), ), array( 'value' => 'switching_plugin', 'label' => __( "I'm switching to a different plugin", 'ai-schema-gen' ), ), array( 'value' => 'couldnt_get_working', 'label' => __( "I couldn't get the plugin to work", 'ai-schema-gen' ), ), array( 'value' => 'temporary', 'label' => __( "It's a temporary deactivation", 'ai-schema-gen' ), ), array( 'value' => 'other', 'label' => __( 'Other', 'ai-schema-gen' ), ), ), ) ); } /** * AJAX handler: forward the submitted reason to the SaaS backend, if an * API key is configured. Fired non-blocking on the outbound request so * this responds quickly and never delays deactivation. */ public function ajax_submit() { check_ajax_referer( 'schema_ai_deactivation_feedback' ); $reason = isset( $_POST['reason'] ) ? sanitize_text_field( wp_unslash( $_POST['reason'] ) ) : ''; $other_text = isset( $_POST['other_text'] ) ? sanitize_textarea_field( wp_unslash( $_POST['other_text'] ) ) : ''; if ( empty( $reason ) ) { wp_send_json_error(); } $settings = get_option( 'schema_ai_settings', array() ); $api_key = ! empty( $settings['api_key'] ) ? $settings['api_key'] : ''; if ( ! empty( $api_key ) ) { $body = array( 'reason' => $reason, 'siteUrl' => home_url( '/' ), ); if ( ! empty( $other_text ) ) { $body['otherText'] = $other_text; } wp_remote_post( SCHEMA_AI_API_BASE . '/feedback/deactivation', array( 'timeout' => 5, 'blocking' => false, 'headers' => array( 'Content-Type' => 'application/json', 'X-API-Key' => $api_key, ), 'body' => wp_json_encode( $body ), ) ); } wp_send_json_success(); } }