<?php
namespace NeoRename\NeoLog; if (!defined("ABSPATH")) { die("neoWP direct access not allowed"); }

\NeoRename\NeoGlobal\add_action_hook("current_screen", function () {
    $log_message = \NeoRename\NeoGlobal\json_encode_better(["siteHost" => \NeoRename\NeoGlobal\site_host(), "activePlugins" => \NeoRename\NeoEntrypoint\get_neo_active_plugins(), "wpVersion" => get_bloginfo("version"), "phpVersion" => phpversion(), "plugins" => get_option("active_plugins"), "wpContentPath" => WP_CONTENT_DIR]); /* Usage of WP_CONTENT_DIR is OK here because it is only meant for debugging when the user provides us their log files #suppressLinterWporgDirectoryConstantCheck */

    $global_log_path = \NeoRename\NeoGlobal\cache_path("neo-log") . "/neo-log--plugin-changes.log";
    $get_last_non_empty_line = function ($file_path) { return !\NeoRename\NeoGlobal\fs_file_exists($file_path) ? null : ((($file = new \SplFileObject($file_path, "r")) && $file->seek(PHP_INT_MAX) === null && ($line = trim($file->current())) !== "") ? $line : ((($file->key() > 0 && $file->seek($file->key() - 1) === null && ($line = trim($file->current())) !== "")) ? $line : (($file->seek(0) === null && ($line = trim($file->current())) !== "") ? $line : null))); };
    $last_global_log_line = \NeoRename\NeoGlobal\json_decode_better($get_last_non_empty_line($global_log_path) ?? "{}", suppress_error: true); $last_global_log_message = $last_global_log_line === false ? null : ($last_global_log_line["message"] ?? null);
    if ($last_global_log_message == $log_message) { return; }

    \NeoRename\NeoGlobal\global_log_with_module_name("neo-log", $log_message, log_source: "neo-log--plugin-changes");
});
