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