WP-Memory-Usage - Version 1.2.4

Version Description

  • Reengineered: Used newer functions to measure memory etc.
  • consider different Wordpress- and PHP-Memorylimits
  • New: German Translation
  • New: Added display of IP-Adress and PHP-max-exec-time
Download this release

Release Info

Developer berkux
Plugin Icon 128x128 WP-Memory-Usage
Version 1.2.4
Comparing to
See all releases

Code changes from version 1.2.3 to 1.2.4

languages/wp-memory-usage_de_DE.mo ADDED
Binary file
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === WP-Memory-Usage ===
2
  Contributors: berkux
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=APWXWK3DF2E22
4
- Tags: memory, admin, php, memory-limit
5
- Requires at least: 3.8
6
  Tested up to: 5.8.2
7
- Stable tag: 1.2.3
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -13,7 +13,7 @@ Show up the PHP version, memory limit and current memory usage in the dashboard
13
  == Description ==
14
 
15
  Show up the PHP version, memory limit and current memory usage in the dashboard and admin footer. You can now simple measure the requirements of your plugins and language files.
16
- <a href="https://profiles.wordpress.org/alexrabe/">The plugin was transferred from alexrabe to bekux on Jan 2 2022</a>
17
 
18
  == Credits ==
19
 
@@ -26,6 +26,12 @@ Copyright 2009-2013 by Alex Rabe, 2022- Bernhard Kux
26
  1. Screenshot Admin footer
27
 
28
  == Changelog ==
 
 
 
 
 
 
29
  = 1.2.3 =
30
  * Plugin ok with PHP 7.2 and WordPress 5.8.2 (fixed some issues)
31
 
1
  === WP-Memory-Usage ===
2
  Contributors: berkux
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=APWXWK3DF2E22
4
+ Tags: memory, admin, php, memory-limit, ip, ips, adress, php, server, info
5
+ Requires at least: 5.3
6
  Tested up to: 5.8.2
7
+ Stable tag: 1.2.4
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
13
  == Description ==
14
 
15
  Show up the PHP version, memory limit and current memory usage in the dashboard and admin footer. You can now simple measure the requirements of your plugins and language files.
16
+ <a href="https://profiles.wordpress.org/alexrabe/">The plugin was transferred from alexrabe to berkux on Jan 2 2022</a>
17
 
18
  == Credits ==
19
 
26
  1. Screenshot Admin footer
27
 
28
  == Changelog ==
29
+ = 1.2.4 =
30
+ * Reengineered: Used newer functions to measure memory etc.
31
+ * consider different Wordpress- and PHP-Memorylimits
32
+ * New: German Translation
33
+ * New: Added display of IP-Adress and PHP-max-exec-time
34
+
35
  = 1.2.3 =
36
  * Plugin ok with PHP 7.2 and WordPress 5.8.2 (fixed some issues)
37
 
screenshot-1.jpg CHANGED
Binary file
screenshot-2.jpg CHANGED
Binary file
wp-memory-usage.php CHANGED
@@ -2,28 +2,16 @@
2
  /*
3
  Plugin Name: WP-Memory-Usage
4
  Plugin URI: https://www.json-content-importer.com
5
- Description: Show up the memory limit and current memory usage in the dashboard and admin footer
6
  Author: Bernhard Kux
7
- Version: 1.2.3
8
-
9
  Author URI: https://www.json-content-importer.com
 
 
 
 
10
 
11
  Copyright 2009-2013 by Alex Rabe, 2022- by Bernhard Kux
12
-
13
- This program is free software; you can redistribute it and/or modify
14
- it under the terms of the GNU General Public License as published by
15
- the Free Software Foundation; either version 2 of the License, or
16
- (at your option) any later version.
17
-
18
- This program is distributed in the hope that it will be useful,
19
- but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- GNU General Public License for more details.
22
-
23
- You should have received a copy of the GNU General Public License
24
- along with this program; if not, write to the Free Software
25
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
-
27
  */
