PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.2.20
Adminify – White Label, Admin Menu Editor, Login Customizer v4.2.20
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Classes / AdminFooterText.php

AdminFooterText.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.2.20, at Inc/Classes/AdminFooterText.php

400 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PXLBSAdminify\Inc\Classes;
4
5 use PXLBSAdminify\Inc\Classes\ServerInfo;
6 use PXLBSAdminify\Inc\Admin\AdminSettings;
7 use PXLBSAdminify\Inc\Admin\AdminSettingsModel;
8
9
10 // no direct access allowed.
11 if (!defined('ABSPATH')) {
12 exit;
13 }
14
15 /**
16 * Admin footer text
17 *
18 * @package WP Adminify
19 * @author: Jewel Theme<support@jeweltheme.com>
20 */
21 class AdminFooterText extends AdminSettingsModel
22 {
23 /**
24 * Server Info
25 *
26 * @var $server_info
27 */
28 public $server_info;
29
30 /**
31 * Default admin_footer_text value supplied by WordPress core.
32 *
33 * Captured via the admin_footer_text filter at an early priority before
34 * the plugin overrides it, so the standard "Thank you for creating with
35 * WordPress." string can be rendered when the credit option is disabled
36 * without hardcoding a copy of that string in the plugin.
37 *
38 * @var string
39 */
40 protected static $wp_default_footer_text = '';
41
42 /**
43 * Constructor
44 */
45 public function __construct()
46 {
47
48 $this->options = (array) AdminSettings::get_instance()->get();
49 $this->options = !empty($this->options['white_label']['wordpress']['admin_footer']) ? $this->options['white_label']['wordpress']['admin_footer'] : '';
50
51 // Remove Admin Footer Version Number
52 if (!empty($this->options) && in_array('wp_version', $this->options)) {
53 add_action('admin_menu', [$this, 'remove_admin_footer_version']);
54 }
55
56 add_action('admin_menu', [$this, 'footer_version_remove']);
57 add_action('network_admin_menu', [$this, 'footer_version_remove']);
58 /** Admin Footer */
59 add_filter('update_footer', [$this, 'change_admin_footer'], 10, 3);
60
61 // Capture WordPress core's default admin_footer_text before
62 // suppressing it, so we can re-render it when the plugin's
63 // "Show Footer Credit" option is disabled.
64 add_filter('admin_footer_text', [$this, 'capture_wp_default_footer_text'], 1);
65
66 add_filter( 'admin_footer_text', '__return_false', 999 );
67 add_filter( 'update_footer', '__return_false', 999 );
68
69 $this->server_info = new ServerInfo();
70 }
71
72 /**
73 * Capture the default admin footer text WordPress passes into the
74 * admin_footer_text filter, then return it unchanged.
75 *
76 * @param string $text
77 * @return string
78 */
79 public function capture_wp_default_footer_text($text)
80 {
81 if (is_string($text) && $text !== '') {
82 self::$wp_default_footer_text = $text;
83 }
84 return $text;
85 }
86
87
88
89 /**
90 * Remove WordPress version
91 *
92 * @return void
93 */
94 public function remove_admin_footer_version()
95 {
96 // Remove WordPress Version except Admin
97 if (!current_user_can('manage_options')) {
98 remove_filter('update_footer', 'core_update_footer');
99 }
100 }
101
102
103 // function footer_get_options()
104 // {
105 // $objects = isset($this->options) && is_array($this->options) ? $this->options : [];
106 // return $objects;
107 // }
108
109 public function footer_version_remove()
110 {
111 remove_filter('update_footer', 'core_update_footer');
112 }
113
114 /**
115 * Default footer credit markup.
116 *
117 * Single source of truth for the "Developed by / Powered by" string,
118 * used both as the default value of the white-label footer text option
119 * and as the rendered fallback when the option is empty.
120 *
121 * @return string
122 */
123 public static function get_default_footer_credit()
124 {
125 return sprintf(
126 /* translators: 1: WP Adminify website URL, 2: Plugin label, 3: WordPress.org URL */
127 __('<p>Developed by <a href="%1$s" target="_blank" title="Adminify by Jewel Theme">%2$s</a></p> <p>Powered by <a target="_blank" href="%3$s">WordPress</a></p>', 'adminify'),
128 esc_url('https://wpadminify.com/'),
129 AdminSettings::get_pro_label(),
130 esc_url('https://wordpress.org/')
131 );
132 }
133
134 /** Footer Credits */
135 public function footer_credits()
136 { ?>
137 <div class="adminify-copyright">
138 <?php echo wp_kses_post(self::get_default_footer_credit()); ?>
139 </div>
140 <?php
141 }
142
143
144 public function change_admin_footer_text()
145 {
146 $footer_text = (array) AdminSettings::get_instance()->get();
147
148 // Attribution is opt-in only. When the site admin has not enabled
149 // the "Show Footer Credit" option, fall back to the standard
150 // WordPress admin footer text instead of plugin credits.
151 $show_credit = !empty($footer_text['white_label']['wordpress']['show_footer_credit']);
152 if (!$show_credit) {
153 $wp_default = self::$wp_default_footer_text;
154 if ($wp_default === '') {
155 return;
156 }
157 ?>
158 <div class="adminify-footer-left">
159 <?php echo wp_kses_post($wp_default); ?>
160 </div>
161 <?php
162 return;
163 }
164
165 if (!empty($footer_text['white_label']['wordpress']['footer_text'])) { ?>
166 <div class="adminify-footer-left">
167 <?php echo wp_kses_post($footer_text['white_label']['wordpress']['footer_text']); ?>
168 </div>
169 <?php
170 return;
171 }
172
173 // Change the content of the left admin footer text.
174 apply_filters('pxlbsadminify_footer_credits', $this->footer_credits());
175 }
176
177
178
179 /**
180 * IP Address
181 */
182 public function ip_address() { ?>
183 <div class="adminify-system-info">
184 <?php
185 if (is_rtl()) {
186 echo sprintf(
187 wp_kses_post('<span>%2$s</span><span>%1$s</span>'),
188 esc_html__('IP: ', 'adminify'),
189 esc_html($this->server_info->get_ip_address())
190 );
191 } else {
192 echo sprintf(
193 wp_kses_post('<span>%1$s</span><span>%2$s</span>'),
194 esc_html__('IP: ', 'adminify'),
195 esc_html($this->server_info->get_ip_address())
196 );
197 }
198 ?>
199 </div>
200 <?php
201 }
202
203
204 /**
205 * PHP Version
206 */
207 public function php_version() { ?>
208 <div class="adminify-system-info">
209 <?php
210 if (is_rtl()) {
211 echo sprintf(
212 '<span>%2$s</span><span>%1$s</span>',
213 esc_html__('PHP: ', 'adminify'),
214 esc_html($this->server_info->get_php_version_lite())
215 );
216 } else {
217 echo sprintf(
218 '<span>%1$s</span><span>%2$s</span>',
219 esc_html__('PHP: ', 'adminify'),
220 esc_html($this->server_info->get_php_version_lite())
221 );
222 }
223 ?>
224 </div>
225 <?php
226 }
227
228 /**
229 * WordPress Version
230 */
231 public function default_wp_version() { ?>
232 <div class="adminify-system-info">
233 <?php
234 if (is_rtl()) {
235 echo sprintf(
236 '<span>%2$s</span><span>%1$s</span>',
237 esc_html__('WordPress: v', 'adminify'),
238 esc_html($this->server_info->get_wp_version())
239 );
240 } else {
241 echo sprintf(
242 '<span>%1$s</span><span>%2$s</span>',
243 esc_html__('WordPress: v', 'adminify'),
244 esc_html($this->server_info->get_wp_version())
245 );
246 }
247 ?>
248 </div>
249 <?php
250 }
251
252 /**
253 * Memory Usage
254 */
255 public function memory_usage() {
256 $memory_usage = $this->server_info->get_wp_memory_usage();
257 $memory_limit = $memory_usage['MemLimitFormat'];
258 $memory_usage_format = $memory_usage['MemUsageFormat'];
259 // $memory_usage_percentage = $memory_usage['MemUsageCalc'];
260 $memory_usage_percentage = ServerInfo::memory_usage_percentage();
261
262 if ($memory_usage_percentage <= 65) {
263 $memory_status = '#00BA88';
264 } elseif ($memory_usage_percentage > 65 && $memory_usage_percentage < 85) {
265 $memory_status = '#ffe08a';
266 } elseif ($memory_usage_percentage > 85) {
267 $memory_status = '#f14668';
268 } ?>
269 <div class="adminify-system-info">
270 <?php
271 if (is_rtl()) {
272 echo sprintf(
273 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>'),
274 esc_html__('WP Memory Usage: ', 'adminify'),
275 esc_html($memory_usage_format),
276 esc_html($memory_limit),
277 esc_html($memory_status),
278 esc_html($memory_usage_percentage) . '%'
279 );
280 } else {
281 echo sprintf(
282 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>'),
283 esc_html__('WP Memory Usage: ', 'adminify'),
284 esc_html($memory_usage_format),
285 esc_html($memory_limit),
286 esc_html($memory_status),
287 esc_html($memory_usage_percentage) . '%'
288 );
289 }
290 ?>
291 </span>
292 </div>
293 <?php
294 }
295
296 /**
297 * Memory Limit
298 */
299 public function memory_limit() {
300 $memory_limit = $this->server_info->get_wp_memory_usage();
301
302 $memory_limit = $memory_limit['MemLimitFormat']; ?>
303
304 <div class="adminify-system-info">
305 <?php
306 if (is_rtl()) {
307 echo sprintf(
308 '<span>%2$s</span><span>%1$s</span>',
309 esc_html__('WP Memory Limit: ', 'adminify'),
310 esc_html($memory_limit)
311 );
312 } else {
313 echo sprintf(
314 '<span>%1$s</span><span>%2$s</span>',
315 esc_html__('WP Memory Limit: ', 'adminify'),
316 esc_html($memory_limit)
317 );
318 }
319 ?>
320 </div>
321 <?php
322 }
323
324
325 /**
326 * Memory Limit
327 */
328 public function memory_available() {
329 $memory_available = $this->server_info->get_wp_memory_usage();
330 $memory_available = rtrim($memory_available['MemLimitGet'], 'MB') - rtrim($memory_available['MemUsageFormat'], 'MB'); ?>
331
332 <div class="adminify-system-info">
333 <?php
334 if (is_rtl()) {
335 echo sprintf(
336 '<span>%2$s</span><span>%1$s</span>',
337 esc_html__('WP Memory Available: ', 'adminify'),
338 esc_html($memory_available)
339 );
340 } else {
341 echo sprintf(
342 '<span>%1$s</span><span>%2$s</span>',
343 esc_html__('WP Memory Available: ', 'adminify'),
344 esc_html($memory_available)
345 );
346 }
347 ?>MB
348 </div>
349 <?php
350 }
351
352
353 /** Admin Footer Text **/
354 public function change_admin_footer($footer_text) { ?>
355
356 <div class="adminify--footer">
357 <?php $this->change_admin_footer_text();
358 if ( !empty($this->options) ) { ?>
359
360 <div class="adminify-footer-right">
361 <div class="adminify-system-info-col">
362 <?php
363 if ( in_array('ip_address', $this->options ) ) {
364 $this->ip_address();
365 }
366
367 if ( in_array('php_version', $this->options ) ) {
368 $this->php_version();
369 }
370
371 if ( in_array('wp_version', $this->options ) ) {
372 $this->default_wp_version();
373 }
374 ?>
375 </div>
376 <div class="adminify-system-info-col">
377 <?php
378 if ( in_array('memory_usage', $this->options ) ) {
379 $this->memory_usage();
380 }
381
382 if ( in_array('memory_limit', $this->options ) ) {
383 $this->memory_limit();
384 }
385
386 if ( in_array('memory_available', $this->options ) ) {
387 $this->memory_available();
388 }
389 ?>
390 </div>
391 </div>
392 <?php return $footer_text;
393 } ?>
394 </div>
395 <?php
396 // Nothing, return blank
397 return '';
398 }
399 }
400