[wp-trac] [WordPress Trac] #6481: Fancy permalinks should be enabled on new sites
WordPress Trac
noreply at wordpress.org
Mon Feb 10 13:19:20 UTC 2014
#6481: Fancy permalinks should be enabled on new sites
-------------------------------+-----------------------------
Reporter: Denis-de-Bernardy | Owner:
Type: enhancement | Status: new
Priority: low | Milestone: Future Release
Component: Permalinks | Version: 2.7
Severity: minor | Resolution:
Keywords: needs-patch | Focuses:
-------------------------------+-----------------------------
Comment (by Denis-de-Bernardy):
Replying to [comment:24 ryan]:
> Maybe do a head request on get_permalink(1) and make sure it doesn't
404?
That wouldn't work if a plugin flushes the content. That would yield no
post, and a whole bunch of candidate test URIs return a 404 when they
really should return a 200 with no content.
I did eventually locate a test uri that doesn't seem to fail when no posts
are around, though. This from my plugin:
{{{
/**
* Enables permalinks on new installs
*
* References:
*
* - https://core.trac.wordpress.org/ticket/6481
**/
protected function setPermalinkStructure()
{
# Bail if a permalink structure is already set
if (get_option('permalink_structure')) return;
# Bail unless we're running on top of Apache
# FIXME: look into making it work with nginx and iis
global $is_apache;
if (!isset($is_apache) || !$is_apache || !got_mod_rewrite())
return;
# Bail if we fail to fetch the admin user
$admin = isset($_POST['user_name']) ? get_user_by('login',
$_POST['user_name']) : false;
if (!$admin || is_wp_error($admin)) return;
# Try to set permalink structure
global $wp_rewrite;
$wp_rewrite->set_permalink_structure(DEFAULT_PERMALINK_STRUCTURE);
flush_rewrite_rules();
# Rollback if permalinks aren't working
$test_url = get_author_posts_url($admin->ID,
$admin->user_nicename);
$response = wp_remote_head($test_url, array('timeout' => 5,
'httpversion' => '1.1'));
if (is_wp_error($response) || 200 !=
wp_remote_retrieve_response_code($response)) {
$wp_rewrite->set_permalink_structure('');
flush_rewrite_rules();
}
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/6481#comment:41>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list