WP-Memory-Usage - Version 1.2.3

Version Description

  • Plugin ok with PHP 7.2 and WordPress 5.8.2 (fixed some issues)
Download this release

Release Info

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

Version 1.2.3

Files changed (4) hide show
  1. readme.txt +32 -0
  2. screenshot-1.jpg +0 -0
  3. screenshot-2.jpg +0 -0
  4. wp-memory-usage.php +125 -0
readme.txt ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
11
+ Show up the PHP version, memory limit and current memory usage in the dashboard and admin footer
12
+
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
+
20
+ Copyright 2009-2013 by Alex Rabe, 2022- Bernhard Kux
21
+
22
+ == Screenshots ==
23
+
24
+ 1. Screenshot Dashboard
25
+
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
+
32
+
screenshot-1.jpg ADDED
Binary file
screenshot-2.jpg ADDED
Binary file
wp-memory-usage.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
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 */
30
+ if ( !function_exists( 'add_action' ) ) {
31
+ echo 'Hello, this is a plugin: You must not call me directly.';
32
+ exit;
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
70
+ $this->memory['color'] = '';
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>
97
+ </div>
98
+ <?php endif; ?>
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
+ }