WordPress.org

Make WordPress Core

Ticket #5235: 5235.2.patch

File 5235.2.patch, 3.6 KB (added by pishmishy, 10 years ago)

Improved, extendable 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');
    193195?>
  • wp-includes/functions.php

     
    17491749        return $default;
    17501750}
    17511751
     1752function preflight_memorycheck(){
     1753        global $preflight_error;
     1754        $memory_limit = ini_get("memory_limit");
     1755        $memory_limit_bytes = trim($memory_limit);
     1756        $last = strtolower($memory_limit_bytes{strlen($memory_limit_bytes)-1});
     1757        switch($last) {
     1758                case 'g':
     1759                                $memory_limit_bytes *= 1024;
     1760                        case 'm':
     1761                                $memory_limit_bytes *= 1024;
     1762                        case 'k':
     1763                                $memory_limit_bytes *= 1024;
     1764        }
     1765
     1766        if($memory_limit_bytes < 8388608)
     1767                $preflight_error->add("preflight_warning_memory",sprintf(__("PHP Memory limit is %s. You may continue but the minimum recommended size is 8MB."),$memory_limit));
     1768}
     1769
     1770function preflight_phpversion(){
     1771        global $preflight_error;
     1772        //A little trick to remove custom portions of the version string       
     1773        $v = phpversion();
     1774        $v2 = Array();
     1775        foreach(explode('.',$v) as $b){
     1776                if(is_numeric($b))
     1777                        $v2[] = $b;
     1778        }
     1779        $v = implode('.',$v2);
     1780        if (version_compare($v,"4.3","<"))
     1781                $preflight_error->add("preflight_fatal_php",__("You need PHP version 4.3 or higher to run WordPress."));
     1782}
     1783
     1784function preflight_phpmysql(){
     1785        global $preflight_error;
     1786        if ( !extension_loaded('mysql') && !file_exists(ABSPATH . 'wp-content/db.php') )
     1787        $preflight_error->add("preflight_fatal_phpmysql",__('Your PHP installation appears to be missing the MySQL extension which is required by WordPress.'));
     1788}
     1789
    17521790?>
  • 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                        print "$error_messages[$i]<br/>";
     57                        if (preg_match('/fatal/',$error_codes[$i]))
     58                                        $fatal = true;
     59                }
     60                if ($fatal)
     61                        die(__("Errors occured which must be corrected before WordPress can be installed."));
     62                ?></p><?php
     63        }
     64
     65?>
    4466<h1><?php _e('Information needed'); ?></h1>
    4567<p><?php _e("Please provide the following information.  Don't worry, you can always change these settings later."); ?></p>
    4668