<?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';

// Get all users
$query = "SELECT * FROM Users";
$result = mysqli_query( $con, $query );
if ( $result ) {
  $users = array();
  while ( $row = mysqli_fetch_assoc( $result ) ) {
    $users[] = $row;
  }
  $response = array(
    'status' => 'success',
    'users' => $users
  );
} else {
  $response = array(
    'status' => 'error',
    'message' => mysqli_error( $con )
  );
}

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

?>