More concise documentation for wp_install_maybe_enable_pretty_permalinks()

See #6481. Props ericlewis.


git-svn-id: https://develop.svn.wordpress.org/trunk@31160 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2015-01-12 04:32:35 +00:00
parent 0aaa2f0f32
commit 32b020bf05

View File

@ -263,11 +263,9 @@ As a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to d
endif; endif;
/** /**
* Enable pretty permalinks if available. * Enable pretty permalinks.
* *
* This function will enable pretty permalinks if it can verify they work. * If after enabling pretty permalinks don't work, fallback to query-string permalinks.
* If all pretty permalinks formats fail to work, WordPress will fall back
* to ugly permalinks by setting an empty permalink structure.
* *
* @since 4.2.0 * @since 4.2.0
* *
@ -276,16 +274,18 @@ endif;
function wp_install_maybe_enable_pretty_permalinks() { function wp_install_maybe_enable_pretty_permalinks() {
global $wp_rewrite; global $wp_rewrite;
// Bail if we alredy have permalinks enabled (Multisite) // Bail if a permalink structure is already enabled.
if ( get_option( 'permalink_structure' ) ) { if ( get_option( 'permalink_structure' ) ) {
return; return;
} }
/* /*
* The Permalink structures which WordPress should attempt to use. * The Permalink structures to attempt.
*
* The first is designed for mod_rewrite or nginx rewriting. * The first is designed for mod_rewrite or nginx rewriting.
* The second is PATHINFO based permalinks offered under configurations *
* without rewrites enabled. * The second is PATHINFO-based permalinks for web server configurations
* without a true rewrite module enabled.
*/ */
$permalink_structures = array( $permalink_structures = array(
'/%year%/%monthnum%/%day%/%postname%/', '/%year%/%monthnum%/%day%/%postname%/',
@ -293,7 +293,6 @@ function wp_install_maybe_enable_pretty_permalinks() {
); );
foreach ( (array) $permalink_structures as $permalink_structure ) { foreach ( (array) $permalink_structures as $permalink_structure ) {
// Set the desired Permalink structure to try
$wp_rewrite->set_permalink_structure( $permalink_structure ); $wp_rewrite->set_permalink_structure( $permalink_structure );
/* /*
@ -302,15 +301,18 @@ function wp_install_maybe_enable_pretty_permalinks() {
*/ */
$wp_rewrite->flush_rules( true ); $wp_rewrite->flush_rules( true );
// Test against a real WordPress Post, or if none were created, a Page URI // Test against a real WordPress Post, or if none were created, a random 404 page.
$test_url = get_permalink( 1 ); $test_url = get_permalink( 1 );
if ( ! $test_url ) { if ( ! $test_url ) {
$test_url = home_url( '/wordpress-check-for-rewrites/' ); $test_url = home_url( '/wordpress-check-for-rewrites/' );
} }
/* /*
* Send a HEAD request to a random page on the site, and check whether * Send a request to the site, and check whether
* the 'x-pingback' header is returned as expected. * the 'x-pingback' header is returned as expected.
*
* Uses wp_remote_get() instead of wp_remote_head() because web servers
* can block head requests.
*/ */
$response = wp_remote_get( $test_url, array( 'timeout' => 5 ) ); $response = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
$x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' ); $x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' );
@ -322,8 +324,8 @@ function wp_install_maybe_enable_pretty_permalinks() {
} }
/* /*
* If it makes it this far, Pretty Permalinks failed to activate. * If it makes it this far, pretty permalinks failed.
* Reset and allow the user to select it themselves. * Fallback to query-string permalinks.
*/ */
$wp_rewrite->set_permalink_structure( '' ); $wp_rewrite->set_permalink_structure( '' );
$wp_rewrite->flush_rules( true ); $wp_rewrite->flush_rules( true );