Make WordPress Core

Ticket #6481: 6481.14.diff

File 6481.14.diff, 3.0 KB (added by valendesigns, 10 years ago)
  • src/wp-admin/includes/upgrade.php

    diff --git src/wp-admin/includes/upgrade.php src/wp-admin/includes/upgrade.php
    index b72303a..51f010a 100644
    function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated 
    8787
    8888        wp_install_defaults($user_id);
    8989
     90        wp_install_maybe_pretty_permalinks();
     91
    9092        flush_rewrite_rules();
    9193
    9294        wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.') ) );
    As a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to d 
    260262}
    261263endif;
    262264
     265if ( ! function_exists( 'wp_install_maybe_pretty_permalinks' ) ) :
     266/**
     267 * Enable pretty permalinks if available.
     268 *
     269 * This function will enable pretty permalinks if it can verify they work.
     270 * If all pretty permalinks formats fail to work, WordPress will fall back
     271 * to ugly permalinks by setting an empty permalink structure.
     272 *
     273 * @since 4.2.0
     274 *
     275 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
     276 */
     277function wp_install_maybe_pretty_permalinks() {
     278        global $wp_rewrite;
     279
     280        // Bail if we alredy have permalinks enabled (Multisite)
     281        if ( get_option( 'permalink_structure' ) ) {
     282                return;
     283        }
     284
     285        /*
     286         * The Permalink structures which WordPress should attempt to use.
     287         * The first is designed for mod_rewrite or nginx rewriting.
     288         * The second is PATHINFO based permalinks offered under configurations
     289         * without rewrites enabled.
     290         */
     291        $permalink_structures = array(
     292                '/%year%/%monthnum%/%day%/%postname%/',
     293                '/index.php/%year%/%monthnum%/%day%/%postname%/'
     294        );
     295
     296        foreach ( (array) $permalink_structures as $permalink_structure ) {
     297                // Set the desired Permalink structure to try
     298                $wp_rewrite->set_permalink_structure( $permalink_structure );
     299
     300                /*
     301                 * Flush rules with the hard option to force refresh of the web-server's
     302                 * rewrite config file (e.g. .htaccess or web.config).
     303                 */
     304                $wp_rewrite->flush_rules( true );
     305
     306                // Test against a real WordPress Post, or if none were created, a Page URI
     307                $test_url = get_permalink( 1 );
     308                if ( ! $test_url ) {
     309                        $test_url = home_url( '/wordpress-check-for-rewrites/' );
     310                }
     311
     312                /*
     313                 * Send a HEAD request to a random page on the site, and check whether
     314                 * the 'x-pingback' header is returned as expected.
     315                 */
     316                $response          = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
     317                $x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' );
     318                $pretty_permalinks = $x_pingback_header && $x_pingback_header === get_bloginfo( 'pingback_url' );
     319
     320                if ( $pretty_permalinks ) {
     321                        return true;
     322                }
     323        }
     324
     325        /*
     326         * If it makes it this far, Pretty Permalinks failed to activate.
     327         * Reset and allow the user to select it themselves.
     328         */
     329        $wp_rewrite->set_permalink_structure( '' );
     330        $wp_rewrite->flush_rules( true );
     331}
     332endif;
     333
    263334if ( !function_exists('wp_new_blog_notification') ) :
    264335/**
    265336 * {@internal Missing Short Description}}