Make WordPress Core

Ticket #9751: 9751.patch

File 9751.patch, 4.9 KB (added by hakre, 16 years ago)
  • wp-admin/includes/upgrade.php

     
    7575        $wp_rewrite->flush_rules();
    7676
    7777        wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password);
    78 
     78        wp_check_php_version();
    7979        wp_cache_flush();
    8080
    8181        return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password, 'password_message' => $message);
     
    268268                return;
    269269
    270270        wp_check_mysql_version();
     271        wp_check_php_version();
    271272        wp_cache_flush();
    272273        make_db_current_silent();
    273274        upgrade_all();
     
    16381639}
    16391640
    16401641/**
     1642 * Check minimum PHP Version
     1643 * 
     1644 * Checks if the current version of PHP is below the nag level and adds usermeta to use to display a notice if it is
     1645 *
     1646 * @since  unknown (at least after 2.8.4)
     1647 * @see    php_below_min_nag() - the nag message display
     1648 * @see    php_below_min_nag_handler() - stops display of the nag message
     1649 * @see    http://core.trac.wordpress.org/ticket/9751
     1650 * @param  string $min_version (optional) minimum version string of version to check for
     1651 * @param  string $version (optional) version string of the version to check against
     1652 * @return void
     1653 */
     1654function wp_check_php_version($min_version = '5.0.0', $version = PHP_VERSION) {
     1655        /* @var $wpdb wpdb */
     1656        global $wpdb;   
     1657        if ( version_compare($version, $min_version, '<') ) {
     1658                $users = $wpdb->get_results(sprintf('SELECT ID from %s', $wpdb->users));
     1659                if ( is_null($users) )
     1660                        die('Failed to query (1) database for users in wp_check_php_version()');                 
     1661                foreach ( (array) $users as $user ) {
     1662                        $user = new WP_User($user->ID);
     1663                        if ( $user->has_cap('install_plugins') )
     1664                                update_usermeta($user->ID, 'php_below_min_nag', 'true');
     1665                                }
     1666        } else {
     1667                $user  = wp_get_current_user();
     1668                $value = get_usermeta($user->ID, 'php_below_min_nag');
     1669                if ('' != $value) {
     1670                        $users = $wpdb->get_results(sprintf('SELECT ID from %s', $wpdb->users));
     1671                        if ( is_null($users) )
     1672                                die('Failed to query (2) database for users in wp_check_php_version()');                 
     1673                        foreach ( (array) $users as $user ) {
     1674                                $user = new WP_User($user->ID);
     1675                                if ( $user->has_cap('install_plugins') )
     1676                                        delete_usermeta($user->ID, 'php_below_min_nag');
     1677                        }
     1678                }
     1679        }
     1680}
     1681
     1682/**
    16411683 * {@internal Missing Short Description}}
    16421684 *
    16431685 * {@internal Missing Long Description}}
  • wp-admin/includes/user.php

     
    403403        return $wpdb->get_results( $query );
    404404}
    405405
     406add_action('admin_notices', 'php_below_min_nag');
    406407/**
     408 * Nag-Message to inform about minimum php version requirements
     409 *
     410 * If the phpversion is below the min, echo html of a nag until it goes away
     411 *
     412 * @since    unknown (at least after 2.8.4)
     413 * @see      wp_check_php_version() - the function that adds the nag on install
     414 * @see      php_below_min_nag_handler() -  the function that removes display of nag message
     415 * @wpfilter admin_notices
     416 * @param    string $version (optional) current php version, default is current php version
     417 * @param    string $moreurl (optional) link-href for more information
     418 * @return   void
     419 */
     420function php_below_min_nag($version = PHP_VERSION, $moreurl = 'http://codex.wordpress.org/Switching_to_PHP5') {
     421        global $user_ID;
     422        if ( ! get_usermeta($user_ID, 'php_below_min_nag') )
     423                return;
     424
     425        echo '<div class="error php_below_min_nag"><p>';
     426        printf(
     427                __('Notice: Your Webserver is currently using PHP version %1$s, which is no longer recieving security updates and will no longer be supported by WordPress in an upcoming version<br /><a href="%2$s">Learn more about this issue</a> | <a href="%3$s" id="php_below_min_nag-no">I understand the issue and want you to stop informing me</a>')
     428                , $moreurl
     429                , '?php_below_min_nag=0'
     430                , $version
     431        );
     432        echo '</p></div>';
     433}
     434
     435add_action('admin_init', 'php_below_min_nag_handler');
     436/**
     437 * Handle minimum php version requirements
     438 *
     439 * Checks if the current version of PHP is below the nag level and adds usermeta to use to display a notice if it is
     440 *
     441 * @since    unknown (at least after 2.8.4)
     442 * @see      php_below_min_nag() - the nag message displayed
     443 * @see      wp_check_php_version() - the function that adds the nag on install/upgrade
     444 * @wpfilter admin_init
     445 * @return   void
     446 */
     447function php_below_min_nag_handler() {
     448        global $user_ID;
     449        if ( ! get_usermeta($user_ID, 'php_below_min_nag') ) //Short circuit it.
     450                return;
     451
     452        if  (isset($_GET['php_below_min_nag']) && '0' == $_GET['php_below_min_nag'])
     453                delete_usermeta($user_ID, 'php_below_min_nag', 'true');
     454}
     455
     456/**
    407457 * Remove user and optionally reassign posts and links to another user.
    408458 *
    409459 * If the $reassign parameter is not assigned to an User ID, then all posts will