28
 
29
  /* block direct requests */
@@ -33,37 +21,62 @@ if ( !function_exists( 'add_action' ) ) {
33
  }
34
  defined('ABSPATH') OR exit;
35
 
36
- define( 'WPMEMORYUSAGEVERSION', '1.2.3' ); // current version number
37
-
38
-
39
  if ( is_admin() ) {
 
 
40
 
 
 
 
 
 
 
 
 
41
  class wp_memory_usage {
 
 
 
42
 
43
- var $memory = false;
44
-
45
- function wp_memory_usage() {
46
  return $this->__construct();
47
  }
48
 
49
- function __construct() {
 
50
  add_action( 'init', array (&$this, 'check_limit') );
51
  add_action( 'wp_dashboard_setup', array (&$this, 'add_dashboard') );
52
  add_filter( 'admin_footer_text', array (&$this, 'add_footer') );
53
-
54
- $this->memory = array();
55
  }
56
 
57
- function check_limit() {
58
- $this->memory['limit'] = (int) ini_get('memory_limit') ;
 
 
 
 
 
 
 
 
 
 
 
59
  }
60
 
61
- function check_memory_usage() {
62
-
63
- $this->memory['usage'] = function_exists('memory_get_usage') ? round(memory_get_usage() / 1024 / 1024, 2) : 0;
64
-
65
- if ( !empty($this->memory['usage']) && !empty($this->memory['limit']) ) {
66
- $this->memory['percent'] = round ($this->memory['usage'] / $this->memory['limit'] * 100, 0);
 
 
 
 
 
 
 
67
  //If the bar is tp small we move the text outside
68
  $this->memory['percent_pos'] = '';
69
  //In case we are in our limits take the admin color
@@ -71,26 +84,48 @@ if ( is_admin() ) {
71
  if ($this->memory['percent'] > 80) $this->memory['color'] = 'background: #E66F00;';
72
  if ($this->memory['percent'] > 95) $this->memory['color'] = 'background: red;';
73
  if ($this->memory['percent'] < 10) $this->memory['percent_pos'] = 'margin-right: -30px; color: #444;';
 
 
 
 
74
  }
75
  }
76
 
77
- function dashboard_output() {
78
-
79
  $this->check_memory_usage();
80
-
81
- $this->memory['limit'] = empty($this->memory['limit']) ? __('N/A') : $this->memory['limit'] . __(' MB');
82
- $this->memory['usage'] = empty($this->memory['usage']) ? __('N/A') : $this->memory['usage'] . __(' MB');
83
-
84
  ?>
85
  <ul>
86
- <li><strong><?php _e('PHP Version'); ?></strong> : <span><?php echo PHP_VERSION; ?>&nbsp;/&nbsp;<?php echo (PHP_INT_SIZE * 8) . __('Bit OS'); ?></span></li>
87
- <li><strong><?php _e('Memory limit'); ?></strong> : <span><?php echo $this->memory['limit']; ?></span></li>
88
- <li><strong><?php _e('Memory usage'); ?></strong> : <span><?php echo $this->memory['usage']; ?></span></li>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  </ul>
90
  <?php if (!empty($this->memory['percent'])) : ?>
91
  <div class="progressbar">
92
  <div style="border:1px solid #DDDDDD; background-color:#F9F9F9; border-color: rgb(223, 223, 223); box-shadow: 0px 1px 0px rgb(255, 255, 255) inset; border-radius: 3px;">
93
- <div class="button-primary" style="width: <?php echo $this->memory['percent']; ?>%;<?php echo $this->memory['color'];?>padding: 0px;border-width:0px; color:#FFFFFF;text-align:right; border-color: rgb(223, 223, 223); box-shadow: 0px 1px 0px rgb(255, 255, 255) inset; border-radius: 3px; margin-top: -1px;">
94
  <div style="padding:2px;<?php echo $this->memory['percent_pos']; ?>"><?php echo $this->memory['percent']; ?>%</div>
95
  </div>
96
  </div>
@@ -99,27 +134,49 @@ if ( is_admin() ) {
99
  <?php
100
  }
101
 
102
- function add_dashboard() {
103
- wp_add_dashboard_widget( 'wp_memory_dashboard', 'Memory Overview', array (&$this, 'dashboard_output') );
104
  }
105
 
106
- function add_footer($content) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
 
 
 
 
 
 
108
  $this->check_memory_usage();
109
-
110
- $content .= ' | Memory : ' . $this->memory['usage'] . ' of ' . $this->memory['limit'];
111
-
 
112
  return $content;
113
  }
114
 
115
  }
116
 
117
  // Start this plugin once all other plugins are fully loaded
118
- #add_action( 'plugins_loaded', create_function('', '$memory = new wp_memory_usage();') );#
119
-
120
- function action_plugins_loaded( $array ) {
121
- $memory = new wp_memory_usage();
122
- return $memory;
123
  };
124
- add_action( 'plugins_loaded', 'action_plugins_loaded', 10, 1 );
125
  }
2
  /*
3
  Plugin Name: WP-Memory-Usage
4
  Plugin URI: https://www.json-content-importer.com
5
+ Description: Show up memory limits, current memory usage, IP-Address, PHP-Version in the dashboard and admin footer
6
  Author: Bernhard Kux
7
+ Version: 1.2.4
 
8
  Author URI: https://www.json-content-importer.com
9
+ Text Domain: wp-memory-usage
10
+ Domain Path: /languages/
11
+ License: GPLv3
12
+ License URI: http://www.gnu.org/licenses/gpl-3.0.html
13
 
14
  Copyright 2009-2013 by Alex Rabe, 2022- by Bernhard Kux
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  */
16
 
17
  /* block direct requests */
21
  }
