<?php
/**
 * Uninstall Capsquery Facial Authentication — remove plugin data.
 *
 * @package Capsquery_Facial_Authentication
 */

if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
	exit;
}

delete_option( 'capsq_encryption_key' );
delete_option( 'capsq_enabled' );
delete_option( 'capsq_match_threshold' );

delete_metadata( 'user', 0, '_capsq_face_descriptor', '', true );
delete_metadata( 'user', 0, '_capsq_pin_hash', '', true );

global $wpdb;
// No core API can enumerate transients by name pattern, so a read-only
// lookup query is unavoidable here — but the actual deletion goes through
// delete_transient(), which correctly handles sites using an external
// object cache (where transients aren't stored in wp_options at all).
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$capsq_transient_names = $wpdb->get_col(
	$wpdb->prepare(
		"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s",
		$wpdb->esc_like( '_transient_capsq_match_' ) . '%'
	)
);

foreach ( $capsq_transient_names as $capsq_option_name ) {
	$capsq_token = str_replace( '_transient_capsq_match_', '', $capsq_option_name );
	delete_transient( 'capsq_match_' . $capsq_token );
}
