Skip to content

Instantly share code, notes, and snippets.

@afragen
Last active January 6, 2026 22:29
Show Gist options
  • Select an option

  • Save afragen/10e88e79370b1061b36ec7fc60932cb3 to your computer and use it in GitHub Desktop.

Select an option

Save afragen/10e88e79370b1061b36ec7fc60932cb3 to your computer and use it in GitHub Desktop.
Write http API debug data to debug.log
<?php
/**
* Plugin Name: GitHub API Debug
* Description: A plugin to help debug GitHub API issues by logging API requests and responses.
* Version: 0.2.1
* Author: Andy Fragen
* License: MIT
* Requires at least: 6.8
* Requires PHP: 8.2
* Network: true
* Gist Plugin URI: https://gist.github.com/afragen/10e88e79370b1061b36ec7fc60932cb3
*/
namespace Fragen\GitHub_API_Debug;
/**
* Bootstrap
*
* @return void
*/
function bootstrap(): void {
add_action('http_api_debug', __NAMESPACE__ . '\\init', 10, 5);
}
/**
* Initialize
*
* @param string $response The response.
* @param string $type The type of request.
* @param string $class The HTTP class.
* @param array $args The request arguments.
* @param string $url The request URL.
*
* @return void
*/
function init($response, $type, $class, $args, $url): void {
if (str_contains($url, 'api.github.com')) {
$log_entry = [
'url' => $url,
'type' => $type,
'class' => $class,
'headers' => $args['headers'] ?? [],
'response' => $response['response'] ?? [],
'response_filename' => $response['filename'] ?? '',
'response_headers' => $response['headers'],
];
error_log(print_r($log_entry, true));
}
}
bootstrap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment