'error', 'message' => 'WP-CLI not found']); exit(1); } // Function to run WP-CLI commands function run_wp_command($command) { $output = []; $return_var = 0; exec("/home/litespeed/bin/wp --path=/var/www/webroot/ROOT $command", $output, $return_var); return ['output' => $output, 'return_var' => $return_var]; } switch ($action) { case 'enable': run_wp_command('litespeed-option set cache 1'); run_wp_command('litespeed-purge all'); echo json_encode(['status' => 'success', 'message' => 'LiteSpeed cache enabled and purged']); break; case 'disable': run_wp_command('litespeed-option set cache 0'); run_wp_command('litespeed-purge all'); echo json_encode(['status' => 'success', 'message' => 'LiteSpeed cache disabled and purged']); break; case 'purge': run_wp_command('litespeed-purge all'); echo json_encode(['status' => 'success', 'message' => 'LiteSpeed cache purged']); break; case 'set-ttl': if (empty($value)) { echo json_encode(['status' => 'error', 'message' => 'TTL value required']); exit(1); } run_wp_command("litespeed-option set cache-ttl_pub $value"); run_wp_command('litespeed-purge all'); echo json_encode(['status' => 'success', 'message' => "TTL set to $value and cache purged"]); break; case 'set-exclusions': if (empty($value)) { echo json_encode(['status' => 'error', 'message' => 'Exclusion paths required']); exit(1); } run_wp_command("litespeed-option set cache-exc \"$value\""); run_wp_command('litespeed-purge all'); echo json_encode(['status' => 'success', 'message' => 'Cache exclusions updated and cache purged']); break; default: echo json_encode(['status' => 'error', 'message' => 'Invalid action']); exit(1); }