Skip to content

Commit

Permalink
Update showip to show it in the footer
Browse files Browse the repository at this point in the history
  • Loading branch information
gnowland committed Oct 17, 2020
1 parent aaf439d commit a1a148c
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/Module/ShowIp.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
*
* Shows the server's IP address in the Admin Toolbar
*
* @example jetfuel('show-ip');
* @example jetfuel('show-ip', $param(string));
* @param string $param A `$_SERVER` key. Some useful ones include: SERVER_ADDR, 'HTTP_X_FORWARDED_FOR'
*
* @link https://developer.wordpress.org/reference/hooks/admin_bar_menu/
* @link https://www.php.net/manual/en/reserved.variables.server.php
*
* @package WordPress
* @subpackage WPJetFuel
Expand All @@ -24,27 +26,19 @@ public function run() {
}

protected function setup() {
$this->setDefaultConfig('false');
$this->setDefaultConfig('SERVER_ADDR');
return $this;
}

protected function hook() {
// Add IP address to the admin toolbar
add_action('admin_bar_menu', [$this, 'add_toolbar_items'], 100);
// Add IP address to the admin footer
add_action( 'update_footer', [$this, 'addIpFooter'], 20 );
}

public function add_toolbar_items($admin_bar){
$ip_addr = $_SERVER['SERVER_ADDR'];

$admin_bar->add_menu( [
'id' => 'ip-addr',
'title' => $ip_addr,
'href' => '#',
'meta' => [
'title' => $ip_addr
]
]);

public function addIpFooter($content){
$param = $this->escArray($this->config);
$content .= '&emsp; IP: <abbr title="' . $param . '">' . $_SERVER[$param] . '</abbr>';
return $content;
}

}

0 comments on commit a1a148c

Please sign in to comment.