WordPress.org

Make WordPress Core

Ticket #5235: 5235.patch

File 5235.patch, 5.6 KB (added by pishmishy, 6 years ago)

Final draft of pre-flight checks

  • wp-includes/default-filters.php

     
    189189add_action('template_redirect', 'wp_old_slug_redirect'); 
    190190add_action('edit_post', 'wp_check_for_changed_slugs'); 
    191191add_action('edit_form_advanced', 'wp_remember_old_slug'); 
    192  
     192// Preflight checks 
     193add_action('wp_preflightchecks','preflight_memorycheck'); 
     194add_action('wp_preflightchecks','preflight_phpversion'); 
     195add_action('wp_preflightchecks','preflight_phpmysql'); 
     196add_action('wp_preflightchecks','preflight_mysqlversion'); 
    193197?> 
  • wp-includes/functions.php

     
    17491749        return $default; 
    17501750} 
    17511751 
     1752/** 
     1753 * function preflight_memorycheck() 
     1754 * Check that the recommended minimum memory limit is exceeded. Warn if not. 
     1755 * @since 2.6 
     1756 * @global $preflight_error WP_Error object for storing cumulative preflight errors 
     1757 */ 
     1758function preflight_memorycheck(){ 
     1759        global $preflight_error; 
     1760        $memory_limit = ini_get("memory_limit"); 
     1761        $memory_limit_bytes = trim($memory_limit); 
     1762        $last = strtolower($memory_limit_bytes{strlen($memory_limit_bytes)-1}); 
     1763        //Change the value from the ini file into bytes 
     1764        switch($last) { 
     1765                case 'g': 
     1766                                $memory_limit_bytes *= 1024; 
     1767                        case 'm': 
     1768                                $memory_limit_bytes *= 1024; 
     1769                        case 'k': 
     1770                                $memory_limit_bytes *= 1024; 
     1771        } 
     1772        if($memory_limit_bytes < 8388608) 
     1773                $preflight_error->add("preflight_warning_memory",sprintf(__("PHP Memory limit is %s. You may continue but the minimum recommended size is 8MB."),$memory_limit)); 
     1774} 
     1775 
     1776/** 
     1777 * function preflight_phpversion() 
     1778 * Check that the required version of PHP in installed.  
     1779 * @since 2.6 
     1780 * @global $preflight_error WP_Error object for storing cumulative preflight errors 
     1781 */ 
     1782function preflight_phpversion(){ 
     1783        global $preflight_error; 
     1784        //A little trick to remove custom portions of the version string         
     1785        $v = phpversion(); 
     1786        $v2 = Array(); 
     1787        foreach(explode('.',$v) as $b){ 
     1788                if(is_numeric($b)) 
     1789                        $v2[] = $b; 
     1790        } 
     1791        $v = implode('.',$v2); 
     1792        if (version_compare($v,"4.3","<")) 
     1793                $preflight_error->add("preflight_fatal_php",__("You need PHP version 4.3 or higher to run WordPress.")); 
     1794} 
     1795 
     1796/** 
     1797 * function preflight_phpmysql() 
     1798 * Check that if MySQL is being used, that the PHP MySQL extention is installed 
     1799 * @since 2.6 
     1800 * @global $preflight_error WP_Error object for storing cumulative preflight errors 
     1801 */ 
     1802function preflight_phpmysql(){ 
     1803        global $preflight_error; 
     1804        if ( !extension_loaded('mysql') && !file_exists(ABSPATH . 'wp-content/db.php') ) 
     1805        $preflight_error->add("preflight_fatal_phpmysql",__('Your PHP installation appears to be missing the MySQL extension which is required by WordPress.')); 
     1806} 
     1807 
     1808/** 
     1809 * function preflight_mysqlversion() 
     1810 * Check that the required version of MySQL is installed (at least for the client) 
     1811 * @since 2.6 
     1812 * @global $preflight_error WP_Error object for storing cumulative preflight errors 
     1813 */ 
     1814function preflight_mysqlversion(){ 
     1815        global $preflight_error; 
     1816        if (version_compare(mysql_get_client_info(),"4.0","<")) 
     1817                $preflight_error->add("preflight_fatal_mysql",__('You need MySQL 4.0 or higher to run WordPress.')); 
     1818} 
     1819 
    17521820?> 
  • wp-admin/css/install.css

     
    121121 
    122122#error-page code { 
    123123        font-size: 1em; 
    124 } 
    125  No newline at end of file 
     124} 
     125 
     126.error  { 
     127        background-color: #ffebe8; 
     128        border-color: #c00; 
     129        margin: 0; 
     130        margin-left: 15px; 
     131        margin-right: 15px; 
     132        padding: 0; 
     133        max-width: 980px; 
     134} 
  • wp-admin/install.php

     
    4040<h1><?php _e('Welcome'); ?></h1> 
    4141<p><?php printf(__('Welcome to the famous five minute WordPress installation process! You may want to browse the <a href="%s">ReadMe documentation</a> at your leisure.  Otherwise, just fill in the information below and you\'ll be on your way to using the most extendable and powerful personal publishing platform in the world.'), '../readme.html'); ?></p> 
    4242<!--<h2 class="step"><a href="install.php?step=1"><?php _e('First Step'); ?></a></h2>--> 
     43<?php 
    4344 
     45        // Perform pre-flight checks. New checks can be added through the wp_preflightchecks hook.  
     46        // See wp-includes/default-filters.php 
     47 
     48        global $preflight_error; 
     49        $preflight_error = new WP_Error(); 
     50        do_action("wp_preflightchecks"); 
     51        if ( !empty($preflight_error->errors) ){ 
     52                ?><h1> <?php _e("Pre-flight checks"); ?> </h1><p><?php 
     53                $error_codes = $preflight_error->get_error_codes(); 
     54                $error_messages = $preflight_error->get_error_messages(); 
     55                for($i=0;$i<count($error_messages);$i++){ 
     56                        ?><div id="message" class="error"><p><strong><?php 
     57                        print "$error_messages[$i]"; 
     58                        ?></strong></p></div><?php 
     59                        if (preg_match('/fatal/',$error_codes[$i])) 
     60                                        $fatal = true; 
     61                } 
     62                if ($fatal) 
     63                        die(__('<p>At least one requirement for the installation of WordPress has not been met. This must be corrected before you proceed. Further information on the <a href="http://wordpress.org/about/requirements/">requirements of WordPress</a> is available.</p>')); 
     64                ?></p><?php 
     65        } 
     66 
     67?> 
    4468<h1><?php _e('Information needed'); ?></h1> 
    4569<p><?php _e("Please provide the following information.  Don't worry, you can always change these settings later."); ?></p> 
    4670