| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Classes; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Utils; |
| 6 |
use WPAdminify\Inc\Classes\ServerInfo; |
| 7 |
use WPAdminify\Inc\Admin\AdminSettings; |
| 8 |
use WPAdminify\Inc\Admin\AdminSettingsModel; |
| 9 |
|
| 10 |
|
| 11 |
// no direct access allowed |
| 12 |
if (!defined('ABSPATH')) exit; |
| 13 |
|
| 14 |
/** |
| 15 |
* @package WP Adminify |
| 16 |
* @author: Jewel Theme<support@jeweltheme.com> |
| 17 |
*/ |
| 18 |
|
| 19 |
class AdminFooterText extends AdminSettingsModel |
| 20 |
{ |
| 21 |
public $server_info; |
| 22 |
|
| 23 |
public function __construct() |
| 24 |
{ |
| 25 |
$this->options = (array) AdminSettings::get_instance()->get(); |
| 26 |
|
| 27 |
$restrict_for = !empty($this->options['admin_footer_user_roles']) ? $this->options['admin_footer_user_roles'] : ''; |
| 28 |
if ($restrict_for) { |
| 29 |
add_filter('admin_footer_text', [$this, 'jltwp_adminify_change_admin_footer_text']); |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
add_action('admin_menu', [$this, 'jltwp_adminify_footer_version_remove']); |
| 35 |
add_action('network_admin_menu', [$this, 'jltwp_adminify_footer_version_remove']); |
| 36 |
|
| 37 |
$this->adminify_footer_text_init(); |
| 38 |
|
| 39 |
$this->server_info = new ServerInfo(); |
| 40 |
} |
| 41 |
|
| 42 |
public function jltwp_adminify_footer_version_remove() |
| 43 |
{ |
| 44 |
remove_filter('update_footer', 'core_update_footer'); |
| 45 |
} |
| 46 |
|
| 47 |
public function adminify_footer_text_init() |
| 48 |
{ |
| 49 |
/** Admin Footer Credits Text **/ |
| 50 |
add_filter('update_footer', [$this, 'jltwp_adminify_change_admin_footer'], 10, 3); |
| 51 |
|
| 52 |
// Footer Right Info |
| 53 |
add_filter('admin_footer_text', [$this, 'jltwp_adminify_change_admin_footer_text']); |
| 54 |
} |
| 55 |
|
| 56 |
/** Footer Credits */ |
| 57 |
public function jltwp_adminify_footer_credits() |
| 58 |
{ ?> |
| 59 |
<div class="wp-adminify adminify-first-child"> |
| 60 |
<div class="wp-adminify--copyright"> |
| 61 |
<?php |
| 62 |
echo sprintf( |
| 63 |
__('Developed by <a href="%s" target="_blank" title="WP Adminify by Jewel Theme" target="_blank">WP Adminify</a> <br> |
| 64 |
Powered by <a target="_blank" href="%s">WordPress</a>', WP_ADMINIFY_TD), |
| 65 |
esc_url('https://wpadminify.com/'), |
| 66 |
esc_url('https://wordpress.org/') |
| 67 |
); |
| 68 |
?> |
| 69 |
</div> |
| 70 |
</div> |
| 71 |
<?php |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
public function jltwp_adminify_change_admin_footer_text() |
| 76 |
{ |
| 77 |
$this->options = (array) AdminSettings::get_instance()->get(); |
| 78 |
if (!empty($this->options['footer_text'])) { |
| 79 |
echo $this->options['footer_text']; |
| 80 |
return; |
| 81 |
} |
| 82 |
// Change the content of the left admin footer text. |
| 83 |
apply_filters('jltwp_adminify_footer_credits', $this->jltwp_adminify_footer_credits()); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
/** |
| 88 |
* IP Address |
| 89 |
*/ |
| 90 |
public function adminify_ip_address() |
| 91 |
{ |
| 92 |
if (!empty($this->options['admin_footer_ip_address'])) { |
| 93 |
?> |
| 94 |
<div class="column has-text-right"> |
| 95 |
<?php if (is_rtl()) { |
| 96 |
echo sprintf( |
| 97 |
'<span class="info-details">%2$s</span><span class="info-id is-uppercase">%1$s</span>', |
| 98 |
esc_html__('IP: ', WP_ADMINIFY_TD), |
| 99 |
$this->server_info->get_ip_address() |
| 100 |
); |
| 101 |
} else { |
| 102 |
echo sprintf( |
| 103 |
'<span class="info-id is-uppercase">%1$s</span><span class="info-details">%2$s</span>', |
| 104 |
esc_html__('IP: ', WP_ADMINIFY_TD), |
| 105 |
$this->server_info->get_ip_address() |
| 106 |
); |
| 107 |
} ?> |
| 108 |
</div> |
| 109 |
<?php |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
/** |
| 115 |
* PHP Version |
| 116 |
*/ |
| 117 |
public function adminify_php_version() |
| 118 |
{ |
| 119 |
if (!empty($this->options['admin_footer_php_version'])) { |
| 120 |
?> |
| 121 |
<div class="column has-text-right"> |
| 122 |
<?php if (is_rtl()) { |
| 123 |
echo sprintf( |
| 124 |
'<span class="info-details">%2$s</span><span class="info-id">%1$s</span>', |
| 125 |
esc_html__('PHP: ', WP_ADMINIFY_TD), |
| 126 |
$this->server_info->get_php_version_lite() |
| 127 |
); |
| 128 |
} else { |
| 129 |
echo sprintf( |
| 130 |
'<span class="info-id">%1$s</span><span class="info-details">%2$s</span>', |
| 131 |
esc_html__('PHP: ', WP_ADMINIFY_TD), |
| 132 |
$this->server_info->get_php_version_lite() |
| 133 |
); |
| 134 |
} ?> |
| 135 |
</div> |
| 136 |
<?php |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* WordPress Version |
| 142 |
*/ |
| 143 |
public function adminify_wp_version() |
| 144 |
{ |
| 145 |
if (!empty($this->options['admin_footer_wp_version'])) { |
| 146 |
?> |
| 147 |
<div class="column has-text-right"> |
| 148 |
<?php if (is_rtl()) { |
| 149 |
echo sprintf( |
| 150 |
'<span class="info-details">%2$s</span><span class="info-id">%1$s</span>', |
| 151 |
esc_html__('WordPress: v', WP_ADMINIFY_TD), |
| 152 |
$this->server_info->get_wp_version() |
| 153 |
); |
| 154 |
} else { |
| 155 |
echo sprintf( |
| 156 |
'<span class="info-id">%1$s</span><span class="info-details">%2$s</span>', |
| 157 |
esc_html__('WordPress: v', WP_ADMINIFY_TD), |
| 158 |
$this->server_info->get_wp_version() |
| 159 |
); |
| 160 |
} ?> |
| 161 |
</div> |
| 162 |
<?php |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* Memory Usage |
| 168 |
*/ |
| 169 |
public function adminify_memory_usage() |
| 170 |
{ |
| 171 |
if (!empty($this->options['admin_footer_memory_usage'])) { |
| 172 |
$memory_usage = $this->server_info->get_wp_memory_usage(); |
| 173 |
$memory_limit = $memory_usage['MemLimitFormat']; |
| 174 |
$memory_usage_format = $memory_usage['MemUsageFormat']; |
| 175 |
// $memory_usage_percentage = $memory_usage['MemUsageCalc']; |
| 176 |
$memory_usage_percentage = ServerInfo::wp_memory_usage_percentage(); |
| 177 |
|
| 178 |
if ($memory_usage_percentage <= 65) { |
| 179 |
$memory_status = '#00BA88'; |
| 180 |
} elseif ($memory_usage_percentage > 65 && $memory_usage_percentage < 85) { |
| 181 |
$memory_status = '#ffe08a'; |
| 182 |
} elseif ($memory_usage_percentage > 85) { |
| 183 |
$memory_status = '#f14668'; |
| 184 |
} |
| 185 |
?> |
| 186 |
<div class="column has-text-right"> |
| 187 |
|
| 188 |
<?php if (is_rtl()) { |
| 189 |
echo sprintf( |
| 190 |
__('<span class="info-details">%2$s of %3$s <span class="percentage tag has-text-white is-rounded" style="background:%4$s">%5$s</span></span><span class="info-id">%1$s</span>', WP_ADMINIFY_TD), |
| 191 |
|
| 192 |
esc_html__('WP Memory Usage: ', WP_ADMINIFY_TD), |
| 193 |
$memory_usage_format, |
| 194 |
$memory_limit, |
| 195 |
esc_html($memory_status), |
| 196 |
$memory_usage_percentage . '%' |
| 197 |
); |
| 198 |
} else { |
| 199 |
echo sprintf( |
| 200 |
__('<span class="info-id">%1$s</span><span class="info-details">%2$s of %3$s <span class="percentage tag has-text-white is-rounded" style="background:%4$s">%5$s</span></span>', WP_ADMINIFY_TD), |
| 201 |
esc_html__('WP Memory Usage: ', WP_ADMINIFY_TD), |
| 202 |
$memory_usage_format, |
| 203 |
$memory_limit, |
| 204 |
esc_html($memory_status), |
| 205 |
$memory_usage_percentage . '%' |
| 206 |
); |
| 207 |
} ?> |
| 208 |
</span> |
| 209 |
</div> |
| 210 |
<?php |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
/** |
| 215 |
* Memory Limit |
| 216 |
*/ |
| 217 |
public function adminify_memory_limit() |
| 218 |
{ |
| 219 |
if (!empty($this->options['admin_footer_memory_limit'])) { |
| 220 |
$memory_limit = $this->server_info->get_wp_memory_usage(); |
| 221 |
$memory_limit = $memory_limit['MemLimitFormat']; |
| 222 |
?> |
| 223 |
<div class="column has-text-right"> |
| 224 |
<?php if (is_rtl()) { |
| 225 |
echo sprintf( |
| 226 |
'<span class="info-details">%2$s</span><span class="info-id">%1$s</span>', |
| 227 |
esc_html__('WP Memory Limit: ', WP_ADMINIFY_TD), |
| 228 |
$memory_limit |
| 229 |
); |
| 230 |
} else { |
| 231 |
echo sprintf( |
| 232 |
'<span class="info-id">%1$s</span><span class="info-details">%2$s</span>', |
| 233 |
esc_html__('WP Memory Limit: ', WP_ADMINIFY_TD), |
| 234 |
$memory_limit |
| 235 |
); |
| 236 |
} ?> |
| 237 |
</div> |
| 238 |
<?php |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
/** |
| 244 |
* Memory Limit |
| 245 |
*/ |
| 246 |
public function adminify_memory_available() |
| 247 |
{ |
| 248 |
if (!empty($this->options['admin_footer_memory_available'])) { |
| 249 |
$memory_available = $this->server_info->get_wp_memory_usage(); |
| 250 |
$memory_available = $memory_available['MemLimitGet']; |
| 251 |
?> |
| 252 |
<div class="column has-text-right"> |
| 253 |
<?php if (is_rtl()) { |
| 254 |
echo sprintf( |
| 255 |
'<span class="info-details is-uppercase">%2$s</span><span class="info-id">%1$s</span>', |
| 256 |
esc_html__('WP Memory Available: ', WP_ADMINIFY_TD), |
| 257 |
$memory_available |
| 258 |
); |
| 259 |
} else { |
| 260 |
echo sprintf( |
| 261 |
'<span class="info-id">%1$s</span><span class="info-details is-uppercase">%2$s</span>', |
| 262 |
esc_html__('WP Memory Available: ', WP_ADMINIFY_TD), |
| 263 |
$memory_available |
| 264 |
); |
| 265 |
} ?> |
| 266 |
</div> |
| 267 |
<?php |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
/** Admin Footer Text **/ |
| 272 |
public function jltwp_adminify_change_admin_footer($footer_text) |
| 273 |
{ |
| 274 |
if ( |
| 275 |
!empty($this->options['admin_footer_memory_usage']) || |
| 276 |
!empty($this->options['admin_footer_memory_limit']) || |
| 277 |
!empty($this->options['admin_footer_memory_available']) || |
| 278 |
!empty($this->options['admin_footer_ip_address']) || |
| 279 |
!empty($this->options['admin_footer_php_version']) || |
| 280 |
!empty($this->options['admin_footer_wp_version']) |
| 281 |
) { |
| 282 |
?> |
| 283 |
<div class="wp-adminify adminify-last-child"> |
| 284 |
|
| 285 |
<div class="system-info has-text-right"> |
| 286 |
<div class="info-line-1"> |
| 287 |
|
| 288 |
<?php |
| 289 |
$this->adminify_ip_address(); |
| 290 |
$this->adminify_php_version(); |
| 291 |
$this->adminify_wp_version(); |
| 292 |
?> |
| 293 |
</div> |
| 294 |
|
| 295 |
<div class="info-line-2"> |
| 296 |
<?php |
| 297 |
$this->adminify_memory_usage(); |
| 298 |
$this->adminify_memory_limit(); |
| 299 |
$this->adminify_memory_available(); |
| 300 |
?> |
| 301 |
|
| 302 |
</div> |
| 303 |
</div> |
| 304 |
|
| 305 |
</div> |
| 306 |
<?php |
| 307 |
return $footer_text; |
| 308 |
} |
| 309 |
|
| 310 |
// Nothing, return blank |
| 311 |
return ''; |
| 312 |
} |
| 313 |
} |
| 314 |
|