From 271146c5a95419d4f99eb6d8d3b054c17e2bc1b8 Mon Sep 17 00:00:00 2001 From: bipoza Date: Mon, 29 May 2023 17:07:10 +0200 Subject: [PATCH] Improvement in the route and disable caching --- check-connection.php | 12 ++++++++++++ readme.md | 2 +- wp-uptime.php | 30 +++++++++++------------------- 3 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 check-connection.php diff --git a/check-connection.php b/check-connection.php new file mode 100644 index 0000000..245a90b --- /dev/null +++ b/check-connection.php @@ -0,0 +1,12 @@ +check_connection(); + + +if ($result) { + header('Content-Type: text/plain; charset=utf-8'); + header('Cache-Control: no-cache, no-store, must-revalidate'); + header('Pragma: no-cache'); + header('Expires: 0'); + echo get_option_or_value("wp_uptime_response_value", 'OK'); +} \ No newline at end of file diff --git a/readme.md b/readme.md index bd7116a..a772549 100644 --- a/readme.md +++ b/readme.md @@ -11,7 +11,7 @@ Just install the plugin and activate it. By default, the API is at this address and if mysql is running it will return OK. ``` -https://your-site.com/wp-json/wp-uptime/ok +https://your-site.com/ok/ ``` ## Edition panel diff --git a/wp-uptime.php b/wp-uptime.php index 6427b11..c3889f0 100644 --- a/wp-uptime.php +++ b/wp-uptime.php @@ -28,38 +28,30 @@ function get_option_or_value($key, $default_value) return $response; } -add_action('rest_api_init', function () { - register_rest_route( - 'wp-uptime', - '/' . get_option_or_value("wp_uptime_endpoint_path", 'ok') . '/', - array( - 'methods' => 'GET', - 'callback' => 'wp_uptime_route_handler', - ) - ); -}); -function wp_uptime_route_handler($request) +add_action('init', 'wpUptimeFeed'); +function wpUptimeFeed() { - global $wpdb; - $result = $wpdb->check_connection(); - + add_feed(get_option_or_value("wp_uptime_endpoint_path", 'ok'), 'wpUptimeResponse'); + global $wp_rewrite; + $wp_rewrite->flush_rules(); +} - if ($result) { - echo get_option_or_value("wp_uptime_response_value", 'OK'); - } +function wpUptimeResponse() +{ + include('check-connection.php'); } add_action('admin_menu', 'wp_uptime_menu'); function wp_uptime_menu() { - add_menu_page('WP Uptime Settings', 'WP Uptime', 'manage_options', 'wp-uptime-settings', 'wp_uptime_settings_page'); + add_options_page('WP Uptime Settings', 'WP Uptime', 'manage_options', 'wp-uptime-settings', 'wp_uptime_settings_page'); } function wp_uptime_settings_page() { - $url = get_rest_url(null, 'wp-uptime/' . get_option_or_value("wp_uptime_endpoint_path", 'ok') . '/'); + $url = get_site_url(null, get_option_or_value("wp_uptime_endpoint_path", 'ok') . '/'); ?>