Plugin Directory

Changeset 1198492


Ignore:
Timestamp:
07/14/2015 04:39:37 AM (10 years ago)
Author:
pento
Message:

Added recommended PHP and MySQL versions, check for utf8mb4 support, fixed a bunch of PHP warnings

Location:
health-check/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • health-check/trunk/health-check.php

    r405385 r1198492  
    33    Plugin Name: Health Check
    44    Plugin URI: http://wordpress.org/extend/plugins/health-check/
    5     Description: Checks the health of your WordPress install
     5    Description: Checks the health of your WordPress install.
    66    Author: The WordPress.org community
    77    Version: 0.3-alpha
    88    Author URI: http://wordpress.org/extend/plugins/health-check/
    99 */
    10 define('HEALTH_CHECK_PHP_VERSION', '5.2.4');
    11 define('HEALTH_CHECK_MYSQL_VERSION', '5.0');
     10define( 'HEALTH_CHECK_PHP_MIN_VERSION', '5.2.4' );
     11define( 'HEALTH_CHECK_PHP_REC_VERSION', '5.6' );
     12define( 'HEALTH_CHECK_MYSQL_MIN_VERSION', '5.0' );
     13define( 'HEALTH_CHECK_MYSQL_REC_VERSION', '5.5' );
    1214
    1315class HealthCheck {
    1416
    15     function action_plugins_loaded() {
    16         if ( get_transient( 'health-check-version-test' ) )
    17             add_action('admin_notices', array('HealthCheck', 'action_admin_notice'));
    18        
     17    static function action_plugins_loaded() {
    1918        add_action( 'admin_menu', array( 'HealthCheck', 'action_admin_menu' ) );
     19        add_filter( 'plugin_row_meta', array( 'HealthCheck', 'settings_link' ), 10, 2 );
    2020    }
    2121
    22     function action_activate() {
    23         set_transient( 'health-check-version-test', '1', 300 );
     22    static function action_admin_menu() {
     23        add_dashboard_page( __( 'Heath Check', 'health-check' ), __( 'Heath Check', 'health-check' ), 'manage_options', 'health-check', array( 'HealthCheck', 'dashboard_page' ) );
    2424    }
    2525
    26     function action_admin_notice() {
    27         echo HealthCheck::get_message();
    28         delete_transient( 'health-check-version-test' );
     26    static function settings_link( $meta, $name ) {
     27        if ( plugin_basename( __FILE__ ) === $name ) {
     28            $meta[] = sprintf( '<a href="%s">' . __( 'Health Check', 'health-check' ) . '</a>', menu_page_url( 'health-check', false ) );
     29        }
     30
     31        return $meta;
    2932    }
    3033
    31     function action_admin_menu() {
    32         add_dashboard_page( __( 'Heath Check', 'health-check' ), __( 'Heath Check', 'health-check' ), 'manage_options', 'health-check', array( 'HealthCheck', 'dashboard_page' ) );
    33     }
    34    
    35     function dashboard_page() {
     34    static function dashboard_page() {
    3635        ?>
    3736        <div class="wrap"><?php screen_icon(); ?>
     
    4241    }
    4342
    44     function get_message() {
     43    static function get_message() {
    4544        global $wpdb;
    46         $php_version_check = version_compare(HEALTH_CHECK_PHP_VERSION, PHP_VERSION, '<=');
    47         $mysql_version_check = version_compare(HEALTH_CHECK_MYSQL_VERSION, $wpdb->db_version(), '<=');
     45
     46        $all_pass = true;
     47
     48        $php_min_version_check = version_compare( HEALTH_CHECK_PHP_MIN_VERSION, PHP_VERSION, '<=' );
     49        $php_rec_version_check = version_compare( HEALTH_CHECK_PHP_REC_VERSION, PHP_VERSION, '<=' );
     50
     51        $mysql_min_version_check = version_compare( HEALTH_CHECK_MYSQL_MIN_VERSION, $wpdb->db_version(), '<=' );
     52        $mysql_rec_version_check = version_compare( HEALTH_CHECK_MYSQL_REC_VERSION, $wpdb->db_version(), '<=' );
     53
    4854        $json_check = HealthCheck::json_check();
    4955        $db_dropin = file_exists( WP_CONTENT_DIR . '/db.php' );
    50         $message ='';
    51        
    52         if ( !$php_version_check )
    53             $message .= "<p><strong>".__('Warning:', 'health-check')."</strong> ".sprintf(__('Your server is running PHP version %1$s. WordPress 3.2 will require PHP version %2$s.', 'health-check'), PHP_VERSION, HEALTH_CHECK_PHP_VERSION)."</p>";
    54         if ( !$mysql_version_check ) {
    55             $message .= "<p><strong>".__('Warning:', 'health-check')."</strong> ".sprintf(__('Your server is running MySQL version %1$s. WordPress 3.2 will require MySQL version %2$s', 'health-check'), $wpdb->db_version(), HEALTH_CHECK_MYSQL_VERSION)."</p>";
    56            
    57             if ( $db_dropin )
    58                 $message .= "<p><strong>".__('Note:', 'health-check')."</strong> ".__('You are using a <code>wp-content/db.php</code> drop-in which may not being using a MySQL database.', 'health-check')."</p>";
     56
     57        $message = '<p>' . sprintf( __( 'Your server is running PHP version <strong>%1$s</strong> and MySQL version <strong>%2$s</strong>.', 'health-check' ), PHP_VERSION, $wpdb->db_version() ) . '</p>';
     58        $success = '';
     59        $warning = '';
     60        $error = '';
     61
     62        if ( ! $php_min_version_check ) {
     63            $error .= "<p><strong>" . __( 'Error:', 'health-check' ) . "</strong> " . sprintf( __( 'WordPress 3.2+ requires PHP version %s.', 'health-check' ), HEALTH_CHECK_PHP_MIN_VERSION ) . "</p>";
     64            $all_pass = false;
     65        }
     66
     67        if ( ! $mysql_min_version_check ) {
     68            $error .= "<p><strong>" . __( 'Error:', 'health-check' ) . "</strong> " . sprintf( __( 'WordPress 3.2+ requires MySQL version %s', 'health-check' ), HEALTH_CHECK_MYSQL_MIN_VERSION ) . "</p>";
     69            $all_pass = false;
     70
     71            if ( $db_dropin ) {
     72                $error .= "<p><strong>" . __( 'Note:', 'health-check' ) . "</strong> " . __( 'You are using a <code>wp-content/db.php</code> drop-in which may not being using a MySQL database.', 'health-check' ) . "</p>";
     73            }
    5974        }
    6075
    6176        if ( ! $json_check ) {
    62             $message .= "<p><strong>".__('Note:', 'health-check')."</strong> ".__('The PHP install on your server has the JSON extension disabled and is therefore not compatible with WordPress 3.2.', 'health-check')."</p>";
     77            $error .= "<p><strong>".__('Note:', 'health-check')."</strong> ".__('The PHP install on your server has the JSON extension disabled and is therefore not compatible with WordPress 3.2.', 'health-check')."</p>";
     78            $all_pass = false;
    6379        }
    6480
    65         if ( $php_version_check && $mysql_version_check && $json_check) {
    66             $message .= "<p><strong>".__('Excellent:', 'health-check')."</strong> ".sprintf(__('Your server is running PHP version %1$s and MySQL version %2$s which will be great for WordPress 3.2 onward.', 'health-check'), PHP_VERSION, $wpdb->db_version())."</p>";
    67             $message = "<div id='health-check-warning' class='updated'>" . $message . "</div>";
     81        if ( version_compare( $wpdb->db_version(), '5.5.3', '<' ) ) {
     82            $warning .= "<p><strong>" . __( 'Error:', 'health-check' ) . "</strong> " . sprintf( __( "WordPress' utf8mb4 support requires MySQL version %s", 'health-check' ), $wpdb->db_version(), '5.5.3' ) . "</p>";
     83            $all_pass = false;
     84        }
     85
     86        if ( $wpdb->use_mysqli ) {
     87            $mysql_client_version = mysqli_get_client_info();
    6888        } else {
    69             $message .= "<p>". sprintf( __('Once your host has upgraded your server you can visit <a href=%s>Dashboard > Health Check</a> to check your compatibility again.', 'health-check' ), menu_page_url( 'health-check', false ) ) ."</p>";
    70             $message = "<div id='health-check-warning' class='error'>" . $message . "</div>";
     89            $mysql_client_version = mysql_get_client_info();
    7190        }
    72        
     91
     92        /*
     93         * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server.
     94         * mysqlnd has supported utf8mb4 since 5.0.9.
     95         */
     96        if ( false !== strpos( $mysql_client_version, 'mysqlnd' ) ) {
     97            $mysql_client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $mysql_client_version );
     98            if ( version_compare( $mysql_client_version, '5.0.9', '<' ) ) {
     99                $warning .= "<p><strong>" . __( 'Warning:', 'health-check' ) . "</strong> " . sprintf( __( 'WordPress\' utf8mb4 support requires MySQL client library (%1$s) version %2$s.', 'health-check' ), 'mysqlnd', '5.0.9' ) . "</p>";
     100                $all_pass = false;
     101            }
     102        } else {
     103            if ( version_compare( $mysql_client_version, '5.5.3', '<' ) ) {
     104                $warning .= "<p><strong>" . __( 'Warning:', 'health-check' ) . "</strong> " . sprintf( __( 'WordPress\' utf8mb4 support requires MySQL client library (%1$s) version %2$s.', 'health-check' ), 'libmysql', '5.5.3' ) . "</p>";
     105                $all_pass = false;
     106            }
     107        }
     108
     109        if ( ! $php_rec_version_check ) {
     110            $warning .= "<p><strong>" . __( 'Warning:', 'health-check' ) . "</strong> " . sprintf( __( 'For performance and security reasons, we strongly recommend running PHP version %s or higher.', 'health-check' ), HEALTH_CHECK_PHP_REC_VERSION ) . "</p>";
     111            $all_pass = false;
     112        }
     113
     114        if ( ! $mysql_rec_version_check ) {
     115            $error .= "<p><strong>" . __( 'Error:', 'health-check' ) . "</strong> " . sprintf( __( 'For performance and security reasons, we strongly recommend running MySQL version %s or higher.', 'health-check' ), HEALTH_CHECK_MYSQL_REC_VERSION ) . "</p>";
     116            $all_pass = false;
     117
     118            if ( $db_dropin ) {
     119                $error .= "<p><strong>" . __( 'Note:', 'health-check' ) . "</strong> " . __( 'You are using a <code>wp-content/db.php</code> drop-in which may not being using a MySQL database.', 'health-check' ) . "</p>";
     120            }
     121        }
     122
     123        if ( $all_pass ) {
     124            $success = "<p><strong>" . __( 'Excellent:', 'health-check' ) . "</strong> " . __( 'Everything is up to date!', 'health-check' ) . "</p>";
     125        }
     126
     127        if ( $error ) {
     128            $message .= "<div id='health-check-warning' class='notice notice-error'>" . $error . "</div>";
     129        }
     130
     131        if ( $warning ) {
     132            $message .= "<div id='health-check-warning' class='notice notice-warning'>" . $warning . "</div>";
     133        }
     134
     135        if ( $success ) {
     136            $message .= "<div id='health-check-warning' class='notice notice-success'>" . $success . "</div>";
     137        }
     138
     139        if ( $error || $warning ) {
     140            $message .= "<p>". sprintf( __('Once your host has upgraded your server you can visit <a href="%s">Dashboard > Health Check</a> to check your compatibility again.', 'health-check' ), menu_page_url( 'health-check', false ) ) ."</p>";
     141        }
    73142
    74143        return $message;
    75144    }
    76    
    77     function json_check() {
     145
     146    static function json_check() {
    78147        $extension_loaded = extension_loaded( 'json' );
    79148        $functions_exist = function_exists( 'json_encode' ) && function_exists( 'json_decode' );
     
    85154/* Initialize ourselves */
    86155add_action('plugins_loaded', array('HealthCheck','action_plugins_loaded'));
    87 register_activation_hook( __FILE__, array( 'HealthCheck', 'action_activate' ) );
    88156?>
  • health-check/trunk/readme.txt

    r405386 r1198492  
    11=== Health Check ===
    22Tags: health check
    3 Contributors: westi
     3Contributors: westi, pento
    44Requires at least: 2.9.2
    5 Tested up to: 3.2
     5Tested up to: 4.3
    66Stable tag: 0.2.1
    77
     
    23231. Upload to your plugins folder, usually `wp-content/plugins/`
    24242. Activate the plugin on the plugin screen.
    25 3. See if your server is prepared for WordPress 3.2
     253. See if your server is prepared for WordPress
    2626
    2727== Screenshots ==
     
    3030
    3131== Changelog ==
     32
     33= v 0.3 =
     34* Added recommended PHP and MySQL versions
     35* Check for utf8mb4 support
     36* Fixed a bunch of PHP warnings
    3237
    3338= v 0.2.1 =
Note: See TracChangeset for help on using the changeset viewer.