From a1a148c0e01d3914c4358a895f5ea2b9c8c526cf Mon Sep 17 00:00:00 2001 From: Gifford Nowland Date: Sat, 17 Oct 2020 02:50:14 -0700 Subject: [PATCH] Update showip to show it in the footer --- src/Module/ShowIp.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/Module/ShowIp.php b/src/Module/ShowIp.php index 9ff04e0..6c4d851 100644 --- a/src/Module/ShowIp.php +++ b/src/Module/ShowIp.php @@ -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 @@ -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 .= '  IP: ' . $_SERVER[$param] . ''; + return $content; } }