PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.1.17
Adminify – White Label, Admin Menu Editor, Login Customizer v4.1.17
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.1.17, at Inc/Classes/AdminFooterText.php

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