I am using login_footer hook to display some info below the login form.

I need to display there info from the last commit of my plugin.

Hook definition:

$this->loader->add_action( 'login_footer', $plugin_admin, 'e4afz_login_footer' );


public function e4afz_login_footer() {
    global $E4AFZ_PLUGIN_ROOT_DIR;
        #e4afz-login-footer-container {
            text-align: center;
            margin-top: 10px;
    <div id="e4afz-login-footer-container">
        <p>&copy <?php echo date( 'Y' ); ?> , Platform Version: <?php echo $this->version; ?></p>
            echo shell_exec( "git log --git-dir ='" . $E4AFZ_PLUGIN_ROOT_DIR . ".git" . 
                             "' -1 --pretty=format:'%h - %s (%ci)' --abbrev-commit --work-tree ='" . $E4AFZ_PLUGIN_ROOT_DIR );

The global variable is defined as follows on the main plugin file:

$E4AFZ_PLUGIN_ROOT_DIR = plugin_dir_path( __FILE__ );

I am getting NULL result from the shell_exec.



Also tried to get what i need form my main plugin file:

$E4AFZ_LAST_COMMIT     = shell_exec( "git log -1 --git-dir=" . ABSPATH . "/wp-content/plugins/e4afz-wp/.git" . " --work-tree=" . ABSPATH . "/wp-content/plugins/e4afz-wp/ 2>&1" );

I am getting a "fatal: Not a git repository (or any of the parent directories): .git" as a result

  • Is PHP running in safe mode on your server? If so, shell_exec() is disabled, per the notes. – Pat J May 6 '16 at 12:29
  • I think no because i am getting a "fatal: Not a git repository (or any of the parent directories): .git" – e4rthdog May 6 '16 at 12:41
  • 1
    When I run that git command, I have to put the --git-dir and --work-tree flags before the log -1[…] part. (Probably just an antiquated version.) Are you able to run the same command on the command line and get something valid? – Pat J May 6 '16 at 13:51
  • 2
    What about using git (post-*) hooks instead, e.g. to generate some custom info to a file that WP can read? Maybe even possible to use a script that uses e.g. wp-cli to write that info to the WP database. – birgire May 6 '16 at 14:21
  • @PatJ You should really make your comment an answer to accept it. It sems that putting log -1 at the end, does the job!!! – e4rthdog May 7 '16 at 5:16

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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.