22
  defined('ABSPATH') OR exit;
23
 
 
 
 
24
  if ( is_admin() ) {
25
+
26
+ define( 'WPMEMORYUSAGEVERSION', '1.2.4' ); // current version number
27
 
28
+ function wp_memory_usage_i18n_init() {
29
+ $pd = dirname(
30
+ plugin_basename(__FILE__)
31
+ ).'/languages/';
32
+ load_plugin_textdomain('wp_memory_usage', false, $pd);
33
+ }
34
+ add_action('plugins_loaded', 'wp_memory_usage_i18n_init');
35
+
36
  class wp_memory_usage {
37
+ private $ipadr = "";
38
+ private $servername = "";
39
+ private $memory = array();
40
 
41
+ public function wp_memory_usage() {
 
 
42
  return $this->__construct();
43
  }
44
 
45
+ public function __construct() {
46
+ $this->get_ip_adress();
47
  add_action( 'init', array (&$this, 'check_limit') );
48
  add_action( 'wp_dashboard_setup', array (&$this, 'add_dashboard') );
49
  add_filter( 'admin_footer_text', array (&$this, 'add_footer') );
 
 
50
  }
51
 
52
+ public function check_limit() {
53
+ $this->memory['phplimit'] = "";
54
+ $this->memory['phplimitunity'] = 'MB';
55
+ if (!is_null(ini_get('memory_limit'))) {
56
+ $this->memory['phplimit'] = (int) ini_get('memory_limit');
57
+ }
58
+ $ret = $this->formatWP_MEMORY_LIMIT(WP_MEMORY_LIMIT);
59
+ $this->memory["wpmb"] = $ret["mb"];
60
+ $this->memory["wpunity"] = $ret["unity"];
61
+
62
+ $ret = $this->formatWP_MEMORY_LIMIT(WP_MAX_MEMORY_LIMIT);
63
+ $this->memory["wpmaxmb"] = $ret["mb"];
64
+ $this->memory["wpmaxunity"] = $ret["unity"];
65
  }
66
 
67
+ private function check_memory_usage() {
68
+ $this->memory['usage'] = function_exists('memory_get_peak_usage') ? round(memory_get_peak_usage(true) / 1024 / 1024, 2) : 0;
69
+ if ( !empty($this->memory['usage'])) {
70
+ $this->memory['percent'] = -1;
71
+ if (!empty($this->memory['wpmb']) && ($this->memory['wpmb']!=0)) {
72
+ $this->memory['percent'] = round($this->memory['usage'] /$this->memory["wpmb"] * 100, 0);
73
+ }
74
+
75
+ $this->memory['percentphp'] = -1;
76
+ if (!empty($this->memory['phplimit']) && ($this->memory['phplimit']!=0)) {
77
+ $this->memory['percentphp'] = round ($this->memory['usage'] / $this->memory["phplimit"] * 100, 0);
78
+ }
79
+
80
  //If the bar is tp small we move the text outside
81
  $this->memory['percent_pos'] = '';
82
  //In case we are in our limits take the admin color
84
  if ($this->memory['percent'] > 80) $this->memory['color'] = 'background: #E66F00;';
85
  if ($this->memory['percent'] > 95) $this->memory['color'] = 'background: red;';
86
  if ($this->memory['percent'] < 10) $this->memory['percent_pos'] = 'margin-right: -30px; color: #444;';
87
+ $this->memory['percentwidth'] = $this->memory['percent'];
88
+ if ($this->memory['percent']>100) {
89
+ $this->memory['percentwidth'] = 100;
90
+ }
91
  }
92
  }
93
 
94
+ public function dashboard_output() {
 
95
  $this->check_memory_usage();
 
 
 
 
96
  ?>
97
  <ul>
98
+ <li><strong><?php echo __('PHP Version', 'wp_memory_usage'); ?>:</strong> <span><?php
99
+ echo PHP_VERSION; ?>&nbsp;/&nbsp;<?php echo (PHP_INT_SIZE * 8) . __('Bit OS', 'wp_memory_usage');
100
+
101
+ if (!is_null(ini_get('max_execution_time'))) {
102
+ $max_execution_time = (int) ini_get('max_execution_time'). __('sec', 'wp_memory_usage');
103
+ echo " / ".__('Max execution time: ', 'wp_memory_usage').$max_execution_time;
104
+ }
105
+
106
+
107
+ ?></span></li>
108
+ <li><strong><?php echo __('Memory limits', 'wp_memory_usage'); ?></strong> : <span>
109
+ <?php
110
+ if ($this->memory["wpmb"]!="") {
111
+ echo __('Wordpress', 'wp_memory_usage').' '.$this->memory["wpmb"]. $this->memory["wpunity"]." / ";
112
+ }
113
+ #if ($this->memory["wpmaxmb"]!="") {
114
+ # echo __('Wordpress-Admin', 'wp_memory_usage').' '.$this->memory["wpmaxmb"]. $this->memory["wpmaxunity"]." / ";
115
+ #}
116
+ if ($this->memory['phplimit']!="") {
117
+ echo __('PHP ', 'wp_memory_usage').' '.$this->memory['phplimit'].$this->memory['phplimitunity'];
118
+ }
119
+ ?>
120
+ </span></li>
121
+ <li><strong><?php echo __('Memory usage', 'wp_memory_usage'); ?></strong> : <span><?php echo $this->memory['usage']."MB"; ?>
122
+ <!--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?PHP #echo "<strong>".__( 'IP-Address', 'wp_memory_usage') . " " . $this->servername. ':</strong> '.$this->ipadr; ?>-->
123
+ </span></li>
124
  </ul>
125
  <?php if (!empty($this->memory['percent'])) : ?>
126
  <div class="progressbar">
127
  <div style="border:1px solid #DDDDDD; background-color:#F9F9F9; border-color: rgb(223, 223, 223); box-shadow: 0px 1px 0px rgb(255, 255, 255) inset; border-radius: 3px;">
128
+ <div class="button-primary" style="width: <?php echo $this->memory['percentwidth']; ?>%;<?php echo $this->memory['color'];?>padding: 0px;border-width:0px; color:#FFFFFF;text-align:right; border-color: rgb(223, 223, 223); box-shadow: 0px 1px 0px rgb(255, 255, 255) inset; border-radius: 3px; margin-top: -1px;">
129
  <div style="padding:2px;<?php echo $this->memory['percent_pos']; ?>"><?php echo $this->memory['percent']; ?>%</div>
130
  </div>
131
  </div>
134
  <?php
135
  }
136
 
137
+ public function add_dashboard() {
138
+ wp_add_dashboard_widget( 'wp_memory_dashboard', __('Memory Overview', 'wp_memory_usage'), array (&$this, 'dashboard_output') );
139
  }
140
 
141
+ private function formatWP_MEMORY_LIMIT($valin) { #WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT come with size and unity
142
+ $size = strtolower(substr($valin, -1));
143
+ $number = (int) substr($valin, 0, -1);
144
+ $ret = Array();
145
+ if ($size=="k") { $ret["mb"] = ($number/1024); $ret["unity"] = "kB"; }
146
+ if ($size=="m") { $ret["mb"] = $number; $ret["unity"] = "MB"; }
147
+ if ($size=="g") { $ret["mb"] = ($number*1024); $ret["unity"] = "GB"; }
148
+ if ($size=="t") { $ret["mb"] = ($number*(1024*1024)); $ret["unity"] = "TB"; }
149
+ if ($size=="p") { $ret["mb"] = ($number*(1024*1024*1024)); $ret["unity"] = "PB"; }
150
+ return $ret;
151
+ }
152
+
153
+ private function get_ip_adress() {
154
+ if (isset($_SERVER[ 'SERVER_ADDR' ]) && !empty($_SERVER[ 'SERVER_ADDR' ])) {
155
+ $this->ipadr = $_SERVER[ 'SERVER_ADDR' ];
156
+ }
157
+ if (empty($this->ipadr) && isset($_SERVER[ 'LOCAL_ADDR' ]) && !empty($_SERVER[ 'LOCAL_ADDR' ])) {
158
+ $this->ipadr = $_SERVER[ 'LOCAL_ADDR' ];
159
+ }
160
 
161
+ if (!empty($_SERVER['SERVER_NAME'])) {
162
+ $this->servername = " (".$_SERVER['SERVER_NAME'].")";
163
+ }
164
+ }
165
+
166
+ public function add_footer($content) {
167
  $this->check_memory_usage();
168
+ $content .= ' | '. __( 'WP Memory Limit:', 'wp_memory_usage'). ' ' . $this->memory['usage'] . ' ' . __( 'of', 'wp_memory_usage') . ' ' . $this->memory["wpmb"].$this->memory["wpunity"]. " (".$this->memory['percent']."%)";
169
+ $content .= ' | '. __( 'PHP Memory Limit:', 'wp_memory_usage'). ' ' . $this->memory['usage'] . ' ' . __( 'of', 'wp_memory_usage') . ' ' . $this->memory['phplimit'].$this->memory['phplimitunity']. " (".$this->memory['percentphp']."%)";
170
+ $content .= ' | '. __( 'IP-Address', 'wp_memory_usage') . " " . $this->servername. ': '.$this->ipadr;
171
+ $content .= ' | '. __( 'PHP', 'wp_memory_usage') . ": " . PHP_VERSION;
172
  return $content;
173
  }
174
 
175
  }
176
 
177
  // Start this plugin once all other plugins are fully loaded
178
+ function WP_Memory_Usage_action_plugins_loaded( $array ) {
179
+ return new wp_memory_usage();
 
 
 
180
  };
181
+ add_action( 'plugins_loaded', 'WP_Memory_Usage_action_plugins_loaded', 10, 1 );
182
  }