From 36c3fa0b141f4f5025a956bc6a8dad800225c0fb Mon Sep 17 00:00:00 2001 From: carpentryplus25 Date: Thu, 26 Feb 2026 15:33:43 -0500 Subject: [PATCH] Added git hash build number to settings general tab --- dapper.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/dapper.php b/dapper.php index 71e1c08..d1466d8 100644 --- a/dapper.php +++ b/dapper.php @@ -46,6 +46,49 @@ function dapper_activation() { } register_activation_hook(__FILE__, 'dapper_activation'); +/** + * Get short Git commit hash (8 chars) as build identifier. + * Safe fallback if .git is missing (e.g. on production deploy). + */ +function dapper_get_git_build() { + static $build = null; + if ($build !== null) return $build; + + $git_dir = DAPPER_PATH . '.git'; + if (!is_dir($git_dir)) { + $build = 'dev-local'; + return $build; + } + + $head_path = $git_dir . '/HEAD'; + if (!file_exists($head_path)) { + $build = 'git-head-missing'; + return $build; + } + + $head_content = trim(file_get_contents($head_path)); + + if (preg_match('#^ref: (refs/heads/.+)$#', $head_content, $matches)) { + $ref_path = $git_dir . '/' . $matches[1]; + if (file_exists($ref_path)) { + $commit = trim(file_get_contents($ref_path)); + $build = substr($commit, 0, 8); + return $build; + } + } + + // Detached HEAD fallback + if (strlen($head_content) >= 40 && preg_match('/^[0-9a-f]{40}$/', $head_content)) { + $build = substr($head_content, 0, 8); + return $build; + } + + $build = 'git-unknown'; + return $build; +} + +define('DAPPER_BUILD', dapper_get_git_build()); + /* // Depreciated in v1.1.1 to be removed in later versions // Checks for an images directory inside the dapper plugin @@ -1245,6 +1288,13 @@ function dapper_settings_page_content() { ?> +
+ Dapper v + • commit + + (local dev – no git detected) + +