<?php
header('Access-Control-Allow-Origin: *');
header(
    'Access-Control-Allow-Methods: HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS'
);
header(
    'Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization'
);
header('Content-Type: application/json');

// Connect to the WordPress database
include '../../../config/db.php';

// Sanitize input
$id = mysqli_real_escape_string( $con, $_GET['id'] );

// Get user by ID
$query = "SELECT * FROM Users WHERE userId = $id";
$result = mysqli_query( $con, $query );
if ( $result ) {
  if ( mysqli_num_rows( $result ) > 0 ) {
    $user = mysqli_fetch_assoc( $result );
    $response = array(
      'status' => 'success',
      'user' => $user
    );
  } else {
    $response = array(
      'status' => 'error',
      'message' => 'User not found'
    );
  }
} else {
  $response = array(
    'status' => 'error',
    'message' => mysqli_error( $con )
  );
}

// Return response as JSON
header( 'Content-Type: application/json' );
echo json_encode( $response );

?>
