forked from colin/SimpleTracking
Update simple-status.php
This commit is contained in:
parent
c140107114
commit
e5182a316f
|
@ -1,26 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: Simple Status
|
Plugin Name: Simple Tracking
|
||||||
Description: Adds a custom health check endpoint for monitoring.
|
Description: Embeds tracking code into your WordPress site.
|
||||||
Version: 1.0
|
Version: 1.0
|
||||||
Author: Your Name
|
Author: Colin
|
||||||
|
Author URI: https://git.nixc.us/colin/SimpleTracking.git
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Add a simple health check endpoint in your custom plugin
|
function add_simple_tracking_code() {
|
||||||
add_action('rest_api_init', function () {
|
$tracking_code_path = plugin_dir_path(__FILE__) . 'tracking-code.php';
|
||||||
error_log('Initializing custom health check route.');
|
if (file_exists($tracking_code_path)) {
|
||||||
register_rest_route('custom/v1', '/health', array(
|
include $tracking_code_path;
|
||||||
'methods' => 'GET',
|
|
||||||
'callback' => 'custom_health_check',
|
|
||||||
));
|
|
||||||
});
|
|
||||||
|
|
||||||
function custom_health_check() {
|
|
||||||
error_log('Health check endpoint hit.');
|
|
||||||
// Perform basic checks here (e.g., database connectivity)
|
|
||||||
if (is_wp_error($response = wp_remote_get(home_url()))) {
|
|
||||||
return new WP_Error('site_down', 'Site is down', array('status' => 500));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WP_REST_Response(array('status' => 'UP'), 200);
|
|
||||||
}
|
}
|
||||||
|
add_action('wp_head', 'add_simple_tracking_code');
|
||||||
|
|
Loading…
Reference in New Issue