Last active
October 14, 2023 02:49
-
-
Save Zodiac1978/155b8efbc1cea12520c5 to your computer and use it in GitHub Desktop.
Show PHP version and if PHP is running in 32-bit or 64-bit mode in At-a-glance dashboard widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Show PHP Version | |
Description: Shows the current PHP version in the "At a Glance" admin dashboard widget. | |
Version: 1.1 | |
Requires at least: 3.8 | |
Author: Torsten Landsiedel | |
Author URI: http://torstenlandsiedel.de | |
*/ | |
/** | |
* Add locations to the new "At a glance" dashboard widget (WP 3.8+). | |
* | |
* @param array $items | |
* @return array | |
*/ | |
function add_to_glance( Array $items ) { | |
$php_version = phpversion(); | |
$bit_mode = (PHP_INT_SIZE * 8); | |
if ( version_compare( $php_version, '5.5', '<' ) ) { | |
$color = 'red'; | |
} | |
elseif ( version_compare( $php_version, '5.5', '=' ) || $bit_mode == 32 ) { | |
$color = 'orange'; | |
} | |
else { | |
$color = 'green'; | |
} | |
$items[] = sprintf( | |
'<a class="showphpversion %s" href="%s">%s %s (%s-bit)</a>', | |
$color, | |
esc_html__( 'http://php.net/supported-versions.php', 'tl-show-php-version' ), | |
esc_html__( 'PHP version:', 'tl-show-php-version' ), | |
$php_version, | |
$bit_mode | |
); | |
return $items; | |
} | |
add_filter( 'dashboard_glance_items', 'add_to_glance' ); | |
function add_to_glance_styles() { | |
echo '<style> | |
#dashboard_right_now .showphpversion.green:before { | |
color: green; | |
content:"\f147"; /* Dashicon YES */ | |
} | |
#dashboard_right_now .showphpversion.red:before { | |
color: red; | |
content: "\f158"; /* Dashicon NO */ | |
} | |
#dashboard_right_now .showphpversion.orange:before { | |
color: orange; | |
content: "\f534"; /* Dashicon WARNING */ | |
} | |
</style>'; | |
} | |
add_action('admin_head', 'add_to_glance_styles'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment