Add latest commit info on login footer using login_footer hook

On the command line, I tried to run git log --git-dir="[dir].git' -1 --work-tree="[dir]" and it gave me an error. When I ran git --git-dir="[dir].git" --work-tree="[dir]" log -1, it worked as expected.

So your code should probably be

 echo shell_exec( 
   "git --git-dir="$E4AFZ_PLUGIN_ROOT_DIR.git" 
    --pretty=format:'%h - %s (%ci)' --abbrev-commit 
    --work-tree="$E4AFZ_PLUGIN_ROOT_DIR"
    log -1 
);

Also: PHP expands variables inside double quotes, so because your string is wrapped in ", you don’t need to break the $E4AFZ_PLUGIN_ROOT_DIR variable out of the quotes. IMHO, this makes the code easier to read.

References

  • git — has the git-dir, --work-tree, etc. flags
  • git log