Added git hash build number to settings general tab
This commit is contained in:
50
dapper.php
50
dapper.php
@@ -46,6 +46,49 @@ function dapper_activation() {
|
|||||||
}
|
}
|
||||||
register_activation_hook(__FILE__, '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
|
// Depreciated in v1.1.1 to be removed in later versions
|
||||||
// Checks for an images directory inside the dapper plugin
|
// Checks for an images directory inside the dapper plugin
|
||||||
@@ -1245,6 +1288,13 @@ function dapper_settings_page_content() {
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
<div style="margin-top:40px; padding:12px; background:#1a1a1a; color:#00ff41; font-family:monospace; font-size:13px; border-radius:4px; text-align:center; border:1px solid #333;">
|
||||||
|
<strong>Dapper v<?php echo esc_html(defined('DAPPER_VERSION') ? DAPPER_VERSION : 'unknown'); ?></strong>
|
||||||
|
• commit <code><?php echo esc_html(DAPPER_BUILD); ?></code>
|
||||||
|
<?php if (DAPPER_BUILD === 'dev-local'): ?>
|
||||||
|
<small>(local dev – no git detected)</small>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div id="email-settings">
|
<div id="email-settings">
|
||||||
|
|||||||
Reference in New Issue
Block a user