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